Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"dev-main": "2.0.x-dev"
},
"durable-workflow": {
"product-train": "2.5.0",
"product-train": "2.5.1",
"laravel-embedded-upgrade-contract": "resources/laravel-embedded-upgrade-contract.json",
"laravel-dependency-security-policy": "resources/laravel-dependency-security-policy.json"
},
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/validate-regression-corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"tests/Fixtures/V2/TestParallelChildReplayWorkflow.php",
"tests/Fixtures/V2/TestSequentialChildReplayWorkflow.php",
"tests/Fixtures/V2/TestServiceResponseReplayWorkflow.php",
"tests/Fixtures/V2/TestLegacyPatchReplayWorkflow.php",
"tests/Fixtures/V2/TestServiceGroupedConditionReopenWorkflow.php",
"tests/Fixtures/V2/TestSignalResumedParallelWorkflow.php",
"tests/Fixtures/V2/TestCancellationContextWorkflow.php",
Expand Down
12 changes: 8 additions & 4 deletions src/V2/Support/QueryStateReplayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,17 @@ public function replayState(WorkflowRun $run): ReplayState
$historySequence = $this->historySequenceForReplayPosition($historySequencesByPosition, $sequence);

$this->applyRecordedUpdates($run, $workflow, $historySequence);
WorkflowStepHistory::assertCompatible($run, $historySequence, WorkflowStepHistory::VERSION_MARKER, [
'change_id' => $current->changeId,
]);

$versionEvent = $this->versionMarkerEvent($run, $historySequence);
$resolution = VersionResolver::resolve($run, $versionEvent, $current, $historySequence);

// A legacy default occupies no history slot. The next durable
// step can already be recorded at this position.
if ($resolution->advancesSequence) {
WorkflowStepHistory::assertCompatible($run, $historySequence, WorkflowStepHistory::VERSION_MARKER, [
'change_id' => $current->changeId,
]);
}

$this->syncWorkflowCursor($workflow, $sequence + ($resolution->advancesSequence ? 1 : 0));
$current = $workflowExecution->send(
$current->resolveValue($resolution->version),
Expand Down
48 changes: 48 additions & 0 deletions tests/Feature/V2/V2EmbeddedReplayRegressionCorpusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Queue;
use Symfony\Component\Uid\Ulid;
use Tests\Fixtures\V2\TestQueryReplayGuardActivity;
use Tests\TestCase;
use Throwable;
use Workflow\Serializers\Serializer;
Expand Down Expand Up @@ -39,6 +40,7 @@
use Workflow\V2\Support\EmbeddedV2HistoryImport;
use Workflow\V2\Support\HistoryExport;
use Workflow\V2\Support\QueryStateReplayer;
use Workflow\V2\Support\ReplayDiff;
use Workflow\V2\Support\RunActivityView;
use Workflow\V2\Support\RunTimelineProjector;
use Workflow\V2\Support\WorkflowFiberRunner;
Expand Down Expand Up @@ -121,6 +123,12 @@ public function testFixturesExecuteThroughDeclaredReplayConsumers(): void
$this->assertRunInheritedScopedCleanupAfterColdReload($fixture);
}

if ($fixture['id'] === 'legacy-version-shared-step-position') {
$this->assertLegacyVersionSharesTheRecordedStepPosition($fixture);

continue;
}

if ($fixture['id'] === 'cooperative-delivery-before-wait-sequence') {
$run = $this->createRunFromFixture($fixture);
$this->assertSame(2, WorkflowStepHistory::nextDurableCommandSequence($run->fresh()));
Expand Down Expand Up @@ -1023,6 +1031,46 @@ private function clearWorkflowState(): void
}
}

