Skip to content

observe-metrics: fit lines that grow with the fleet under 4096 bytes - #994

Merged
hhff merged 5 commits into
mainfrom
operator/obs-metrics-line-size
Dec 5, 2026
Merged

hhff merged 5 commits into
mainfrom
operator/obs-metrics-line-size

Conversation

@hhff

@hhff hhff commented Dec 4, 2026

Copy link
Copy Markdown
Member

Cause

A log line is at most 4096 bytes (LINE_MAX); appendLog dies on a longer one. Two writes in observe-metrics build text from the fleet's own words with no cap:

  1. The stuck-work digest (keepStuckDigest, run after the tick's recorded … line). It names up to ten stuck items by title and move words, and titles have no cap. Ten long ones pass 4096 bytes. writeStuckDigest catches the die, so the run goes on (devteam: log line is over 4096 bytes… then warning: the stuck-work digest was not written), but the owner's Inbox question is never asked. The report on main 8cb127d printed the 4096 message after recorded 41 spend line(s) and 6 new observation(s). Only writes after that line can explain it, so this is almost certainly the write that failed there. No observation was lost, and the tidy and moves cache that come after it still ran.
  2. observeFindings writes each metrics finding's detail as it is. move-stalled lists every goal waiting on a stuck root (N goals wait on it: "…", "…"), and every move finding carries a title. On a big fleet one detail can pass the limit. Here the die is not caught: it ends the whole tick, losing the remaining findings, the tick's line, the digest, the worktree tidy and the hub's moves cache. The checked spend and learning lines have fixed shapes.

Fix

  • fitObservation: an observation whose line wouldn't fit keeps the longest cut of its detail that does. The cut ends … (whole text: docs/devteam/run/observations/<hash>.txt), and that file holds the whole text. There is one file per source_key, rewritten each time, and the dir is registered via runPath. The fix hint is shortened only when even an empty detail can't fit.
  • Each finding's write runs under dieThrows. A line the log still refuses costs that one finding (with a warning), not the run.
  • The digest names as many of its first ten items as its line has room for and counts the rest (- +N more). Which items it names depends only on the items and the time, so the same/within checks read an asked digest back unchanged.

Kept small to stay clear of #982 (observe-metrics-fast): cmdObserveMetrics itself is untouched.

Tests

test/observe-metrics-line-size.test.mjs:

  • A goal with a ~3600-char title makes a move-owed finding. Before the fix observe-metrics exits 1 with the 4096 message. After it, the observation is written at ≤ 4096 bytes and names a file that holds the whole title.
  • 12 stuck tickets with 600-char titles. Before the fix the digest is never asked (the 4096 message, then the warning). After it, it is asked naming fewer than 10 items with the right +N more, its line is ≤ 4096 bytes, and the next run keeps it as is.

Mutation check: with the script reverted to main, both tests fail with the reported message. Nearby suites pass locally: wait-standing-digest, stalled-vs-waiting, next-moves-findings, observe-metrics-overdue, ooda-learning, every-report-findings, fleet-idle. One gap: no test covers the per-finding skip, because no fixture finding I found makes a line too long even with an empty detail and fix hint. Files in run/observations/ are bounded by the number of distinct oversized findings, and nothing prunes them yet.

Opened by the box operator.

🤖 Generated with Claude Code

hhff and others added 2 commits December 4, 2026 14:02
A log line is at most 4096 bytes (LINE_MAX), and two writes of the
supervisor's tick build text from the fleet's own words with no cap:

- observeFindings: a metrics finding's detail goes into its observation
  as is. move-stalled names every goal waiting on a stuck root ("N goals
  wait on it: ...") and every move finding carries a title nothing caps,
  so on a big fleet one detail passes the limit. appendLog then dies,
  and the die aborts the whole tick: the findings after it, the out line,
  the stuck-work digest, the worktree tidy and the hub's moves cache.
- the stuck-work digest names up to ten items by title and move words.
  Ten long titles pass the limit; the die is caught (a warning), so the
  owner's Inbox question is simply never asked. This is the write that
  failed on main 8cb127d after "recorded 41 spend line(s) and 6 new
  observation(s)" was printed.

Now an observation whose line would not fit keeps the longest cut of its
detail that does, ending "... (whole text: docs/devteam/run/observations/
<hash>.txt)", the whole text in that file (one per source_key, rewritten
each time); only when even an empty detail can't fit does the fix hint
give way. Each finding's write runs with dieThrows, so a line the log
still refuses costs that finding alone, with a warning. The digest names
as many of its first ten items as its line has room for and counts the
rest ("- +N more"), deterministic in the items and the time, so the
same-list and within-the-list checks read it back unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…data scrapes class lines)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hhff

