Skip to content

accelerate-v0.6.396

@kanat kanat tagged this 26 Nov 16:26
## Race

CI (Go) on #2517 failed with a data race in
`TestAgentSuite/TestAVoiceLostWhileAReplyIsHeldForAGreetingDropsIt`; the
rerun passed.

```
Write:         (*Agent).loseVoice.func1  pipeline.go:943   a.performs = next.Performs()   (under a.mu)
Previous read: (*Agent).say              agent.go:3577     if !a.performs                  (no lock)
               consumeLLM -> handle -> say
```

`loseVoice` swaps `a.tts`, `a.voicePrompt` and `a.performs` under `a.mu`
in its own goroutine. `say` and `finish` run on the goroutine that reads
the model, and read `a.performs` without the lock. So did the two
helpers they call, `sentencesOf` and `inMessage`. A reply could be cut
with the wrong voice's rule.

## Readers of the three fields in `internal/agent`

| Field | Reader | Under `a.mu` |
|---|---|---|
| `performs` | `say`, `finish`, `sentencesOf`, `inMessage` | no (fixed
here) |
| `performs` | `sayAgain` | yes, snapshot |
| `voicePrompt` | `prompted` | yes, every caller holds the lock (`ask`,
`respondAfterTool`, `respondTurn`, `follow`, `pauseAsker.Moment`,
`speculate`, and `instructions()` from the photo question, `compose`,
`followNative` and the tool update) |
| `tts` | every other read (`sayFor`, `backchannel`, `checkIn`,
`sayComposed`, `sayToolUpdate`, `voice`, `settleVoice`,
`releaseUnheard`, `abandonReply`, `replyHeardLocked`, `modelsChanged`,
`loseVoice`, `swapCascade`, `releasePipeline`) | yes |

## Fix

`say` and `finish` read `performs` once under `a.mu` (new
`performing()`, beside `voice()`), and pass it to `sentencesOf` and
`inMessage`. `sayAgain` already snapshots the field this way.

## Runs

- Before: 8 processes of the race-built test binary, 150 runs each of
the CI test, on base: 5 `WARNING: DATA RACE` reports in 1200 runs
(`agent.go:3577`, `speaking.go:447`). A single process, 100 runs, had
none.
- After: same 8 x 150 on the fix: 0 reports.
- New `TestAReplyIsCutWhileTheVoiceIsReplaced` (a swap loop against
`say` and `finish`): on base it reports a race at each of
`agent.go:3577`, `agent.go:3619`, `speaking.go:436` and
`speaking.go:447`; on the fix it is clean. Each reader reverted alone
fails it.
- `go test -race ./internal/agent`: `ok` (182 s).

## Review

- **Round 1: NO-GO.** The new test did not reach the two `inMessage`
calls in `finish`. With `a.performs` put back at either call, the test
still passed. Its reply is now `"Hello there. Then <ask x. Bye"`, so it
reaches both calls, and all 10 mutants of the fix fail it.
- **Delta 1: GO**, with no new findings.
- **Follow-up:** `say` and `finish` also read `a.harness` without the
lock while `stopPipeline` clears it. This PR does not change that code.
It is filed as AI-3985 to probe under `-race`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Assets 2
Loading