feat(sessions): run threads on Superset chat-v3 (ACP) instead of terminals

Merged
HA
2mo ago
+4848-3493

Summary

Threads now run as a Superset chat-v3 (ACP) session on the host instead of a CLI in a terminal. Roster reaches the host through the same relay with the same member JWT; only the transport changed.

  • Engine (packages/api/src/services/sessions/supervisor.ts): workspaces.create → createSession → prompt. Steers are prompts, Stop is cancelTurn. One stream socket per session handles turns, replies, live progress (text deltas), approvals (needs_input; a "yes" in the thread answers) and background tasks. Events are handled one at a time with the cursor saved after each, so a worker restart replays what it missed; idle sessions from the last hour are reattached.
  • Removed: agents.run, terminal.*, transcript scraping, the /events lifecycle socket, the terminals router and service, the terminal dock, the full-screen terminal page and xterm.
  • Web: Session opens a floating chat (full conversation, tool calls, approvals) that minimises into a bottom-bar tab and expands to /thread/[id]/chat. The thread popover lists subagents and background processes with Stop; the channel reply line shows a badge while they run.
  • Migration 0020: adds superset_chat_session_id, superset_harness_session_id, chat_cursor, background_tasks. Additive only; superset_terminal_id and transcript_offset are left for a later migration so old instances survive the rolling deploy.

Requirements

Hosts need Superset 1.36.0+ for chat-v3 (relay /chat-v3/trpc forwarding shipped in superset-sh/superset#8159). Background tasks need superset-sh/superset#8199 / #8168, which land in the next Superset release.

Validation

  • tsc clean for api, web, superset packages.
  • api: 365 tests pass (Redis queue suites excluded locally because a dev worker was consuming the queues; they passed earlier with the worker stopped). web: 368. superset: 19.
  • New regression tests: the host's zero-length startup turn does not end a session; a turn that finishes while the session reads idle still posts its reply. Both fail without their fix.
  • Round trip verified against a real host through the production relay (create, stream, prompt, reply, getItems, close).
  • Dev stack end to end: a thread started, replied, ran a subagent, and recovered a reply missed during a worker restart.

Summary by cubic

Threads now run as Superset chat-v3 (ACP) sessions on the host instead of CLI terminals, reached through the same relay with the same member JWT. Steers become chat prompts, Stop is cancelTurn, and a single stream socket per session carries turns, replies, live progress deltas, approvals (answered by a reply in the thread), and background tasks. Events are handled one at a time with the cursor saved after each so a worker restart replays what it missed; idle sessions from the last hour are reattached.

The terminal path is removed: agents.run, terminal.*, transcript scraping, the /events lifecycle socket, the terminals router and service, the terminal dock, the full-screen terminal page, and xterm. On web, a session opens as a floating chat that minimizes into a bottom-bar tab and expands to /thread/[id]/chat; the thread popover lists subagents and background processes with Stop. Threads already running in a terminal when this deploys are parked idle with a note, and a reply starts a chat in their worktree.

Reliability

  • Idle, parked, or person-waiting sessions stop watching quietly when the host goes offline; only a mid-turn session fails, and a failed token mint retries.
  • Pending approvals are rebuilt on reconnect from items the watch already saw; one that arrived while disconnected comes back with the replay and parks the thread at needs_input, and a completed turn reads its reply back from the host.
  • A failed event takes the socket out of service at once so nothing saves a cursor past it; it is skipped after three failures, and a reset reconnects from scratch.
  • A reply starting with "yes" allows an approval unless it also hesitates; a bare "no" that declines is not also sent as a new prompt; retry counters reset on the first message, and the browser no longer mistakes the stream open event for its own.
  • Chat envelopes are validated before use, a session is marked running before prompt, and malformed thread ids 404.

Migration

  • 0020 adds superset_chat_session_id, superset_harness_session_id, chat_cursor, and background_tasks; it leaves superset_terminal_id and transcript_offset in place so old instances survive a rolling deploy.
  • Hosts need Superset 1.36.0+ for chat-v3 and ROSTER_CHAT_HARNESS set (default claude-acp); background tasks need the release after 1.36.

Regression tests cover the host's zero-length startup turn and a turn that finishes while the session reads idle; both fail without their fixes. A run-as test checks the chat stream opens as the folder owner. Round trip verified against a real host through the production relay, and end-to-end in the dev stack including a reply recovered after a worker restart.