Skip to content

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

Merged
harshithmullapudi merged 4 commits into
mainfrom
acp-chat
Oct 6, 2026
Merged

harshithmullapudi merged 4 commits into
mainfrom
acp-chat

Conversation

@harshithmullapudi

@harshithmullapudi harshithmullapudi commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

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 ParadevAI/Paradev#8159). Background tasks need ParadevAI/Paradev#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.

Written for commit 67ef7b9. Summary will update on new commits.

Review in cubic

…inals

A thread's agent ran as a CLI in a terminal on the host. Roster typed into it
over the relay, scraped its transcript every 2s for progress and the reply,
and guessed when a turn ended from idle bindings and silence. Permission
prompts were never seen.

Threads now run as a chat-v3 session on the host, reached through the same
relay with the same member JWT:

- start is workspaces.create, then createSession and prompt; a steer is a
  prompt (the host queues it); Stop is cancelTurn.
- one stream socket per session drives everything: turn events end a turn,
  the last agent message of the turn is the reply, text deltas give the live
  progress line, approval requests park the thread at needs_input and a
  "yes" reply in the thread answers them.
- events are handled one at a time and the cursor is saved after each, so a
  worker restart replays what it missed. Idle sessions from the last hour are
  reattached too, and a turn that finished unseen still posts its reply.
- the host's zero-length startup turn is ignored.
- background tasks (subagents and background processes) are stored per
  session and published with the thread.

The terminal path is gone: agents.run, terminal.*, transcript scraping, the
/events lifecycle socket, the terminals router, the terminal dock, the
full-screen terminal page and xterm. The relay stays, for chat-v3 and
workspace create/delete.

Web:
- Session opens a floating chat with the whole conversation (tool calls,
  reasoning, plans, diffs, approvals). It minimises into a tab in the bottom
  bar and expands to a full page at /thread/[id]/chat. Messages sent from it
  are posted to the thread.
- the thread header popover lists background processes and subagents with
  Stop, above what the thread shared; the reply line in the channel shows a
  badge while background work runs.

Migration 0020 adds superset_chat_session_id, superset_harness_session_id,
chat_cursor and background_tasks to thread_sessions. It is additive:
superset_terminal_id and transcript_offset are no longer used but stay until
a later migration, so old instances keep working through a rolling deploy.

Hosts need Superset 1.36.0+ for chat-v3; background tasks need the release
after it.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5e273522-992d-4e32-a63a-ef29464ed114
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 72 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/api/src/services/sessions/supervisor.ts">

<violation number="1" location="packages/api/src/services/sessions/supervisor.ts:558">
P1: A failed event handler is logged, but this still advances the persisted cursor past the event, so startup recovery cannot replay a failed reply or lifecycle transition. Keep the cursor at the last successfully handled event and retry before consuming later events.</violation>
</file>

<file name="packages/api/src/services/mention-routes-to-main.db.test.ts">

<violation number="1" location="packages/api/src/services/mention-routes-to-main.db.test.ts:44">
P2: `promptsSent` now inherits `waitFor`'s 3-second deadline, down from the previous 8-second polling window. Since `sendMessage` starts routing asynchronously, a slow database or CI run can make these tests fail before `promptChat` is called; preserve the longer timeout or allow this call to specify one.</violation>
</file>

<file name="apps/web/src/utils/chat-session.ts">

<violation number="1" location="apps/web/src/utils/chat-session.ts:49">
P2: This replaces the detail on every background delta, so the row shows only the latest chunk. Append each chunk to the accumulated detail instead.</violation>
</file>

<file name="apps/web/src/components/threads/thread-background-work.tsx">

<violation number="1" location="apps/web/src/components/threads/thread-background-work.tsx:178">
P3: The bulk stop button remains enabled while its requests are pending, so repeat clicks send duplicate stop commands for every process. Disable it while any stoppable task is already stopping.</violation>
</file>

<file name="packages/superset/src/chat.ts">

<violation number="1" location="packages/superset/src/chat.ts:38">
P1: These `/chat-v3/trpc` calls bypass the `SuperJSON` transformer used by the relay's other tRPC calls. Serialize the inputs and deserialize `result.data`; otherwise typed inputs may fail parsing and results can remain `{ json: ... }` wrappers (making a returned `false` truthy).</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

`[sessions] chat event failed for ${watch.sessionId}: ${sessionErrorDetail(cause)}`,
);
}
watch.cursor = cursor;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: A failed event handler is logged, but this still advances the persisted cursor past the event, so startup recovery cannot replay a failed reply or lifecycle transition. Keep the cursor at the last successfully handled event and retry before consuming later events.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/api/src/services/sessions/supervisor.ts, line 558:

<comment>A failed event handler is logged, but this still advances the persisted cursor past the event, so startup recovery cannot replay a failed reply or lifecycle transition. Keep the cursor at the last successfully handled event and retry before consuming later events.</comment>

<file context>
@@ -393,516 +358,591 @@ export async function markWaiting(args: {
+            `[sessions] chat event failed for ${watch.sessionId}: ${sessionErrorDetail(cause)}`,
+          );
+        }
+        watch.cursor = cursor;
+        await saveChatCursor(watch, true);
+      });
</file context>

