Skip to content

test(dash,statusline): make two timing guards relative to the runner's speed - #693

Merged
amiddavid merged 3 commits into
mainfrom
test/flaky-timing-guards
Oct 25, 2026
Merged

amiddavid merged 3 commits into
mainfrom
test/flaky-timing-guards

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

Fixes 2 of the 3 flaky timing tests from #674 (the third, the watchdog race test, was
already fixed by #684 and is not touched here). Written by GLM through Claude Code.

Both guards asserted on wall-clock time. A loaded CI runner stretches the clock, so
they failed with nothing wrong in the code. Each guard now measures the runner's own
speed first and asserts relative to it. Each still catches its regression, proven by
mutation on the eval box.

What changed

  • proxy/dash_test.go — TestDashboardAddsNoRequestLatencyWithContentCapture
    • Before: the budget was min(max(5 ms, 20% of the baseline), 30 ms). The 30 ms cap
      read 32.6 ms of paired noise on a 517 ms CI baseline and failed (test(proxy): make the dashboard latency guard robust on a loaded runner #576 tried to fix
      this and it still flaked).
    • After: the budget is max(5 ms, 20% of the baseline), no cap. The redaction
      regression this guard exists for is request-path CPU work, so on a loaded runner it
      stretches with the same load factor that stretched the baseline, and stays far
      above 20% of it.
    • TestLatencyBudgetStillCatchesTheRedactionRegression pins that at baselines from
      1 ms to 5 s through regressionAt.
  • context-guru-plugin/statusline_golden_test.go — TestStatuslineFinishesInHalfASecondOnASlowProxy
    • Before: a flat 0.5 s wall limit. Python start-up alone can eat most of that on a
      loaded runner; it failed on main on 2026-10-22.
    • After: the test measures the runner's floor first (median of 3 renders against a
      stub that answers at once — the same Python start-up and render work), then allows
      that floor plus 1 s. The 1 s covers the script's own 0.36 s render budget with
      stretch room. A status line that really waits on the proxy pays its full 5 s sleep.

How it was tested

Every run on the eval box, folder glm674 (the change) and glm674-mut (the change
plus a mutation that brings the regression back):

Run Copy Result
gofmt -l proxy context-guru-plugin (as /usr/local/go/bin/gofmt) glm674 clean
go vet ./proxy/... ./context-guru-plugin/... glm674 ok
The 2 changed dash tests glm674 PASS — baseline 60.8 ms, added 1.1 ms, budget 12.2 ms
The changed statusline test glm674 PASS — floor 71-77 ms, limit ~1.07 s, slow runs inside it
Mutation: e.Redact() back in dashcapture.go finish glm674-mut FAIL as it must — added 79.9 ms vs budget 12.5 ms
Same mutation, GOMAXPROCS=2 glm674-mut FAIL as it must — added 82.4 ms vs budget 13.3 ms on a 66.5 ms baseline
Mutation: statusline.py render budget and HTTP timeout lifted to 30 s glm674-mut FAIL as it must — every slow run 5.08 s vs limit ~1.07 s, exit code 0
go test -race -count=1 ./proxy/... glm674 PASS (418.8 s)
go test -race -count=1 ./context-guru-plugin/... glm674 PASS except the 2 known box failures (TestInstallRefusesAnUnverifiedDownload, TestInstallReportsPATHFromTheSourceFallbackToo — the box has a root-owned /usr/local/bin/context-guru-proxy; they fail on unmodified main too)

Closes #674

🤖 Generated with Claude Code

…s speed