hhff commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

PR #994 review a: observe-metrics lines over 4096 bytes (observation fitting + stuck-digest fitting)

  • Reviewer: operator-review-a (fresh subagent, claude-opus-5-5), not the author
  • Head: b4738a5
  • Date: 2026-12-04 UTC

What I ran vs only read

Ran (scratch clone, DEVTEAM_HUB_PORT set to a throwaway port, DEVTEAM_BOX=off, DEVTEAM_IMAGE_HUB unset, through testslot):

  • test/observe-metrics-line-size.test.mjs: 2/2 pass.
  • test/wait-standing-digest.test.mjs: 23/23 pass. test/next-moves-findings.test.mjs: 42/42 pass.
  • test/dashboard-data.test.mjs: 8/9. The failure is kit-595: one build ... reused for 20 s ("a read 21 s after the last build ended starts a new one", 1 !== 2), a timing test on a box at 84% CPU (another full run timed out at 600 s). Run alone it passed at this head twice, and once at origin/main. The PR doesn't touch the dashboard build cache. Box flake, not this PR.
  • Probe (fixture fleet, real CLI): three goals with titles near the goal line's own limit, multi-byte and escape-heavy: 'Emoji 😀é"\\' x228, 'Q"\\' x730, 'é😀' x608 (about 3.6 KB as JSON each). observe-metrics exited 0 with 3 new observations and no warning. Each raw line was 4096/4096/4095 bytes counting the newline, each detail ended in … (whole text: docs/devteam/run/observations/<16 hex>.txt), there was no lone surrogate in any detail or \ud8.. escape in any raw line, and each file held the whole title. A second run wrote 0 new observations, so dedupe on source_key still holds with a truncated detail.
  • Mutation: if (lineFits(fields, by)) return fields; -> return fields;. Test 1 went red. The run still exited 0 and warned the move-owed observation on goal:... was not written: log line is over 4096 bytes. That also shows a refused line now costs only its own finding. Restored afterwards, and git status was clean.
  • CI at head: test success (attempt 2: one flaky rerun, as reported), box-image success. 46/46 checks green.
  • observe-metrics: read findings at one sha (thousands of git processes per tick on a big fleet) #982 conflict check: git merge-tree of this head with observe-metrics: read findings at one sha (thousands of git processes per tick on a big fleet) #982's head (8b3662a) merges clean. observe-metrics: read findings at one sha (thousands of git processes per tick on a big fleet) #982 wraps collectMetrics(0) and nextMoves() in readsAtOneSha inside cmdObserveMetrics. This PR changes observeFindings/stuckDigestText/keepStuckDigest, and the writes still happen outside the read-at-sha caches. They don't clash in text or in behaviour.

Read only:

  • lineFits builds the line through logLineFor with an id of the real shape and serialises it with JSON.stringify, then measures Buffer.byteLength plus the newline. So the size check counts bytes, not characters, after escaping, envelope included, exactly what appendLog writes. redactClaimLinks (appendLog only) can only shrink the line.
  • The cut happens on the raw string before serialisation, so it can't split an escape. It drops a trailing high surrogate. The binary search is monotone.
  • Spill path: sha256(source_key) truncated to 16 hex, under runPath('observations'), so no traversal. run/ is gitignored, and observations joins RUN_KNOWN (kit-made, not moved).
  • Digest determinism: same() rebuilds stuckDigestText(items, asked_at). The fit depends only on the fields, so it reproduces the same shown. A changed order or title changes the text and re-asks as before. within() still reads +N more, and that now counts the trimmed items too, so "the list only shrinks" stays not re-asked.
  • Readers of detail that parse it (sensor-ignored, deploy*, package-*) are other detectors. Metrics observations' detail is only displayed or searched (findings/search/lineage), so the suffix breaks no reader. Weekly learning records are written separately and are unaffected.

Findings

Findings: none at Critical or Important.

Notes

  • Minor (spill files are machine-local, quality.md §3 "correct but worse"): run/observations/ isn't moved in a fleet move (RUN_KNOWN marks it kit-made), and other machines never see it, but the observation line that names it is synced. After a move, the "whole text:" path in old observations dangles. The files are also never pruned (one per source_key, and the keys include goal ids), which is slow litter. A note in the comment, or pruning files whose key is no longer seen, would close it.
  • Minor: in the digest, one title over about 3.3 KB makes shown fall to 0, so the owner gets only "- +N more" with no item named. Truncating each title in stuckLine (deterministically) would keep the list informative.
  • Minor (tests): no test covers multi-byte or escape-heavy truncation (my probe above does), the fix_hint fallback, or a second finding still being written after one is refused (the mutation shows it only by chance).
  • Nit: observeFindings sets dieThrows = false in finally rather than restoring the old value. That's harmless today because its only caller runs with it false.

