Skip to content

Read the WorkerReplayClock entry carrier in replay_now() - #380

Merged
rmcdaniel merged 3 commits into
mainfrom
general/215-replay-clock-entry
Nov 25, 2026
Merged

rmcdaniel merged 3 commits into
mainfrom
general/215-replay-clock-entry

Conversation

@rmcdaniel

Copy link
Copy Markdown
Member

What

ctx.replay_now() now has a value at ordinary workflow entry, before any durable step. It reads the workflow task's replay_clock carrier (WorkerReplayClock v1), which Server has sent since 3.6.0 (durable-workflow/server#1156). This is the Python slice of durable-workflow/.github#215.

Rules

The SDK accepts the carrier only if every one of these holds:

  • it is an object with schema == "durable-workflow.worker-replay-clock/v1";
  • workflow_run_id equals the task's run_id, and is not empty;
  • started_at is strict UTC with six fractional digits and Z, and is a real instant;
  • source agrees with the history's own start kind: run_started_at for an ordinary, continued or child run, redrive_replayed_started_at when the history declares a redrive.

Anything else counts as absent, and no other time is substituted. A redrive anchor that history already proves is never replaced. The carrier sets only the entry value; every existing boundary, group and unavailability rule is unchanged after the first consumed step. Query, update and other reconstruction-only paths don't receive a carrier and stay unavailable.

Compatibility: tasks without the carrier behave exactly as before, and ctx.now() still returns the fixed start time.

Evidence

  • tests/test_business_replay_clock_entry.py covers:
    • an entry read that returns the carrier instant, identically across replays and across two worker leases;
    • absence;
    • microsecond precision;
    • 19 rejected carrier shapes;
    • the run-id requirement;
    • source/history mismatch;
    • a history-proved redrive anchor that is never replaced;
    • an unproved redrive that accepts only a redrive anchor, at entry only.
  • Regression corpus fixture business-clock-ordinary-entry-carrier runs a real Worker._run_workflow_task on two leases. It fails on base: clock[0] is None. It passes here.
  • Locally: pytest tests/ -m "not integration" (7972 passed, 3 skipped), ruff check, mypy src/durable_workflow/, and validate-regression-corpus.py --base-ref origin/main all pass.

Docs: the replay_now() docstring, the SDK reference's new "Advancing replay clock" section and CHANGELOG (Unreleased).

Refs durable-workflow/.github#215

🤖 Generated with Claude Code

ctx.replay_now() now returns the run's canonical start at ordinary workflow
entry when the workflow task carries a valid replay_clock object
(WorkerReplayClock v1, server#1156). The carrier must name the task's run, use
strict six-digit UTC and agree with the history's start kind; a redrive anchor
that history already proves is never replaced. Tasks without a carrier keep
entry unavailable and ctx.now() keeps its fixed start.

Refs durable-workflow/.github#215

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rmcdaniel and others added 2 commits November 25, 2026 19:51
Review of #380: a body that reads replay_now() at entry must rebuild with
the same entry value for updates. apply_update, query_state and
validate_update (and the worker paths that call them), replay_history and
Replayer.replay now accept the task's replay_clock object. Query tasks and
pre-accept validation don't receive one from Server yet, so those rebuilds
fail visibly; the docs now say so. The carrier key set must be exact, a
non-string source counts as absent, and an unproved redrive start's own
replayed_started_at must agree with the carrier.

Refs durable-workflow/.github#215

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The worker calls _prepare_query_state and _prepare_update_validation, so
the public query_state and validate_update don't need the carrier. A present
but unreadable replayed_started_at now refuses the carrier, the entry
pattern is ASCII-only, and the docs name proof-less starts and the in-memory
environment among the unavailable cases.

Refs durable-workflow/.github#215

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

Copy link
Copy Markdown

@rmcdaniel
rmcdaniel merged commit 70d83a4 into main Nov 25, 2026
25 checks passed
@rmcdaniel

Copy link
Copy Markdown
Member Author

Independent review: PASS at f3716bfd73150269aa7232286d645779c9a53f1e after two rounds. Merged at that head as 70d83a4.

  • Round 1 (blocking): query, update and validation rebuilds didn't get the task's carrier. Fixed: apply_update, _prepare_query_state and _prepare_update_validation now take it, and the worker passes it at every call site.
  • Round 2 (blocking): SonarCloud S107 failed because public query_state and validate_update exceeded the parameter count. Fixed by keeping the parameter on the private helpers only.
  • Also addressed: exact key set, non-string source, unproved-redrive anchor agreement, docs and offline APIs.

All 21 checks pass (4 intended skips), including SonarCloud. The regression fixture business-clock-ordinary-entry-carrier fails on base and passes here.

A further gap (tolerant bodies in carrier-less query rebuilds) is handled in #382.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant