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
+2 -6
View File
@@ -176,12 +176,8 @@ func handleChat(ctx context.Context, request protocol.Message, broker chatBroker
// External chat admission and readback must follow durable turn/queue
// restoration: even readback can reconcile hub state. Internal recovery
// does not dispatch requests here. The cold registry scan runs afterward.
if hub != nil && hub.recoveryReady != nil && strings.HasPrefix(string(request.Type), "chat_") {
select {
case <-hub.recoveryReady:
case <-ctx.Done():
return true
}
if strings.HasPrefix(string(request.Type), "chat_") && !hub.awaitRecovery(ctx) {
return true
}
switch request.Type {
case protocol.ChatPrompt: