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
+6 -4
View File
@@ -137,10 +137,6 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
settingsStore = stores[0]
}
hub.settings = settingsStore
if options.Chat != nil {
// A Claude chat refused for usage continues on another saved account.
hub.watchUsageRefusals(options.Chat)
}
if len(stores) > 0 {
// Prompts queued behind a running turn are durable and owned by their
// session; resume delivering any a previous process left queued.
@@ -641,6 +637,12 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
hub.retryReattachments(ctx, options.Chat)
}()
}
if options.Chat != nil {
// A Claude chat refused for usage continues on another saved account.
// Registered once the hub is fully wired (stores, recovery gate), since
// a refusal can arrive on its own goroutine at any moment after this.
hub.watchUsageRefusals(options.Chat)
}
if runs != nil {
// Continue the runs a previous process left in flight, now that the
// runner's collaborators are wired and before any request is served.