Skip to content

Graph upgrade and publication pipeline

Publishing a graph revision means making a particular definition retrievable by your application under its graph code and version. The upgrade pipeline takes a saved definition and a migration plan, constructs a candidate, checks it, and asks your application’s repository to store that exact revision. Your application can then select the published version when loading a graph.

The pipeline coordinates the checks; your repository owns storage and the guarantee that an existing revision cannot be overwritten. Keeping those roles explicit is especially useful when a write may have succeeded but its confirmation was lost.

We will reuse the example from Graph migrations and rollback. The support-request graph starts at node 10 and reaches terminal node 20 through edge 100. Its source version is 1.0.0. The migration changes the initial title from “Contact support” to “Describe your request”, with the equivalent Spanish change. Here we will publish that changed definition as 1.1.0.

The pipeline needs the complete source snapshot, the reviewed migration plan, and a later target graph version. UpgradeExportRequest identifies the graph and both revisions:

use ExecKernel\Domain\Versioning\Pipeline\UpgradeExportRequest;
$request = new UpgradeExportRequest(
graphCode: 'support-request',
graphVersion: '1.0.0',
targetGraphVersion: '1.1.0',
);

The target must be an explicit, later SemVer revision that passes compatibility checks. It is not inferred from the migration identifier. In this example, 1.0.0-mig.001 records the change, while 1.1.0 identifies the definition that the application will retrieve.

The source declares engine_version: "1.0.0" and DSL/schema version 1.0. These declarations select a combination accepted by the embedded compatibility matrix. They are configuration inputs to that policy, not a claim that the installed Composer package is release 1.0.0. Keep your chosen policy consistent with your graph-loading configuration; Version compatibility and session upgrades explains the version contracts.

The snapshot also carries active_nodes and active_edges. They are empty in this isolated example. When they describe an application’s active usage, your application must obtain and supply them accurately before using strict migration validation.

UpgradePipelineRunner runs the following stages in order:

Stage What it establishes
EXPORT Retrieves the source snapshot and checks that its identity and versions agree with the request.
CHECK Checks the source’s declared version compatibility.
MIGRATOR Obtains the migration plan.
VALIDATE Validates and applies the plan, assigns the target graph version, and validates the resulting candidate.
ROLLBACK Builds and verifies a compensating plan bound to that candidate.
DRY_RUN Exercises the candidate under controlled execution inputs.
PUBLISH Stores the candidate and confirms that the same revision can be read back.

The runner materializes the forward change once. Later stages receive that candidate, including the target version and migration ledger. A successful dry run therefore checks the definition that is passed to the publisher.

One source and plan produce the candidate checked before publication; an exact readback confirms it, while a lost or mismatching confirmation requires reconciliation.

If a stage fails before publication begins, the runner does not invoke the publisher. This lets your application reject a change that is incompatible, invalid, cannot be faithfully compensated, or cannot complete the execution check before attempting a repository write.

The example uses SnapshotExportStage for a source array and MigrationPlanStage for the JSON plan. In your application, SnapshotExportStage can instead use a GraphSnapshotProviderInterface to retrieve a source by code and revision. This export contains a graph definition; it is separate from exporting a session’s current state.

The following fragment assumes $source is the decoded source snapshot, $planJson contains the plan, and $repository implements ConfirmedPublishedGraphRepositoryInterface. The complete download includes the imports and an example adapter.

$mode = CompatibilityMode::STRICT;
$check = new CompatibilityCheckStage($mode);
$runner = new UpgradePipelineRunner(
exportStage: new SnapshotExportStage(snapshot: $source),
compatibilityCheckStage: $check,
migratorStage: new MigrationPlanStage(
migrationContents: $planJson,
migrationFormat: 'json',
),
validationStage: new MigrationValidationStage(
$check,
new MigrationValidator(),
$mode,
),
rollbackStage: new RollbackPlanStage(),
dryRunStage: new MigrationDryRunStage(
mode: $mode,
smoke: new EngineRuntimeDryRun(
mode: $mode,
context: new Context([]),
timestamp: 1700000000,
maxSteps: 8,
),
),
publishStage: new PublishStage($repository),
mode: $mode,
);

