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:
@@ -2,7 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
@@ -53,19 +52,26 @@ func handleChatClose(ctx context.Context, request protocol.Message, broker chatB
|
||||
}
|
||||
resetCompaction()
|
||||
}
|
||||
if err := registry.CloseOperatorSession(ctx, sessionID); err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
// A closed chat takes no more turns: prompts it still held are dropped.
|
||||
// Drop queued work before releasing the native runtime so a queued prompt
|
||||
// cannot restart background work after the release succeeds.
|
||||
hub.clearQueue(ctx, sessionID)
|
||||
hub.invalidateRecovery(sessionID)
|
||||
// A harness that keeps the agent alive across restarts (Claude Code's
|
||||
// host) stops it now; the transcript stays and a later prompt resumes it.
|
||||
if releaser, ok := broker.(chatSessionReleaser); ok {
|
||||
if err := releaser.ReleaseSession(ctx, sessionID); err != nil {
|
||||
log.Printf("chat session %s: release after close: %v", sessionID, err)
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + sessionID + " could not be released: " + err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := hub.clearRecovery(ctx, sessionID); err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + sessionID + " recovery state could not be cleared: " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := registry.CloseOperatorSession(ctx, sessionID); err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
session, found, err := registry.OperatorSession(ctx, sessionID)
|
||||
if err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
|
||||
Reference in New Issue
Block a user