Hold external chat admission until live turn recovery completes

This commit is contained in:
2026-11-07 16:41:02 +00:00
parent 132a94192a
commit 62406f7fdb
4 changed files with 93 additions and 0 deletions
+11
View File
@@ -7,6 +7,7 @@ import (
"git.a-wan.net/alan/pipelines/internal/opencode"
"regexp"
"strconv"
"strings"
"sync/atomic"
"git.a-wan.net/alan/pipelines/internal/pipeline"
@@ -161,6 +162,16 @@ func chatClientToken() string {
// connection-scoped write function so the read loop and the stream goroutine
// never interleave partial websocket writes.
func handleChat(ctx context.Context, request protocol.Message, broker chatBroker, hub *chatHub, registry operatorRegistry, clientID string, write func(protocol.Message) error) bool {
// 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
}
}
switch request.Type {
case protocol.ChatPrompt:
handleChatPrompt(ctx, request, broker, hub, registry, clientID, write)