Skip to content

ACP chats keep working when Orca restarts (macOS and Linux) - #47828

Merged
brennanb2025 merged 447 commits into
mainfrom
brennanb2025/chat-relay-acp
Nov 27, 2026
Merged

brennanb2025 merged 447 commits into
mainfrom
brennanb2025/chat-relay-acp

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #47783 (Codex chats keep working through a restart), which is stacked on #47229. This PR's base is #47783's branch; review those first. #47819 (Claude) stacks on this one, because it uses the daemon keep feature added here.

ELI5

Today, quitting or updating Orca stops every working chat with agents such as Copilot, Cursor, OpenCode, Goose, Qwen Code or Grok. With this change those chats keep working while Orca is closed, like terminals and Codex chats already do. When Orca opens again, the chat picks up where it was: the same agent is still running, the reply it was writing finishes in place, its mode, model and command menus are as they were, and an approval it was waiting on is asked again.

Files Added Deleted Net
Test 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1722 $\color{#cf222e}{\Huge{\mathbf{−}}}$​8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1714
Prod 108 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4087 $\color{#cf222e}{\Huge{\mathbf{−}}}$​617 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3470

What Changed

Before: quitting Orca stopped each ACP chat's agent and cut its running turn; the next launch offered to continue it with a fresh agent.

After (macOS and Linux): a chat's ACP agent runs under Orca's terminal host. On quit the chat hands it to the host and nothing is cut. On the next launch the chat reconnects to the same agent:

  • its model, mode and command menus come back as they were, and the chat's permission mode is written to it live (never by replacing the agent)
  • the reply it was working on finishes into the same turn, the same as an uninterrupted run, for agents with and without message ids, including agents that resume a message after reasoning or a tool call
  • output from while Orca was closed appears in order, also when the agent ended while Orca was closed; the next message then goes to a fresh agent exactly once
  • a held permission request shows as a normal prompt again
  • background tasks and subagents it was running are shown as running (with Stop where the agent supports it) and settle when they end, also when they ended while Orca was closed
  • a message queued before the quit, or sent while the earlier turn is still running, waits for that turn, exactly as a queued message does without a restart; Stop still ends the turn

If what the host kept isn't enough to carry the session on, the agent is ended like any agent the host had to stop: the chat's turn settles and its next message starts the agent again, reopening the conversation as today. The session is never reloaded into the kept agent.

This PR adds a daemon feature behind its own capability (providerRelayKeep, about 22 daemon and provider-relay files), held to the same bar as #47229: bounded memory, a bounded per-line cost, and compatibility with older daemons and apps (a daemon without the capability means ACP launches as today). Relay proof for the keep capability was run on macOS and Linux (see Testing).

Mechanism:

  • Host (providerRelayKeep): at spawn the app may name request methods whose latest successful answer to keep, request methods whose latest accepted request to keep (the model setter, whose answer says nothing), substrings whose latest matching agent line to keep (only a line's first 64 KiB is scanned), and request methods to list while unanswered (at most 64). The host keeps one line per name on the relay record (1 MiB per line, 2 MiB in all, counted with held requests toward the record's memory cap), sends kept lines before held requests on attach, and lists the unanswered requests in the attach reply, each saying whether its turn is in the replay whole. An unanswered listed request counts as work, so the idle stop never ends a chat mid-prompt. While one is unanswered, only lines naming an id are parsed as possible answers.
  • ACP: a reattached agent is already initialized and its session is live, so initialize and the session start are answered from what the host kept and never sent to the agent: session/load would replay history and in most agents replace the live session mid-turn. Request ids start above the last app's. The chat's running turn is adopted: the agent's answer to the earlier app's prompt ends it as usual. Output held since the last ack, including held permission requests, is let through once the chat is ready, and history catch-up is skipped. A reopening chat never acks output it hasn't shown, so at the host's cap the agent waits instead of unsaved lines being dropped. Quitting while a chat reopens hands its agent back to the host.
  • Acks: a relayed ACP chat acks only lines its journal has saved, and only past the start of each open message and call (a session's 16 latest-streamed messages are held whole; the turn's start for agents without message ids), so a reattach replays each from its first line and rewrites its row whole. Each ack also names the messages a replay from there would split, with how far the journal saved; a reattach drops a named message's saved lines and continues the rest on its own row, so nothing is shown twice or overwritten. A seeded test drives the real ack floor, output and continuation through thousands of orderings (messages resuming ids, reasoning, calls, child sessions, held replays, agent-started turns, forced cuts, graceful restarts and crashes) and checks every message's saved rows join to exactly the agent's text.
  • Launch cleanup of earlier runs' instruction files keeps every folder of a chat whose relayed run its own terminal host hasn't proven gone (it asks without changing the chat's recovery state; with no relay route, such a chat is kept), and every folder this app run made. A launch never waits for the cleanup, only for removals of its own chat already under way. A reattached chat's freshly prepared config folder is removed at once, so nothing accumulates across restarts.
  • Whether a kept chat's agent still runs is decided by the base's per-run placement: only the run's own terminal host start says, and this PR adds no liveness rule of its own. A conversation copy of a kept chat checks the CLI's minimum version itself.
  • Shared: the JSON-RPC answer checks Codex used move to the relay layer so both providers use them (for Codex the only change is that an answer whose id comes after its result is read as one too), and a replaced "outgrown" agent's log line now says why.

Requests answered while no app is attached: a few agent→client requests block the agent until answered, and their answer is fixed, so the host answers them itself while Orca is closed (the same reply the open app sends):

  • Qwen Code craft/drainMidTurnQueue → { messages: [], hasQueuedPrompt: false } (no prompts were queued mid-turn) and _qwencode/start_turn → { accepted: true } (a finished background task starts the turn that reports it): qwen-code-dialect.ts:46-49, wired at :65.
  • Cursor cursor/update_todos, cursor/task and cursor/generate_image → {}: reports Cursor sends as requests and whose reply it ignores (cursor-dialect.ts:21-22, the same reply the open app gives at :121-122, wired at :225).
    They are passed to the host at spawn (acp-kept-agent.ts:49). Requests needing a person (permissions, questions, plans) are held for the next attach instead.

OMP: OMP can't prove that a finished parent has no background work or pending results, so a kept OMP chat is never idle-stopped while Orca is closed (its open work is reported as unknown), matching how the open app already never idle-stops it. A kept Droid chat carries unknown work the same way.

Known limits:

  • A message the agent already finished, in a turn it started itself, can show twice after a restart if Orca quits while the next one is streaming.
  • After a crash (not a normal quit), a few lines of a message the host's file cap split can show twice on its continuation row; nothing is lost (STA-18239).
  • When more than 16 messages of one session resume their ids within a step (OpenCode), the older ones continue on their own rows after a restart, in order and without loss (STA-18179).
  • A single message larger than the host's 1 MiB in-memory keep, still streaming when Orca quits, continues on its own row after the restart, in order and without loss.
  • A Grok subagent restored after a restart shows a generic label until it reports again (its name came from the spawn call, which isn't replayed).
  • A kept agent can't reattach after an update removes the explicit executable path it was launched from; the chat starts a fresh agent instead (STA-18238).
  • A chat whose detached agent was stopped at the host's 24 h cap doesn't yet show the output kept from while it was closed (STA-18240).
  • Gemini keeps today's launch: its sign-in link is read from its error output as it arrives, which the host only passes on at exit. Live error output is a follow-up in the update-path PR.
  • Bot chats keep today's launch: a bot's tool access is granted by the running app, so a kept bot would lose its tools. A follow-up makes those grants survive a restart, then bots relay.
  • Windows and Antigravity keep today's launch.
  • After a restart, mail sent to a chat whose running prompt was kept can't join that prompt; it starts as its own prompt when the turn ends (Stop withdraws it), nothing lost (STA-19066).
  • A conversation copy checks the CLI's version itself, so an ordinary copy runs --version twice (a stalled probe can cost up to 5 s of the copy's deadline), and forking an inherited response shows "open the original chat" instead of a too-old CLI's version message (STA-18877).
  • A kept agent that can't carry on its chat is closed, and the chat's next message starts a fresh agent. This happens when its session start wasn't kept, or when a stream disconnect hit during the attach's preamble wait. Output it wrote while Orca was closed that the chat hadn't read yet is lost (STA-19117).
  • A kept agent whose launch's tools changed (a server turned off while Orca was closed, or tools tied to this app run) keeps working with its old tools until its turn ends and its replay is acknowledged. The chat's next send then goes to one fresh agent. If the replay can't be acknowledged within 3 s, that send still goes to the kept agent. An OMP kept agent keeps its old tools until it ends on its own (STA-19117).
  • Other relay edges are ticketed in STA-19117:
    • awaited request payloads sit outside the retention budget;
    • a kept load's session ID isn't checked;
    • rapid back-to-back permission picks;
    • an exited relay whose floor keeps an open item's tail.

Design, as built:

At relaySpawn the app may name request methods whose latest answer to keep, and markers whose latest matching agent line to keep. The daemon keeps these on the relay record (beside the first initialize answer) and sends them on attach before replay. This mirrors how the terminal daemon keeps terminal state for reattach. It is advertised by its own daemon capability; without that capability (an older relay daemon) the app falls back to today's cold start for that provider. First user: ACP (session/new|load answer plus config_option_update, current_mode_update, available_commands_update), because ACP must not send session/load on reattach.

The daemon may also list unanswered client→agent requests named at spawn (ACP session/prompt) in the attach reply, and counts one as work for the idle stop. Bounded at 64 entries, behind the same capability.

Interim exclusions (they keep today's launch): Gemini (its sign-in link is read live from stderr; needs live stderr events from the daemon, added in the update-path PR) and bot chats (the bot tool relay URL and token in env change on restart). New PR before default-complete: bot tool grants survive restarts, then bots relay.

Why

Restarts and updates should not cost users their running work. Reattaching to the same process keeps the in-flight tool call, background shells, MCP servers and approvals, which a resumed session cannot. Reloading the session on the kept agent was ruled out: it replays the whole conversation and can drop the turn that is still running.

Linked Issue

Part of #46100

Visual Proof

N/A for screenshots of a static change: the behavior is a process surviving a restart. QA captured DOM snapshots and process tables before quit, while closed and after relaunch (same agent PIDs, one rendered block identical to an uninterrupted run); the macOS screenshots are in the review status comment.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Platforms tested: Linux (QA rounds 4–27 on a packaged copy) and macOS (a packaged, re-signed copy under the launchd terminal host). Windows is unchanged and keeps today's launch.

  • Relay on: agents run under the terminal host on both platforms; the daemon advertises providerRelayKeep.
  • 10+ kept chats across repeated relaunches with the same agent PIDs and no failed reattach.
  • One block after a mid-message and mid-call relaunch, with and without message ids, across Hermes, Goose, Grok, OpenCode, Qwen Code and Cline dialects (rendered turns diffed against uninterrupted runs), including OpenCode messages resuming after reasoning blocks and forced cuts at the host's caps.
  • An agent that ended while Orca was closed: its output shows once, no error row, and the next message goes once to a new agent (Qwen Code, OpenCode); a kept agent that crashes on a message fails that message as today.
  • After the base's liveness revision (round 21, 13/13): a running chat across a relaunch with and without Grok's prompt tag, a held approval, an agent that ended while closed, quitting again while a chat reopens (same PID throughout, nothing settled), and an uninterrupted reference.
  • Held approvals across a graceful quit and a crash; kept model, mode and command menus; a mode picked mid-turn on a kept agent applies to the next agent; queued messages behave as on main; background tasks and subagents across two restarts; a cap release followed by a quit.

Unit tests cover the host's kept lines and outstanding-request list (including the replayed-whole accounting and the kept model request), the ACP ack floor, the reattach of a kept and an ended agent, the quit hand-off of a reopening agent, and the cap-cut continuation. A seeded ordering test (3,000 orderings by default, run to 100,000) drives the real floor, output and continuation through crashes and lazily saved text. A perf contract checks that tool output quoting an answer key is never parsed on the host while a prompt is unanswered.

Performance

Kept lines cost the host one envelope scan per agent line, capped at the first 64 KiB of the line, and at most 2 MiB of memory per relay. While a prompt is unanswered, only lines naming an id are parsed, and a perf contract checks that tool output quoting an answer key is never parsed. In the app, ack naming is bounded (16 held messages per session, capped cut keys), and the replay reader ends at the first send after a reattach. A perf scan of every changed hot-path, publish, startup and subscribe surface on the final head found no regression.

Risk

Level: Medium. The ACP side only runs when the daemon advertises providerRelayKeep; otherwise ACP launches exactly as today. Main risks: a reattach that renders a turn differently from an uninterrupted run, and daemon memory for kept lines (bounded at 2 MiB per relay). Windows and Claude behavior is unchanged; Codex changes only in the shared answer check above.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/chat-relay-acp branch 3 times, most recently from 7b2ee54 to 8b8d224 Compare November 24, 2026 01:31
@brennanb2025
brennanb2025 force-pushed the brennanb2025/chat-relay-codex branch 2 times, most recently from dccbec8 to a4bba66 Compare November 24, 2026 01:52
@brennanb2025
brennanb2025 force-pushed the brennanb2025/chat-relay-acp branch 2 times, most recently from a0bc8f0 to 12a1264 Compare November 24, 2026 03:06
@brennanb2025
brennanb2025 force-pushed the brennanb2025/chat-relay-codex branch from e46d01d to 007d1cd Compare November 24, 2026 03:37
@brennanb2025
brennanb2025 force-pushed the brennanb2025/chat-relay-acp branch 14 times, most recently from c498dcb to 3463352 Compare November 25, 2026 04:17
…nto brennanb2025/chat-relay-acp

# Conflicts:
#	src/main/daemon/protocol/daemon-provider-relay-protocol.ts
#	src/main/provider-relay/provider-relay-carried-work.ts
#	src/main/provider-relay/relayed-provider-continuation.ts
#	src/main/provider-relay/relayed-provider-output.ts
… to take what it was handed

(cherry picked from commit a6e41a4)
… so a stuck chat can't slow the quit

(cherry picked from commit 603ebd1)
…lit continues on its own row; a reattach restates the commands the daemon carried open
…f while Orca was closed) owes a fresh agent, read from the launch note's tools key; an idle one waits for its replay's last ack so the next send reaches the fresh agent
…ion (url, command, args, env, headers), so an edited server changes the key
…tyle ack (reader drained, every handed-on line acked); a stalled write or reader no longer holds the chat's delivery
…n OMP kept agent whose own servers read empty without a version is no longer replaced), and a send waits for the attach's whole replay to be acked within the 3 s bound
…ead (OMP without a version), so a kept agent is never replaced over a set that only looks different
…kground work is invisible here; it keeps the tools it has
…ll secret (32 random bytes in userData, owner-only, made once), so no stored key lets a secret in a server's settings be guessed; it is now async
…y comparison too, since its background work is invisible here
…an owner-only ACL on Windows), then linked in exclusively; one that can't be stored privately stays in memory for the run

The launch's server list call is shortened to keep the resolution under the line cap.
…ner-only mode and owner, or an owner-only ACL read on the same handle), and once published its key is kept even if cleanup or sync fails; fix its import paths
… (keychain or host key) and published whole with an async link, so the file needs no privacy and nothing blocks main; unsealable means a run-only key
…st key's privacy can't be proven everywhere, so those hosts keep a run-only key
… seals the install secret, and an empty server set keys as 'none' so a run-only secret doesn't replace a tool-less kept agent
… is a test mock (fixed password); Electron reads Chromium's own switch table

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 78a63531-7e58-470b-abad-2b5c5b8faed7
Commits

