Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(flow): preserve event order and refuse clock rollback [R1,R2]
Corey Olson72f38ae666ec
diff --git a/docs/formats.md b/docs/formats.mdindex f7925da2..6e8a9225 100644--- a/docs/formats.md+++ b/docs/formats.md@@ -535,3 +535,5 @@ The engine-68 `recordSpecApprovalBaseline` move carries `{agentId, baseline: {veThe default policy, `{"order":"recorded"}`, keeps recorded stage starts, durations and seat concurrency, reproducing complete measured cycles. `--policy <file>` accepts an explicit item-id order (a partial list prioritizes those ids), plus optional positive integer `settings.buildWip`, `settings.reviewWip` and `settings.landingWip`. These are hypothetical replay limits, not changes to the live board or machine. Unspecified limits come from observed concurrent stage intervals; recorded seat identities and their observed concurrency remain fixed. A different order or limit schedules ready work without preemption, retaining item arrivals and every measured build/review/landing interval. Recorded policy has exact observed start constraints; alternate policy has none of the observed queue delays.`replay` reports landing order, each first-claim-to-landed time, and stage quartiles in minutes using the existing flow-window convention (fast/slow quarters use the sorted sample at floor(n/4) and floor(3n/4), with the middle pair averaged for an even median). These counterfactual predictions are not timings measured under an alternate live queue. Landing intervals are the recorded accept-to-merged spans, including observed waiting, not an estimate of CPU work. Incomplete, abandoned or missing-boundary cycles appear in `unmeasured`; they never become zero-duration work. Rejected complete attempts retain their actual builder/reviewer seats and durations. No wall clock or random values enter the replay result.++Native `event_id` order is canonical, even when an input array is shuffled. A history whose recorded timestamps decrease in that order is refused explicitly: the bench never reorders lifecycle events by a clock, clamps timestamps, or presents contradictory clock evidence as an exact reproduction.diff --git a/src/flow-replay-history.js b/src/flow-replay-history.jsindex 03e2afa0..818ddad3 100644--- a/src/flow-replay-history.js+++ b/src/flow-replay-history.js@@ -23,7 +23,10 @@ export function replayHistory(events) {rows.push({ event_id: id, event_at: new Date(at).toISOString(), event_kind: event.event_kind,item_id: event.event_kind === 'join' ? null : item, event_by: by });}- rows.sort((a, b) => Date.parse(a.event_at) - Date.parse(b.event_at) || a.event_id - b.event_id);+ rows.sort((a, b) => a.event_id - b.event_id);+ if (rows.some((row, index) => index > 0 && Date.parse(row.event_at) < Date.parse(rows[index - 1].event_at))) {+ throw new Refused('USAGE', 'replay history clocks moved backwards in native event order; use a history with nondecreasing recorded times, never reorder or clamp timestamp evidence');+ }return { version: 1, events: rows };}diff --git a/test/flow-replay-policy.test.js b/test/flow-replay-policy.test.jsindex 2167f30f..2d9397bd 100644--- a/test/flow-replay-policy.test.js+++ b/test/flow-replay-policy.test.js@@ -34,8 +34,8 @@ test('replay retains rejected work and fixed seats without reading private detai});test('unmeasured cycles are reported rather than invented as zero work [R1,R2]', () => {- const input = events([[0, 'add', 1, 'coordinator'], [1, 'claim', 1, 'web-1'], [2, 'submit', 1, 'web-1'],- [3, 'accept', 1, 'review-1'], [4, 'merged', 1, 'coordinator'], [0, 'add', 2, 'coordinator']]);+ const input = events([[0, 'add', 1, 'coordinator'], [0, 'add', 2, 'coordinator'], [1, 'claim', 1, 'web-1'], [2, 'submit', 1, 'web-1'],+ [3, 'accept', 1, 'review-1'], [4, 'merged', 1, 'coordinator']]);const result = replayFlow(input);assert.deepEqual(result.replay.items, []);assert.deepEqual(result.replay.unmeasured.map(item => item.id), [1, 2]);@@ -72,3 +72,12 @@ test('show retains its boolean history flag while flow accepts a history file [Rassert.equal(code, 0, err);assert.match(out, /--history/u);});+++test('a clock rollback refuses replay instead of silently reordering native history [R1,R2]', () => {+ const input = rework();+ input[1].event_at = new Date(BASE - 60_000).toISOString();+ assert.throws(() => replayFlow(input), /clocks moved backwards in native event order/u);+ assert.throws(() => replayFlow([...input].reverse(), { order: [1] }), /clocks moved backwards/u,+ 'array order cannot hide rollback by placing lower timestamps first');+});