/**
* @param array<string, mixed> $fixture
*/
private function assertLegacyVersionSharesTheRecordedStepPosition(array $fixture): void
{
$run = $this->createRunFromFixture($fixture);
$started = WorkflowHistoryEvent::query()
->where('workflow_run_id', $run->id)
->where('event_type', HistoryEventType::WorkflowStarted->value)
->firstOrFail();
$payload = $started->payload;
unset($payload['workflow_definition_fingerprint']);
$started->forceFill([
'payload' => $payload,
])->save();
$bundle = HistoryExport::forRun($run->fresh());
$before = WorkflowHistoryEvent::query()->where('workflow_run_id', $run->id)->get()->toArray();
TestQueryReplayGuardActivity::$executions = 0;

$this->assertSame(
$fixture['expected']['result'],
(new QueryStateReplayer())->query($run->fresh(), 'currentState'),
);
$this->assertSame(ReplayDiff::STATUS_REPLAYED, (new ReplayDiff())->diffExport($bundle)['status']);
$this->assertSame(
$before,
WorkflowHistoryEvent::query()->where('workflow_run_id', $run->id)->get()->toArray(),
);

$this->runReadyWorkflowTask($run);
$workflow = WorkflowStub::loadRun($run->id);
$this->assertTrue($workflow->completed());
$this->assertSame($fixture['expected']['result'], $workflow->output());
$this->assertSame(0, TestQueryReplayGuardActivity::$executions);
$this->assertFalse(WorkflowHistoryEvent::query()
->where('workflow_run_id', $run->id)
->where('event_type', HistoryEventType::VersionMarkerRecorded->value)
->exists());
}

/**
* @param array<string, mixed> $fixture
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"$schema": "https://raw.githubusercontent.com/durable-workflow/.github/main/regression-corpus/evidence-schema.json",
"fixture_schema": "durable-workflow.replay-regression/v1",
"id": "legacy-version-shared-step-position",
"protocol_version": "1.19",
"bindings": ["php"],
"consumers": ["workflow-fiber-runner", "query-state-replayer", "workflow-executor"],
"workflow": {
"type": "Tests\\Fixtures\\V2\\TestLegacyPatchReplayWorkflow",
"arguments": [],
"payload_codec": "avro"
},
"history": [
{
"sequence": 1,
"event_type": "WorkflowStarted",
"payload": {},
"recorded_at": "2026-10-01T12:00:00+00:00"
},
{
"sequence": 2,
"event_type": "ActivityScheduled",
"payload": {
"sequence": 1,
"activity_type": "Tests\\Fixtures\\V2\\TestQueryReplayGuardActivity",
"activity_execution_id": "01j00000000000000000000001"
},
"recorded_at": "2026-10-01T12:00:01+00:00"
},
{
"sequence": 3,
"event_type": "ActivityCompleted",
"payload": {
"sequence": 1,
"activity_type": "Tests\\Fixtures\\V2\\TestQueryReplayGuardActivity",
"activity_execution_id": "01j00000000000000000000001",
"result": "wwHioz3/VYAiNwoecmVjb3JkZWQtcmVzdWx0",
"payload_codec": "avro"
},
"recorded_at": "2026-10-01T12:00:02+00:00"
},
{
"sequence": 4,
"event_type": "TimerScheduled",
"payload": {
"sequence": 2,
"timer_id": "01j00000000000000000000002",
"timer_kind": "durable_timer",
"delay_seconds": 60,
"fire_at": "2026-10-01T12:01:02+00:00"
},
"recorded_at": "2026-10-01T12:00:02+00:00"
},
{
"sequence": 5,
"event_type": "TimerFired",
"payload": {
"sequence": 2,
"timer_id": "01j00000000000000000000002",
"timer_kind": "durable_timer",
"fired_at": "2026-10-01T12:01:02+00:00"
},
"recorded_at": "2026-10-01T12:01:02+00:00"
}
],
"expected": {
"completed": true,
"result": {
"patched": false,
"value": "recorded-result",
"stage": "completed"
},
"commands": [{"type": "complete_workflow"}]
}
}
46 changes: 46 additions & 0 deletions tests/Fixtures/V2/TestLegacyPatchReplayWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\V2;

use Workflow\QueryMethod;
use Workflow\V2\Workflow;

final class TestLegacyPatchReplayWorkflow extends Workflow
{
private bool $patched = false;

private ?string $value = null;

private string $stage = 'starting';

public function handle(string $patchBefore = 'activity'): array
{
if ($patchBefore === 'activity') {
$this->patched = Workflow::patched('legacy-upgrade');
}

$this->value = Workflow::activity(TestQueryReplayGuardActivity::class);

if ($patchBefore === 'timer') {
$this->patched = Workflow::patched('legacy-upgrade');
}

$this->stage = 'waiting-for-timer';
Workflow::timer(60);
$this->stage = 'completed';

return $this->currentState();
}

#[QueryMethod]
public function currentState(): array
{
return [
'patched' => $this->patched,
'value' => $this->value,
'stage' => $this->stage,
];
}
}
Loading
Loading