timeoutMs?: number;
}): Promise<T> {
const base = `${RELAY_URL}/hosts/${args.routingKey}/chat-v3/trpc/${args.procedure}`;
const serialized = JSON.stringify(args.input ?? {});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: These /chat-v3/trpc calls bypass the SuperJSON transformer used by the relay's other tRPC calls. Serialize the inputs and deserialize result.data; otherwise typed inputs may fail parsing and results can remain { json: ... } wrappers (making a returned false truthy).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/superset/src/chat.ts, line 38:

<comment>These `/chat-v3/trpc` calls bypass the `SuperJSON` transformer used by the relay's other tRPC calls. Serialize the inputs and deserialize `result.data`; otherwise typed inputs may fail parsing and results can remain `{ json: ... }` wrappers (making a returned `false` truthy).</comment>

<file context>
@@ -0,0 +1,264 @@
+  timeoutMs?: number;
+}): Promise<T> {
+  const base = `${RELAY_URL}/hosts/${args.routingKey}/chat-v3/trpc/${args.procedure}`;
+  const serialized = JSON.stringify(args.input ?? {});
+  const url =
+    args.method === "GET"
</file context>

Comment thread apps/web/src/hooks/use-thread-chat.ts Resolved
type="button"
aria-label="Stop all background processes"
title="Stop all background processes"
onClick={() => void stop(stoppable)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The bulk stop button remains enabled while its requests are pending, so repeat clicks send duplicate stop commands for every process. Disable it while any stoppable task is already stopping.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At apps/web/src/components/threads/thread-background-work.tsx, line 178:

<comment>The bulk stop button remains enabled while its requests are pending, so repeat clicks send duplicate stop commands for every process. Disable it while any stoppable task is already stopping.</comment>

<file context>
@@ -0,0 +1,198 @@
+                type="button"
+                aria-label="Stop all background processes"
+                title="Stop all background processes"
+                onClick={() => void stop(stoppable)}
+                className="text-muted-foreground hover:bg-accent hover:text-foreground flex size-6 items-center justify-center rounded-sm transition-colors"
+              >
</file context>

harshithmullapudi and others added 2 commits October 5, 2026 23:35
Review found ways the chat-v3 move fails in production:

- A finished thread was marked failed when its machine went offline. An idle
  or parked session now stops watching quietly; only a session mid-turn
  fails. A failed token mint retries instead of failing the session.
- Threads running in a terminal when this deploys had nothing to watch them.
  They are parked idle with a note; a reply starts a chat in their worktree.
- A pending approval was only in memory, so after a restart a "yes" reply was
  queued behind the blocked turn. Pending approvals are rebuilt from the
  session's items on reconnect.
- A reply was only in memory too; a turn that ends after a restart now reads
  its reply back from the host.
- Cancel paused the host's prompt queue, so later replies never ran.
- A failed event left the cursor moving past it; it now reconnects and
  replays. A reset reconnects from scratch instead of carrying on with a gap.
- The startup patch to running could overwrite an immediate failure.
- Losing the worker lease now stops every chat watch.
- Retry counters reset on the first message, not on open, so a relay that
  accepts and then denies does not reconnect every second. Same in the
  browser, which also no longer mistakes the EventSource's own open event for
  the stream's.
- The SSE proxy closes its upstream socket and keepalive on cancel and on a
  failed write.
- The zero-length startup turn rule only skips completed turns, and a "yes"
  must be the whole reply.

Co-authored-by: Claude Opus 5.5 <[email protected]>
- Pending approvals are rebuilt only from items the watch had already seen.
  One that arrived while disconnected comes back with the replay and parks the
  thread at needs_input as it should.
- A failed event takes the socket out of service at once, so events queued
  behind it cannot save a cursor past it. After three failures on the same
  event it is skipped rather than replayed forever.
- Reading items back mints a fresh token, and only completed turns look up a
  missing reply.
- A reply that starts with yes allows an approval unless it also hesitates
  ("not", "wait", "later" and the like).
- A session waiting on a person is not failed when its machine goes offline.

Co-authored-by: Claude Opus 5.5 <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files (changes from recent commits).

You’re at about 90% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/api/src/services/sessions/supervisor.ts">

<violation number="1" location="packages/api/src/services/sessions/supervisor.ts:619">
P2: This reads only one 200-item page, so a recovered turn whose reply falls outside it is silently omitted from the thread. Follow `nextBefore` until the turn's message is found or the history is exhausted.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

jwt: watch.jwt,
routingKey: watch.hostKey,
sessionId: watch.chatSessionId,
limit: 200,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This reads only one 200-item page, so a recovered turn whose reply falls outside it is silently omitted from the thread. Follow nextBefore until the turn's message is found or the history is exhausted.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/api/src/services/sessions/supervisor.ts, line 619:

<comment>This reads only one 200-item page, so a recovered turn whose reply falls outside it is silently omitted from the thread. Follow `nextBefore` until the turn's message is found or the history is exhausted.</comment>

<file context>
@@ -594,6 +594,62 @@ function scheduleChatRetry(watch: ChatWatch): void {
+    jwt: watch.jwt,
+    routingKey: watch.hostKey,
+    sessionId: watch.chatSessionId,
+    limit: 200,
+  }).catch(() => null);
+  if (!page?.ok) return [];
</file context>

- A bare "no" that declines an approval is not also sent as a new prompt; a
  refusal with more to say still is.
- A session is marked running before it is prompted, so a fast turn end can
  no longer be overwritten back to running.
- Stopping a background task checks the stored task can be stopped.
- Chat envelopes are validated before use, so a malformed event is dropped
  rather than handled and its cursor saved.
- The chat panel resets when the organization changes.
- A failed "load older" no longer ends history loading for good.
- Diffs in tool calls are order-aware.
- The send button respects disabled; the textarea has a label; stop-all
  ignores tasks already stopping; links underline only on their own hover; a
  malformed thread id on the chat page is a 404.
- The run-as test checks the chat stream is opened as the folder owner.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@harshithmullapudi
harshithmullapudi merged commit 54ac060 into main Oct 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant