Send mid-turn chat prompts to the harness and queue the rest durably on the server
Claude Code (stream-json stdin) and Codex (turn/steer pinned to the active turn) receive a prompt sent while a turn runs immediately. Other harnesses (OpenCode) get a durable chat_prompt_queue row owned by the session: it survives the last client detaching and a server restart, is delivered in order when the turn ends with or without a client, and is deduplicated by operation id. chat_subscribe carries the queue, chat_queue frames report delivered/removed/failed changes, and chat_unqueue removes a waiting prompt.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChatPromptQueueOrderDedupeAndBound(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
path := filepath.Join(t.TempDir(), "queue.db")
|
||||
store, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, op := range []string{"a", "b"} {
|
||||
if _, created, err := store.EnqueueChatPrompt(ctx, ChatQueuedPrompt{SessionID: "ses_1", OperationID: op, MessageID: "m-" + op, Text: op}, 2); err != nil || !created {
|
||||
t.Fatalf("enqueue %s: created=%v err=%v", op, created, err)
|
||||
}
|
||||
}
|
||||
if row, created, err := store.EnqueueChatPrompt(ctx, ChatQueuedPrompt{SessionID: "ses_1", OperationID: "a", Text: "again"}, 2); err != nil || created || row.Text != "a" {
|
||||
t.Fatalf("duplicate operation: row=%+v created=%v err=%v", row, created, err)
|
||||
}
|
||||
if _, _, err := store.EnqueueChatPrompt(ctx, ChatQueuedPrompt{SessionID: "ses_1", OperationID: "c", Text: "c"}, 2); !errors.Is(err, ErrChatQueueFull) {
|
||||
t.Fatalf("bound not enforced: %v", err)
|
||||
}
|
||||
store.Close()
|
||||
store, err = Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
sessions, err := store.ChatQueuedSessions(ctx)
|
||||
if err != nil || len(sessions) != 1 || sessions[0] != "ses_1" {
|
||||
t.Fatalf("sessions = %v %v", sessions, err)
|
||||
}
|
||||
if removed, err := store.DeleteChatQueuedPrompt(ctx, "ses_1", "a"); err != nil || !removed {
|
||||
t.Fatalf("delete: %v %v", removed, err)
|
||||
}
|
||||
rows, err := store.ChatQueuedPrompts(ctx, "ses_1")
|
||||
if err != nil || len(rows) != 1 || rows[0].OperationID != "b" || rows[0].MessageID != "m-b" {
|
||||
t.Fatalf("rows = %+v %v", rows, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user