Reviewing files that changed from the base of the PR and between 1412198 and 4b13aa0.

Files selected for processing: 21

  • src/main/acp/launch/acp-structured-launch-resolution.ts
  • src/main/acp/process/acp-kept-agent.ts
  • src/main/acp/process/acp-kept-launch-permission.ts
  • src/main/acp/process/acp-kept-session.ts
  • src/main/acp/session/acp-child-relay-open-work.ts
  • src/main/acp/session/acp-structured-session-adapter.ts
  • src/main/bots/bot-tools-acp.ts
  • src/main/host/electron-secret-store.ts
  • src/main/mcp-servers/mcp-server-set-key-secret.ts
  • src/main/mcp-servers/mcp-server-set-key.test.ts
  • src/main/mcp-servers/mcp-server-set-key.ts
  • src/main/native-chat/agent-session-wire/delivery/structured-agent-session-delivery-loop-deps.ts
  • src/main/native-chat/agent-session-wire/delivery/structured-agent-session-host-delivery.ts
  • src/main/native-chat/agent-session-wire/delivery/structured-agent-session-outgrown-retirement.ts
  • src/main/native-chat/agent-session-wire/providers/structured-agent-session-adapter-router.ts
  • src/main/native-chat/agent-session-wire/providers/structured-agent-session-adapter.ts
  • src/main/provider-relay/app-provider-relays.ts
  • src/main/provider-relay/relayed-provider-child.ts
  • src/main/provider-relay/relayed-provider-input.ts
  • src/main/provider-relay/relayed-provider-output.ts
  • src/shared/secure-storage/secret-store.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread src/main/acp/process/acp-kept-agent.ts Resolved