Opened by the box operator.

Verdict: APPROVE b4738a5

@hhff

hhff commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

PR #994 review d1: delta since APPROVE at b4738a5 (main merge)

  • Reviewer: operator-review-d1 (fresh subagent), not the author
  • Head: ddcd3a8

What I checked

  • Merge shape: ddcd3a8 has two parents: b4738a5 (the approved head) and 2f5dd15 (origin/main, the kit-1202-upkeep-files-split: upkeep, next-moves and plain-words test files: none over 60 s, no test over 30 s #988 merge). The merge base is 8cb127d.
  • The merge resolved cleanly: git merge-tree --write-tree b4738a50 2f5dd15e gives tree cbda4bdd, which is the same as ddcd3a8's tree. No hand resolution and no extra edits went into the merge commit. No conflict markers.
  • The PR's own files are unchanged: git diff b4738a50 ddcd3a85 -- docs/devteam/scripts/devteam.mjs test/observe-metrics-line-size.test.mjs is empty.
  • What main changed: the 10 commits from 8cb127d to 2f5dd15 (kit-1202, upkeep test-file split) touch only test/ files: 76 files, mostly splits of existing test files into parts, plus test/lib/kit-1202-next-moves-findings.mjs. None of them touch devteam.mjs. So main made no change to cmdObserveMetrics, observeFindings, the observation write path, stuckItems or keepStuckDigest, and nothing on main can conflict with the 4096-byte line fit or the stuck-work digest fit.
  • Main's test parts that touch these paths: the split moved some tests that exercise observe-metrics and the stuck digest into new files: next-moves-findings.{output,owed}.test.mjs, exterior-plain.{names,stale}.test.mjs and ack-budget.inbox.test.mjs. I ran them against the merged head along with the requested files.

Tests (scratch clone at the head, DEVTEAM_HUB_PORT=4998 DEVTEAM_BOX=off, node test/run.mjs --file-timeout 900)

file result
test/observe-metrics-line-size.test.mjs ok (2/2)
test/wait-standing-digest.test.mjs ok
test/next-moves-findings.test.mjs ok
test/next-moves-findings.output.test.mjs ok
test/next-moves-findings.owed.test.mjs ok
test/exterior-plain.names.test.mjs ok
test/exterior-plain.stale.test.mjs ok
test/ack-budget.inbox.test.mjs ok

Totals: 8 files, 155 tests, 0 failed, exit 0.

Verdict: APPROVE ddcd3a8

Opened by the box operator.

@hhff

hhff commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

PR #994 review d2: delta since APPROVE at ddcd3a8

  • Reviewer: operator-review-d2 (fresh subagent, Claude Opus 5.5), not the author
  • Head: 0e4d38d
  • Date: 2026-12-05 15:33 UTC

What I ran vs only read

  • The merge, redone. Head 0e4d38d has parents ddcd3a8 (the approved head) and 4c002b7, which is origin/main now. I checked out ddcd3a8, ran git merge 4c002b73, and git merged docs/devteam/scripts/devteam.mjs with no conflict. The result has tree 82264057, the same as the head's. The operator added nothing to the merge.
  • How the merge joined the two observe-metrics changes (read at the head):
  • The PR's diff against main. git diff <old merge-base 2f5dd15e> ddcd3a85 and git diff origin/main 0e4d38d0 touch the same 2 files (+138/−11), and their +/− lines match exactly. The change is the one approved in d1.
  • Other main changes since 2f5dd15 (267 commits; read only):
    • Nothing on main changes LINE_MAX, lineFits/logLineFor, appendLog, STUCK_SHOWN/stuckLine/stuckItems, observeFindings or the observation schema.
    • log.schema.json gained only test-proof fields on another type.
    • The test/lib/kit.mjs changes add fixtureRun to bareProject/peekFixture/inboxFixture. This PR's test uses fleetFixture, which they don't touch.
    • observe-metrics: read findings at one sha (thousands of git processes per tick on a big fleet) #982 extended test/reads-at-a-sha.test.mjs with an observe-metrics subtest that compares the log written with live reads and with reads at one sha, line for line, and checks that nothing is written with a cache on. It covers this PR's path.
  • Tests at the head, one at a time via testslot, DEVTEAM_HUB_PORT set to a throwaway port, DEVTEAM_IMAGE_HUB unset. They ran on my redo-merge commit, whose tree is identical to the head's:
    • test/observe-metrics-line-size.test.mjs: 2/2 pass.
    • test/observe-metrics-overdue.test.mjs: 10/10 pass.
    • test/reads-at-a-sha.test.mjs: 7/7 pass, including "observe-metrics reads its findings at one sha … no write with a cache on". The first try hit the 600 s file timeout before any test finished, with the box at load average 115 on 32 cores. Rerun with --file-timeout 1800, it passed in 773 s.
  • Mutation. I dropped fitObservation(...) around the observation in observeFindings, so appendLog gets the raw fields. observe-metrics-line-size went red: test 1 failed with warning: the move-owed observation on goal:… was not written: log line is over 4096 bytes. Test 2 stayed green, since it covers the digest path. I restored the file and the tree is clean.
  • CI at the head, run 47532786441:
    • Attempt 1 failed only in kit (24, chrome 5/5), in test/thread-streaming.test.mjs "P8 the layout holds … 390x844: no bubble". That chrome layout check is in a file this PR doesn't touch and has nothing to do with observe-metrics, so I reran the failed jobs once.
    • Attempt 2 passed: every job green, including tests. box-image passed.

Findings

Findings: none.

Notes

  • Nothing new since d1: as before, no test covers the per-finding skip when a line can't fit even with an empty detail, and nothing prunes run/observations/.
  • The thread-streaming P8 layout failure in CI attempt 1 is a flake not on the list, and it passed on retry.

Opened by the box operator.

Verdict: APPROVE 0e4d38d

@hhff

hhff commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

PR #994 review d3: delta since APPROVE at 0e4d38d (flaky.json only)

  • Reviewer: operator-review-d3 (fresh subagent, Claude Opus 5.5), not the author
  • Head: aba6e35
  • Date: 2026-12-05 15:58 UTC
  • Previous APPROVE: review d2 (comment 7440538989) at 0e4d38d

What I ran vs only read

  • Parents of the head: git log -1 --format=%P aba6e35a gives 0e4d38d and ab7b533 (origin/main, merge of kit-1216-flaky-gate-triage: Flaky gate: every test that failed then passed at one commit since 2026-12-01 is named, and each is fixed upstream or quarantined with its cause #1018).
  • Redid the merge: checked out 0e4d38d detached, ran git merge ab7b5338, no conflicts. The resulting tree is ffbb2ae56eecde73139052f27516bd33b0ff18c8, the same as the head's tree, so the merge adds nothing by hand.
  • Main's delta: the merge-base of 0e4d38d and ab7b533 is 4c002b7 (0e4d38d's main parent). git diff --stat 4c002b73 ab7b5338 shows test/flaky.json | 34 +, 1 file, and nothing else (commits bc7a5b7, 31705e0, e85b6d1, ab7b533). git diff --stat 0e4d38d0 aba6e35a shows the same single file.
  • The PR's own diff is unchanged: git diff --stat ab7b5338 aba6e35a gives docs/devteam/scripts/devteam.mjs (+57/-11 net as before) and test/observe-metrics-line-size.test.mjs (+92). That is 2 files, +138/-11, the same as 4c002b73..0e4d38d0. The new flaky.json does not list test/observe-metrics-line-size.test.mjs or any test the PR changes, so the PR's code and tests are unaffected. I ran no local tests, because the delta is data the PR does not touch.
  • CI at the head: box-image passed. In attempt 1, run 47536992547 (test) failed on one job, kit (24, chrome 3/5): test/dashboard-library.viewer.bar.test.mjs, "the viewer bar: its sizes and order", failed on a :hover background colour (rgb(242, 242, 242)) and then passed on its retry. It is not listed in flaky.json, so the run fails by design. That test covers the dashboard Library viewer bar, which this PR's diff does not touch: no viewer, library or dashboard in it, and the hunks are in observeFindings/stuckItems/keepStuckDigest. I reran the failed jobs once (gh run rerun 47536992547 --failed), and attempt 2 passed. Both workflows are green at the head.

Findings

Findings: none.

Notes

  • The viewer-bar test is an unlisted flake on main's side, not this PR's. It may be worth a flaky.json entry or a fix under its own cause, outside this PR.

Opened by the box operator.

Verdict: APPROVE aba6e35

@hhff
hhff merged commit 34711a0 into main Dec 5, 2026
89 of 91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant