Repository navigation
test(modes): wait on the condition, not on time - #1422
Conversation
Replace the local 3 s waitFor with testutil.WaitFor. Replace the settle sleeps with a bounded poll of runtime.NumGoroutine. Raise the 2 s and 5 s hang detectors to 30 s. Gate the tight Stop grace bound with testutil.TimingEnabled. Remove 5 tests from the pending timing list. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| 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.332 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 35910817ef49 |
approve |
Verdict: approve
Findings
None. The change is test-only and correct.
Non-blocking
- modes/modes_test.go:582 —
beforecan count goroutines that are still exiting. The oldsettle()ran before the capture; the new code capturesruntime.NumGoroutine()at once. A worker of the test before (TestFullQueueDropsAndNeverBlocks) may not be off the goroutine list yet.beforethen reads 1-2 too high, and the check<= beforecan mask a leak of that many goroutines. A real leak loses all 4 workers, so the check still catches it. Fix if you want it exact: wait first for the count to stop falling, then capturebefore. - modes/modes_test.go:618 — the default Stop bound is now loose. A plain run accepts a Stop that blocks up to
stopGrace + 30 s. The tight bound (stopGrace + 3 s) runs only withCG_TIMING_TESTS=1. This follows the timing-test rules, and the tight bound does run: tier 2 flags this PR (timing-tests-needed.shsees the newTimingEnabledline), heavy CI and Part A set the variable. No change needed. I list it so the merge record names the weaker default.
What I checked
- The full diff: 3 files, 1 commit (
35910817). The commit message matches the change. DCO sign-off andAssisted-By:per the repo convention. - timingguard baseline. I applied the scanner rules of
internal/timingguard/timingguard_test.goby hand to the newmodes/modes_test.go: 0 sleeps, 0 poll loops, 3 select cases on<-time.After(lines 503, 629, 645). Thedeadline := time.After(30 s)at line 555 counts as none of the three kinds (no receive oftime.After, andcase <-deadlineis not a deadline-name check). The edited linemodes/modes_test.go after=3is what-updatewould write. No other file's counts moved. testutil.WaitFor/WaitForState/TimingEnabled. Readinternal/testutil/testutil.go. The 30 s bound is cut to the test deadline minus 5 s, so no run hangs past-timeout. TheTimingEnabledguard matches the documented rule "a test that checks more than time can guard only its time check", and has precedent (proxyapp/shutdown_test.go:75,proxy/tooldefer_866_test.go:237).- Each rewritten test keeps its assertion. Only the wait strategy changed:
TestPoolRunsJobs,TestEnqueueDedupIsAtomic,TestPanickingJobIsContained: same conditions, longer safety bound.TestFullQueueDropsAndNeverBlocks: the 30 sdeadlineis a hang detector onEnqueue, not a timing assertion; the counter checks are unchanged.TestStopDoesNotWaitForASlowJob: the functional check (Stop returns false while a job runs) still runs without the variable; the wall-clock bound moves behindTimingEnabled.TestStopLeaksNoGoroutines: the wait-for-condition replaces the fixedsettle(); a real leak still fails, after up to 30 s instead of immediately.
- Test order.
TestStopDoesNotWaitForASlowJobleaves its blocked worker until its owndefer close(release). It runs afterTestStopLeaksNoGoroutinesin file order, so it cannot pollute the goroutine check. pending-timing-fixes.txt. The 5 removed modes tests are the 5 this PR makes load-robust.TestStopDoesNotWaitForASlowJobwas never in the list. The only consumer of the file is the hand rule in CLAUDE.md; no script parses it.- Coverage of the gated bound.
scripts/dev/timing-tests-needed.shprints "run" for this PR (the diff adds aTimingEnabledline),.github/workflows/ci.yamlsetsCG_TIMING_TESTS: "1"(lines 95, 237), andscripts/release/part-a.shdefaults it to 1. So the tight Stop bound runs in tier 2 for this PR, in heavy CI, and in Part A. - No production code changed.
modes/pool.goandmodes/tracker.goare untouched. No data-dependence row applies (no feature change). No behavior change to name at the top of the PR.
amiddavid
left a comment
There was a problem hiding this comment.
| 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.332 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 35910817ef49 |
blocking |
Verdict: blocking
Findings
- modes/modes_test.go:582 — the leak check can pass while the pool leaks one goroutine, because the baseline is captured before the prior test's goroutines exit
- What fails: a regression where
Pool.Stopleaves 1 of the 4 workers alive still passesTestStopLeaksNoGoroutines. - Proof:
Pool.Stopreturns as soon asdonecloses, but the waiter goroutine that closeddonemay still exist (modes/pool.go:190-199). The test before this one in source order ends withdefer p.Stop()(modes/modes_test.go:546), so that waiter can still be alive when line 582 capturesbefore.beforeis then S+1 while the steady count is S. A pool that leaks 1 worker ends at S+1, and the conditionruntime.NumGoroutine() <= before(modes/modes_test.go:592) holds, so the test passes. The removedsettle()call ran before the capture, so the old code compared against the steady count S and failed on the same leak. The repo's own equivalent test states this rule:proxy/modes_test.go:301-305settles first, with the comment "Everything unrelated (the mock upstream's own goroutines) is created BEFORE the baseline, so the only difference this measures is the pool's." - Fix: make the baseline tight before you capture it. For example, wait (bounded,
testutil.WaitForState) untilruntime.NumGoroutine()is unchanged across two polls, then capturebefore; or keep a small settle before the capture, marked//timing:ok the leak baseline must be quiet.
- What fails: a regression where
Non-blocking
modes/modes_test.go:592-595— thestatefunc readsruntime.NumGoroutine()again, so the number it reports can differ from the one the condition just read. Cosmetic; the message stays useful.modes/modes_test.go:617-621— in a normal run,TestStopDoesNotWaitForASlowJobnow proves only thatStopreturns within ~32 s, not within its grace. This is deliberate, commented, and the tight bound still runs whenCG_TIMING_TESTS=1. Accepted.
What I checked
- The full diff of the one commit (3591081):
modes/modes_test.go,internal/timingguard/baseline.txt,scripts/release/pending-timing-fixes.txt. The commit message follows the DCO andAssisted-Byrules. modes/modes_test.goin full, andmodes/pool.go(NewPool,Enqueue,Stop,stopGrace = 2 s) as the behavior under test.testutil.WaitFor,WaitForStateandTimingEnabled(internal/testutil/testutil.go): 30 s bound, cut to the test deadline minus 5 s, condition checked once more after the last sleep. Correct replacements for the deleted localwaitFor.- The timingguard scanner (
internal/timingguard/timingguard_test.go), traced by hand over the new file: 3 select cases on<-time.After(lines 503, 629, 645), notime.Sleep, no poll loop.deadline := time.After(30 * time.Second)(line 555) is an assign, not a receive, so it counts as nothing. The new baseline entrymodes/modes_test.go after=3matches. - The deleted
waitForandsettlehelpers have no other user in themodespackage. - The 5 lines removed from
scripts/release/pending-timing-fixes.txt: each named test is fixed by this diff (localwaitFor,settle, or a tight bound replaced). The file header says a PR that fixes a listed test removes its line in the same PR. - No behavior change, no data-dependence change, no binaries: test-only PR.
- I did not run builds or tests. Live tests are not approved for this review.
A previous test's Stop waiter could still be alive when the baseline was read, so a leak of 1 worker passed. Wait until the count holds still for 5 polls, then read the baseline. The failure message now shows the same count the condition read. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
|
Fixed in the new head. Finding 1 (modes_test.go:582): the test now waits until Vacuity: one leaked goroutine after Stop fails the new test at the 30 s bound ("goroutines before 2, now 3"). On the old head the same leak also failed 5 of 5 runs here, because the previous test's waiter exits fast and the window is narrow. The window is real, so the quiet baseline closes it. |
amiddavid
left a comment
There was a problem hiding this comment.
| 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.332 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | c390c109dd78 |
approve |
Verdict: approve
Findings
None. The fix commit is correct and closes the round-1 window.
Earlier findings
- Baseline read too early in
TestStopLeaksNoGoroutines(my non-blocking note; reviewer 2's finding 1, blocking): fixed by16aa8147. The test now waits untilruntime.NumGoroutine()holds the same value over 5 polls in a row (2 ms apart, 30 s bound) before it readsbefore. I checked the fix myself:- A foreign goroutine that is still alive makes the count drop when it exits, which resets
steady, so the quiet wait does not end while the count is still falling. - The closure state (
last,steady) is used byWaitForon the test goroutine only, so there is no race. - The wait runs before
NewPool, so it cannot mask a leak of the pool under test. - Reviewer 2 asked for 2 steady polls; the fix uses 5. Stronger than asked.
- I agree with reviewer 2's blocking framing. I had the same point as non-blocking in round 1; a partial leak (1 of 4 workers) is realistic, so blocking was the right call.
- A foreign goroutine that is still alive makes the count drop when it exits, which resets
- The
statefunc readNumGoroutineagain (reviewer 2's non-blocking): fixed. The condition now storesnow, and the message prints that same value. - Loose default Stop bound (my non-blocking; reviewer 2's non-blocking): unchanged, accepted. The author says so in the PR comment. The tight bound runs under
CG_TIMING_TESTS=1, which tier 2, heavy CI and Part A set. No action needed.
What I checked
- Last review: round 1,
35910817ef4937d577c2838321b5e9334ac05016, 2026-11-25T17:10:27Z. - New commits read: 4 in
35910817..c390c109— 2 PR-owned:16aa8147(test(modes): make the goroutine baseline quiet before the leak check),c390c109(merge of origin/main); 2 from main via the merge:9c64a6a3(proxy test price callback),ecd3c648(RELEASING.md docs). I read both main commits' diffs; they do not touchmodes/,internal/timingguard/orscripts/release/pending-timing-fixes.txt, so they cannot interact with this PR's change. - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (17:10:57Z): re-derived its finding against my own round-1 analysis (same defect, tighter proof: the Stop waiter at
modes/pool.go:190-199). Confirmed. - Author comment (17:15:49Z): describes the fix and a 5-of-5 local vacuity check. Verified each claim against the diff of
16aa8147. - Commit
16aa8147: read the full diff and the changed test in the file around it. - Merge
c390c109: verified it is a clean merge —git diff 16aa8147..c390c109changes onlyRELEASING.mdandproxy/predictive_agent_test.go, exactly main's two commits.
- Reviewer 2's round-1 review (17:10:57Z): re-derived its finding against my own round-1 analysis (same defect, tighter proof: the Stop waiter at
- The PR diff against the new base (
9c64a6a3..c390c109) is still the same 3 files as round 1:modes/modes_test.go,internal/timingguard/baseline.txt,scripts/release/pending-timing-fixes.txt. - timingguard baseline still matches. The fix adds no
time.Sleep,time.Afteror poll loop;testutil.WaitForis in the exemptinternal/testutil/prefix. The file still counts 3 selecttime.Aftercases (the hang detectors), somodes/modes_test.go after=3stays correct. - Flake risk of the quiet wait. A GC cycle or a slow-to-schedule dying goroutine can reset
steady; the wait then simply continues inside its 30 s bound (cut to the test deadline minus 5 s). Nothing in this package keeps changing the count at that point. I see no realistic false timeout. - No production code changed, no data-dependence row applies, no client rule, no host-boundary question. DCO sign-off and
Assisted-By:are on both new commits. - I did not run builds or tests. Live tests are not approved for this review.
amiddavid
left a comment
There was a problem hiding this comment.
| 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.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | c390c109dd78 |
approve |
Verdict: approve
Findings
None. My round-1 finding is fixed.
Earlier findings
- My round-1 finding 1 (modes_test.go:582, an inflated goroutine baseline can mask a 1-worker leak): fixed in
16aa8147. The test now waits untilruntime.NumGoroutine()holds the same value over 5 polls in a row, then readsbefore(modes/modes_test.go:582-594). A straggler from the prior test'sStopresets the stability counter when it exits, so it cannot inflate the baseline. A leak of 1 worker now ends at S+1 against a baseline of S and fails. The comment on the test states the rule, in the words of theproxy/modes_test.goprecedent. The 5-poll quiet window is a heuristic, not a proof — a straggler that needs more than ~10 ms to exit can still slip past it — but the oldsettle()was the same kind of heuristic at 100 ms, and this closes the window I named. - My round-1 non-blocking note (the
statefunc read a different count than the condition): fixed. The condition now stores the count innowand thestatefunc reports that same value (modes/modes_test.go:605-610). - My round-1 non-blocking note (the loose Stop bound in a normal run): accepted, unchanged. The author's comment says so, and the tight bound still runs under
CG_TIMING_TESTS=1. - Reviewer 1's two non-blocking notes: the first is the same baseline issue as my finding — fixed by the same commit. The second is the same loose Stop bound — accepted, unchanged. I checked both myself; I have nothing to add.
What I checked
- Last review: round 1, 3591081, 2026-11-25T17:10:57Z.
- New commits read: 4 —
ecd3c648docs(release): 3 merge rules from v0.7.9;9c64a6a3test(proxy): pass the prompt-size price callback;16aa8147test(modes): make the goroutine baseline quiet;c390c109merge of origin/main. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did about each:
- Reviewer 1's round-1 review (posted 30 s before mine): read in full. Its two non-blocking notes match my checks; no new finding to verify beyond them.
- The author's comment (2026-11-25T17:15:49Z): describes the fix and a vacuity check (a forced 1-goroutine leak failed the new test). I verified the claim by reading the code, not by running it.
- Commit
16aa8147: the fix. Verified as above. - Commits
ecd3c648and9c64a6a3(arrived through the merge of main): read both diffs in full.ecd3c648is docs-only (RELEASING.md).9c64a6a3changes one test line; I checked the new callback againstcampaign.Rows(campaign/replay.go:161), which takesfunc(model string, promptTokens int64)— the fix matches. Both came from their own merged PRs (#1405, #1426).
- The fix commit against the timingguard rules: the quiet-wait loop lives in
internal/testutil(exempt);modes/modes_test.goitself gains no sleep, poll, ortime.After. The mergedinternal/timingguard/baseline.txtstill saysmodes/modes_test.go after=3, the PR's value — the merge did not keep main's stalesleep=2 poll=1 after=3line, which would have failed the ratchet. - The fix's variables (
last,steady,now) are written and read only inside the condition and state closures, whichWaitFor/WaitForStatecall from the test goroutine (internal/testutil/testutil.go:46-71). No race under-race. - The full PR diff against the new base (
9c64a6a3..HEAD): 3 files, the same set as round 1 plus the fix. No production code, no behavior change, no data dependence, no binaries. - I did not run builds or tests. Live tests are not approved for this review.
Signed-off-by: DAVID AMID <[email protected]> # Conflicts: # internal/timingguard/baseline.txt # scripts/release/pending-timing-fixes.txt
Signed-off-by: DAVID AMID <[email protected]> # Conflicts: # internal/timingguard/baseline.txt
|
Head moved by a merge of main, with a conflict resolved only in the timing lists.
CI is green at 4070aec. Local tests: waived (owner rule) |
Summary
Owner, 2026-11-24: "tests that are based on time will go into the pool that runs on integrator, and tests that can be fixed since time is a by product of poor design are fixed."
This PR fixes the 5
modestests on the pending list and removes their 5 lines.Test-only. No behavior change. Data dependence: none. Only
modes/modes_test.go, the pending list and the timingguard baseline change.Overlap: #35 also changes
modes/modes_test.go. It is a held draft since 2026-08-10, so its next rebase gets a small conflict here.What changed
waitFortestutil.WaitForwaitFortestutil.WaitForwaitFor, 5 s detectortestutil.WaitFor, 30 s detectorwaitFor, 2 s detectortestutil.WaitFor, 30 s detectorsettle()ran 20 sleeps of 5 msWaitForState) untilruntime.NumGoroutine() <= beforeAlso:
waitForandsettlehelpers are gone.stopGrace+3sbound only whentestutil.TimingEnabled(). Otherwise the bound isstopGrace+30s.modes_test.gois lower.How it was tested
macOS, Go 1.27.4,
GOMAXPROCS=4.CGO_ENABLED=1 go test -race -count=20 -run '^(the 5 tests)$' ./modes/: pass.CGO_ENABLED=1 go test -race ./modes/: pass.gofmt,go vet ./modes/,go test ./internal/timingguard/: pass.Stop: TestStopLeaksNoGoroutines fails at the 30 s bound with "goroutines before 2, now 3".close(done)removed from the job that follows the panic: TestPanickingJobIsContained fails at the 30 s detector.Local tests: waived (owner rule)