Repository navigation
test: add internal/testutil.WaitFor and use it for #1110 and the hot-path polls - #1122
Conversation
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.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | e55a7f5251e0 |
approve |
Verdict: approve
Findings
None.
Non-blocking
proxy/agentmodel_test.go:90— thet.Cleanupdrain ignores the bool that
offload.WaitForAllSummariesForTestreturns. A summary stuck past 10 s leaks into a later test
with no signal. The fake upstream answers at once, so this cannot fire today. Passing on the
return value, or logging it, would make a future hang visible.internal/testutil/testutil.go:26—boundis one process-global.SetBoundForTestis safe now
because no test in the package runs in parallel. A futuret.Paralleltest in the package would
inherit another test's 50 ms bound and fail for no reason. A one-line note onSetBoundForTest
("no parallel tests in this package") would pin that assumption.internal/testutil/testutil_test.go(the import guard) — a file that fails to parse is skipped
with no message. A file that does not parse cannot compile, so nothing real can hide there. The
seen < 50floor already guards against a broken walk.
What I checked
- Read the full diff (10 files, one commit) and the code around each change. Test-only; no
production file changed. No behavior change, so the human-permission rule for behavior changes
does not apply. Data dependence: none, as the PR states; no component or feature row is due. - The
want == 0claim inpostSummarizable("a call still on its way cannot slip past the
check"). Proved it holds:Summarizecommissions throughstartAsyncSummary
(components/offload/summarize.go:647), which callsinFlight.beginon the request's own
goroutine (summarize_async.go:227) before the response is written. So when the client has its
response, every commissioned summary of that request is already ininFlight.jobs, and
WaitForAllSummariesForTestpolls exactly that map.inFlight.finishis the firstdefer, so
it runs after the HTTP call and the checkpoint commit. The plainsummarizepipeline used here
has no deferred-commission path (cold/warm deferrals are cache-aware only). - Cleanup ordering.
up.Close(registered bysummaryUpstream), thenh.Close, then the
drain (registered insidepostSummarizable).t.Cleanupis LIFO, so the drain runs first, while
the fake upstream is still open. A summary in flight can still complete. Correct. - Session-key sharing. All
agentmodel_test.gotests post the same body with no session
header, so they share one derived session key and one globalinFlight. The per-test drain
cleanup prevents a leftover summary from refusing the next test's commission.cgllm_test.go
posts the same first user message but setsx-context-guru-session, so no cross-file key
collision. - The six migrated poll loops keep their old semantics: same stop conditions, same
error handling (a DB error stops the wait and fails the test, as before), and the failure
messages now carry the last-seen state.waitForRowindashemitter_waitcause_test.gochanges
from returning a timeout error to failing directly; both callers only didt.Fatal(err), so the
outcome is the same. testutil.Upstream: recording is mutex-guarded,Callsreturns a copy, headers are cloned.
WaitForCallfails throughWaitForStateon timeout and returns all matching calls on success.
The client chat cannot be mistaken for a summary call:isSummaryCallkeys onmax_tokens,
whichsummarizableOpenAIRequestdoes not send.- The import guard (
TestNoProductionPackageImportsTestutil): walks the repo root, skips
.git/.claude/node_modules/testdataand_test.gofiles, parses imports of every other
.gofile, and fails on any import ofinternal/testutil.internal/boundarytreats
internal/testutilas a core package;upstream.gouses no bannednet/httpselector
(httptest.NewServerandhttp.HandlerFuncare not in the banned set), so the boundary rule
holds. No non-test file in the repo imports the package (grep confirms). - Compile-level checks on all changed files: added imports are used, removed imports (
io,
syncinagentmodel_test.go) have no remaining uses,fmtwas already imported in
keepalivehost_test.goanddashemitter_waitcause_test.go. - The PR's own numbers (0 failures in 200 loaded iterations, vacuity check) are consistent with
the code as read. Live tests were not run; this review is read-only as instructed.
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.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | e55a7f5231e0 |
approve |
Verdict: approve
Test-only change. No production file changed. I found no defect that produces a wrong
test result, a false pass, or a race.
Findings
None.
Non-blocking
-
internal/testutil/testutil.go:39 —
WaitForandWaitForStateignoret.Deadline().- A 30 s bound can outlive a tight
-timeoutfor the package. The failure then shows as
"test timed out" and the helper's message is lost. - Not wrong today. The proxy package ran 585 s with
-race, well under the 10 m default.
- A 30 s bound can outlive a tight
-
proxy/agentmodel_test.go:109 — the
want == 0drain does not wait out deferred commissions.offload.WaitForAllSummariesForTestpolls onlyinFlight.jobs
(components/offload/summarize_testhook.go:64). It does not wait on
coldDeferred/warmDeferred/dispatching, unlikeWaitForSummaryForTest
(summarize_testhook.go:24).- This is sound for these tests: the pipeline is
[summarize]
(proxy/agentmodel_test.go:49), and plainsummarizecallsinFlight.beginon the
request goroutine (components/offload/summarize_async.go:227), before the proxy returns
the response. So every summary of these tests is ininFlight.jobsbefore the check,
and a finished job means its call reached the upstream first. - The risk is latent: if these tests ever run a pipeline with
cache_aware_summarizer,
a deferred summary could pass thewant == 0check. Suggest one sentence in the
postSummarizablecomment that names this limit.
-
internal/testutil/upstream.go:31 —
NewUpstreamcallsrespondwith no nil check.- A nil
respondpanics on the first request. Every caller passes a func. A nil check
with a 200 reply would make the helper safer for future callers.
- A nil
-
internal/testutil/testutil.go:62 —
state()runs while theFatalfmessage is built.- A panic inside
state()would mask the timeout. The current callers are safe:
dash.DB().Requestsreturns a nil page only with an error
(dash/query.go:288-313), anderr != nilshort-circuits beforelen(page.Requests)
in every condition closure.
- A panic inside
What I checked
- Read the full diff and every changed file in full:
internal/testutil(3 files),
proxy/agentmodel_test.go,proxy/keepalive_billed_contract_test.go,
proxy/keepalivehost_test.go, and the fourproxyapp/dashemitter_*_test.gofiles. - The #1110 fix is correct. For
want > 0,WaitForCallwaits until the summary call
is recorded by the fake upstream. Forwant == 0,WaitForAllSummariesForTestwaits
until the summary job finished, and the job finishes only after its HTTP call completed,
so the call is recorded before the check runs. No window remains where a summary call
reaches the upstream after the test read the calls. - Cleanup order is correct.
t.Cleanupruns LIFO: the drain registered in
postSummarizableruns beforeh.Closeand before the fake upstream'sClose. A
summary in flight at test end cannot hit a closed server. - Cross-test contamination is prevented.
inFlightis package-global and keyed by a
session derived from the request body, which is the same in all these tests. The drain
at test end, plus the in-body drain, stop one test's summary from gating the next
test's (summary_already_in_flight). ForTestMalformedAgentModelTarget..., which
runs 7 requests in one test function, the in-body drain after each request carries this. - No nil-pointer path in the migrated polls.
dash.DB().RequestsandComponents
return a nil result only with an error; every condition closure testserrfirst
(Go||short-circuit), and thestatefuncs run only after a final check that
returned false witherr == nil. - No compile issue found by reading. All imports in the changed files are used
(fmtinproxy/keepalivehost_test.go,timeinproxyapp/dashemitter_savings_test.go,
offload/timeinproxy/agentmodel_test.go). No name collision: the package-level
seenfunc does not clash with the localtype seeninproxy/keepalive_wire_test.go:36
(function scope shadows it), andtestutil.Upstreamis always qualified against the
proxy's ownUpstreamtype (proxy/tenancy.go:176). internal/boundarystays green.internal/testutilis not a host package, and its
non-test files use no bannedhttp.*selector (NewServer,HandlerFunc,Header,
ResponseWriterare all allowed).- The guard test is sound.
TestNoProductionPackageImportsTestutilskips_test.go
files, theinternal/testutildir itself, and.claude(which holds other review
worktrees on a laptop). Files that fail to parse are skipped, but such files cannot
compile anyway. Theseen < 50check catches a broken walk. - The negative tests cannot pass vacuously.
runFatalreturns "" when the wait does
not fail, and the message assertions then fail. - Repo rules. No production behavior change, so the data-dependence statement
("none") and the no-human-permission rule are satisfied. No file outside test code
changed;docs/data-dependence.mdneeds no rebuild. - I did not run builds or tests. Live tests were not approved for this review.
e55a7f5 to
2826e20
Compare
|
Round 1 follow-up. New head Reviewer 1
Reviewer 2
Tests (box, |
Part 1 of the repo-wide flaky-test fix. Test-only, no behavior change. - internal/testutil: WaitFor, WaitForState, and a recording fake upstream with WaitForCall. The safety bound is 30 s, cut to the time left before the test deadline. A passing test ends as soon as its condition holds. - A guard test fails when a non-test file imports internal/testutil. - Replace six fixed 2 s poll loops in proxy and proxyapp. #1110 was fixed by #1112. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
2826e20 to
a9c441e
Compare
|
Plan change. #1112 fixed #1110, so head Still in this PR, from both reviews:
Tests (box, |
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.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | a9c441e4e085 |
approve |
Verdict: approve
Findings
None.
Status of the earlier findings
Mine, round 1:
- Cleanup drain ignores the return value (
agentmodel_test.go:90) — no longer applies. The
PR droppedagentmodel_test.go: its diff against the new base is empty. Main's #1112 now owns
that fix, and its version does check the return
(if !offload.WaitForAllSummariesForTest(10 * time.Second) { t.Fatal(...) }), so the point is
covered there. SetBoundForTestandt.Parallel— fixed. The doc onSetBoundForTestnow says the bound
is process-wide and no test in the package may callt.Parallel.- Import guard skips unparsable files — rejected by the author: a file that does not parse
cannot compile, and theseen < 50floor guards the walk. The reason is right. I accept it.
Reviewer 1, round 1 (checked myself against the new head):
t.Deadline()ignored — fixed.effectiveBoundcuts the bound to the time left before the
test deadline minus 5 s, floored at one poll interval.TestWaitForGivesUpBeforeTheTestDeadline
covers it. I traced the test double (deadlineTBembedsrecorderby value; the promoted
pointer-receiverFatalfpanics with&d.recorder, which the test's recover swallows): the
test fails if the wait runs long or the message is missing, so it cannot pass vacuously.- Drain does not wait out deferred commissions — no longer applies, same as my point 1.
- Nil
respondpanics — fixed.NewUpstream(t, nil)replies 200 with{}, before which the
call is still recorded. Covered by
TestNewUpstreamWithNilRespondReplies200AndEmptyJSON. - A panic in
state()masks the timeout — fixed.describerecovers and turns the panic into
text in the message. Covered byTestWaitForStateSurvivesAPanickingStateFunc.
Non-blocking
- The final head ran
internal/testutil,internal/boundaryandproxyappin full, but the
proxypackage only as targeted keep-alive and billed runs (-count=20, under load). The two
changedproxyfiles are byte-identical to the round-1 head, where the full package passed
(585 s,-race), so the risk is small. A fullproxyrun on the final head before merge would
close it. effectiveBound: aWaitForthat starts in the last 5 s before the package deadline gets a
2 ms bound and fails at once. That is the intended trade — the helper's message in place of a
bare "test timed out" — and both outcomes are failures. Noted only so the trade is on record.
What I checked
- Last review: round 1, e55a7f5, 2026-11-12T08:18:26Z.
- New commits read: 8 —
89c98dedocs(claude-md) #1121,245f584fix(config) #1115,
c8f9b67test(proxy) #1112,826e46fdocs #1117,fff61bffeat(mod) #1096,
cd82e95test(proxy) #1092,b503724fix(bob) #1111 (the new base), anda9c441e— this
PR's rewritten commit. The seven before the base arrived by rebase from main; each went through
its own reviewed PR (named in its commit message). I read each message and stat, and read
#1112'sagentmodel_test.gochange in full because it replaces this PR's core fix. - Read in full: 2 reviews, 2 comments, 0 inline comments (from the three saved files).
- New items since my last review, and what I did about each:
- Author comment 09:11:12 (round-1 follow-up, head
2826e20f): read. Superseded by the next
comment. - Author comment 09:29:46 (plan change, head
a9c441e4): read. Verified the claim:
git diff b5037247..HEAD -- proxy/agentmodel_test.gois empty, so the PR takes main's #1112
version exactly. Main's version covers my round-1 point 1 by checking the drain's return. - The rewritten commit
a9c441e4: read the full diff (9 files) and each changed file around
the changes. Details below. - Updated PR body: read. It matches the new state (no agentmodel claim, no-caller note for
Upstream, the deadline cap, and theproxy-suite omission disclosed).
- Author comment 09:11:12 (round-1 follow-up, head
- The six migrated poll loops (
proxy/keepalive_billed_contract_test.go,
proxy/keepalivehost_test.go, the fourproxyapp/dashemitter_*_test.go) are byte-identical to
the round-1 head (empty diffe55a7f52..a9c441e4on those files). I approved them in round 1
after checking stop conditions, error handling and nil-page safety; nothing to re-review. - The new
internal/testutilcode since round 1:effectiveBound(testutil.go:74): type-assertsDeadline(), cuts the bound by
deadlineMargin(5 s), floors atpollIntervalvia themaxbuiltin (Go 1.21+, module is
Go 1.26). With no deadline (-timeout 0) or a test double withoutDeadline, the old 30 s
bound stands. Correct.describe(testutil.go:88): named return plusrecover, so a panickingstatebecomes
(state func panicked: ...)in the message instead of masking the timeout. Correct.NewUpstream(t, nil)(upstream.go:44): replies 200{}after recording. Correct.- The three new tests: traced each for vacuous-pass paths; each fails when the behavior is
missing (d.msgempty, message without "boom", status or body mismatch).iois the one new
import intestutil_test.goand is used.
- Compile-level checks on the new files: all imports used (
fmtintestutil.gofordescribe),
no name collisions,deadlineTB's promoted methods resolve through the embedded value. - Repo rules: test-only, no production behavior change, data dependence none — unchanged from
round 1. The rebase brought main'sCLAUDE.mdforce-push rules into this worktree; this review
changed no file outside.review.md. - Live tests were not run; this review is read-only, as instructed.
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.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | a9c441e4e085 |
approve |
Verdict: approve
Still test-only. No production file changed. The three fixes I checked in the new
internal/testutil code are correct. I found no defect.
Findings
None.
Earlier findings
Mine (round 1):
WaitFor/WaitForStateignoret.Deadline()— fixed.effectiveBound
(internal/testutil/testutil.go:64) cuts the bound to the time left before the test
deadline minus 5 s, never below one poll interval.TestWaitForGivesUpBeforeTheTestDeadline...
covers it. The type assertion oninterface{ Deadline() ... }is the right idiom:
testing.TBhas noDeadlinemethod, so a fakeTB(therecorder) simply skips the
cut instead of panicking on a nil promoted method.- The
want == 0drain does not wait out deferred commissions — left this PR.
#1112 (commitc8f9b67e) took overproxy/agentmodel_test.go; this PR no longer
touches that file (empty diff against the new base). I read #1112's change: it drains
withWaitForAllSummariesForTest(10 s)in the body and checks the return value. My
round-1 proof still holds there: plainsummarizeregisters ininFlight.jobson the
request goroutine (summarize_async.go:227), before the response, so the drain cannot
miss a summary of these tests. - Nil
respondpanics inNewUpstream— fixed. A nilrespondnow replies 200
with{}(internal/testutil/upstream.go:44). New test covers it. - A panic in
state()masks the timeout — fixed.describe
(internal/testutil/testutil.go:87) recovers and turns the panic into text.
TestWaitForStateSurvivesAPanickingStateFunccovers it.
Reviewer 2 (round 1), checked myself:
- Cleanup drain ignores the bool — moot in this PR (the agentmodel code left with
#1112). #1112's merged version checks the return value in the body, so the substance
is addressed there. t.Parallelrisk on the process-wide bound — fixed.SetBoundForTestnow says
the bound is process-wide and no test in the package may callt.Parallel.- Unparsable file skipped in the import guard — rejected by the author. The reason
is right: a file that does not parse cannot compile, and theseen < 50floor guards
the walk. I verified the same in round 1.
Non-blocking
NewUpstream,Upstream,Matching, andWaitForCallhave no caller outside their
own tests. The PR body says so and names the reason (the next migrations will use
them). Fine as staging.
What I checked
- Last review: round 1,
e55a7f5251e0d7cf4466dbb95ba030aacc441b2c, 2026-11-12T08:18:56Z. - New commits read: 8 —
a9c441e4(this PR, rewritten head),b5037247(#1111, new
base),cd82e95a(#1092),fff61bfb(#1096),826e46f7(#1117),c8f9b67e(#1112,
the #1110 fix that left this PR),245f584b(#1115),89c98de6(#1121). - Read in full: 2 reviews, 2 comments, 0 inline comments (from the three saved files).
- New items since my last review: the rewritten head
a9c441e4(reviewed below), the
author's two comments (09:11 and 09:29 — plan change: #1110 left for #1112), and the 7
main commits from the rebase (checked for interaction; none touches the six migrated
test files). - The round-2 diff (
b5037247..a9c441e4), file by file.proxy/agentmodel_test.go
is absent: the file matches main exactly, as the author's comment says. effectiveBound. Read the logic:max(left, pollInterval)keeps the bound at one
poll when the deadline is inside the margin, so the wait fails fast with its own
message instead of hanging into "test timed out". The bound is cut once, at wait start;
correct, since the cut only needs to hold for that wait.deadlineTBtest. Traced the panic path:Fatalfis promoted onto&d.recorder,
the deferred recover matches that pointer, so the fake swallow works and the message
assertions run. IfWaitForreturned without failing,d.msgstays empty and the test
fails — it cannot pass vacuously.- Nil-
respondand panicking-statetests. Both reach the new code paths and assert
on the reply body and the message text. - The six migrated poll loops are byte-identical to round 1 (same hunks against the
new base). My round-1 checks stand: stop conditions, error handling, nil-page safety
(dash.DB().Requestsreturns a nil page only with an error,dash/query.go:288-313),
anderr != nilshort-circuit in every condition closure. internal/boundary. The newtestutil.gocode adds onlyfmt(indescribe);
no bannednet/httpselector. The boundary rule holds.- Repo rules. Test-only; data dependence "none" is right; no behavior change. The
commit carries DCO sign-off andAssisted-By:attribution per repo convention. The PR
body matches the new state of the branch, including the "no caller yet" disclosure. - I did not run builds or tests. Live tests were not approved for this review.
…tests (#1132) The agentmodel tests wait for the detached summary calls before they count them. Since #1073 the summary call runs off the request path, and #1112's drain waits only for summaries already in flight, so "none started yet" passed as "none in flight". Each test that counts summary calls now waits through testutil.WaitForState (#1122) for the wanted call, with a 30 s bound, after first waiting for any summary an earlier test left running. The want-0 tests keep one read after the drain. The failures were not reproduced locally (0 in 7,000 runs before and after), so the race is inferred from the code. CI failed on these tests 3 times on 2026-11-12, on PRs that did not touch them. Behavior change: none (one test file). Data dependence: none. Fixes #1110. Reviews: 2 offload review rounds (GLM). Round 2: both approve at 3ad22bd, which is the PR head. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Summary
Part 1 of the repo-wide flaky-test fix. Test-only, no behavior change.
-racemakes both worse.#1110 was fixed by #1112. This PR no longer touches
proxy/agentmodel_test.go. It holds the shared helpers and the hot-path migrations (keep-alive and dashemitter).Data dependence: none. The PR changes tests only. No component or feature changes.
What changed
internal/testutil(test files only).WaitFor(t, what, cond): polls every 2 ms. Safety bound is 30 s. On timeout it callst.Fatalfwithwhatand the elapsed time.WaitForState(t, what, cond, state): same, and the failure shows what the test saw last.Upstream: a fake HTTP server that records each request.WaitForCall(t, what, n, match)waits fornmatching requests.TestNoProductionPackageImportsTestutilfails when a non-test file imports the package.UpstreamandWaitForCallhave no caller yet. The next migrations will use them. They have their own tests.WaitForalso stops beforet.Deadline()(minus 5 s), so its message shows in place of a bare "test timed out".WaitFor:proxyapp/dashemitter_{limits,savings,manual,waitcause}_test.go,proxy/keepalivehost_test.go(waitPings,waitSkipped),proxy/keepalive_billed_contract_test.go(two loops).How it was tested
Box,
-race. Load = 16 busy loops undertaskset -c 0-3, with the test under the sametasksetandGOMAXPROCS=4. Loops killed by pid after.-count=20to-count=50: 0 failures.internal/testutil: a condition that never holds fails with itswhat, elapsed time and state; a nilrespond; a panickingstate(); the test deadline cap.go test -race -count=1:internal/testutil,internal/boundary,proxyapppass.go vetandgofmt -lclean.TestHandlerKeysRowsAndKeepAliveByThread(proxy/thread_test.go) fails under load on unmodified main too. It is a flake candidate for a later PR.Follow-ups (not in this PR)
About 50 test files still have
time.Now().Add(N*time.Second)loops. Local copies of a wait helper to move totestutil:modes/modes_test.gowaitForproxy/modes_test.goawaitSnapshotproxy/dash_test.gowaitForRowsproxy/feedback_test.gowaitForSinkdash/grace_test.gowaitForRowCountdash/reprice_test.gowaitFor(best shape; 5 s bound)keepalive/keeper_test.gowaitPings,waitSkippedinternal/modelinfo/litellm/decode_test.go,internal/modelinfo/builtin_test.gocomponents/offload/summarize_testhook.go(production-side hook; leave as is)Other files with fixed-deadline loops:
dash/*(about 20 files),keepalive/*(6),proxy/*(about 12),components/offload/*(2),context-guru-plugin/*(3),proxyapp/hooks_test.go.Also: 54
time.Aftertimeouts to review.