Passing the same mode to the relevant stages keeps their validation policy consistent. RollbackPlanStage prepares a later migration and the runner verifies that its actions restore the source content while retaining the candidate’s target graph version. The returned plan is bound to the exact candidate snapshot. Preparing this plan does not execute a rollback against your repository.

The built-in EngineRuntimeDryRun starts the candidate with the supplied context and fixed timestamp, then follows the first available edge until it reaches a terminal or the step limit. Our graph needs no context values and reaches node 20 in one transition. If your rules need data, supply a representative context; otherwise an unavailable path can correctly stop publication.

This is a bounded execution check of one path. It does not explore every alternative or contact your application’s external services. It uses built-in rules and discards deferred event batches. An optional RuntimeDryRunInterface integration check can add checks that your application needs, but it does not replace the built-in execution check. Configure such an integration check with controlled dependencies.

Make the repository’s confirmation meaningful

Section titled “Make the repository’s confirmation meaningful”

PublishStage requires ConfirmedPublishedGraphRepositoryInterface. Your adapter provides two operations:

public function publish(
UpgradeGraphExport $export,
?MigrationPlan $plan = null,
): PublishedGraphReference;
public function readPublished(
string $graphCode,
string $graphVersion,
): ?UpgradeGraphExport;

publish() must atomically create a revision only if that code/version does not already exist. Enforce that rule in the actual storage operation, for example with a transaction and a unique key. The stage’s preliminary read is useful for detecting an existing revision, but two publishers could both read “absent”; that read alone does not provide concurrency protection.

Return a PublishedGraphReference containing the stored graph code, graph version, and full snapshot hash. readPublished() must retrieve stored data independently; echoing the input would not prove that the repository retained it.

After writing, PublishStage compares the returned reference and the readback with the candidate. The code, version, full snapshot, and snapshot hash must agree. This checks more than the graph checksum used to identify a runtime projection.

The downloadable PublicationMemoryRepository demonstrates this contract in one synchronous PHP process. Its stored revisions disappear with that instance. Replace it with your application’s persistent adapter when the revision must survive the process, and enforce atomic creation in that adapter’s storage.

Run the pipeline and retrieve the revision by the returned identity:

$result = $runner->run($request);
$published = $result->published;
$stored = $repository->readPublished(
$published->graphCode,
$published->graphVersion,
);

A successful run() returns UpgradePipelineResult: the confirmed publication reference, the compensating plan, and any collected compatibility warnings. In this example, the stored graph is support-request version 1.1.0, and its English title is “Describe your request”. The returned compensation is 1.0.0-mig.002, bound to the published snapshot.

Your application decides when to use that definition for new sessions. Publishing it does not change existing sessions or automatically make their histories compatible. Keep their original revisions retrievable and apply the separate session upgrade policy where appropriate.

Likewise, applying the compensating plan to an array does not replace the published 1.1.0 revision. To make restored content available, prepare and publish a further immutable revision through the same review and validation process.

Reconcile a write that could not be confirmed

Section titled “Reconcile a write that could not be confirmed”

A failure after the repository’s publish() has been invoked can mean that the revision exists even though the caller did not receive confirmation. The pipeline reports an unconfirmed publication. It does not automatically retry, delete the revision, or publish a compensation.

The complete example runs a second scenario with a repository that stores the candidate and then deliberately loses its receipt. A later read finds the expected revision. The two observed outcomes are:

Observation Confirmed publication Receipt lost after writing
Pipeline returns a confirmed result Yes No
Version 1.1.0 is stored Yes Yes
Stored snapshot matches the candidate Yes Yes, established during reconciliation
Write attempts One One

Retain the source, plan, target identity, and expected candidate so your application can reconcile that outcome. Read the target revision from the authoritative repository and compare it with the expected snapshot. If it matches, record that the publication exists without issuing another write. If it differs, is missing, or cannot yet be read reliably, keep the operation unresolved while you establish what the repository accepted. An exception by itself is not evidence that nothing was written.

Download publication-example.php and publication-memory-repository.php, together with migration-source.json and migration-plan.json. Place these files in your project root, alongside vendor/. The script loads the project’s autoloader and the example repository class.

Terminal window
php publication-example.php

The result shows the confirmed code/version/hash and the changed title, verifies the returned compensation on a separate array, and reports the deliberately unconfirmed write followed by its readback comparison. Both repositories exist only in the example process; the script does not publish to your application’s catalog.