…kes the transition, which writes the mode before the send; every idle kept agent waits once (3 s) for its replay so a tools change is compared, and a spent wait isn't repeated
…which writes the mode live to a kept agent before the send, so a pick landing after the send's write wait can't admit a prompt under the old mode
…ether the host's own tools changed since launch, so a provider waits for a replay only when that answer could matter
…a fresh agent or the host's tools changed since launch, so the first send after a restart isn't held up to 3 s for a comparison that can't change
@brennanb2025

brennanb2025 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Review status: ACP chats keep running through a restart (head c4b046e)

Since the last status:

  • A launch whose tools belong to this app run reattaches the chat's kept agent first. This covers a host MCP server delivered through Orca's tool relay, and a tool-free run. Before, such a launch could start a second agent beside the kept one. The kept agent finishes its turn, and the chat's next send then goes to one fresh agent with the new tools.
  • A kept agent launched with other Orca MCP servers is replaced at its next send, for example when one was turned off while Orca was closed. The launch note carries a key of its servers: an HMAC under a per-install secret, which is sealed only by the real OS keychain and otherwise kept in memory for the run.
  • Replacement waits for safe ground. It happens only when the chat owes no work and the kept agent's replayed output is acknowledged. An idle kept agent waits once, up to 3 s, for that acknowledgment, and only when the answer could change: it owes a fresh agent, or the host's tools changed since launch.
  • Permission picks on a kept agent: a send whose mode differs from the one the agent runs goes through the transition. The transition writes the mode live to a kept agent that can take it, else restarts it. A late pick can't admit a prompt under the old mode.
  • Relay review fixes:
    • cut-key overflow;
    • the writing marker;
    • escaped fixed-reply methods;
    • the answer-id shortcut;
    • stdout resuming after held requests are answered on release.
  • The shared hook keptLaunchOutgrown(sessionId, toolsOutdated) and RelayedProviderChild.replayAcked(), for the other provider lanes.