Both guards flaked on the loaded CI runner with nothing wrong in the
code (#674): a flat 30 ms cap read 32.6 ms of paired noise on a 517 ms
baseline, and a flat 0.5 s wall limit lost to Python start-up alone.

- dash: the budget is now max(5 ms, 20% of the request's own median),
  with no absolute cap. The redaction regression this guard exists for
  is request-path CPU work, so on a loaded runner it stretches with
  the same load factor that stretched the baseline and stays far above
  20% of it. TestLatencyBudgetStillCatchesTheRedactionRegression pins
  that at baselines from 1 ms to 5 s.
- statusline: the limit is now the runner's own floor (median of 3
  renders against a stub that answers at once, Python start-up
  included) plus 1 s of allowance. A status line that really waits on
  the proxy pays its full 5 s sleep and clears the limit many times
  over.

Written by GLM (rits/zai-org/glm-5-3) through Claude Code

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 88618dd18c4a blocking

Verdict: blocking

Findings

  1. proxy/dash_test.go:418 — with the 30 ms cap removed, the guard can pass while the redaction regression is present

    • What fails: on a runner like #674's (baseline 517-546 ms), the budget is 20% of the baseline, so 103-109 ms. The regression costs ~53 ms at the idle baseline. If that runner's load stretches the baseline by scheduler delay and not by CPU starvation, the redaction stays near 53-80 ms. It stays under the budget. TestDashboardAddsNoRequestLatencyWithContentCapture passes with the defect it exists to catch.
    • Proof: the safety claim is "it stretches with the same load factor" (dash_test.go:414-416, and regressionAt at :436-442). Take it literally at the #674 baseline: the load factor is 517 ms / 1.5 ms ≈ 345x, so the redaction would present as ~18 s per request. That has never been observed for CPU work on a 16-core box, and the test would run for minutes on its ON side. So the model cannot be literal. The real stretch factor is unmeasured. The base commit said the cap existed exactly to prevent this: "The cap is what keeps a slow runner from hiding the regression this guards (about 53 ms)". TestLatencyBudgetStillCatchesTheRedactionRegression (:444) only re-derives regressionAt's own arithmetic. It cannot fail while the model is wrong, so it pins nothing about a real runner.
    • Fix: pick one, in order of strength. (a) Measure the redaction under real load once, and validate or replace the scaling model. (b) Reinstate a cap above the observed noise and below the regression floor — 45-50 ms (noise read 32-36 ms on #674's runner, regression floor 53 ms; the margin is thin, which is a reason to measure first). (c) As #674 itself proposed, apply the absolute check only when the baseline is near the 1-2 ms the test was written for.
  2. context-guru-plugin/statusline_golden_test.go:1371 — the same flat 0.5 s wall limit stays in sibling asserts, so the #674 status-line flake is only partly fixed

    • What fails: TestStatuslineMoneyShowsWhenCachestateIsSlowerThanTheRender still fails on a slow runner with nothing wrong. Its stub sleeps 700 ms on /api/cachestate (:1330-1335), longer than the 0.36 s render budget, so the first renders of its loop pay Python start-up plus the full budget window — the same shape as the test this PR fixes. The old limit in the fixed test was start-up + ~0.41 s against a flat 0.5 s; line 1371 has the identical arithmetic. The PR's own comment states the cause: "on a loaded CI runner Python start-up alone eats a large part of a second" (:1000-1001).
    • Proof: statusline_golden_test.go:1371 (elapsed > 500*time.Millisecond) with the 700 ms stub at :1330; the SIGALRM net bounds the render itself at 0.41 s (statusline.py:1805), so elapsed ≈ start-up + 0.41 s, over 0.5 s whenever start-up passes ~90 ms. Lines 710, 765 and 1251 carry the same flat 500 ms limit against fast stubs, so they are exposed too when start-up alone nears 0.5 s.
    • Fix: apply the same floor-plus-allowance shape at :1371 (or drop the wall assert there and keep the functional 8 s loop). For :710, :765 and :1251, either the same treatment or a tracked decision that their headroom is enough.

Non-blocking

  • The test name TestStatuslineFinishesInHalfASecondOnASlowProxy no longer matches what it enforces (floor + 1 s). The comment explains it, so this is a naming point only.
  • slowAllowance = time.Second is ~2.8x the 0.36 s budget window it covers. The comment says "with room ... to stretch" but not why 1 s is the right multiple. One sentence would help the next reader.
  • regressionAt multiplies durations (off * redactionCostAtIdle); it overflows only past a ~170 s baseline, which the pinned list never reaches. Fine as is.

What I checked

  • The full diff of head 88618dd against base 1953b47 (one commit, two test files).
  • proxy/dash_test.go around the change: latencyBudget, regressionAt, the pinning test, and the main guard test. I recomputed the budget and the model at every pinned baseline (1 ms, 2 ms, 50 ms, 100 ms, 331 ms, 571 ms, 5 s) — the arithmetic is correct; my finding is about whether the model matches a real runner.
  • context-guru-plugin/statusline_golden_test.go in full, plus the helpers it uses (runStatusline, routedEnv, sandboxEnv, cgStub) in plugin_test.go.
  • statusline.py: RENDER_BUDGET_SECONDS (0.36), _remaining, _http_get, the SIGALRM net at :1805, and the cache paths (_stats_cache_path, cachestate keys). Cache keys include the port, so the floor renders against the fast stub cannot warm the slow server's cache keys — the floor/slow comparison is clean.
  • The statusline test's timing arithmetic: the slow render is bounded at start-up + ~0.41 s by the itimer, so floor + 1 s leaves ~0.6 s of margin. Sound.
  • Issue #674 (the flake report this PR answers), including its proposal for the latency guard.
  • No tests were run (live tests not approved). All conclusions come from code reading and arithmetic.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 88618dd18c4a blocking

Verdict: blocking

Findings

  1. proxy/dash_test.go:418 — the latency guard no longer catches a fixed added cost on a slow runner
    • What fails: the test promises "It fails if the dashboard adds a perceptible cost" (dash_test.go:411). With the 30 ms cap removed, any added cost under 20% of the runner's baseline now passes. A cost that waits rather than computes — a synchronous flush, a lock, a channel send with a timeout — does not stretch under CPU load, so it keeps its idle size while the budget grows with the baseline. On the #674 CI runner cited in the comment (baseline 517-546 ms, dash_test.go:413) the budget is 103-109 ms. A fixed 40 ms cost passes there. The base version caught it on every runner: 40 > 30.
    • Proof: latencyBudget(517ms) = 517/5 = 103.4 ms, uncapped (dash_test.go:418-424). Base version: min(max(5ms, 103.4ms), 30ms) = 30 ms. So for every fixed cost C with 30 ms < C ≤ 0.2 × baseline, the base test failed and this test passes. The comment's defense — "it stretches with the same load factor" (dash_test.go:414-416) — covers CPU-bound costs only, and states a model, not a measurement. TestLatencyBudgetStillCatchesTheRedactionRegression cannot check the model: regressionAt (dash_test.go:436) is built from the same assumption as the budget, so the test compares the model with itself. The base comment said "If a runner's paired noise ever nears the cap, raise it rather than removing it" (1953b47, dash_test.go:414-415); this PR removes it.
    • Fix: keep an absolute ceiling and raise it, as the base comment instructed. The #674 noise (32-36 ms paired) and the guarded regression (53 ms of CPU work, whose wall time never drops below its idle cost) are separable: a ceiling near 45 ms sits above the observed noise and below the regression on every runner. Better: set the ceiling from the measured spread of the diffs samples — the residual paired noise is the quantity that actually flaked #674, and it is what a ceiling must track. For the redaction regression itself (CPU work on a CPU-saturated runner) the new guard probably still holds; the loss is the general promise and any future cost that waits instead of computing.

Non-blocking

  • statusline_golden_test.go:1007 — the name TestStatuslineFinishesInHalfASecondOnASlowProxy now describes the script's budget, not the wall limit (floor + 1 s). The comment explains this well; a reader skimming test names may still be misled.
  • statusline_golden_test.go:1040 — the comment "later ones find whatever the earlier ones left" is wrong, and was wrong before this PR: runStatusline pins a fresh TMPDIR and XDG_CACHE_HOME per call (plugin_test.go:2085), so every render starts cold. Worth fixing while the line is being touched.
  • dash_test.go:437 — off * redactionCostAtIdle overflows int64 for a baseline above ~174 s and then clamps to 53 ms. Unreachable in practice (the test would time out long before); noted only because the helper invites larger sample baselines.

What I checked

  • Read the full diff (2 files, test-only) and the code around every change; read docs/design.md and both CLAUDE.md files first.
  • TestStatuslineFinishesInHalfASecondOnASlowProxy: the floor is the median of 3 renders against an instant stub with the same stdin, layout and script, so it measures the same work minus the waiting. runStatusline gives each render a fresh TMPDIR/XDG_CACHE_HOME, and the fast stub runs on a different port than the slow server, so no cache or lock file crosses between floor and slow renders. Verified the script side: RENDER_BUDGET_SECONDS = 0.36 with _T0 set at import (statusline.py:75-77), reads sized from the remaining budget with a 20 ms floor (statusline.py:363), a SIGALRM hard net at 0.41 s (statusline.py:1805), and the detached refresher spawned with DEVNULL and start_new_session (statusline.py:913-915) so it cannot hold CombinedOutput. The slow-versus-floor delta is bounded near 0.41 s; the 1 s allowance gives ~2.4× headroom, and a render that truly waits pays the full 5 s. The floor approach is sound.
  • latencyBudget/regressionAt: checked the arithmetic at every sampled baseline by hand (1 ms, 2 ms, 50 ms, 100 ms, 331 ms, 571 ms, 5 s — the unit test passes, and the two floor/relative assertions match the new behavior). The old and new budget values at the #674 baseline are the proof of finding 1.
  • Grepped the repo: no leftover references to maxAddedLatency, and no doc mentions the 30 ms cap, so nothing else depends on the removed ceiling.
  • Confirmed the base versions of both tests (1953b47) to separate new behavior from pre-existing comments.
  • No live tests were run (not approved); Go is not installed on this machine.

… wall limit

Round 2 of #693. Both reviewers blocked the capless budget: on a slow
runner a fixed added cost passes under 20% of a large baseline, and the
"stretches with the same load factor" defence was a model, never
measured.

proxy/dash_test.go:
- latencyBudget keeps its relative part but is capped again, at
  maxAddedLatency = 45 ms: above the 32-36 ms of paired noise the #674
  CI runner showed with nothing wrong, under the guarded regression's
  53 ms floor (CPU work that load can stretch but never shrink). A cost
  that waits instead of computing (a lock, a flush, a channel send)
  keeps its idle size, and the cap catches that on every runner too.
- regressionAt and its load-factor model are gone. The pinning test
  checks the plain 53 ms regression against the budget at baselines
  from 1 ms to 5 s (517 ms added to the list), and pins the cap itself.

context-guru-plugin/statusline_golden_test.go:
- every flat 0.5 s wall limit is gone, not just the one fixed in round
  1. A shared statuslineFloor helper measures the runner's own floor
  (median of 3 renders against a stub that answers at once); the limit
  is floor plus statuslineAllowance (1 s: the 0.36 s render budget
  window, about 2.4x stretch room). Applied to the money, agent-names,
  weekly-tip and slow-cachestate tests; the slow-proxy test now uses
  the shared helper too.
- TestStatuslineFinishesInHalfASecondOnASlowProxy renamed to
  TestStatuslineFinishesWithinItsBudgetOnASlowProxy: the name said
  0.5 s after the limit had stopped being 0.5 s.
- the wrong "later ones find whatever the earlier ones left" comment is
  fixed: runStatusline pins a fresh TMPDIR per call, so every run
  starts cold.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 2 — both blocking findings fixed

Commit: ad85d0fc (on top of 88618dd1, no force-push). Only the 2 test files changed.

Reviewer 1, finding 1 / Reviewer 2, finding 1 — the capless latency budget

Fixed. You were right that the load-factor claim was a model, not a measurement, and that it
says nothing about a cost that waits instead of computing.

  • latencyBudget is capped again: maxAddedLatency = 45 ms. That is above the observed paired
    noise (32-36 ms on test: 3 timing tests flake on the CI runner (watchdog race, latency guard, status line) #674's runner, nothing wrong) and under the regression's floor (53 ms of CPU
    work, which load can stretch but never shrink). A fixed cost — a lock, a flush, a channel send —
    keeps its idle size, so the cap catches it on every runner, exactly as you both argued.
  • regressionAt and the "stretches with the same load factor" claim are gone, in the code and the
    comments.
  • TestLatencyBudgetStillCatchesTheRedactionRegression now checks the plain 53 ms regression
    against the budget at baselines 1 ms, 2 ms, 50 ms, 100 ms, 331 ms, 517 ms, 571 ms and 5 s,
    and pins the cap itself (latencyBudget(517ms) == 45ms). At 517 ms and at 5 s the budget is the
    45 ms cap, so the 53 ms regression is over it.

Proof on the eval box, all against ad85d0fc:

  • Both dash tests pass -count=10. Clean run: baseline 60.8 ms, added 0.59 ms, budget 12.2 ms.
  • Mutation (e.Redact() back in dashcapture.go finish): FAILS. Added 81.6 ms vs budget
    12.2 ms. Under GOMAXPROCS=2 (slow-runner shape) it also fails: added 82.7 ms vs budget 13.8 ms
    on a 68.8 ms baseline — the cap, not the relative part, is what holds there.

Reviewer 1, finding 2 — the flat 0.5 s wall limits in sibling status-line tests

Fixed, at all four sites (1371, 710, 765, 1251), not just 1371.

  • A shared statuslineFloor helper measures the runner's own floor: the median of 3 renders
    against a stub that answers at once. Every wall assert in the file is now
    floor + statuslineAllowance (1 s: the 0.36 s render-budget window with about 2.4x stretch
    room). No flat number is left.
  • Line 1371 (TestStatuslineMoneyShowsWhenCachestateIsSlowerThanTheRender): the floor stub serves
    the same payloads on a different port, so its cache keys cannot warm the slow server's.
  • Lines 710 and 765: the floor is the same render shape — for the agent-names test, the same
    5,000 files and 2 MB blob, so the floor carries that work too.
  • Line 1251 (TestStatuslineGoldenWeeklyTip): one floor per test, against scratch state so the
    floor runs cannot write into a case's state directory. The 15 cases differ only in state files
    and flags, which do not change the cost shape.

Proof: all five touched status-line tests pass -count=10 (95.9 s total). Mutation
(RENDER_BUDGET_SECONDS and HTTP_TIMEOUT_SECONDS lifted to 30 s): FAILS. Every slow-proxy
render reads 5.08 s against a limit of floor ~73 ms + 1 s, and the cachestate test fails too (no
refresher is spawned, so the stale .tmp/lock cleanup it asserts never happens).

Non-blocking notes (both reviewers)

  • Test name — TestStatuslineFinishesInHalfASecondOnASlowProxy is renamed to
    TestStatuslineFinishesWithinItsBudgetOnASlowProxy.
  • Why 1 s — the statuslineAllowance comment now states the arithmetic: it covers the 0.36 s
    budget window (SIGALRM net near 0.41 s) with about 2.4x stretch room; a render that truly waits
    pays seconds.
  • regressionAt overflow — moot: regressionAt is deleted.
  • Reviewer 2, the wrong "later ones find whatever the earlier ones left" comment — fixed:
    runStatusline pins a fresh TMPDIR per call, so every run starts cold.

Full box-run record

Run Result
gofmt -l (full path), go vet both packages clean
Changed dash tests, -count=10 PASS (57.2 s)
Changed status-line tests, -count=10 PASS (95.9 s)
Mutation A: e.Redact() on the request path FAIL, as it must (81.6 ms vs 12.2 ms)
Mutation A under GOMAXPROCS=2 FAIL, as it must (82.7 ms vs 13.8 ms)
Mutation B: budgets lifted to 30 s FAIL, as it must (5.08 s renders; refresher never spawns)
go test -race ./proxy/... (detached) PASS, 418.0 s
go test -race ./context-guru-plugin/... (detached) Only the 2 known box failures (TestInstallRefusesAnUnverifiedDownload, TestInstallReportsPATHFromTheSourceFallbackToo, root-owned /usr/local/bin/context-guru-proxy on the box). Same as on origin/main; not related to this change.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 ad85d0fc3db2 approve

Verdict: approve

Findings

None.

Earlier findings

  1. Mine, round 1, finding 1 (capless latency budget) — fixed. latencyBudget is capped again at maxAddedLatency = 45 ms (dash_test.go:415). I recomputed the budget at every baseline the pinning test lists: 1 ms → 5 ms, 2 ms → 5 ms, 50 ms → 10 ms, 100 ms → 20 ms, 331 ms → 45 ms, 517 ms → 45 ms, 571 ms → 45 ms, 5 s → 45 ms. All are under the 53 ms regression floor, on every runner, with no load-scaling assumption left in the code — regressionAt and the "same load factor" claim are gone. The cap sits above the 32-36 ms paired noise from #674's runner, and the comment says what to do if noise ever nears it. This is my round-1 fix option (b), and the author added mutation runs on the eval box (redaction on the request path fails at 81.6 ms and, under GOMAXPROCS=2, at 82.7 ms), which is the measurement I asked for in option (a). Accepted.
  2. Mine, round 1, finding 2 (flat 0.5 s wall limits in siblings) — fixed. All four sites now use a floor plus statuslineAllowance, through a shared statuslineFloor helper (median of 3 renders against an instant stub): TestStatuslineGoldenMoney (:662), TestStatuslineAgentNamesAreBounded (:766, floor re-runs the same 5,000-file listing), TestStatuslineGoldenWeeklyTip (:1206-1225, scratch state so the floor cannot write into a case's state dir), and TestStatuslineMoneyShowsWhenCachestateIsSlowerThanTheRender (:1415, floor stub on a different port, so its cache keys cannot warm the slow server's). I checked each floor matches its cases' render shape (same script, args, stdin, stub payload). Accepted.
  3. Reviewer 2, round 1, finding 1 — fixed the same way (agree with reviewer 2; I verified the cap myself above). Reviewer 2's extra point, that the capless budget also hid costs that wait instead of computing, is answered by construction: the budget never exceeds 45 ms, so any fixed cost above 45 ms fails on every runner.
  4. Non-blocking notes from round 1 — all addressed. The test is renamed TestStatuslineFinishesWithinItsBudgetOnASlowProxy; the statuslineAllowance comment now states the arithmetic (0.36 s window, SIGALRM net near 0.41 s, ~2.4x room); regressionAt's overflow note is moot (deleted); the wrong "later ones find whatever the earlier ones left" comment is replaced with the correct fact — I verified it: runStatusline calls t.TempDir() per render, and each call returns a unique directory, so every render starts cold.

Non-blocking

  • statusline_golden_test.go:115 — TestStatuslineGoldenOutput still asserts a flat elapsed > time.Second, and the helper comment at :1018 says "every wall assert in this file is such a floor plus statuslineAllowance". That sentence now overstates: one flat assert remains. The assert itself is low risk (instant stub, about 2x the headroom the 0.5 s ones had, and it is not in #674's flake list). Convert it, or narrow the comment to "every 0.5 s wall limit".
  • The 45 ms cap is 9-13 ms above the one observed noise sample (32-36 ms). The comment already instructs raising it if noise nears. Nothing to change now; noting the margin is thin by design.

What I checked

  • Last review: round 1, 88618dd, 2026-10-25T10:34:56Z
  • New commits read: 1 — ad85d0fc "test(dash,statusline): cap the latency budget, floor every statusline wall limit" (plain descendant of my round-1 sha, no force-push; only the two test files changed)
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files)
  • New items since my last review, and what I did about each:
    • Commit ad85d0fc: read the full diff and the code around every change. Checked the cap arithmetic at all eight pinned baselines and the three extra budget assertions; checked the error-message format verbs against its arguments (5 and 5); grepped for leftover regressionAt/slowAllowance/idleRequestMedian references (none).
    • Author's round-2 comment (2026-10-25T11:09:13Z): read in full. Checked each code claim in the diff myself — cap value and placement, the 517 ms baseline added to the pinning list, the shared statuslineFloor helper, all four wall-assert sites, the rename, and the corrected cold-start comment. The box-run record (clean runs, both mutations failing, -race runs) I could not re-run — live tests are not approved — so I verified the code side of each claim instead; nothing in the record contradicts the code.
    • Reviewer 2's round-1 review (posted 2026-10-25T10:35:21Z): read now, after my round-1 post, as the rules require. Its finding matches my finding 1 in substance; verified fixed as described above.
  • Re-verified the load-bearing facts from round 1 that the new code leans on: t.TempDir() returns a unique directory per call (so runStatusline renders start cold); cache keys include the port (floor stubs cannot warm the slow servers' keys); the SIGALRM net at statusline.py:1805 bounds a budget-missing render near 0.41 s against a 1 s allowance.
  • No tests were run (live tests not approved). All conclusions come from code reading and arithmetic.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 ad85d0fc3db2 blocking

Verdict: blocking

Findings

  1. context-guru-plugin/statusline_golden_test.go:115 — one flat wall limit survives the sweep, and the new invariant comment is false
    • What fails: TestStatuslineGoldenOutput still asserts elapsed > time.Second (statusline_golden_test.go:115) — a flat wall limit, the exact flake class this PR removes (issue #674: on a loaded runner Python start-up alone eats a large part of a second). All 13 subcases carry it. The new statuslineFloor doc comment claims "every wall assert in this file is such a floor plus statuslineAllowance" (statusline_golden_test.go:1018), and the PR comment says "No flat number is left". Both are false: lines 716, 1068, 1299 and 1427 use floor + statuslineAllowance; line 115 does not. A maintainer trusting the invariant will not look there when it flakes.
    • Proof: grep of the file for wall asserts: line 115 is the only one not written against a floor. It predates this PR (base 1953b47, line 114), so the commit message's literal claim — "every flat 0.5 s wall limit is gone" — stays true; the false statements are the new comment at :1018 and the PR reply. The exposure is real but smaller than the 0.5 s sites: the threshold is 1 s, double the limit that flaked, and the stubs answer at once. Still, on the #674 runner a start-up near 0.9 s puts 13 renders within 10% of the limit.
    • Fix: give TestStatuslineGoldenOutput the same treatment — one statuslineFloor for the test (the 13 cases differ only in payload, layout and width, which do not change the cost shape), limit = floor + statuslineAllowance. Or, if the 1 s headroom is judged enough, correct the comment at :1018 to name this one exception.

Non-blocking

  • proxy/dash_test.go:575 — the failure message has one closing parenthesis too many ("...20% of the %v baseline)))"). Cosmetic; the format verbs and arguments match.

Earlier findings

  • Reviewer 2, round 1, finding 1 (capless latency budget): fixed. latencyBudget is capped at maxAddedLatency = 45 ms (dash_test.go:411-426), which sits above the #674 paired noise (32-36 ms) and under the regression's 53 ms floor. regressionAt and the "stretches with the same load factor" model are gone, from the code and the comments. The unit test now checks the plain 53 ms against the budget at eight baselines and pins the cap itself; I recomputed all eight by hand (1 ms→5 ms, 2 ms→5 ms, 50 ms→10 ms, 100 ms→20 ms, 331 ms→45 ms, 517 ms→45 ms, 571 ms→45 ms, 5 s→45 ms; 53 > 45 at the top). The author also mutation-tested the guard on the eval box, including under GOMAXPROCS=2. This is the fix I proposed; the thin noise-to-cap margin (36→45→53) is documented with an instruction to raise the cap but stay under 53 ms.
  • Reviewer 1, round 1, finding 1 (same cap): fixed, same change. Agree.
  • Reviewer 1, round 1, finding 2 (flat 0.5 s limits at :1371, :710, :765, :1251): fixed at all four sites. I checked each floor setup: the money test's floor runs the same arg shape (--layout=balanced --show=agents) against an instant stub on its own port; the agent-names floor reuses the same env and stdin, so it carries the 5,000-file and 2 MB work too; the weekly-tip floor runs against scratch state (CONTEXT_GURU_STATE under a fresh home), so it cannot write a first-seen file into a case's state, and each case's sandboxEnv call creates a new HOME, so the floor's cache cannot warm a case; the slow-cachestate floor stub serves the same payload on a different port, and the floor renders use runStatusline's fresh TMPDIR/XDG_CACHE_HOME, so they cannot touch the loop's shared tmp. The one site this sweep missed is finding 1 above.
  • Round-1 non-blocking notes: all addressed. The test is renamed to TestStatuslineFinishesWithinItsBudgetOnASlowProxy; the statuslineAllowance comment states the arithmetic (0.36 s window, SIGALRM net near 0.41 s, ~2.4x room); the regressionAt overflow note is moot (deleted); the wrong "later ones find whatever the earlier ones left" comment now says every run starts cold, which matches runStatusline's fresh TMPDIR/XDG_CACHE_HOME per call.

What I checked

  • Last review: round 1, 88618dd, 2026-10-25T10:35:21Z
  • New commits read: 1 (ad85d0f "test(dash,statusline): cap the latency budget, floor every statusline wall limit")
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files saved in my folder)
  • New items since my last review: the fix commit ad85d0f (full diff read, both files, plus the code around every change) and the author's round-2 comment at 2026-10-25T11:09:13Z (read in full; its per-finding claims checked against the code above). Reviewer 1's round-1 review was posted 25 s before mine and I did not see it before posting; this round I read it and verified both its findings against the fix myself.
  • statuslineFloor and statuslineAllowance: helper is the median of 3 renders with the caller's exact env/stdin/args; slices was already imported; every call site passes an instant stub. The weekly-tip test builds its floor inline against the copied script and scratch state — same shape, and it cannot reuse the helper because the helper always runs scriptsDir's script.
  • The dash pinning test's three exact-value assertions (5 ms floor, 20 ms at 100 ms, 45 ms cap at 517 ms) match the new latencyBudget.
  • Grepped statusline_golden_test.go for every wall assert: lines 716, 1068, 1299, 1427 use floor + statuslineAllowance; line 115 is the one flat limit (finding 1). Also checked plugin_test.go's timing asserts (lines 1026, 1191, 2245): pre-existing, different files, different shapes (half of a hooks budget, a 2 s fetch-timeout guard) — the helper's claim is scoped to this file, so they do not contradict it.
  • No live tests were run (not approved); Go is not installed on this machine. The author's box-run record is taken as reported and is consistent with the code.

TestStatuslineGoldenOutput still held the one flat wall limit left in
this file: elapsed > 1 s, on all 13 subcases. It is the flake class
issue #674 removes: on a loaded runner Python start-up alone eats a
large part of a second. The round-2 invariant comment on
statuslineFloor claimed every wall assert was a floor plus the
allowance; line 115 made that false, and so did the PR reply.

The test now takes the same shape as the other status-line guards:
one statuslineFloor for the whole test (the subcases differ only in
payload, layout and width, which do not change the cost shape), and
the limit is that floor plus statuslineAllowance. The invariant
comment now says "every wall limit on a render", which the grep in
the PR reply shows to be true.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 3, reviewer 2's round-2 finding — fixed in 34ecfa3.

You were right, and my round-2 claim "no flat number is left" was wrong. TestStatuslineGoldenOutput kept elapsed > time.Second on all 13 subcases, and the statuslineFloor comment at :1018 said "every wall assert in this file is such a floor plus statuslineAllowance" — false while that line stayed.

What changed

TestStatuslineGoldenOutput now takes the same shape as the other status-line guards: one statuslineFloor for the whole test (the 13 subcases differ only in payload, layout and width, which do not change the cost shape), and the limit is floor + statuslineAllowance. The floor runs the warm/balanced shape — instant stub, small stdin, --layout=balanced.

Every wall-time use in the file, re-grepped (elapsed, time.Since, Duration, time.Second, Millisecond)

Render wall limits — the flake class — all now floor + statuslineAllowance:

  • :120 — TestStatuslineGoldenOutput, elapsed > limit, limit = floor + statuslineAllowance (fixed this round; was the flat > time.Second)
  • :722 — TestStatuslineGoldenMoney, elapsed > limit, floor via statuslineFloor before the case loop
  • :781 — TestStatuslineAgentNamesAreBounded, elapsed > floor+statuslineAllowance
  • :1075 — TestStatuslineFinishesWithinItsBudgetOnASlowProxy, elapsed > limit, floor per layout
  • :1306 — TestStatuslineGoldenWeeklyTip, d > limit, floor is the inline median of 3 against scratch state
  • :1434 — TestStatuslineMoneyShowsWhenCachestateIsSlowerThanTheRender, elapsed > limit, floor via statuslineFloor

Not render wall limits, for completeness:

  • :52, :441, :587, :710, :1051, :1393 — ReadHeaderTimeout: 5 * time.Second: HTTP server config on the test stubs, not an assert
  • :481 — time.Now().Add(-12 * time.Second): builds a fixture timestamp
  • :1053 — time.After(5 * time.Second): the slow stub's delay
  • :1228 — time.Since(start): measures the floor itself
  • :1358 — time.Since(time.Unix(...)) > time.Minute: checks the timestamp record-run wrote is about now; the value under test is written at that moment, so the runner's speed cannot push it near a minute
  • :1387 — time.After(700 * time.Millisecond): the slow stub's delay
  • :1425 — time.Now().Add(8 * time.Second): the poll deadline of the refresher loop
  • :1441 — time.Sleep(200 * time.Millisecond): that loop's poll sleep

So the claim, restated exactly: every wall limit on a render in this file is a floor plus statuslineAllowance. The doc comment on statuslineFloor now says that, in those words.

Box runs (glm674r3 = the change, glm674r3-mut = the change plus the budget mutation)

Run Copy Result
gofmt -l (full path), go vet on both packages glm674r3 clean
The 6 status-line timing tests (golden output now among them), -count=10 glm674r3 PASS, 114.7 s
Budget mutation: RENDER_BUDGET_SECONDS/HTTP_TIMEOUT_SECONDS = 30 s glm674r3-mut FAIL, as it must. TestStatuslineFinishesWithinItsBudgetOnASlowProxy fails at 46.52 s (renders wait the proxy's full 5 s sleep); TestStatuslineMoneyShowsWhenCachestateIsSlowerThanTheRender fails too (no refresher spawns, the stale .tmp/lock cleanup never happens)
go test -race -count=1 ./context-guru-plugin/... (detached) glm674r3 Only the 2 known box failures (TestInstallRefusesAnUnverifiedDownload, TestInstallReportsPATHFromTheSourceFallbackToo, root-owned /usr/local/bin/context-guru-proxy on the box). Same as origin/main; unrelated. 331.0 s

The mutation was applied only in the box copy glm674r3-mut, never committed. Commit 34ecfa31 is pushed on top of ad85d0fc, no force-push.

Why the golden test cannot fail under the budget mutation

TestStatuslineGoldenOutput passes under the budget mutation, and it cannot fail under it. All 13 subcases render against stubs that answer at once, so a render never waits and the render budget (the SIGALRM net) never binds. That budget is what stops a render waiting on a slow proxy — the slow-proxy test's job, and it does fail. The golden test's limit is a regression guard on render cost relative to the runner's own floor (floor ~70 ms, limit ~1.07 s on this box): a slow path in the render itself, or a loaded runner, still trips it.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 offload-review skill, @amiddavid's session resumed 1 of 2 3 of 3 34ecfa3107b9 approve

Verdict: approve

Findings

None.

Earlier findings

  1. Reviewer 2, round 2, finding 1 (flat elapsed > time.Second at :115, false invariant comment) — fixed. I checked it myself before accepting it: it was the same point I had raised as non-blocking in round 2, and reviewer 2 showed the comment made it worse than cosmetic. Commit 34ecfa31 converts TestStatuslineGoldenOutput to the shared shape: one statuslineFloor for the whole test and limit = floor + statuslineAllowance at :120. Verified in the code:
    • The floor runs the warm/balanced case's exact shape — the same cache body cs(60, 300, 52000, "0.30"), the same small stdin, --layout=balanced, against an instant cgStub (:77-78). The 13 subcases differ only in payload, layout and width, all against instant stubs, so each case's elapsed sits at the floor and the 1 s allowance is pure headroom.
    • My own grep of the file agrees with the author's re-grep: the six render wall limits (:120, :722, :781, :1075, :1306, :1434) are all floor plus statuslineAllowance; every other time.Second/Millisecond use is a stub delay, a fixture timestamp, a poll deadline, or the floor measurement itself.
    • The statuslineFloor doc comment now says "every wall limit on a render in this file" (:1024-1025), which my grep confirms is true.
    • The author's note on why this test cannot fail under the budget mutation is correct: all its stubs answer at once, so the render never waits and the SIGALRM net never binds; its limit guards render cost against the runner's own floor. The slow-proxy and slow-cachestate tests carry the waiting behavior, and the mutation fails there.
  2. My round-1 findings and reviewer 2's round-1 finding — fixed in ad85d0fc, unchanged this round. The round-2 commit is untouched by 34ecfa31 (only statusline_golden_test.go changed, 10 insertions, 3 deletions). My round-2 verification stands.

Non-blocking

  • Agree with reviewer 2's round-2 note, still present: proxy/dash_test.go:575 has one closing parenthesis too many in the failure message ("...20% of the %v baseline)))"). Cosmetic; the format verbs and arguments match. Fine to fix whenever that file is next touched.

What I checked

  • Last review: round 2, ad85d0f, 2026-10-25T11:14:31Z
  • New commits read: 1 — 34ecfa31 "test(statusline): floor the golden output wall limit too" (plain descendant of ad85d0fc, no force-push; one file changed)
  • Read in full: 4 reviews, 2 comments, 0 inline comments (from the three saved files)
  • New items since my last review, and what I did about each:
    • Reviewer 2's round-2 review (2026-10-25T11:14:58Z): read in full. Its finding is the blocking version of my round-2 non-blocking note; I re-verified the flat assert and the false comment existed at ad85d0fc, then verified the fix (see above).
    • Author's round-3 comment (2026-10-25T11:43:48Z): read in full. Cross-checked its re-grep of every wall-time use against my own grep — the lists match. Its box-run record (clean -count=10 on the six timing tests, budget mutation failing in the two waiting tests, -race with only the two known box failures) I could not re-run — live tests are not approved — but nothing in it contradicts the code.
    • Commit 34ecfa31: read the full diff and the test around it. Checked variable scoping (cs, small defined above the floor call; statuslineFloor/statuslineAllowance are package-level), the error-message format verbs (3 verbs, 3 arguments), and that the time import is still used.
  • Re-ran the file-wide grep for wall asserts after the change to confirm the invariant the new comment states.
  • No tests were run (live tests not approved). All conclusions come from code reading and arithmetic.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 offload-review skill, @amiddavid's session resumed 2 of 2 3 of 3 34ecfa3107b9 approve

Verdict: approve

Findings

None.

Non-blocking

  • proxy/dash_test.go:575 — the extra closing parenthesis in the failure message ("...20% of the %v baseline)))") is still there; this commit did not touch that file. Carried over from round 2, still cosmetic.

Earlier findings

  • Reviewer 2, round 2, finding 1 (flat elapsed > time.Second in TestStatuslineGoldenOutput, false invariant comment): fixed. The test now measures one statuslineFloor before its case loop (statusline_golden_test.go:74-78) — instant stub, small stdin, --layout=balanced, the warm/balanced shape — and the assert at :120 reads elapsed > limit with limit = floor + statuslineAllowance. The floor stub runs on its own port and each case builds its own stub, and runStatusline pins a fresh TMPDIR/XDG_CACHE_HOME per call, so the floor cannot warm a case. The 13 cases differ only in payload, layout and width, which do not change the cost shape. The statuslineFloor doc comment now says "every wall limit on a render in this file" (:1021-1022) — I re-grepped the file myself and that claim is now true (see What I checked).
  • Reviewer 1, round 2, non-blocking note on the same line: fixed by the same commit. Reviewer 1 judged it non-blocking (2x headroom, instant stubs); I judged the false invariant comment worth blocking. Both readings are answered by the same change.

What I checked

  • Last review: round 2, ad85d0f, 2026-10-25T11:14:58Z
  • New commits read: 1 (34ecfa3 "test(statusline): floor the golden output wall limit too")
  • Read in full: 4 reviews, 2 comments, 0 inline comments (from the three files saved in my folder)
  • New items since my last review, and what I did about each:
    • Commit 34ecfa3: read the full diff (one file, three hunks) and the code around each. Verified the floor variables are defined before use (cs at :62, small at :70, the floor block at :74-78), and the assert message matches the other floor-based asserts.
    • The author's round-3 comment (2026-10-25T11:43:48Z): read in full. Reproduced its wall-time grep myself: six render wall limits (:120, :722, :781, :1075, :1306, :1434), all floor + statuslineAllowance; every other wall-time use is a stub delay, a server ReadHeaderTimeout, a fixture timestamp, the floor measurement itself, a poll deadline/sleep, or the record-run freshness check at :1358 (the value under test is written at that moment, so a loaded runner cannot push it near a minute). The restated invariant holds.
    • Reviewer 1's round-2 review (2026-10-25T11:14:31Z, approve): read now. Its two non-blocking notes — the line-115 flat limit and the thin 36→45→53 ms cap margin — I checked myself: the first is fixed by this commit, the second is documented in the code with an instruction to raise the cap but stay under the 53 ms floor.
  • The fix keeps the golden test's strength: on a fast box floor + 1 s sits near the old flat 1 s, and on a loaded runner it scales with the runner instead of flaking. The author's note that this test cannot fail under the budget mutation is sound: all 13 subcases render against instant stubs, so the render budget never binds there — the slow-proxy test carries that mutation, and the box record shows it fails as it must.
  • The box-run record (gofmt/vet clean, the 6 timing tests -count=10, mutation failing, -race with only the 2 known box failures) is taken as reported; live tests are not approved, and nothing in it contradicts the code.
  • No tests were run by me (not approved); Go is not installed on this machine.

@amiddavid
amiddavid merged commit d72ffe2 into main Oct 25, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 25, 2026
amiddavid added a commit that referenced this pull request Oct 27, 2026
)

fix(proxy): join feedback mail before a test's sink goes away (#213)

The feedback POST commits the row and hands the mail to a goroutine. The
dev sink path (CG_MAIL_DEV_SINK) is read at SEND time, so a send still in
flight when its test ends reads whatever the NEXT test has set, and lands
in that test's sink. TestFeedbackMailCannotInjectHeaders then counts more
than one real subject line and fails.

The handler now tracks those goroutines in a WaitGroup. The hosted test
fixture joins them in t.Cleanup, registered after the sink's t.Setenv so
it runs before it (cleanups are LIFO): by the time the env points
anywhere else, no send is about to read it. Production behaviour is
unchanged — the wait exists only on the test teardown path.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
test(keepalive): wait on the state Arrive reports, not the ping counter (#206)

TestArriveCancelsAndReports waited on the pings counter, then asserted on
what Arrive reports. The counter is bumped when the ping's round trip is
over; e.refreshed is written a moment later under k.mu. A test that waits
on the counter can therefore read the entry before the field it asserts
on is set — the original #206 race, still latent now that the keeper
tests run fire inline.

The test now uses waitRefreshed, which polls the entry's own refreshed
field. It is correct under any runner, so the waitPings doc comment no
longer claims counter-waiting is enough for state assertions.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
test(proxy): stop asserting absolute values on process-global counters (#192)

Two tests asserted absolute values on counters that live for the whole
test binary: the extract registry (metrics.ExtractSnapshot) and expand's
unresolved pair. A -count=2 run of ./proxy failed on its second
iteration, because iteration 2 starts from iteration 1's counts.

TestExtractEconomicsAreExported now reads a baseline first and asserts
the delta, the same shape TestAdjudicateStraySeriesRender already uses.
TestExpandUnresolvedSeriesRender resets the two unresolved counters at
the top, so its at-zero assertions hold on every iteration.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
test(proxy): wait for the campaign aggregate the assertion reads (#163)

TestCtlGetCampaignAggregatesPredictedAndRealPerTenant waited for each
recorded ROW to persist, then asserted on real_saved_usd — an aggregate
computed over several rows at read time. On a starved 2-core CI runner
(#163) it read 0 with every row persisted.

The test now polls the campaign detail route until the tenant's
real_saved_usd is non-zero (5 s deadline, loud failure), then asserts on
that response. A wrong value still fails the assertion, so the check
keeps its meaning; only the load sensitivity goes.

Could not reproduce on today's main on the eval box (50x at -cpu=1, 20x
under -race at -cpu=1, and 5 concurrent runs pinned to 2 cores all
passed), so this is the wait the issue proposed rather than a fix for an
identified remaining race.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
test(dash): wait for hub publication, not just row persistence (#91)

The scope fixture drained the writer by polling the DATABASE. The writer
publishes to the SSE hub only AFTER the insert commits, so a row
/api/requests could see was not yet a row /api/events could replay, and
TestEventsDerivesItsScopeFromTheResolver could read a manager's live
feed with no events in it.

The fixture now also waits for the hub's ring to hold the same three
events, so both the positive and the negative assertions on /api/events
run against a published backlog.

The latency half of #91 is not touched: it was fixed on main by #576 and
#693, which landed after the issue and implement its addendum.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
fix(dash): stop the insights tests reading the runner's own disk (#700)

The insights handler reads the machine's ~/.claude: it parses every
transcript under projects (90 MB on a measured machine) and walks the
whole plugin cache. The project API tests passed home "" — the real
machine — so their cost was a property of whatever box ran them. Under
-race in a full-package run on a loaded box, TestTheInsightsDocumentIs-
ScopedToOneProject went past the route's fixed 10 s handler timeout and
failed. Reproduced here at 10.21 s with an 81 MB transcript tree.

Two changes:

- The tests' projectAPI helper passes an empty t.TempDir, so the route's
  cost is about the store, which is its subject. The 10 s timeout stays
  meaningful: a handler that really hangs still trips it.
- The handler sources skill descriptions from a.diskHome() instead of
  the hardcoded "". Local behaviour is unchanged (diskHome is "" there);
  a hosted API now gets the empty map its own doc already promised; and
  a test home now reaches the plugin walk too.

Written by GLM through Claude Code.

Assisted-By: GLM
Signed-off-by: DAVID AMID <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

test: 3 timing tests flake on the CI runner (watchdog race, latency guard, status line)

1 participant