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
feat(stats): record the clock behind every queue age [R1,R2]
Corey Olsond67a38c6948b
diff --git a/docs/api.md b/docs/api.mdindex 27200b38..87ba7463 100644--- a/docs/api.md+++ b/docs/api.md@@ -18,8 +18,9 @@ The board-state API's item projection includes `check` and, when recorded, `chec`stats.flow` adds the flow through the board:+- `asOf` is the ISO UTC timestamp of this observation, shared by every queue age.- `stages.build`, `reviewWait`, `review` and `mergeWait` each contain `count`, `totalMinutes`, `averageMinutes`, `medianMinutes` and `unmeasuredCompleted`. Build runs from first claim to the final submission, including rework. Review wait ends at the reservation whose verdict closes that submission; released or expired reservations remain waiting time. Review runs from that reservation to verdict, and merge wait from accept to the first merge receipt. Each stage enters its averages when its end is inside the inclusive `--since` window. Unfinished or missing intervals are omitted; averages and medians with no samples are `null`. Legacy verdicts without reservations leave review wait and review unmeasured, never zero.-- `queues.open`, `claimed`, `submitted` and `accepted` contain `size` and `oldest` (`{id, ageMinutes}`, or `null`). These are current queues, including work added before the window; accepted means accepted but not merged. Open age starts at the latest add, reopen, reject, build release or claim lapse. Claimed age starts at claim, unaffected by renewal; submitted age starts at final submit, and accepted age at accept. Equal ages choose the lower item id. Expired claims become open at their recorded lease expiry.+- `queues.open`, `claimed`, `submitted` and `accepted` contain `size` and `oldest` (`{id, since, ageMinutes}`, or `null`). These are current queues, including work added before the window; accepted means accepted but not merged. Open age starts at the latest add, reopen, reject, build release or claim lapse. Claimed age starts at claim, unaffected by renewal; submitted age starts at final submit, and accepted age at accept. Equal ages choose the lower item id. Expired claims become open at their recorded lease expiry. Each `since` is the ISO UTC timestamp of that queue origin, and `ageMinutes` is exactly `(Date.parse(asOf) - Date.parse(since)) / 60000`. Separate observations check that equation independently; their invariant content, including `since`, stays comparable without a tolerance band.- `daily` contains UTC `{date, added, merged}` counts for dates with those moves in the window. An item's first merge completes its cycle; repeated receipts never create another completion, even in a later window. `submitsPerMerged` divides window submission attempts by first completions in the window, or is zero without completions. `stats.rejectionShare` remains the share of window submissions sent back.- `activeAgents` contains `total`, an `agents` list (`id`, `lane`, `role`), and counts in `roles` and `lanes`. Activity means any move in the inclusive last 60 minutes, independent of `--since`. Builder roles come from claim, submit or build release; verifier roles from reserve, verdict or review release. A roleless move retains the latest recorded role, including earlier history; without one the role is `unknown`. The coordinator's role is `coordinator`. Lanes come from recorded joins, not a guess from the id.- `bottleneck` contains `stage`, `share`, `completedItems`, `fullyMeasuredCycles`, `totalCycleMinutes`, `lowConfidence`, `message` and `recommendation`. Only completed cycles with all four measured stages contribute stage shares; the line states how many fully measured cycles support it. Fewer than half the completed cycles fully measured sets low confidence. The largest summed share wins, with ties in build, review wait, review, merge wait order. No completed cycles, or none fully measured, means no named stage or action (`null`).diff --git a/src/help.js b/src/help.jsindex da8a79cc..129ae51a 100644--- a/src/help.js+++ b/src/help.js@@ -107,6 +107,8 @@ Receiptsreleased/expired reservations remain wait, not review;review: closing reservation to verdict; merge wait: accept to first mergeunfinished stages are omitted; missing legacy reservations are unmeasured+ JSON flow.asOf records one observation clock; oldest.since records its origin;+ ageMinutes = (asOf - since) / 60000 for every queue agequeues include all current work, even added before --since;open age restarts on add, reopen, reject, release or claim lapse;claimed age starts at claim (not renewal), submitted at final submit,diff --git a/src/stats-flow.js b/src/stats-flow.jsindex d73f7dce..dbe830c0 100644--- a/src/stats-flow.js+++ b/src/stats-flow.js@@ -96,7 +96,7 @@ function queuesFrom(items, now) {const start = { open: item.openAt, claimed: item.claimAt, submitted: item.submitAt, accepted: item.acceptAt }[item.state];const ageMinutes = interval(start, now);if (ageMinutes !== null && (!queue.oldest || ageMinutes > queue.oldest.ageMinutes ||- ageMinutes === queue.oldest.ageMinutes && item.id < queue.oldest.id)) queue.oldest = { id: item.id, ageMinutes };+ ageMinutes === queue.oldest.ageMinutes && item.id < queue.oldest.id)) queue.oldest = { id: item.id, since: new Date(start).toISOString(), ageMinutes };if (item.state === 'open') openByLane.set(item.lane, (openByLane.get(item.lane) ?? 0) + 1);if (item.state === 'accepted') accepted.push(item.id);}@@ -194,7 +194,7 @@ export function flowStats(history, boundary, now, counts) {} : { stage: null, share: null, completedItems, fullyMeasuredCycles: 0, totalCycleMinutes: 0, lowConfidence: completedItems > 0,message: completedItems ? `not enough measured flow to name a bottleneck (${completedItems} items completed since ${boundary ?? 'the beginning'}, none with every stage measured)` :`not enough flow to name a bottleneck (0 items completed since ${boundary ?? 'the beginning'})`, recommendation: null };- return { stages, queues: queueData.queues, daily: [...daily.values()].sort((a, b) => a.date.localeCompare(b.date)),+ return { asOf: new Date(now).toISOString(), stages, queues: queueData.queues, daily: [...daily.values()].sort((a, b) => a.date.localeCompare(b.date)),submitsPerMerged: completedItems ? counts.submissions / completedItems : 0, activeAgents, bottleneck };}diff --git a/test/stats-cli.test.js b/test/stats-cli.test.jsindex 0a6f0f85..b85e5432 100644--- a/test/stats-cli.test.js+++ b/test/stats-cli.test.js@@ -51,10 +51,13 @@ function fixture(t) {test('[R1,R2,A1] stats JSON is versioned, text states the same proof numbers and neither records a move', async (t) => {const { root, board } = fixture(t);const before = store.events(board);- const expected = proofStats(board);+ const observationBefore = Date.now();const json = await run(root, ['stats', '--json']);assert.equal(json.code, 0, json.stderr);assert.equal(json.stderr, '');+ const observed = Date.parse(json.data.stats.flow.asOf);+ assert.ok(observed >= observationBefore && observed <= Date.now(), 'the CLI records its own observation clock');+ const expected = proofStats(board, { now: observed });assert.deepEqual(json.data, { version: 1, stats: expected });assert.deepEqual([expected.submissions, expected.rejections, expected.rejectionShare, expected.merged, expected.mergedWithoutAccept], [2, 1, 0.5, 1, 0]);const text = await run(root, ['stats']);@@ -75,7 +78,7 @@ test('[R2,A1] stats forwards the inclusive date window and returns an actionableconst { root, board } = fixture(t);const json = await run(root, ['stats', '--since', '2026-10-09', '--json']);assert.equal(json.code, 0, json.stderr);- assert.deepEqual(json.data.stats, proofStats(board, { since: '2026-10-09' }));+ assert.deepEqual(json.data.stats, proofStats(board, { since: '2026-10-09', now: Date.parse(json.data.stats.flow.asOf) }));assert.equal(json.data.stats.submissions, 0);assert.equal(json.data.stats.firstEventAt, null);const bad = await run(root, ['stats', '--since', '2026-02-30', '--json']);@@ -101,5 +104,9 @@ test('[R1,R2,A2] local HTTP state exposes exactly the command statistics', asyncconst command = await run(root, ['stats', '--json']);assert.equal(command.code, 0, command.stderr);assert.equal(document.version, 1);- assert.deepEqual(document.state.proofStats, command.data.stats);+ const observed = Date.parse(document.state.proofStats.flow.asOf);+ assert.deepEqual(document.state.proofStats, proofStats(board, { now: observed }));+ assert.deepEqual(command.data.stats, proofStats(board, { now: Date.parse(command.data.stats.flow.asOf) }));+ assert.deepEqual({ ...document.state.proofStats, flow: { ...document.state.proofStats.flow, asOf: command.data.stats.flow.asOf } },+ command.data.stats, 'the two observations retain every invariant field exactly');});diff --git a/test/stats-flow.test.js b/test/stats-flow.test.jsindex 14fd29eb..169417da 100644--- a/test/stats-flow.test.js+++ b/test/stats-flow.test.js@@ -92,6 +92,7 @@ test('flow numbers match a hand computation through rework, released reviews andconst { board, stats } = fixture(t, entries);const result = stats();assert.ok(result.flow, 'stats JSON carries event-derived flow');+ assert.equal(result.flow.asOf, at(200), 'all queue ages use this one recorded observation');assert.equal(store.getItem(board, 1).item_status, 'open', 'fixture rows cannot substitute for the event history');assert.deepEqual(result.flow.stages, {build: summary(4, 135, 33.75, 25),@@ -100,8 +101,8 @@ test('flow numbers match a hand computation through rework, released reviews andmergeWait: summary(2, 80, 40, 40),}, 'build samples80,40,10,5; wait30,10,5; review10,30,5; merge20,60');assert.deepEqual(result.flow.queues, {- open: { size: 3, oldest: { id: 3, ageMinutes: 160 } }, claimed: { size: 1, oldest: { id: 6, ageMinutes: 25 } },- submitted: { size: 1, oldest: { id: 7, ageMinutes: 10 } }, accepted: { size: 1, oldest: { id: 8, ageMinutes: 5 } },+ open: { size: 3, oldest: { id: 3, since: at(40), ageMinutes: 160 } }, claimed: { size: 1, oldest: { id: 6, since: at(175), ageMinutes: 25 } },+ submitted: { size: 1, oldest: { id: 7, since: at(190), ageMinutes: 10 } }, accepted: { size: 1, oldest: { id: 8, since: at(195), ageMinutes: 5 } },});assert.deepEqual(result.flow.daily, [{ date: '2026-10-10', added: 8, merged: 2 }]);assert.equal(result.flow.submitsPerMerged, 2.5, 'five submissions divided by two first merges');@@ -183,7 +184,7 @@ test('flow distinguishes expired and released reviews, open resets, legacy gaps];const { stats } = fixture(t, entries);const flow = stats().flow;- assert.deepEqual(flow.queues.open, { size: 2, oldest: { id: 5, ageMinutes: 50 } });+ assert.deepEqual(flow.queues.open, { size: 2, oldest: { id: 5, since: at(150), ageMinutes: 50 } });assert.deepEqual(flow.stages.reviewWait, summary(2, 40, 20, 20, 2), 'legacy review intervals are omitted; reopen has no closing reservation');assert.deepEqual(flow.stages.review, summary(2, 15, 7.5, 7.5, 2));assert.equal(flow.bottleneck.completedItems, 3);@@ -249,9 +250,9 @@ test('open age restarts on each return and equal queue ages choose the lower id[180, 'core-2', 'submit', 2, { commit: '2'.repeat(40) }], [185, 'coordinator', 'reopen', 2],[0, 'coordinator', 'add', 3, { lane: 'core' }], [10, 'core-3', 'claim', 3, { leaseUntil: at(190) }],];- assert.deepEqual(fixture(t, entries).stats().flow.queues.open, { size: 3, oldest: { id: 2, ageMinutes: 15 } });+ assert.deepEqual(fixture(t, entries).stats().flow.queues.open, { size: 3, oldest: { id: 2, since: at(185), ageMinutes: 15 } });assert.deepEqual(fixture(t, entries.filter(entry => entry[2] !== 'reopen'), 200).stats().flow.queues.open,- { size: 2, oldest: { id: 1, ageMinutes: 10 } });+ { size: 2, oldest: { id: 1, since: at(190), ageMinutes: 10 } });});test('active lane counts preserve recorded names that also exist on Object.prototype [R1,R2]', t => {@@ -273,3 +274,22 @@ test('recommendations name an empty target queue honestly and choose the busiest[150, 'coordinator', 'add', 4, { lane: 'web' }]];assert.equal(fixture(t, entries).stats().flow.bottleneck.recommendation, 'add a builder in web');});++test('every queue age has one exact observation clock and its recorded origin [R1,R2]', t => {+ const { stats } = fixture(t, [+ [1, 'coordinator', 'add', 1, { lane: 'core' }],+ [2, 'coordinator', 'add', 2, { lane: 'core' }],+ [3, 'core-2', 'claim', 2, { leaseUntil: at(1000) }],+ ]);+ const first = stats({ now: BASE + 200 * 60_000 });+ const second = stats({ now: BASE + 200 * 60_000 + 129 });+ assert.equal(second.flow.asOf, '2026-10-10T03:20:00.129Z');+ for (const state of ['open', 'claimed']) {+ const a = first.flow.queues[state].oldest;+ const b = second.flow.queues[state].oldest;+ assert.equal(b.since, a.since, 'a later read retains the exact lifecycle origin');+ assert.equal(b.ageMinutes, (Date.parse(second.flow.asOf) - Date.parse(b.since)) / 60_000);+ assert.equal(a.ageMinutes, (Date.parse(first.flow.asOf) - Date.parse(a.since)) / 60_000);+ assert.equal(b.ageMinutes, a.ageMinutes + 129 / 60_000);+ }+});