Verified:

  • Gate: check:changed passed on c4b046e against main (Linux). CI is green: 61 passed, 11 skipped.
  • Reviews at c4b046e:
    • Codex audit: SAFE. Every finding was fixed, or deferred with the auditor's agreement.
    • Claude: PASS.
    • Perf scan: clean, and its earlier P1 (a 3 s wait on the first send after a restart) is closed.
  • Linux QA (packaged copy, real OpenCode), rounds 24–26, 9/9:
    • Relay-backed server added mid-turn, quit, relaunch: one agent with the same PID streamed across the relaunch, the text appeared once and in order, and the turn ended once. The next send started exactly one new agent, and the tool ran through the relay (authorization proven). A second relaunch left nothing duplicated.
    • Server turned off mid-turn, quit, relaunch (×3, the last on c4b046e): the same PID streamed across the relaunch. The next send started one new agent without the server, about 1 s from submit to the prompt.
    • Permission pick on a kept agent: Full access was switched to Ask after a relaunch. The mode was written live, with the same PID. An approval card appeared and nothing ran before approval. Switching back to Full access ran the next command with no card.
    • No tools change: the next send went to the same kept agent at once (40 ms from submit to the prompt).
    • Reference chat with no kept agent: it started directly, as before.
    • No log lines for an unrestorable kept chat, a relay rebind, a kept agent gone, or an unknown liveness answer.
  • Linux QA round 27 on this head, Claude and Codex chats (the shared delivery code changed), 6/6:
    • Send and tools: in Ask, an approval card appeared and nothing ran before approval; in Full access, no card.
    • MCP tools refresh between sends: adding a server gave a fresh agent with the tool working, and turning it off gave a fresh agent without it, as on main.
    • Quit and relaunch: the transcript was identical and nothing was duplicated. The next send started one agent.
  • All CodeRabbit threads are answered and resolved.

