fix(codex): reconcile cold connections without resuming queued goals
This commit is contained in:
@@ -147,6 +147,13 @@ func checkChatBrowserLifecycle(t *testing.T, backend string) {
|
||||
handler := HandlerWithOptions(ctx, Options{Chat: browserModelFixture{fake, forms}}, store)
|
||||
defer func() { cancel(); WaitRuns(handler) }()
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
if req.URL.Path == "/fixture-resync" && req.Method == http.MethodPost {
|
||||
fake.mu.Lock()
|
||||
fake.messages = append(fake.messages, protocol.ChatMessage{ID: "msg_resync", Role: protocol.ChatRoleAssistant, Parts: []protocol.ChatPart{{Type: protocol.ChatPartText, Text: "Authoritative resync evidence"}}})
|
||||
fake.mu.Unlock()
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
if req.URL.Path == "/fixture-shell" && req.Method == http.MethodPost {
|
||||
fake.mu.Lock()
|
||||
fake.shells = []protocol.ChatShell{{ID: "sh_" + backend + "_fixture", Status: protocol.ChatShellRunning, Command: "printf controlled"}}
|
||||
|
||||
@@ -147,6 +147,7 @@ type chatRoom struct {
|
||||
pollerStarted bool
|
||||
wake chan struct{}
|
||||
turnDone chan struct{}
|
||||
nativeTurnID string
|
||||
}
|
||||
|
||||
func newChatRoom(base context.Context, sessionID string) *chatRoom {
|
||||
@@ -373,6 +374,15 @@ func (h *chatHub) emitRoom(source *chatRoom, frame protocol.ChatEventFrame) {
|
||||
h.mu.Unlock()
|
||||
return
|
||||
}
|
||||
if room != nil && frame.Kind == protocol.ChatEventStep && frame.Step != nil && frame.Step.TurnID != "" && !frame.Step.Intermediate {
|
||||
if frame.Step.Status == protocol.ChatStepStarted {
|
||||
room.nativeTurnID = frame.Step.TurnID
|
||||
}
|
||||
if frame.Step.Status == protocol.ChatStepEnded && room.nativeTurnID != frame.Step.TurnID {
|
||||
h.mu.Unlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
h.applyLocked(frame)
|
||||
buffered := false
|
||||
var targets []*chatSub
|
||||
@@ -475,6 +485,7 @@ func (h *chatHub) replaceShellsLocked(sessionID string, shells []protocol.ChatSh
|
||||
// wait. Callers must hold h.mu.
|
||||
func (h *chatHub) finishTurnLocked(room *chatRoom) {
|
||||
room.running = false
|
||||
room.nativeTurnID = ""
|
||||
if room.turnDone != nil {
|
||||
close(room.turnDone)
|
||||
room.turnDone = nil
|
||||
@@ -660,6 +671,7 @@ func (h *chatHub) nextPrompt(room *chatRoom) (*chatQueuedPrompt, chan struct{},
|
||||
p := room.queue[0]
|
||||
room.queue = room.queue[1:]
|
||||
room.running = true
|
||||
room.nativeTurnID = ""
|
||||
room.turnDone = make(chan struct{})
|
||||
done := room.turnDone
|
||||
h.mu.Unlock()
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLateHarnessCompletionCannotReleaseNextChatTurn(t *testing.T) {
|
||||
h := newChatHub()
|
||||
room := newChatRoom(context.Background(), "ses_turn")
|
||||
defer room.cancel()
|
||||
room.running = true
|
||||
room.nativeTurnID = "new"
|
||||
room.turnDone = make(chan struct{})
|
||||
h.rooms[room.sessionID] = room
|
||||
h.emitRoom(room, protocol.ChatEventFrame{SessionID: room.sessionID, Kind: protocol.ChatEventStep, Step: &protocol.ChatStep{Status: protocol.ChatStepEnded, TurnID: "old"}})
|
||||
if !room.running {
|
||||
t.Fatal("old terminal frame freed next turn queue")
|
||||
}
|
||||
h.emitRoom(room, protocol.ChatEventFrame{SessionID: room.sessionID, Kind: protocol.ChatEventStep, Step: &protocol.ChatStep{Status: protocol.ChatStepEnded, TurnID: "new"}})
|
||||
if room.running {
|
||||
t.Fatal("matching terminal frame did not finish turn")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user