Skip to content

Read the same clock after inline steps on first execution and replay - #1309

Closed
rmcdaniel wants to merge 3 commits into
mainfrom
general/215-fiber-runner-inline-clock
Closed

rmcdaniel wants to merge 3 commits into
mainfrom
general/215-fiber-runner-inline-clock

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

What

A determinism fix found while checking the embedded side of durable-workflow/.github#215.

Finding. I tested a Workflow::now() read right after an inline step through each real runner path, on both first execution and replay.

Path Inline step First execution Replay Result
WorkflowExecutor (embedded engine) side effect records SideEffectRecorded synchronously, then resumes with its recorded_at same event time agrees; unchanged. New feature test testSideEffectClockAgreesOnFirstExecutionAndReplay
WorkflowFiberRunner (external PHP workers) side effect, memo upsert, search-attribute upsert runs inline before Server records it, so keeps the previous boundary time moved to the step's later recorded_at diverged; fixed here
WorkflowFiberRunner local activity resumes from recorded history resumes from recorded history agrees
WorkflowFiberRunner version marker previous time when no marker exists yet marker's recorded_at diverges, but not changed; see below

Change. On replay, WorkflowFiberRunner now keeps the previous boundary time after a side effect, memo upsert or search-attribute upsert. That is the time first execution already used. The changed lines are the three replay sendToWorkflow calls, which no longer pass recorded_at.

Not changed: version markers. The pinned, immutable corpus fixture repeated-version-legacy-clock-boundaries requires WorkflowFiberRunner, QueryStateReplayer and WorkflowExecutor all to advance to the marker's recorded_at on replay. That is parity with the embedded executor, which records markers synchronously. Keeping the previous time there would break that pinned contract, and with it mixed-fleet parity with executor-written histories. The remaining fiber-runner version-marker divergence is a decision for General.

Trade-off for side effects, memos and upserts: if a history written by the embedded executor is replayed by WorkflowFiberRunner (a mixed fleet), the executor's first execution read the step's time and this runner now reads the previous time. No pinned fixture covers that combination. For histories produced by external workers, which is this runner's own case, replay now matches first execution.

Evidence

  • tests/Unit/V2/WorkflowFiberRunnerInlineClockTest.php: side effect, memo and search-attribute cases. It fails on main (after_inline 00:00:03 on first execution vs 00:00:07 on replay) and passes here.
  • New replay-regression fixture worker-protocol-side-effect-keeps-previous-clock. It fails with main's runner and passes here.
  • V2DeterministicTimeReplayTest::testSideEffectClockAgreesOnFirstExecutionAndReplay shows the embedded executor agrees (12:09:00 on both paths).
  • Locally: WorkflowFiberRunnerInlineClockTest, ReplayRegressionCorpusTest and WorkflowFiberRunnerTest pass (283 tests), including the pinned version fixture. The feature test passes on sqlite. 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, the worker-protocol runner for external PHP workers,
runs a side effect, memo upsert or search-attribute upsert inline before the
Server records it, so first execution kept the previous boundary time. Replay
moved Workflow::now() to the step's later recorded_at, so code that read the
clock right after such a step could decide differently on replay. Replay now
keeps the previous boundary time too. Version decisions keep their replay
time, which repeated-version-legacy-clock-boundaries pins for parity with the
embedded executor. A feature test shows the embedded executor, which records
side effects synchronously, already agrees on both paths.

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 26, 2026
rmcdaniel and others added 2 commits November 26, 2026 00:17
…ner-inline-clock

# Conflicts:
#	CHANGELOG.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@rmcdaniel

Copy link
Copy Markdown
Member Author

Independent review: CHANGES REQUESTED at 5433289

A reviewer in a fresh context reviewed this PR's own changes against main and .github#215.

Verified

  • The runtime change is three replay sendToWorkflow calls in WorkflowFiberRunner.php (:537, :644, :672). With no event time and advanceCancellationTime: false, WorkflowExecution::send leaves both clocks alone, matching the runner's own first execution.
  • WorkflowFiberRunnerInlineClockTest 3/3 and ReplayRegressionCorpusTest 217/217 pass. All 3 new unit cases and the new fixture fail on main, so the tests catch the change.

BLOCKING

  1. WorkflowFiberRunner.php:537, :644, :672: an ungated change to replay clock values. It applies to every history the runner replays, not only histories it wrote.
    • Executor-written histories replayed by an external worker regress. The embedded executor's first execution reads the step's recorded_at (12:09 in the new feature test). Main's fiber runner replayed that value; this PR reads the previous boundary (12:05). docs/api-stability.md:292-295 covers mixed embedded and external fleets.
    • In-flight runs on cold-replaying external workers: a decision committed under main using the recorded time can take the other branch on replay after the upgrade. Nothing in the history distinguishes the two cases.
    • Consumers disagree: QueryStateReplayer, WorkflowExecutor/WorkflowReplayer and replay-verify still read the recorded time.
    • Preferred fix: gate it. The runner marks its inline commands (for example clock: "previous_boundary"), the Server persists the mark, and every PHP consumer honours it. Unmarked histories replay exactly as today. List all consumers on the fixture and add an unmarked counterpart.
    • Alternative: record the inline-step clock decision on .github#215, document the break, and give operators drain guidance.
  2. CHANGELOG.md:14-24 is materially incomplete. It leaves out the effects above.

Non-blocking

  • The recorded_at indexes (around :2524) are no longer read on these paths.
  • The version-marker divergence needs its own tracked decision.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Held out of the Workflow 2.42.0 round. The blocking finding above needs a decision on .github#215: either gate the inline-step clock with a mark the Server persists and every PHP consumer honours, or accept a documented break with drain guidance. Without one, merging would change replay values for executor-written histories and for in-flight external-worker runs. The PR stays open, and #1307 (the entry carrier) ships without it.

@rmcdaniel

Copy link
Copy Markdown
Member Author

Closing per General's #215 decision (.github#215, Nov 26). Changing the replay-time read after inline steps alters replay output for runs already in flight and for embedded-written histories, without gating. The limit is documented instead: clock reads immediately after inline steps aren't portable until Core defines a persisted time for those steps. Revisit with a gated design if Core does.

@rmcdaniel rmcdaniel closed this Nov 26, 2026
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