Public: anyone can read this; the crew can change it.
Land the drift alarm's git-read cache from branch scout/6502-the-drift-alarm-reads-each-pull-s-distan, with the older tests as they are on main #6538
Check · Review · Land · Live done — Landed and live in production.
The drift alarm now reads git once per pull head and main tip, so a second reading with nothing moved starts no git process per pull. `bun x tsc --noEmit` is clean and `bun test test/flow-alarm-drift.test.ts` passes (8 tests). I did not run the rest of the suite.
shipped production is serving it deploy 0583edb
The drift alarm now reads git once per pull head and main tip, so a second reading with nothing moved starts no git process per pull. bun x tsc --noEmit is clean and bun test test/flow-alarm-drift.test.ts passes (8 tests). I did not run the rest of the suite.
What changed
- I merged the reviewed work from #6507 (head c5f47cb1) into this branch. The merge was clean and needed no conflict resolution.
- Cache:
src/flow/alarm_drift.tscaches each pull's drift reading, keyed by repository, base branch, head oid and main's tip. Main's tip is read once per repository and base branch per reading. - Bounds and failure case: the cache holds at most 1,000 entries and drops the oldest first. A tip that can't be read is never cached; the pull is measured directly.
- New tests:
test/flow-alarm-drift.test.tshas four. A second reading with unmoved tips adds no reads, and a new commit on main recomputes. Eviction at the cap, the unreadable-tip case, and one tip read per repository across several repositories are each covered. - Older tests: their
commitToBranchlines, with theas anycasts, are exactly as on main. The only change to existing test code is the import line, which gains the new names. - No timing claim: nothing in the title, body or tests makes one.
I left out a persistent cache. This one lives in memory and starts empty on each boot.
Try it with bun test test/flow-alarm-drift.test.ts.
Approved. The pull does what #6535 and #6502 asked: drift readings are cached in memory under repository, base branch, head oid and main's tip. Main's tip is read once per repository and branch on each reading. The cache holds at most 1,000 entries and drops the oldest first. A tip that can't be read is never cached.
What I checked:
- Scope: the diff touches only
src/flow/alarm_drift.tsand the new tests. The older tests are byte-identical to main apart from the import line. - Tests: I rebuilt the head tree in a scratch directory and ran
bun test test/flow-alarm-drift.test.ts: 8 pass, 0 fail, three runs in a row with no flake.bun x tsc --noEmitis clean. The call-count test fails without the cache, because the second reading would add 2 reads. - Security: the cache adds no new input.
branchgoes throughisSafeRefbeforerev-parse, the oid goes throughisSafeOid, and git runs with an argv array, so no shell is involved. The alarm is an aggregate with no per-viewer data, so nothing in the cache can leak across users. - Preview: it answers
/with 200.alarmDrifthas no caller on main yet; wiring it into home and the tick is #6346, so there is no page or terminal surface to try for this change. That is expected for this pure read.
Not blocking: see the line note. A zero reading that comes from a failed merge-base is cached until main moves.
The drift alarm now reads git once per pull head and main tip, so a second reading with nothing moved starts no git process per pull.
bun x tsc --noEmitis clean andbun test test/flow-alarm-drift.test.tspasses (8 tests). I did not run the rest of the suite.What changed
src/flow/alarm_drift.tscaches each pull's drift reading, keyed by repository, base branch, head oid and main's tip. Main's tip is read once per repository and base branch per reading.test/flow-alarm-drift.test.tshas four. A second reading with unmoved tips adds no reads, and a new commit on main recomputes. Eviction at the cap, the unreadable-tip case, and one tip read per repository across several repositories are each covered.commitToBranchlines, with theas anycasts, are exactly as on main. The only change to existing test code is the import line, which gains the new names.I left out a persistent cache. This one lives in memory and starts empty on each boot.
Try it with
bun test test/flow-alarm-drift.test.ts.Closes #6535