Release native chat runtimes on lifecycle changes
Ensure /new and chat close stop native foreground and background work before changing registry state. Preserve transcripts while surfacing release and recovery cleanup failures instead of reporting false success, with focused adapter and server regressions.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -43,6 +44,9 @@ func TestChatCloseRecordsClosedState(t *testing.T) {
|
||||
if _, interrupts, _ := broker.counts(); interrupts != 0 {
|
||||
t.Fatalf("idle close interrupted a turn: %d", interrupts)
|
||||
}
|
||||
if released, _ := broker.releaseQuery(); len(released) != 1 || released[0] != "ses_1" {
|
||||
t.Fatalf("released sessions = %v", released)
|
||||
}
|
||||
rows, err := store.OperatorSessions(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -67,6 +71,27 @@ func TestChatCloseRecordsClosedState(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatCloseReportsReleaseFailureAndKeepsOpenState(t *testing.T) {
|
||||
store := newOperatorStore(t)
|
||||
broker := scriptedChat()
|
||||
broker.releaseErr = errors.New("native runtime unavailable")
|
||||
ctx, _, conn := dialChatOptions(t, Options{Chat: broker, OperatorRegistry: store})
|
||||
if err := store.RecordOperatorSession(ctx, "ses_1", "/work/a", "A", protocol.ChatSessionTagOperator); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := wsjson.Write(ctx, conn, protocol.Message{Type: protocol.ChatClose, ID: "cl1", ChatQuery: &protocol.ChatQuery{SessionID: "ses_1"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reply := readMessage(t, ctx, conn)
|
||||
if reply.Type != protocol.Error || !strings.Contains(reply.Error, "could not be released") {
|
||||
t.Fatalf("release failure reply = %+v", reply)
|
||||
}
|
||||
row, found, err := store.OperatorSession(ctx, "ses_1")
|
||||
if err != nil || !found || row.ClosedAt != 0 {
|
||||
t.Fatalf("release failure changed registry: row=%+v found=%v err=%v", row, found, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestChatCloseStopsRunningTurn is the close-stops-a-running-turn evidence: a
|
||||
// prompt holds the session (its stream is live), and chat_close from another
|
||||
// connection interrupts it through the existing broker interrupt and reports that
|
||||
|
||||
Reference in New Issue
Block a user