Repository navigation
test(offload): arrange the cross-session single-flight join, not a 150ms sleep (#748) - #749
Merged
Merged
Conversation
…0ms sleep (#748) TestConcurrentIdenticalExtractionsCollapseToOneCall slept 150ms and hoped both sessions were at the single-flight join when the leader was released. Under load a straggler joined after the leader finished, made its own model call, and failed the count assertion. #479 and #162 had the same defect; #742 fixed both with a parked leader. Use that machinery here: parkingModel parks the leader in Complete, the beforeInflightJoinForTest hook reports each candidate's arrival at the join, and the test closes release only after both sessions' candidates have arrived. The follower is now a fact the fixture arranged, not scheduling luck. Remove the sleep and the now-unused blockingModel. Proof on the eval box, 64 concurrent copies of the test binary, 20 runs each under -race: clean origin/main fails 17 of 64 ("made 2 model calls"); this change passes 64 of 64. Also passes -race -count=20 -cpu 1,2,4. Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Oct 27, 2026
amiddavid
left a comment
Collaborator
Author
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.311 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | be1c6e476199 |
approve |
Verdict: approve
Findings
None.
Non-blocking
components/offload/extract_econ_test.go:621— thearrivedchannel has capacity exactlyarrivals. If the fixture ever drifts to more candidates per request (a second tool result, a gate change), the extra hook send blocks forever insidebeforeInflightJoinForTest, and the timeout path'swg.Wait()then hangs too — the failure mode becomes the package timeout, not the intendedFatalfmessage.offloadWithParkedLeader(common_test.go:136) has the same shape, so this matches house style. A send with aselecton a done channel, or a buffer with slack plus an exact-count assertion, would fail cleanly instead.components/offload/extract_econ_test.go:620-656— the hook setup and wait loop re-implementoffloadWithParkedLeaderinline. Justified: the helper takes one request, this test needs two. If a third test needs the same arrangement, generalize the helper to take a list of requests.
What I checked
- Read the full diff: one file,
components/offload/extract_econ_test.go, test-only.blockingModelis deleted; no other file referenced it (grep overcomponents/). - Verified the arrangement is sound, not just different:
beforeInflightJoinForTest(extract_llm.go:1319-1321) fires once per candidate, one statement beforeextractInflight.Do.toolIndices(common.go:457) picks only tool-role messages, so one tool result per request gives one candidate per request — 2 arrivals total, as the fixture expects.- The two requests share
e, soe.modelNameandextCfgare identical;extCfg.CacheContextis false in both (1 candidate each, extract_llm.go:1229).cands[k].idisextract.ContentKey(content)(extract_llm.go:919), which is content-derived and session-independent (internal/extract/resultkey_test.gopins this). So both candidates compute the same single-flight key. - The leader parks in
parkingModel.Complete(common_test.go:114-118), so the key is still held when the other candidate reachesDo. Both arrivals are consumed beforeclose(release), so the follower joins as a fact. The cross-session persistent cache (getResultGlobal, extract_llm.go:1023) cannot hit for the second request: the leader parks beforeputResultGlobal(extract_llm.go:1629) runs.e.mode = markerFullkeeps that global path active, so the fixture exercises the real window. - Assertion: only the leader's closure runs, so
model.callsis 1; a follower that failed to dedup would make 2 and fail. Counting viaatomic.AddInt64/atomic.LoadInt64is race-clean.
- Checked the failure paths. On a short-arrival timeout, the test closes
releaseandwg.Wait()s beforeFatalf, so no goroutine races the cleanup that nils the hook. Hook set before the goroutines start, so the write happens-before their reads.wg.Wait()before the assertion on the happy path too. - Checked imports:
time,sync,atomic,mathall still used after thetime.Sleepremoval; nothing dangling. - Checked this is not a vacuous pass: the arrivals loop
Fatalfs if fewer than 2 candidates reach the join, so a gate or cap that trims the batch fails the test rather than passing it silently. - Confirmed no production code changed, so fail-open behavior and data dependence are untouched;
docs/data-dependence.mdneeds no update for a test-only PR.
amiddavid
commented
Oct 27, 2026
amiddavid
left a comment
Collaborator
Author
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.311 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | be1c6e476199 |
approve |
Verdict: approve
Findings
None. The change is correct and removes the timing dependence it targets.
Non-blocking
components/offload/extract_econ_test.go:644— The arrangement has a residual two-statement window. A goroutine can be preempted between the hook send and theextractInflight.Docall (extract_llm.go:1319-1322). If that happens, the leader can finish and drop the key before the follower registers, and the count becomes 2. The window is nanoseconds wide, and the same seam already ships inoffloadWithParkedLeader(common_test.go:133).x/sync/singleflightoffers no observable "waiter registered" point, so this is the best seam available. Note only; no change requested.components/offload/extract_econ_test.go:644-656— Each loop iteration makes a newtime.After(10 * time.Second), so the total wait is up to 20s for 2 arrivals. One deadline for the whole loop would be tighter. Cosmetic.- The arrival loop, hook assignment, and cleanup duplicate
offloadWithParkedLeaderrather than reusing it. The reuse is not possible as-is: the helper runs oneOffload, and this test needs two concurrent ones. Fine as it is.
What I checked
- The full diff
d08eff8b..HEAD: one file,components/offload/extract_econ_test.go, 34 insertions, 19 deletions. One commit,be1c6e47. - The hook seam:
beforeInflightJoinForTestfires atextract_llm.go:1319, one statement beforeextractInflight.Do, insiderunCalland past thellmConcurrencysemaphore (const 4,extract_llm.go:106). Only the leader reachesparkingModel.Complete, so the in-flight key stays held while the other candidate joins. - Candidate count: each request has one tool message and one user message; candidates come from
toolIndices(common.go:457), so exactly one candidate per request and exactly 2 arrivals. The buffered channel of size 2 can never block a sender. - Key identity:
ResultKeyhashesContentKey(content), model name, and config (internal/extract/extract.go:205). Content is byte-identical across the two requests and nothing in the key is session-scoped, so both candidates share one single-flight key. - No vacuous pass: the global result cache is written only after the leader finishes (
extract_llm.go:1510onward, phase 3), andreleaseis closed only after both arrivals. A trimmed or gated candidate now fails the test loudly at the 10s window instead of passing silently. - Cleanup safety:
Offloadwaits for allrunCallgoroutines (extract_llm.go:1498), and the test callswg.Wait()on both the normal and the timeout path beforet.Fatalf. So thet.Cleanupthat nils the hook cannot race a firing goroutine. The timeout path also closesreleasebefore waiting, so it cannot hang. - Concurrency discipline: no test in the package calls
t.Parallel()(both grep hits are comments), so the package-global hook matches the disciplinecommon_test.go:129documents. - Dead code and imports:
blockingModelhad no other references;time,sync,sync/atomic,strings, andcontextare all still used in the file. parkingModel.callsis written withatomic.AddInt64and read withatomic.LoadInt64. No race.
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes one flaky test. Written by GLM through Claude Code.
TestConcurrentIdenticalExtractionsCollapseToOneCallwaited for its two sessions withtime.Sleep(150ms), not a join. The sleep is now gone.What changed
components/offload/extract_econ_test.go: the test now parks the single-flight leader withparkingModeland uses thebeforeInflightJoinForTesthook. It closesreleaseonly after both sessions' candidates have reached the join. The follower is a fact the fixture arranged, not scheduling luck. The unusedblockingModelhelper is removed.Why it happens
The test started two identical extractions in parallel, then slept 150 ms and hoped both had joined the single-flight call by then. On a loaded box, a caller can join late. Then it makes its own model call, and the "one call" assertion fails. #479 and #162 had the same defect; #742 fixed both with the parked-leader helper this change reuses.
How it was tested
All runs on the eval box,
components/offloadonly.go test -race -run TestConcurrentIdenticalExtractionsCollapseToOneCall -count=20 -cpu 1,2,4origin/main-test.count=20 -test.cpu=1, under-racego test -race -count=1 ./components/offload/gofmt -l components/offload/go vet ./components/offload/Data dependence
None changes. Test-only change.
Skipped
None.
Closes #748
🤖 Generated with Claude Code