Chat queue: handle usage refusals only after start-up recovery; fix shell share test ordering

TestAutoSwitchReplacesTheAutoContinue flaked because a usage refusal (delivered
on its own goroutine) was acted on while start-up recovery was still running.
resumeQueued read the durable auto-continue row, the server's account switch
then removed it, and resumeQueued put it back into the room; as the queue head
scheduled an hour out it held the switch's continue prompt behind it. The
refusal handler (and the schedule_followup tool) now wait for the same
recovery gate chat_* requests already wait for, and the refusal watcher is
registered only once the hub is fully wired.

TestChatShellShareQueuesAnOrdinaryPrompt flaked because the turn runner writes
the sender's reply straight to its connection while the echoed user turn goes
through the subscription writer, so the reply can arrive first and the test
discarded it while reading for the echo. The test now accepts either order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 00:24:22 +00:00
parent accb9970b6
commit 026942b9b7
7 changed files with 101 additions and 12 deletions
+7
View File
@@ -115,6 +115,13 @@ func (h *chatHub) continueOnAnotherAccount(broker chatBroker, refusal claude.Usa
if base == nil {
base = context.Background()
}
// A refusal arrives on its own goroutine, possibly while start-up
// recovery is still restoring the durable queue; acting on it then could
// have recovery put back the auto-continue this removes (see
// awaitRecovery).
if !h.awaitRecovery(base) {
return
}
ctx, cancel := context.WithTimeout(base, time.Minute)
defer cancel()
title := ""