Deferred (tickets, each agreed by its raiser):

  • STA-19117: this PR's residual edges, items 1–13, including:
    • the awaited payload budget;
    • the replay wait's placement;
    • rapid consecutive picks;
    • a kept load's session ID check;
    • a disconnect during the preamble wait.
  • STA-19116: a protocol marker for a failed Codex reattach.
  • STA-19066, STA-18877 and STA-18721.

Screenshots (Linux QA round 26, chat pane only):

Server turned off mid-turn: the same agent still streaming after a relaunch:
Still streaming after relaunch

The next send started a fresh agent without the server:
Fresh agent without the server

No tools change: the kept agent streaming after a relaunch, and later sends go to it:
Kept agent after relaunch

@brennanb2025

brennanb2025 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Perf scan (head c4b046e)

Clean: no P0 and no P1. The earlier P1 is closed. An idle kept agent's replay wait (one time, at most 3 s, 50 ms retries) used to run before the cheap check that decides whether it can matter. It now runs only when the kept agent owes a fresh agent or the host's tools changed since launch. Otherwise the first send after a restart goes straight to the kept agent (QA measured 40 ms from submit to the prompt).

Per-launch work stays bounded:

  • Tools key: one HMAC over the chat's MCP server set. The per-install secret is loaded once and cached.
  • Permission at a send: an in-memory comparison.
  • Replay wait: latched, so it never repeats after it runs out of time. Teardown holds no promise or per-session state beyond the kept session.

@brennanb2025
brennanb2025 merged commit fd35714 into main Nov 27, 2026
73 checks passed
pythonberg1997 added a commit to pythonberg1997/orca that referenced this pull request Nov 29, 2026
Reconcile the non-linear upstream v1.4.281 release tree directly from v1.4.281 so release-branch-only commits from v1.4.280 do not carry over.

Adapt ACP fork files to upstream stablyai#47828 (relayed ACP chats across restarts): support requestGeneration in acp-request-row-identity.ts, adopt public publishChildWork via AcpLiveChildWork in acp-structured-lane.ts, pass messageKey and keep inferred agentTurnCalls alongside confirmBackgroundTask in acp-timeline-translator.ts, and keep both restateBackgrounded and confirmBackground in acp-tool-timeline.ts while compacting helpers under max-lines.
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