fix(kernel): stamp each start when journaled, not when its batch was elected

Merged
KH
2mo ago
+174-1

Problem

The scheduler elects an independent batch at one instant; the drive loop then runs it serially. Each step.attempt.started was built with the election-time now_ms and kept it, even when journaled after a deterministic peer had run. Found while building the observer run projection (#570). Journal of a fan-out run (fetch → {lint: sleep 10, test: sleep 14} → report), elapsed seconds per entry:

7 18.06 step.completed lint 10023
8 18.06 step.routed test
9  8.03 step.attempt.started test      <- stamped at election, journaled at 18.06
10 32.09 step.completed test 24055     <- wallclock_ms for a `sleep 14`

Two consequences:

  1. Wrong wall clock. It includes the peer's runtime (24055ms for a 14s step), feeding spend/budget accounting and every surface that reports durations.
  2. A lease spent in advance. lease_deadline_ms comes from the same stale time. With the 30s default, a step started 10s late holds a 20s lease and can be judged expired while it is running. An llm/agent step dispatched later in the same batch gets the same shortened lease in its StepDispatch.

Change

engine/drive.rs: when a start is appended, stamp it with the current clock and move its lease_deadline_ms by the delay. The batch's Dispatch for that step/attempt moves by the same delay, so the worker and the journal agree. Lease ids are unchanged (identity, not time).

Serial execution is unchanged on purpose. deterministic_spend_and_wallclock_limit_gate_parallel_batch_starts and stop_after_one_holds_for_an_independent_deterministic_batch pin it: the budget gate re-folds between starts, and crash injection stops after one completion. Under a simulated clock the delay is zero, so deterministic replay is unaffected.

Evidence

  • New tests in relayflowd/tests/parallel_driver.rs:
    • a_start_after_a_slow_deterministic_peer_is_stamped_when_journaled: the start is not earlier than the peer's completion; wall clock < 300ms for a no-op after a sleep 0.4 peer; lease deadline − start = 30000 for both steps.
    • a_dispatch_after_a_slow_deterministic_peer_keeps_its_full_lease: StepDispatch.lease_deadline_ms equals the start entry's, and is 30000 after it.
  • Mutation check (if delay > 0 → if false && delay > 0):
    test a_dispatch_after_a_slow_deterministic_peer_keeps_its_full_lease ... FAILED
    test a_start_after_a_slow_deterministic_peer_is_stamped_when_journaled ... FAILED
    quick started at 1790259503865 before slow completed at 1790259504277
    test result: FAILED. 0 passed; 2 failed
    
    Restored (cmp identical): test result: ok. 2 passed.
  • sh ../ops/cargo.sh test --workspace --no-fail-fast → cargo_exit=0, 26 test binaries all ok, crash-injection suites included.

🤖 Generated with Claude Code


[!NOTE]
Cursor Bugbot is generating a summary for commit 2fa82dd183dd7e4e23e6f1f1f42f7c341abd864b. Configure here.


Summary by cubic

Fixes the scheduler stamping step.attempt.started entries with election time even when journaled after a deterministic peer ran, so wall-clock duration and lease deadlines no longer include the peer's runtime.

  • Each start is now stamped when appended, after placement, and its lease_deadline_ms plus the matching StepDispatch deadline are extended by the delay.
  • Serial batch execution and deterministic replay under a simulated clock are unchanged.
  • Adds two regression tests, moved to their own file, covering a start and a dispatched model step after a slow deterministic peer; they assert ordering and lease structure rather than wall-clock bounds so a loaded CI host cannot fail them.

Agent Relay sessions

  • claude session 110a8f49 · opened via gh pr create · last active 2026-09-24