Skip to content

AI-3671: fix two flaky TestAgentSuite subtests (transcriber, held ms) - #2557

Merged
kanat merged 4 commits into
mainfrom
kanat/ai-3671-agent-suite-flake
Nov 27, 2026
Merged

kanat merged 4 commits into
mainfrom
kanat/ai-3671-agent-suite-flake

Conversation

@kanat

@kanat kanat commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Two causes, both in tests, flake TestAgentSuite (AI-3671).

  1. TestATranscriberThatDiesIsReplacedOnTheNextAudio failed in CI (Go) run 45660334287 with "the dead transcriber was kept". The agent did replace the transcriber. The cause is in the test: its stub transcriber factory hands every session the same s.ears, and closing the dead session closes that stub's event stream for good. So each replacement ends as soon as it opens, the next chunk opens another, and the counter the test waited on runs past 2. opened == 2 is true only between two polls, and a slow poll misses it.

How it works

before: every session is s.ears
  chunk ─> session 1 ─ fatal ─> closed (s.ears events end)
  chunk ─> session 2 (s.ears, already ended) ─> ends at once
  chunk ─> session 3 ─> ends at once ...    opened: 1, 2, 3, ... 400
  test polls "opened == 2" every 5 ms ─> misses it when one poll sees 1, the next 3

after: sessions after the first get s.earsAfter, a fresh stub
  chunk ─> session 1 ─ fatal ─> closed
  chunk ─> session 2 (s.earsAfter) ─> stays, hears every later chunk
  test waits until s.earsAfter heard a chunk, then one more, then opened == 2

The new fixture field earsAfter is set before the agent joins, so no goroutine races the write (as replacement does for the voice).

  1. TestHeldMsIsRecordedWhenTheReplyWaitedForTheCheck failed in run 45445002013 with "0" is not positive. The test closed the check's release as soon as the model was asked (guardrail_test.go). A reply that reached screening.wait (agent.go:3288) after that found the verdict in and held for 0, which is what wait is meant to say. The test now releases the check only once a goroutine is blocked receiving in screening.wait. wait is unchanged.
before: model asked ─> test closes release ─> verdict in ─> reply reaches wait(): held 0 (fails)
after:  model asked ─> test waits until the reply is blocked in wait() ─> closes release ─> held > 0

Evidence

What Base 92fcbb8 Head
The subtest x500, -race -cpu 4 1 failure, same message as CI 0
The subtest, -race -cpu 1 0 in 442 (9 min cap at load ~180) 0 in 300
Probe: keep talking until a 3rd transcriber opens opens one in 40 of 40 runs 0 of 40
Session-end lines after the fatal line, per run (-cpu 4 x500) 2 or more in 363 of 499 runs, 402 in the failing one 1

CI's failing log shows the same run-away: after the fatal speech transcription timing ... error_code=provider_fatal line, one success=true session-end line per chunk.

TestHeldMsIsRecordedWhenTheReplyWaitedForTheCheck: a probe that delays the reply's arrival at wait by 20 ms (a sleep before the call in startReply, scratch only) fails the old test 19 of 20 at -race -cpu 1 and 20 of 20 at -cpu 4, and the new test 0 of 100 at each. Without the probe the new test passes 100 of 100 at each. Its failing CI run already had #2347, and no fix on main touched guardrail_test.go or guardrail.go, so that failure is not explained by a merged fix.

The other subtests listed on AI-3671 do not fail on base, at 100 runs each under -race -cpu 4 (60 for TestActingWithAnotherTranscriberARunItEndsMidSentenceIsNoTurn). Whether the merged fixes #2347 (turn ids), #2343 and #2323 explain TestAnAnswerNoVoiceSaidIsOwedAgain and TestActingWithAnotherTranscriberARunItEndsMidSentenceIsNoTurn was checked only by commit ancestry (their failing runs lack those fixes). TestAnAnswerTalkedOverWhilePlayingIsToldAgain, TestACorrectionOverAnAnswer... and TestACallersToolFailureIsLoggedWithoutItsWords were not reproduced and their cause is unverified (#2304 touches only the last one's file). No other test in the suite reopens a transcriber after its stub has closed; the two that let a caller leave and come back give it a new s.ears themselves.

The websocket: close 1006 lines in the failing logs are logged by the speech-to-speech path (native.go:400), which this subtest does not use; each of the three local runs of the suite printed 21 to 24 of them, rounds 2 and 3 all green, so they are not the cause.

Validation

  • Mutation for the held-ms wait: dropping the new eventually(waitingOnACheck) line fails the test under the 20 ms probe (above).
  • Mutations of the transcriber fix, each killed by that subtest: the agent reads on after a fatal error; the agent keeps a dropped transcriber in its map; the agent opens a new transcriber for every chunk; the fixture gives no fresh stub.
  • TestAgentSuite under -race on head merged with main: five runs (1 + 2 + 2) green. A sixth run failed and its output was lost, so which test is unknown.
  • Earlier, on the transcriber fix alone, x3 under -race: green except one failure of TestAudioANativeModelHeardIsNotJudgedForWords (silence_test.go), which [AI-3803] Wait for the audible native frame before judging the call #2424 (AI-3803) fixes.
  • The subtest on head: 0 failures in 300 runs at -race -cpu 1 and 300 at -race -cpu 4, plus 500 at -cpu 4 on the first commit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE

