Stop background tasks separately from chat turns

Keep Esc and /stop scoped to the foreground turn while exposing an explicit stop-tasks operation for supported chat backends. Add the protocol, server routing, app command, and coverage for task stopping and unsupported harnesses.
This commit is contained in:
2026-11-13 16:47:41 +00:00
parent c3c2c1bbc9
commit 2a182d7f17
19 changed files with 331 additions and 2 deletions
+39
View File
@@ -0,0 +1,39 @@
package server
import (
"context"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
func handleChatStopTasks(ctx context.Context, request protocol.Message, broker chatBroker, write func(protocol.Message) error) {
query := request.ChatQuery
if query == nil || !validChatSessionID(query.SessionID) {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid chat session id is required"})
return
}
if broker == nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat is not configured on this server"})
return
}
stopper, ok := broker.(chatTaskStopper)
if !ok {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "this chat backend cannot stop background tasks separately"})
return
}
stopped, err := stopper.StopTasks(ctx, query.SessionID)
if err != nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
return
}
message := "No background tasks are running in this chat."
if stopped > 0 {
message = "Stopped background tasks."
}
_ = write(protocol.Message{
Type: protocol.ChatStopTasks, ID: request.ID,
ChatStopTasks: &protocol.ChatStopTasksResult{
SessionID: query.SessionID, Stopped: stopped, Message: message,
},
})
}