Skip to content

Let the worker-protocol runner read the replay_clock entry carrier - #1307

Merged
rmcdaniel merged 6 commits into
mainfrom
general/215-fiber-runner-entry-carrier
Nov 26, 2026
Merged

rmcdaniel merged 6 commits into
mainfrom
general/215-fiber-runner-entry-carrier

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

What

The embedded side of the cross-SDK replay-clock check for durable-workflow/.github#215.

Finding.

  • The embedded executor already uses the run's started_at at entry. WorkflowExecutor and QueryStateReplayer call WorkflowExecution::start(..., RedriveReplayClock::startedAt($run)), which reads workflow_runs.started_at, or the redrive replayed_started_at. Server's WorkerReplayClock v1 carrier reads that same column, so embedded entry already equals the carrier.
  • The exception is the worker-protocol runner WorkflowFiberRunner, used by external PHP workers. It took entry from the WorkflowStarted event's recorded_at. That timestamp comes from its own now() call, separate from the run's started_at: DefaultWorkflowControlPlane sets $startedAt = now() and WorkflowHistoryEvent records $now = now(), and the native server's append does the same. So the two can differ by microseconds.

Change. WorkflowFiberRunner takes an optional replayClock argument, the task's replay_clock object, on its constructor and on forClass().

  • When the carrier validates, ordinary entry uses the carrier's started_at, which is the reference. A valid carrier has exactly the four v1 keys, the v1 schema, the runner's run id, strict six-digit UTC with Z on a real date, and one of the two sources.
  • The source must agree with the history's start kind.
  • A redrive anchor that history proves is never replaced. A carrier with a redrive source is used only when the history declares a redrive without a readable anchor.
  • Without a carrier, or with an unproved one, entry keeps the WorkflowStarted time, so external runs already in flight replay unchanged. This is additive.

Evidence

  • New tests/Unit/V2/WorkflowFiberRunnerEntryCarrierTest.php (13 tests) covers:
    • entry equals the carrier, later boundaries keep their recorded times, and two replays match;
    • without a carrier, entry keeps the WorkflowStarted time;
    • 10 unproved carriers are ignored;
    • a history-proved redrive anchor wins.
  • New replay-regression fixture worker-protocol-entry-replay-clock-carrier uses worker_task.replay_clock. Both corpus runners forward it to the runner. It fails on base and passes here.
  • Locally: WorkflowFiberRunnerEntryCarrierTest, WorkflowFiberRunnerTest and ReplayRegressionCorpusTest pass (293 tests), and phpstan and ecs are clean on the changed files. CI runs the full suites and the corpus counterfactual.

Refs durable-workflow/.github#215

🤖 Generated with Claude Code

WorkflowFiberRunner took Workflow::now() at entry from the WorkflowStarted
event time. That event is written with its own now(), separate from the run's
started_at, which the embedded executor and the Server's WorkerReplayClock v1
carrier use. The runner now accepts the task's replay_clock object as an
optional replayClock argument. When it validates for the run and its source
agrees with the history's start kind, ordinary entry uses its started_at.
A redrive anchor the history proves is kept, and without a carrier entry is
unchanged, so runs already in flight replay identically.

Refs durable-workflow/.github#215

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rmcdaniel rmcdaniel added the agent:general Work owned by General label Nov 25, 2026
rmcdaniel and others added 3 commits November 26, 2026 00:17
The corpus counterfactual runs this harness against base source, where the
runner has no replayClock parameter. Passing it only for fixtures that carry
a replay_clock keeps every other fixture runnable on base, so only the new
fixture fails there.

Refs durable-workflow/.github#215

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs durable-workflow/.github#215

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rmcdaniel

Copy link
Copy Markdown
Member Author

Independent review: PASS at e30e661

A reviewer in a fresh context reviewed this PR's own changes against main and .github#215. The merge of main only resolved a CHANGELOG conflict.

Verified

  • The validation matches the v1 contract (docs/contracts/worker-replay-entry-clock.md): exactly four keys, the v1 schema, the run id equal to the runner's run, one of the two sources, and strict six-digit UTC with Z, anchored with \A...\z, ASCII \d and a round-trip check. An invalid carrier is ignored and the WorkflowStarted time is kept.
  • Entry selection matches the embedded RedriveReplayClock::startedAt. A redrive anchor that history proves wins, a source that disagrees with history is ignored, and only entry moves.
  • Without a carrier, or with replayClock: null, behaviour is unchanged. The new parameter is optional and comes last.
  • Local runs (PHP 8.4): WorkflowFiberRunnerEntryCarrierTest 13/13, WorkflowFiberRunnerTest 64/64 and ReplayRegressionCorpusTest 217/217 pass. A probe also covered the empty history, redrive without an anchor, list-shaped, 24:00, non-ASCII digit and trailing newline cases.

Blocking: none.

Non-blocking

  • A run that started without a carrier and later replays on a worker that receives one sees entry Workflow::now() move back by the start/WorkflowStarted gap, which is microseconds to milliseconds. This matters only if that value feeds a decision that replay re-checks. Mention it in the release notes.
  • "sent by Server 3.6.0 and later" should be "native Server 3.6.0 and later".
  • The redrive-carrier-without-anchor branch (WorkflowFiberRunner.php:1628-1633) has no unit case.

@sonarqubecloud

Copy link
Copy Markdown

@rmcdaniel
rmcdaniel merged commit d30ed9d into main Nov 26, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:general Work owned by General

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant