Skip to content

test(proxy): wait for the detached calls in the remaining agentmodel tests (#1110) - #1132

Merged
amiddavid merged 4 commits into
mainfrom
test/agentmodel-wait-more
Nov 12, 2026
Merged

amiddavid merged 4 commits into
mainfrom
test/agentmodel-wait-more

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Two agentmodel tests read the upstream's calls once, right after the response. They now wait for the summary call, with a time limit. Test only.

What we found

  • TestPanickingAgentModelTargetFailsOpenToTheHostDefault and TestMalformedAgentModelTargetKeepsTheHostDefault use summaryCallWith. It takes one snapshot of the calls.
  • test(proxy): wait for the detached summary call in the agentmodel tests #1112 made postSummarizable wait until no summary is in flight. That check cannot tell "no summary started" from "the summary has not started yet".
  • A summary that an earlier test left running also holds a process-wide slot and a session key. It can make summarize decline the next test's summary.
  • We could not reproduce the failure on the box. Before the fix: 0 failures in about 11,000 runs (see below). The change closes the two gaps above. It is not proven against the CI failure.

What changed

  • postSummarizable waits for earlier summaries to end before it sends the request.
  • New awaitSummaryCalls: polls (2 ms) until the wanted summary calls arrive, 10 s limit. Then waits for all summaries to end, so a late extra call shows.
  • summaryCallWith uses it. No fixed sleep.

How it was tested

On the box, -race, programs pinned to 2 CPUs, many copies in parallel.

  • Before: 0 failures in 3,000 runs of the 2 tests (30 copies x 100), 0 in 4,000 (40 x 100), 0 in about 4,000 runs of the Bob/OpenAI/AgentModel/Summar group.
  • After: 8 copies x -count=300 of the 2 tests (2,400 runs): 0 failures. The wider group at -count=2: pass.
  • gofmt -l and go vet: clean.

Test only. No behavior change. Data dependence: none.

Fixes #1110.

Update

  • Rebased on main with test: add internal/testutil.WaitFor and use it for #1110 and the hot-path polls #1122. The summary-call wait now uses testutil.WaitForState (30 s bound, reports the last state seen). No new helper.
  • After this change: 7 agentmodel tests at -race -count=100: pass.
  • Not changed: WaitForAllSummariesForTest still ignores the deferred and dispatching sets. These tests use plain summarize, which does not defer.

…tests (#1110)

The panic and malformed-target tests read the summary call once, right
after the response. They now wait, with a time limit, until the summary
call arrives, then wait for every detached summary to end. The request
helper also drains summaries that an earlier test left running.

Test only. No behavior change. Data dependence: none.

Fixes #1110.

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid
amiddavid force-pushed the test/agentmodel-wait-more branch from 5fca0a2 to db1b347 Compare November 12, 2026 11:57

@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.322 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 db1b34718c1b approve

Verdict: approve

Findings

None.

Non-blocking

  • proxy/agentmodel_test.go:157, 178, 309 — three tests that want one summary call still read a fixed snapshot. TestBobSummaryCallUsesBobsModelPathAndApikey, TestOpenAISummaryCallTargetIsUnchanged and TestOpenAIRouteStillFallsBackToTheOperatorsKey read the calls that postSummarizable returns. TestOpenAISummaryCallTargetIsUnchanged is one of the two tests #1110 names. The new comment on awaitSummaryCalls (line 135) says "A test that wants a call must use it". I traced the timing and these three are safe today: inFlight.begin runs inside the pipeline, before the proxy answers (proxy/proxy.go:1523 runs applyMode before the forward); the fake upstream records the call in the goroutine body, before the deferred inFlight.finish (components/offload/summarize_async.go:267-268); WaitForAllSummariesForTest reads the same registry. So the drain cannot return before the call is recorded. The gap that remains for them is diagnosis only: on a decline they fail with "got 0 summary calls" and no state. Converting them would give one rule and a better failure text.
  • proxy/agentmodel_test.go:144 — the second wait is not deadline-aware. testutil.WaitForState cuts its bound to the test deadline minus 5 s, so its failure message shows. The WaitForAllSummariesForTest(30 * time.Second) after it has no such cut. If a job hangs after the wanted calls arrived, the t.Fatal can be replaced by a bare "test timed out". The window is narrow (the job ends right after the call and the commit), so this is minor.

What I checked

  • The full diff (1 file, +31/−1) and both commits, line by line.
  • The flake paths the change closes. A summary left over from an earlier test is the only decline the CI failure shape fits ("0 summary calls, all calls: 1" with the drain in place means summarize never commissioned): summary_already_in_flight (same derived session key, process-wide registry) and summary_concurrency_full (8 process-wide slots). Both are drained by the new pre-wait, for every postSummarizable caller, not only the two converted tests.
  • The happens-before chain for the post-response drain, named under the first non-blocking item. The start-latency window the PR description names ("not started yet") cannot produce a 0-call result for a commissioned summary, because begin runs before the response.
  • awaitSummaryCalls itself: the poll condition and the state func are mutex-safe reads of the fake upstream; WaitForState fails with t.Fatalf on the test goroutine; a second summary arriving before the final read is caught by the len(got) != 1 check with a clear message.
  • The want-0 tests (TestBobRouteNeverSendsTheOperatorsOpenAIKey, TestAMisbehavingAgentRouteNeverSendsTheOperatorsOpenAIKey): their decline is decided during request handling (no_model, proxy/proxy.go:1106-1111), so no late summary can make them pass spuriously.
  • Scope and hygiene: no production file touched; fmt and internal/testutil imports are used; testutil is test-only by design and this is a _test.go file; the helpers are used only in this file. No behavior change, data dependence none — matches the PR text.
  • I did not run the tests. Live runs are not approved for this review.

@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 @amiddaid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 offload-review skill, @amiddaid's session fresh 1 of 2 1 of 2 db1b34718c1b approve

Verdict: approve

Findings

None.

Non-blocking

  • proxy/agentmodel_test.go:157, 178, 309 — three tests that want one summary call still read a fixed snapshot. TestBobSummaryCallUsesBobsModelPathAndApikey, TestOpenAISummaryCallTargetIsUnchanged and TestOpenAIRouteStillFallsBackToTheOperatorsKey read the calls that postSummarizable returns. TestOpenAISummaryCallTargetIsUnchanged is one of the two tests #1110 names. The new comment on awaitSummaryCalls (line 135) says "A test that wants a call must use it". I traced the timing and these three are safe today: inFlight.begin runs inside the pipeline, before the proxy answers (proxy/proxy.go:1523 runs applyMode before the forward); the fake upstream records the call in the goroutine body, before the deferred inFlight.finish (components/offload/summarize_async.go:267-268); WaitForAllSummariesForTest reads the same registry. So the drain cannot return before the call is recorded. The gap that remains for them is diagnosis only: on a decline they fail with "got 0 summary calls" and no state. Converting them would give one rule and a better failure text.
  • proxy/agentmodel_test.go:144 — the second wait is not deadline-aware. testutil.WaitForState cuts its bound to the test deadline minus 5 s, so its failure message shows. The WaitForAllSummariesForTest(30 * time.Second) after it has no such cut. If a job hangs after the wanted calls arrived, the t.Fatal can be replaced by a bare "test timed out". The window is narrow (the job ends right after the call and the commit), so this is minor.

What I checked

  • The full diff (1 file, +31/−1) and both commits, line by line.
  • The flake paths the change closes. A summary left over from an earlier test is the only decline the CI failure shape fits ("0 summary calls, all calls: 1" with the drain in place means summarize never commissioned): summary_already_in_flight (same derived session key, process-wide registry) and summary_concurrency_full (8 process-wide slots). Both are drained by the new pre-wait, for every postSummarizable caller, not only the two converted tests.
  • The happens-before chain for the post-response drain, named under the first non-blocking item. The start-latency window the PR description names ("not started yet") cannot produce a 0-call result for a commissioned summary, because begin runs before the response.
  • awaitSummaryCalls itself: the poll condition and the state func are mutex-safe reads of the fake upstream; WaitForState fails with t.Fatalf on the test goroutine; a second summary arriving before the final read is caught by the len(got) != 1 check with a clear message.
  • The want-0 tests (TestBobRouteNeverSendsTheOperatorsOpenAIKey, TestAMisbehavingAgentRouteNeverSendsTheOperatorsOpenAIKey): their decline is decided during request handling (no_model, proxy/proxy.go:1106-1111), so no late summary can make them pass spuriously.
  • Scope and hygiene: no production file touched; fmt and internal/testutil imports are used; testutil is test-only by design and this is a _test.go file; the helpers are used only in this file. No behavior change, data dependence none — matches the PR text.
  • I did not run the tests. Live runs are not approved for this review.

@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.322 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 db1b34718c1b blocking

Verdict: blocking

Findings

  1. proxy/agentmodel_test.go:178 — the issue's first named test keeps the one-shot read, so the fix for #1110 is incomplete
    • What fails: issue #1110 names two flaky tests. This PR converts only one of them
      (TestMalformedAgentModelTargetKeepsTheHostDefault, through summaryCallWith). The other,
      TestOpenAISummaryCallTargetIsUnchanged, still reads the summary calls once, after only the
      in-flight wait. The PR's own helper comment (agentmodel_test.go:133-136) states the rule:
      "A test that wants a call must use it: the in-flight check alone cannot tell 'no summary
      started' from 'the summary has not started yet'." Three want-a-call sites break that rule:
      line 157 (TestBobSummaryCallUsesBobsModelPathAndApikey), line 178
      (TestOpenAISummaryCallTargetIsUnchanged), and line 309
      (TestOpenAIRouteStillFallsBackToTheOperatorsKey). If the CI flake of #1110 comes back, it
      lands on line 178 first, with the old confusing message ("0 summary calls, want 1"), not the
      new state-reporting one.
    • Proof: the failure message #1110 quotes for this test is "OpenAI upstream got 0 summary
      calls, want 1; all calls: 1". The test at line 178 does not use summaryCallWith, so it gets
      only the new pre-drain, not awaitSummaryCalls. The pre-drain closes one decline path: a
      summary already registered when the drain polls. It does not close a summary that registers
      after the drain and before this request's commission (a deferred or observe-pool commission
      another test left pending — WaitForAllSummariesForTest ignores the deferred and dispatching
      sets, which the PR body itself notes). In that case summarize declines, the test reads 0
      calls, and it fails exactly as #1110 reports. The PR body also says "Two agentmodel tests
      read the upstream's calls once" — the issue's first named test is a third one, outside that
      set.
    • Fix: pick one position and apply it everywhere. Either route lines 157, 178 and 309 through
      awaitSummaryCalls (two lines per site, as summaryCallWith now does), or keep the one-shot
      read and state why it is safe for them: the commission happens in Offload, on the request
      goroutine, before the forward (proxy/modes.go:57, components/offload/summarize.go:647), so a
      commissioned summary is always in flight when the post-response drain runs. If the second
      position holds, the helper comment's rule is wrong as written and should say so.

Non-blocking

  • WaitForAllSummariesForTest does not wait out pending deferred commissions or the dispatching
    set, unlike WaitForSummaryForTest (components/offload/summarize_testhook.go:24-48 vs 64-76).
    These tests run plain summarize, which defers nothing, so it is harmless here. The PR body
    says the same.
  • summaryCallWith now drains twice: once inside postSummarizable, once in awaitSummaryCalls.
    The second drain is nearly always instant. Harmless.
  • A declined summary in a summaryCallWith test now costs up to 30 s before the clear
    WaitForState failure, where the base code failed at once with a confusing message. Better
    diagnostics, slower failure. Acceptable.

What I checked

  • Read both commits in full (c85063c, db1b347) and the diff against base abb77b1. One file
    changed: proxy/agentmodel_test.go, test only.
  • Read every changed line and the code around it: postSummarizable, summaryCallsOf,
    awaitSummaryCalls, summaryCallWith, and all six postSummarizable call sites.
  • Traced the wait chain: offload.WaitForAllSummariesForTest (components/offload/summarize_testhook.go:64)
    and testutil.WaitForState (internal/testutil/testutil.go:45), including the bound, the
    deadline margin and the panic-safe state func.
  • Traced the commission path to check the one-shot read's soundness: the proxy runs the pipeline
    synchronously before the forward (proxy/proxy.go:1523, proxy/modes.go:57), Summarize.Offload
    calls startAsyncSummary (components/offload/summarize.go:647), and inFlight.begin registers
    the job before the request continues (components/offload/summarize_async.go:227, 136-150). So a
    commissioned summary is in flight before the client sees a response, and the drain cannot miss
    it. The only failure mode left for a want-a-call test is a decline, which needs a colliding
    job: same conv key (session derived from the transcript, components/offload/state.go:543,
    session/session.go:206 — all tests in this file share it) or a full global bound (8 slots).
  • Checked the contamination sources the pre-drain guards against: test files that run before
    agentmodel_test.go in file order commission no summaries; observe-mode and cache-aware tests
    that can commission late live in later files, so they matter only under -count>1, which is
    the issue's own repro method.
  • Checked the want-zero tests (TestBobRouteNeverSendsTheOperatorsOpenAIKey,
    TestAMisbehavingAgentRouteNeverSendsTheOperatorsOpenAIKey): a one-shot read after the drain is
    correct for them; awaitSummaryCalls would not fit a want-zero assertion.
  • Checked compile-level concerns: fmt and internal/testutil imports are used and allowed
    (other proxy test files already import testutil; the guard test targets production files).
  • Checked the process rules: test only, no behavior change, data dependence none, DCO sign-off
    and Assisted-By present on both commits, conventional-commit titles.
  • Did not run builds or tests: live tests are not approved for this review, and Go is not on
    this machine.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 fixed. The three tests that wanted 1 summary call and still read once now use awaitSummaryCalls (testutil.WaitForState): TestBobSummaryCallUsesBobsModelPathAndApikey, TestOpenAISummaryCallTargetIsUnchanged, TestOpenAIRouteStillFallsBackToTheOperatorsKey.

The two tests that want 0 calls keep the one-shot read after the drain, as reviewer 2 found sound.

Box, -race -count=100, the 7 agentmodel tests: pass. gofmt -l: clean.

@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.322 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 3ad22bdcdea7 approve

Verdict: approve

Findings

None.

Earlier findings

  • Reviewer 2, round 1, finding 1 (the three one-shot want-1 tests) — fixed. Commit 3ad22bdc routes TestBobSummaryCallUsesBobsModelPathAndApikey, TestOpenAISummaryCallTargetIsUnchanged and TestOpenAIRouteStillFallsBackToTheOperatorsKey through awaitSummaryCalls (proxy/agentmodel_test.go:157-158, 179-180, 311-312). I checked the fix: every want-1 site now uses the wait, and the two want-0 tests keep the one-shot read, which is correct for them. This was also my round-1 non-blocking note 1, now resolved. The fix follows the first remedy reviewer 2 proposed, so the helper comment's rule and the code now agree.
  • My round-1 non-blocking note 2 (the second wait in awaitSummaryCalls is not deadline-aware) — not addressed, still minor. proxy/agentmodel_test.go:144 keeps the plain 30 s bound. The window is narrow and the failure text is only diagnostic, so this stays non-blocking.

Non-blocking

  • summaryCallWith and the three converted tests now drain twice per test: once at the end of postSummarizable, once inside awaitSummaryCalls. The second drain is nearly always instant. Harmless.
  • Reviewer 2's round-1 non-blocking note on WaitForAllSummariesForTest ignoring the deferred and dispatching sets still holds. These tests run plain summarize, which defers nothing. No change needed.

What I checked

  • Last review: round 1, db1b34718c1b01d005662f43b9fed8dcddd4cf04, 2026-11-12T12:18:45Z.
  • New commits read: 3 — 192b5f65 (merge of origin/main), 9d20eef3 (#1091, from main), 3ad22bdc (the fix). 981c7eaf (#1119) also came in through the merge.
  • Read in full: 3 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 (12:41:36Z, blocking): read in full. Its finding names the same three sites as my round-1 note. I checked the fix against it (see "Earlier findings").
    • The author's comment (12:46:32Z): read. It states the fix and the box result (-race -count=100, pass). Nothing in it asks for more work.
    • The merge 192b5f65: verified clean. git diff 9d20eef3..192b5f65 shows only this branch's test changes (+31/−1, one file), and the merge changes nothing in proxy/agentmodel_test.go against the branch parent. No hand resolution. The two main commits it brings (#1119, #1091) carry their own two-round reviews and are outside this PR's diff.
    • Commit 3ad22bdc: read the whole diff and the file around each change. The conversion is mechanical, the same pattern summaryCallWith already uses. The len(got) != 1 checks and their messages are kept.
  • The PR diff against the new base 9d20eef3 is one file, proxy/agentmodel_test.go, +37/−4. No production code, no behavior change, data dependence none.
  • Grepped every postSummarizable / awaitSummaryCalls call site: 4 want-1 sites use the wait, 2 want-0 sites keep the one-shot read.
  • I did not run the tests. Live runs are not approved for this review.

@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.322 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 3ad22bdcdea7 approve

Verdict: approve

Findings

None.

Earlier findings, this round

  • My round-1 finding (agentmodel_test.go:178 — three want-a-call tests on the one-shot read):
    fixed.
    Commit 3ad22bd routes all three sites through awaitSummaryCalls(t, calls, 1):
    TestBobSummaryCallUsesBobsModelPathAndApikey (line 158),
    TestOpenAISummaryCallTargetIsUnchanged (line 180) — one of the two tests #1110 names — and
    TestOpenAIRouteStillFallsBackToTheOperatorsKey (line 312). The pattern matches
    summaryCallWith. The assertions are unchanged. The helper comment's rule ("a test that wants
    a call must use it") now holds for every want-a-call site in the file.
  • Reviewer 1's non-blocking item, same three sites: fixed by the same commit. I checked it
    myself; same proof as above.
  • Reviewer 1's non-blocking item (agentmodel_test.go:144 — the second wait is not
    deadline-aware): not addressed, still non-blocking.
    The WaitForAllSummariesForTest(30s)
    after WaitForState still has no deadline cut. The window is narrow (it starts only after the
    wanted calls arrived), and three more tests now run this path, but a hung job there still ends
    in a bare "test timed out" rather than the helper's message. Fine to leave.

Non-blocking

  • The fix commit's message body is empty: no "Data dependence: none" line, unlike the two earlier
    commits. The PR body carries the statement, and the change is test only. Not a problem.
  • The PR body's Update section says "Rebased on main with #1122". The merge (192b5f6) brings in
    #1119 and #1091. A reader may look for the wrong PR number. Cosmetic.

What I checked

  • Last review: round 1, db1b347, 2026-11-12T12:41:36Z.
  • New commits read: 3 (192b5f6 "Merge remote-tracking branch 'origin/main' into
    test/agentmodel-wait-more", which brings 981c7ea #1119 and 9d20eef #1091 from main;
    3ad22bd "test(proxy): wait for the summary call in the three remaining one-shot tests
    (#1110)").
  • Read in full: 3 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:
    • Author comment at 12:46:32Z ("Round 1 fixed... -race -count=100... pass"): verified every
      claim against the code. The three named tests do use awaitSummaryCalls now. The two want-0
      tests keep the one-shot read, which matches my round-1 analysis (a want-0 assertion cannot
      use awaitSummaryCalls as written).
    • Fix commit 3ad22bd: read the full diff and the three changed tests in the file. Checked the
      assertions are unchanged, the pattern matches summaryCallWith, postSummarizable's return
      is still used by the two want-0 tests (no dead code), and no other line of the file moved.
    • Merge 192b5f6: checked it does not touch proxy/agentmodel_test.go (empty diffstat for the
      file), and the PR diff against the new base 9d20eef is the test file only (+37/−4). The two
      main commits it brings (#1119, #1091) touch store, tenancy, accountant and dash code, none of
      which these tests or the summarize wait path read; both carried their own two review rounds.
  • Re-checked the round-1 trace on the final head: postSummarizable still pre-drains and
    post-drains; awaitSummaryCalls (lines 135-150) is unchanged since round 1.
  • Commit conventions on 3ad22bd: conventional title, DCO sign-off, Assisted-By. Present.
  • Did not run builds or tests: live tests are not approved, and Go is not on this machine. The
    author's box runs (-race -count=100, pass) are the author's report.

@amiddavid
amiddavid merged commit c8e3d5b into main Nov 12, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 12, 2026
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(proxy): agentmodel_test summary-call tests are flaky in CI

1 participant