Repository navigation
observe-metrics: read findings at one sha (thousands of git processes per tick on a big fleet) - #982
Conversation
… sha The tick's metrics step called collectMetrics with git read live: each ticket's branch was resolved with its own rev-parse, several times over, and each open branch's reviews listed again and again. On a fleet of ~540 tickets that is thousands of git processes forked from a large node process per tick (sys-heavy), so observe-metrics ran past its caller's bound and supervisors skipped it, leaving spend and metrics lines stale. collectMetrics now runs inside readsAtOneSha, as ack and metrics already read it; the digest's and the hub cache's nextMoves reads too. Every write still comes after the caches are dropped. Fixture, 300 tickets / 150 branches / 30 worktrees / 40 scratch kit copies in run/: 116-123 s (6.5 s user, 24 s sys) before, 3.6-4.0 s (0.6 s user, 0.4 s sys) after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A real devteam-dev observe-metrics profile spent ~160 s in workerState, which filtered the whole log once per ticket. The lines are now grouped by writer once per read of the log (memo) and looked up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR #982 review a1: observe-metrics reads at one sha; workerState grouping
What I ran vs only read
Findings
Notes
Opened by the box operator. Verdict: APPROVE fe4cca7 |
No textual conflicts. log-unsynced's git log -1 of origin/chore-log and observe-metrics-overdue's byType/span reads run inside collectMetrics' readsAtOneSha phase: cached once each, nothing in the phase moves that ref, and neither finding writes the log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged origin/main (8cb127d, which includes #980 observe-metrics-overdue, #984 and #983 log-unsynced) into this branch as a1e391b. This was a merge, with no rebase and no force-push. Conflicts: none in the text. I still checked how main's new code behaves inside this PR's read phases:
PR body: following the approval's Minor, "Every write" is now "Every log write". The body also says that collectMetrics' own cache files are still written inside the phase. Tests (node test/run.mjs, local, DEVTEAM_BOX=off): reads-at-a-sha 7/7, next-moves-findings 10/10, observe-metrics-overdue 9/9, log-unsynced 5/5, every-report-findings 42/42. All pass. Opened by the box operator. |
Conflict in test/next-moves-findings.test.mjs: kit-1202 moved A9-A12 to test/next-moves-findings.output.test.mjs and its siblings. Took main's side, and carried this PR's one change there: the source-shape assertion on cmdObserveMetrics' last statements expects writeMovesCache(readsAtOneSha(() => nextMoves())). devteam.mjs had no change on main since the last merge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged origin/main again (2f5dd15, which includes #988 kit-1202) into this branch as 8b3662a. This was a merge, with no rebase and no force-push. Conflict: CI at a1e391b: the 3 failures were the known flaky browser e2e tests, not this PR. Tests (local, DEVTEAM_BOX=off): reads-at-a-sha 7/7, next-moves-findings 9/9, next-moves-findings.output 10/10, observe-metrics-overdue 10/10, log-unsynced 9/9, every-report-findings 5/5. All pass. Opened by the box operator. |
PR #982 review d1: delta since APPROVE at fe4cca7 (two main merges: #980, #983, #984, #988)
What I ran vs only readRan, in a scratch clone at the head with DEVTEAM_HUB_PORT set to an unused port, DEVTEAM_BOX=off and DEVTEAM_IMAGE_HUB unset, using
Read only:
FindingsFindings: none. Notes
Opened by the box operator. Verdict: APPROVE 8b3662a |
PR #982 review d2: delta since APPROVE at 8b3662a
Delta review. The last approval was d1, What I ran vs only read
FindingsFindings: none. Notes
Opened by the box operator. Verdict: APPROVE 6effc7a |
Cause
On devteam-dev (kit v0.114.0, ~540 tickets, ~760 branches, ~60 worktrees),
observe-metricsran 30+ minutes and its caller's bound killed it. A second run, with the spend backlog already written, printed nothing in 30 min: 2m49s user, 6m58s sys. Supervisors skip a step that slow, and spend lines and metrics observations went stale for days in 3 fleets.The step reads its findings through
collectMetrics(0)with git read live. Without the read cache, each ticket's branch is resolved by its owngit rev-parse --verify refs/heads/ticket/<id>^{commit}(and theorigin/one), several times per ticket. Each open branch'sreviews/folder is also listed several times. With 120 tickets in a fixture that came to 1,863 git processes in one tick, about 15 per ticket. Each one is forked from a node process holding the fleet's large log in memory, and that is where the sys time goes.metrics,statusandackalready avoid this withreadsAtOneSha/ theGIT_READ_ONLYcache.observe-metricswrites, so it never turned the cache on.Scratch folders in run/ and the worktrees themselves were not the cause. 40 kit-copy scratch dirs and 20 worktrees changed nothing measurable in a second run. The per-worktree tidy only runs every 30 min.
Change
cmdObserveMetricsnow does three reads insidereadsAtOneSha, the read phaseackalready uses for the samecollectMetrics(0):collectMetrics(0)(the findings)nextMoves()nextMoves()Each git question is asked once, ticket refs resolve from one
for-each-ref, and each open branch's reviews are listed once per phase. Every log write (observations, the digest) happens after the caches are dropped, so it never acts on a stale read; the moves cache file is written after them too. (collectMetrics' own cache files are still written inside the phase.)The real run's CPU profile (devteam-dev, v0.114.0)
node --cpu-profof one observe-metrics on devteam-dev: 2,554 s sampled (SIGINT at 25 min, exit at 42m35s; 4m07 user, 8m41 sys). 2,235 s (87%) is the self time ofspawnSync, the synchronous git processesgit()starts. All of it is undercollectMetrics(2,318 s) plusnextMoves/writeMovesCache. Top 10 by total time (function:line in v0.114.0's devteam.mjs):git showper review file (no batch outside a read phase)rev-parseper ref (no for-each-ref listing)Below those:
workerState163 s (57 s self, plus a 105 s filter of the whole log once per ticket),nextMoves160 s,writeMovesCache59 s,tidyFinishedWorktrees38 s,readLog/foldLog39 s. The only synchronous fs time of note wasreadFileSync(23 s). Nothing walked run/ or the worktrees' files.The whole read side is the git work that
readsAtOneShaexists to share (reviewMemo, batchedcat-file, onefor-each-ref, a tree index per commit). Every hot path above is inside one of the three calls now wrapped. The second commit groups the log's lines by writer once per read (workerState, ~160 s in the profile), with the same lines in the same order.Timings (fixture, through the test harness)
300 tickets, 150 ticket branches, 30 worktrees, 40 kit-copy scratch dirs in run/. The old and new kit ran alternately on the same fixture:
With 120 tickets, the git processes in a second tick went from 1,863 to 300. The remaining ~1 per ticket is one listing per open branch per read phase.
Tests
test/reads-at-a-sha.test.mjs, new subtest.observe-metricswith live reads (DEVTEAM_TEST_LIVE_READS=1) and at one sha, under a frozen clock, must:DEVTEAM_TEST_READ_CACHE_TRACE)Mutation check: with the
collectMetricswrap removed, the subtest goes red ("no ticket ref asked one at a time").test/next-moves-findings.test.mjs: the source-shape assertion on the last statements ofcmdObserveMetricsnow expectswriteMovesCache(readsAtOneSha(() => nextMoves())).Locally, all 19 test files that call
observe-metricspass (423 tests), andnext-moves-findingspasses again after its update.Not tested: a run against a real fleet (by design); the profile above is from the operator's profiled run, read read-only. The
workerStategrouping has no test of its own: it is CPU only, gives the same lines in the same order, and is covered by the suites that read worker state (components G1 goldens, next-moves, fleet-idle, worktree-tidy, ooda-learning, reads-at-a-sha: all pass locally).Not in this PR (separate causes, found on the way)
metrics --jsonas the operator role also timed out at 300 s on devteam-dev. That command already reads git cached. The likely cost is spend parsing:usageCache().save()skips the operator, so every operatormetricsre-parses all of the fleet's Claude Code transcripts (~8,200 files, ~10.9 GB).cachedParse'sreadFileSync(f, 'utf8')throws on every tick. The file is read whole each time and parsed as empty, so the supervisor's spend goes unmeasured.Both need their own PR.
Opened by the box operator.
🤖 Generated with Claude Code