@kanat kanat 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.

VERDICT: NO-GO

Reviewed 53cbc20e4 merged onto current main a8e8ba2c2 (the two new main commits touch nothing in internal/agent, stt, sttrouter or audiofloor). CI: go and integration skip on a draft; they run at gh pr ready.

[Should fix] R1.1 PR body, «Evidence»: the line "Their failures predate fixes now on main: #2347, #2304, #2343, #2328, #2323" does not hold for TestHeldMsIsRecordedWhenTheReplyWaitedForTheCheck (CI run 45445002013, head 83d7b2738). That head already had #2347 (git merge-base --is-ancestor d13cc6b13 83d7b2738 succeeds). The three it lacked are test-only and touch other files: #2343 floor_words_test.go, #2328 telephony_test.go, #2323 new tests in agent_test.go. git log 83d7b2738..HEAD -- acceleration/internal/agent/guardrail_test.go acceleration/internal/agent/guardrail.go is empty. The window is still open. The test closes release as soon as the model is asked (guardrail_test.go:617). screening.wait (agent.go:3288-3292) returns 0 when the verdict is already in by the time the reply gets there. In a scratch copy, a probe that makes the reply reach wait() 20 ms late fails 10 of 10 runs with CI's exact "0" is not positive. Fix: correct the body (TestHeldMs has a different cause, is still open, and did not fail in 100 runs). Give it its own ticket, or fix it here if the task owner prefers. The transcriber fix itself is sound.

Checked and sound:

  • Reproduced on base 21b2551e4: 3 failures in 3000 runs at -race -cpu 4, CI's message at agent_test.go:5109. Head: 0 in 1200 runs at -race -cpu 4, 0 in 1200 at -race -cpu 1. Merged tree: 0 in 300 at each. TestAgentSuite x1 under -race is green on the head and on the merged tree.
  • Mechanism: a probe keeps talking after the fatal until a third transcriber opens. Base opens one in 40 of 40 runs (-cpu 1,4). With earsAfter, 0 of 40.
  • Test power: earsAfter is returned only when opened > 1, so "earsAfter heard" implies opened >= 2, and the final EqualValues(2, ...) pins it. Every agent the old opened == 2 check caught is still caught. A transcriber opened per chunk is now caught too. No timeout raised, no assertion dropped.
  • Mutations, 6 of 6 killed 10 of 10 (-race -count=5 -cpu 1,4): the author's M1-M4, plus listen never storing the session and consumeSTT closing instead of dropping its session.
  • Other users: earsAfter is set only in this test and reset in SetupTest. Every other join/joinWithVoice caller keeps the old factory path. consumeEdge is listen's only caller and runs on one goroutine, so opened cannot pass 2 through a double open.

kanat and others added 2 commits November 26, 2026 12:59
TestHeldMsIsRecordedWhenTheReplyWaitedForTheCheck closed the check as soon as the
model was asked, so a reply reaching the gate later found the verdict in and held
for zero. Wait until a goroutine is blocked receiving in screening.wait first.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
@kanat kanat changed the title AI-3671: give the test's replaced transcriber its own stub AI-3671: fix two flaky TestAgentSuite subtests (transcriber, held ms) Nov 26, 2026

@kanat kanat 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.

VERDICT: GO
REVIEWED: d9d2037 (4bef60f + merge of origin/main b11e578, no conflicts: git show --remerge-diff empty) merged onto main b11e578
PRIOR:

  • R1.1 fixed. Old test + 20 ms probe fails; new test passes it (old test: 93/100 at -race -cpu 1 and 100/100 at -cpu 4 fail with the CI message "0" is not positive; new test: 0/100 at each, with the delay before wait() and with it inside). PR body corrected (title, two causes, probe line, honest note on the lost sixth run).
    NEW FINDINGS:
    [Nit] guardrail_test.go:632 waitingOnACheck matches any goroutine in screening.wait: a blocked wait leaked by another test would release early (the old flake returns). No such leak exists today: only the 3 tests that set guards.held block there, each closes release; the suite is serial. In the full suite the dump is 8554 B of the 1 MiB buffer with 12 goroutines, so no truncation. Same technique as internal/session/settings_test.go:304. No action.
    MUTATIONS: 4 checked, 0 survived (old test under a probe before wait() and under a probe inside wait(): killed; helper without the "[chan receive" state check + sleep in wait: 60/60 fail)
    UNVERIFIED:
  • CI: go and integration "skipping" (draft); CodeQL/GitGuardian/labeler pass.
  • TestAgentSuite failure in silence_test.go (AI-3803, #2424, out of scope) seen once in a probe-instrumented build.

Without the probe the new test passes 200/200 at -cpu 1 and 4, with and without -race. TestAgentSuite x3 under -race on the head (= merged onto main b11e578): 1021 subtests pass, 0 fail in each run. One extra run of an instrumented build failed only TestAudioANativeModelHeardIsNotJudgedForWords (silence_test.go:233-234): that is AI-3803 (#2424), out of scope. Delta: one test-only commit (4bef60f) plus a conflict-free merge of main.

@kanat
kanat marked this pull request as ready for review November 26, 2026 18:40
@kanat
kanat merged commit 882c914 into main Nov 27, 2026
15 checks passed
@kanat
kanat deleted the kanat/ai-3671-agent-suite-flake branch November 27, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant