Skip to content

Add the cross-SDK replay-safe clock conformance case - #439

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

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

Conversation

@rmcdaniel

@rmcdaniel rmcdaniel commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What

This adds the cross-SDK replay-clock conformance case for #215 under conformance/replay-clock/.

What it checks. The case replays one history and each WorkerReplayClock v1 carrier case (server#1156) through four bindings:

Binding Clock
Python ctx.replay_now()
Rust replay_now()
PHP service SDK replayNow()
Embedded worker-protocol runner WorkflowFiberRunner, Workflow::now()

Every binding must report identical values for:

  • entry: the carrier's started_at, not the history insertion time;
  • repeated entry reads, which must return the same value;
  • the read after an activity and the read after a timer, which must equal their recorded times;
  • the elapsed microseconds between the two steps.

Missing or unproved carriers must leave entry unavailable in the service SDKs. That covers no carrier, another run's carrier, a low-precision started_at, and a redrive source on ordinary history. The embedded runner's documented exception is pinned in binding_overrides: it keeps the WorkflowStarted time without a proved carrier.

Files.

  • vectors-v1.json: the shared history, cases and expected observations.
  • One thin runner per binding: python/runner.py, rust/src/main.rs, php/sdk-runner.php and php/embedded-runner.php.
  • run.py: installs exact published releases (DW_PYTHON_SDK_VERSION, DW_RUST_SDK_VERSION, DW_PHP_SDK_VERSION, DW_WORKFLOW_PHP_VERSION) in throwaway containers and compares every observation.
    • requires_newer_than names the last release without the entry carrier: Python 2.23.1, Rust 4.24.0, PHP 3.31.0 and Workflow 2.41.0. A release at or below it is reported as not_yet_released rather than failed.
    • --source runs an unreleased checkout. It is for development only.
  • tests/test_replay_clock_conformance.py pins the vectors' consistency, the comparator, the overrides, the version gate, the private scratch mount and per-binding error handling.
    • It does not run in CI. ci.yml and sonar.yml must keep their reviewed workflow bytes, and adding a test to their lists is not a routine data update (it needs a reviewed runtime change). Run it with python -m unittest tests.test_replay_clock_conformance.
    • The Docker-only runners are therefore excluded from coverage (sonar.coverage.exclusions=conformance/replay-clock/** in sonar-project.properties). They stay in security, reliability and maintainability analysis.

Container hygiene. Each container runs as the invoking user with --rm --init, CPU and memory limits, and a private --tmpfs /scratch (mode 0700). The venv, the source copy, HOME, CARGO_HOME and COMPOSER_HOME live there, not in /tmp. If one binding's container fails or prints no observations, it is recorded as "status": "error" and the other bindings still run. The exit status is non-zero on any fail or error.

Embedded finding.

  • The embedded executor's entry uses workflow_runs.started_at (RedriveReplayClock::startedAt), the same column the carrier is built from, so the two are equal.
  • WorkflowFiberRunner, used by external PHP workers, took the WorkflowStarted event time, which is written with a separate now(). workflow#1307 adds the optional carrier to it.

Evidence

  • Source mode against current main of sdk-python, sdk-rust and sdk-php, plus the workflow#1307 branch: all four bindings pass with no mismatches. With the currently published tuple (2.23.1, 4.24.0, 3.31.0, 2.41.0), every binding reports not_yet_released.
  • Re-run at the review-fix head with the /scratch mount, in source mode against current main of sdk-python, sdk-rust and sdk-php: all three pass. The embedded binding passes against the workflow#1307 head (0804b368). Against current workflow main it is recorded as error (Unknown named parameter $replayClock) while the other bindings still run, as expected before #1307 merges.
  • python -m unittest tests.test_replay_clock_conformance: 10 OK.
  • ruff: clean.

After the release round, run it against the published tuple as the README describes, and record the per-binding result.json statuses on the release issue.

Refs #215

🤖 Generated with Claude Code

conformance/replay-clock replays one history with each WorkerReplayClock v1
carrier case through the published Python, Rust and PHP SDKs and the embedded
worker-protocol runner. It requires the same replay_now() values at entry,
for repeated entry reads, after an activity and after a timer, and the same
unavailable entry for missing or unproved carriers. run.py installs exact
releases in throwaway containers and reports releases that predate the entry
carrier as not yet released. Unit tests pin the vectors and the comparison.

Refs #215

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rmcdaniel rmcdaniel added the agent:general Pull request opened by General agent label Nov 26, 2026
ci.yml and sonar.yml must keep their exact reviewed bytes, so the new
conformance unit test is not added to their lists. It runs with
python -m unittest tests.test_replay_clock_conformance.

Refs #215

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

Copy link
Copy Markdown
Member Author

Independent review: CHANGES REQUESTED at 69cfa83

A reviewer in a fresh context reviewed this PR against .github#215 and the current main of server, sdk-python, sdk-rust, sdk-php and workflow, including workflow#1307.

Verified

  • vectors-v1.json encodes the contract correctly. Entry is the carrier's started_at, later reads are the consumed events' recorded times, and elapsed time is 2530865 µs. The three refused carriers leave entry unavailable, and nothing is substituted.
  • run.py --source against the four checkouts gives all four bindings passing, with 0 mismatches across 5 cases. With the published 2.23.1, 4.24.0, 3.31.0 and 2.41.0, all four report not_yet_released, which is correct.
  • Injection: the version env vars are regex-checked before use, and subprocess gets argument lists. The net diff touches no workflow YAML.
  • The unit test passes locally (6 OK).

Why it is BLOCKED: Shared contract tests failed on a bound setup-php HTTP 403, which is infrastructural and needs a re-run. The SonarCloud gate fails on security D, reliability C and 0% new coverage.

BLOCKING

  1. The new unit test never runs in CI, and new coverage is 0%. tests.test_replay_clock_conformance is in neither the ci.yml nor the sonar.yml list after 69cfa83, and the PR body still says it is wired in. Fix: wire it through the reviewed-workflow policy, or exclude conformance/replay-clock/** from coverage in sonar-project.properties and say so. Correct the PR body either way.
  2. Sonar security D is a false positive, but the gate still fails: python:S5443 at run.py:100,107 (/tmp inside a --rm container) and S8707 at python/runner.py:20. Fix: use a private --tmpfs /scratch mount inside the containers instead of /tmp.
  3. Sonar reliability C: php:S2003 at php/embedded-runner.php:10 and php/sdk-runner.php:10. Use require_once.

Non-blocking

  • README.md:26 and rust/src/main.rs:59-60 overstate what the Rust builder refuses: it refuses only the other-run and low-precision carriers. .unwrap_or(history) hides builder errors.
  • rust/src/main.rs:13 maps every Err to null. Match only ReplayClockUnavailable.
  • run.py:159: one crashing binding aborts the whole run. Record a per-binding error and continue.
  • Images are pinned by tag, and the Rust and Composer dependencies float.

- run.py: each container gets a private --tmpfs /scratch (mode 0700,
  owned by the invoking user) for the venv, source copy, HOME,
  CARGO_HOME and COMPOSER_HOME instead of /tmp. One binding's container
  or JSON failure is recorded as "status": "error" and the remaining
  bindings still run; the exit status is non-zero on fail or error.
  Split per binding, validate exact versions before any run, and add
  --container-prefix.
- python/runner.py reads only the case's own vectors file; an argv path
  that does not resolve to it is refused.
- PHP runners load the autoloader with require_once.
- rust/src/main.rs maps only ReplayClockUnavailable to null and asserts
  the builder refuses exactly the other-run and low-precision carriers;
  the redrive-source carrier must be accepted. README wording matches.
- ci.yml and sonar.yml are reviewed workflow bytes; adding a test to
  their lists is not a routine data update, so the Docker-only runners
  are excluded from coverage in sonar-project.properties instead.
- Tests cover the scratch mount, per-binding errors and selection.

Refs #215

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

Copy link
Copy Markdown

@rmcdaniel

Copy link
Copy Markdown
Member Author

Independent review: PASS at 40fbcf5 (re-review)

The same reviewer re-checked the diff 69cfa83..40fbcf5 and the live state.

  • The required checks (Shared contract tests, SonarCloud) are green, and the PR is CLEAN. The new-code security and reliability ratings are A. S5443, S8707 and S2003 are gone.
  • Blocking 1: sonar.coverage.exclusions=conformance/replay-clock/** is added with a comment, and the PR body is corrected. ci.yml and sonar.yml are untouched.
  • Blocking 2: each container gets a private --tmpfs /scratch (0700, the caller's uid/gid), and no container path uses /tmp. runner.py reads only its own vectors file.
  • Blocking 3: both PHP runners use require_once.
  • A real source-mode run at this head against sdk-python, sdk-rust and sdk-php main and workflow#1307 3a41a461 passes for all 4 bindings with 0 mismatches. The published tuple still reports not_yet_released. A crashing binding is recorded as error, and result.json is still written.
  • Rust maps only ReplayClockUnavailable to null and asserts is_err for exactly the two refused carriers. 10 unit tests pass.

Blocking: none.

Non-blocking: the unit test still runs in no CI job; wire it in at the next approved review of ci.yml/sonar.yml. Images are pinned by tag and the Rust and Composer dependencies float.

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

Labels

agent:general Pull request opened by General agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant