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:
@@ -211,6 +211,16 @@ func (f *fakeChat) Interrupt(context.Context, string) error {
|
||||
return f.interruptErr
|
||||
}
|
||||
|
||||
type fakeTaskStopChat struct {
|
||||
*fakeChat
|
||||
stopped int
|
||||
}
|
||||
|
||||
func (f *fakeTaskStopChat) StopTasks(context.Context, string) (int, error) {
|
||||
f.stopped++
|
||||
return f.stopped, nil
|
||||
}
|
||||
|
||||
func (f *fakeChat) ReleaseSession(_ context.Context, sessionID string) error {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
@@ -850,6 +860,27 @@ func TestChatInterruptAndReply(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestChatStopTasksRepliesWithStoppedCount(t *testing.T) {
|
||||
broker := &fakeTaskStopChat{fakeChat: scriptedChat()}
|
||||
ctx, _, conn := dialChat(t, broker)
|
||||
if err := wsjson.Write(ctx, conn, protocol.Message{
|
||||
Type: protocol.ChatStopTasks, ID: "st1",
|
||||
ChatQuery: &protocol.ChatQuery{SessionID: "ses_1"},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var response protocol.Message
|
||||
if err := readTestFrame(ctx, conn, &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response.Type != protocol.ChatStopTasks || response.ID != "st1" || response.ChatStopTasks == nil {
|
||||
t.Fatalf("stop tasks response = %+v", response)
|
||||
}
|
||||
if response.ChatStopTasks.Stopped != 1 || response.ChatStopTasks.Message != "Stopped background tasks." {
|
||||
t.Fatalf("stop tasks result = %+v", response.ChatStopTasks)
|
||||
}
|
||||
}
|
||||
|
||||
// TestChatInterruptEndsRunningPrompt is the task evidence: it starts a
|
||||
// long-running turn through the real opencode.Chat adapter over an httptest SSE
|
||||
// fixture, sends chat_interrupt, and asserts the run ends. The fixture records
|
||||
|
||||
Reference in New Issue
Block a user