Repository navigation
AI-3671: fix two flaky TestAgentSuite subtests (transcriber, held ms) - #2557
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE
kanat
left a comment
There was a problem hiding this comment.
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 atagent_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.TestAgentSuitex1 under-raceis 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). WithearsAfter, 0 of 40. - Test power:
earsAfteris returned only whenopened > 1, so "earsAfter heard" impliesopened >= 2, and the finalEqualValues(2, ...)pins it. Every agent the oldopened == 2check 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, pluslistennever storing the session andconsumeSTTclosing instead of dropping its session. - Other users:
earsAfteris set only in this test and reset inSetupTest. Every otherjoin/joinWithVoicecaller keeps the old factory path.consumeEdgeislisten's only caller and runs on one goroutine, soopenedcannot pass 2 through a double open.
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
left a comment
There was a problem hiding this comment.
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 beforewait()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.
Why
Two causes, both in tests, flake
TestAgentSuite(AI-3671).TestATranscriberThatDiesIsReplacedOnTheNextAudiofailed 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 sames.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 == 2is true only between two polls, and a slow poll misses it.How it works
The new fixture field
earsAfteris set before the agent joins, so no goroutine races the write (asreplacementdoes for the voice).TestHeldMsIsRecordedWhenTheReplyWaitedForTheCheckfailed in run 45445002013 with"0" is not positive. The test closed the check'sreleaseas soon as the model was asked (guardrail_test.go). A reply that reachedscreening.wait(agent.go:3288) after that found the verdict in and held for 0, which is whatwaitis meant to say. The test now releases the check only once a goroutine is blocked receiving inscreening.wait.waitis unchanged.Evidence
-race -cpu 4-race -cpu 1-cpu 4x500)CI's failing log shows the same run-away: after the fatal
speech transcription timing ... error_code=provider_fatalline, onesuccess=truesession-end line per chunk.TestHeldMsIsRecordedWhenTheReplyWaitedForTheCheck: a probe that delays the reply's arrival atwaitby 20 ms (a sleep before the call instartReply, scratch only) fails the old test 19 of 20 at-race -cpu 1and 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 touchedguardrail_test.goorguardrail.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 forTestActingWithAnotherTranscriberARunItEndsMidSentenceIsNoTurn). Whether the merged fixes #2347 (turn ids), #2343 and #2323 explainTestAnAnswerNoVoiceSaidIsOwedAgainandTestActingWithAnotherTranscriberARunItEndsMidSentenceIsNoTurnwas checked only by commit ancestry (their failing runs lack those fixes).TestAnAnswerTalkedOverWhilePlayingIsToldAgain,TestACorrectionOverAnAnswer...andTestACallersToolFailureIsLoggedWithoutItsWordswere 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 news.earsthemselves.The
websocket: close 1006lines 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
eventually(waitingOnACheck)line fails the test under the 20 ms probe (above).TestAgentSuiteunder-raceon head merged with main: five runs (1 + 2 + 2) green. A sixth run failed and its output was lost, so which test is unknown.-race: green except one failure ofTestAudioANativeModelHeardIsNotJudgedForWords(silence_test.go), which [AI-3803] Wait for the audible native frame before judging the call #2424 (AI-3803) fixes.-race -cpu 1and 300 at-race -cpu 4, plus 500 at-cpu 4on the first commit.🤖 Generated with Claude Code
https://claude.ai/code/session_01EZsRxWUwySyG1JAn9T7GpE