Skip to content

feat(bots): bot chats keep their tools across an Orca restart and update - #51086

Merged
brennanb2025 merged 69 commits into
mainfrom
brennanb2025/bot-chats-survive-restart
Nov 29, 2026
Merged

brennanb2025 merged 69 commits into
mainfrom
brennanb2025/bot-chats-survive-restart

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Before: when you quit or updated Orca, a bot's chat lost its tools. Its agent could keep running, but every tool call failed from then on, so Orca never let a bot's chat outlive the app.

After: on macOS and Linux, a bot's chat (and any chat using the MCP servers from Settings) keeps running through a restart, a crash or an update, when its agent is Claude, Codex running its own app-server, or an ACP agent that runs under the background service. While Orca is away, a tool call is told that Orca is restarting and to try again in a few seconds. Once Orca is back, tools with saved values work again at once. Tools that use Orca's own sign-in start a new session, which the agent does on its own. Nothing is written to disk and no keychain is needed, so this works on Linux without a keyring too.

Nothing changes on Windows, on remote hosts, or with an older background service: there, a bot's chat still ends with the app, as before. The same goes for Pi chats, Codex chats using shared app-servers or a custom command, and ACP agents with a sign-in step.

Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​857 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​854
Prod 57 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2393 $\color{#cf222e}{\Huge{\mathbf{−}}}$​197 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2196

What Changed

  • Daemon front. A terminal daemon start that relays agents (macOS and Linux) now offers toolRelayFront, new in daemon protocol 65 (so an update starts a fresh daemon that has it, while the older one keeps its agents): one loopback port, opened on first use, that lives as long as that daemon start. The daemon never connects to the app and never parses request bytes. For each connection it accepts, it announces an id on the app's authenticated stream. The app then opens its own connection to the daemon socket with a token-checked tool-relay hello, and the daemon splices the two together. The app hands that socket to the relay's HTTP server in-process, so the existing Host, bearer, path and admission checks all still run.
    • While no app is attached, a connection is held for up to 30 s and then answered with 503, Retry-After: 5 and a plain-text body that says Orca is restarting. Plain text, not a JSON-RPC error: the daemon never reads the request, so such an error could name no request id, and an MCP client drops an id-less error and waits out its own timeout. A plain-text error fails the call at once, with this message. The same answer goes out at once past 64 held connections or 128 live pipes, so the front's descriptors stay under 400. Past 64 connections already being answered, a new one is closed with no answer.
    • While the app has more than 1 MiB unread on its daemon stream, the front's notices wait instead of piling up: connections still held are announced when it drains, and relay ends held back meanwhile come as one notice that makes the app serve again and reconcile.
    • The front counts every descriptor it holds (listener, held and answering connections, two per pipe) against a fixed budget; refused connections are capped too and closed on shutdown.
    • The daemon can't tell an event stream from a call, so the app budgets each front's pipes: at most 96 event streams, and at most 120 requests other than cleanup, so tool calls and DELETE always get a pipe. Every connection through a front closes after its answer.
    • The app serves every daemon start that holds a front, so agents kept under an older start keep their tools after an update. A failed serve is retried on its own up to four times (after 5, 10, 20 and 40 s, one at a time) while that start is connected, and again at the next chat launch or reconnect. A connection that arrives while its front's serve has failed stays held and gets the 503, and asks for one serve itself (at most once per 5 s), so its retry finds the front served.
  • Grants held by the daemon, in memory. Only a launch whose agent the daemon will run gets a front: Claude, Codex with its own app-server (not shared servers or a custom command), and ACP agents that relay, in a folder the daemon can read. Every other launch (Pi, shared Codex servers, agents with a sign-in step or a private temp folder) keeps the app's own address. A chat launch whose tools point at a front sends the agent's relay grant (owner, token, folders) with the agent's spawn (relaySpawn.toolGrants). That daemon start holds it in memory, keyed by the agent's relay, from the moment its relay forms (before any I/O) until the relay ends; when it ends, the app serving that front hears so and drops the token and caller it took back. A kept ACP chat's shared-tool caller token travels the same way.
    • A restarted app gets the grants back only in reply to its authenticated toolRelayFrontServe, and recognizes those tokens again. When a terminal service is replaced, what the app took back from the old one goes with it. A deleted bot's grants are dropped then and there.
    • Deleting a bot ends its token in the app at once, then sends toolRelayFrontRevoke to every daemon start; a start that doesn't answer can't bring it back, since adoption skips a revoked or deleted bot. Narrowing a bot's reach narrows every token it has.
    • Nothing reaches disk, so there's no keychain dependency and nothing to clean up.
  • Launch. With a front, tool URLs use it, and SessionMcpTools.appBound is false, so Codex, Claude and ACP chats of bots relay like any other chat. A launch is pinned to its front's daemon start. One that lands on another start is refused with an ordinary "send again" error, and the next send takes the new start's front. One that still doesn't run under it (a spawn that fails, or shared servers turned on mid-launch) is refused the same way, and that chat's next launch uses the app's own address.
  • A reattached agent goes on with the tokens it already holds; a Codex chat whose tools are app-bound first reattaches the agent it kept running, so a second agent never starts beside it.
  • Windows, remote hosts and older daemons are unchanged: there is no front, and those chats stay app-bound.

Why

Bot chats were always app-bound because their relay port and token lived only in the app's memory. Re-binding the same port after a restart would let any local process take it while Orca is closed. A port held by Orca's own daemon for the life of the agents that use it can't be taken, and the daemon already holds every kept agent's environment, so holding its grant beside it adds no new exposure.

Linked Issue

N/A (internal design).

Visual Proof

N/A: no UI change. Behavior is covered in Testing.

Testing

  • Daemon protocol test: an agent's bytes are spliced only into a connection the app authenticated. A tool-relay hello with a wrong token is refused before any request byte reaches it. An older daemon offers no front.
  • State test: a daemon start's kept grants live exactly as long as their relay, a revoke takes only that owner's, and a malformed or oversized hand-over keeps nothing.
  • A real call through the front reaches the relay's own HTTP checks; 132 keep-alive calls through a real front (past its pipe cap) each close after their answer and say Connection: close (even when the handler asked for keep-alive), and a DELETE after them still gets through.
  • Perf contracts: a kept agent's token and caller taken back by a restarted app go as soon as its relay ends, and those of live agents stay; held connections stay at 64 or fewer and live pipes at 128 or fewer, and all are freed on splice, close and app disconnect; refused connections are counted, capped and closed on dispose; the front never holds more descriptors than its budget; the same connection re-serving announces nothing new; streams and calls through one front stop at their budgets and leave room for cleanup; front notices to an app that stopped reading stay under 1 MiB and are recovered when it reads again; a relay paused at its cap neither asks a client that stopped reading for acks nor polls it, and asks again once that client's stream drains; a tool call's own daemon connection closing runs no idle check.
  • QA on Linux (built PR head, no keyring: basic_text safe storage), with real Codex and Claude bot chats and a shared command server as the tool:
    • Graceful restart with the daemon kept, and a crash of the app's main process: the daemon, both agents and their background callers kept their processes. Calls made while Orca was down were held 30 s, then answered 503, Retry-After: 5, plain text, Connection: close. Calls succeeded once Orca was back, and the next user turn in each chat used the tool.
    • Restarting answer as each agent sees it: Codex fails the call promptly with "unexpected server response: HTTP 503: Orca is restarting…", no longer waiting out its 300 s timeout. Claude shows "Error POSTing to endpoint: Orca is restarting…".
    • Two daemon starts: after an update to a build with a newer daemon protocol, the chat kept by the older start and a new chat on the newer start both kept their tools, through another restart too.
    • Deleting a bot: a caller holding that bot's token got 401 at once and still 401 after another restart. The other bot kept working.
    • Launch gate: with shared Codex servers on, a new Codex chat's first send worked and its tools used the app's own port. With them off, they used the front. A Pi chat's tools also used the app's own port.
    • Every answer through the front, event streams included, says Connection: close, and Orca closes the socket right after.
    • Nothing grant-related is written to the app's data folder.

Performance

Up to three daemon requests per chat launch (open the front, a folder check on macOS, and a serve once per daemon connection), one token-file read per daemon connection, and one extra local socket per tool connection while a front is in use. Each tool call through a front uses its own connection. The daemon holds a few hundred bytes per kept agent. At startup the app serves fronts only when a daemon start reports an agent holding a grant.

Risk

Level: Medium. Adds a loopback listener owned by the daemon. It passes bytes only into connections the app authenticated, and only on macOS and Linux. The daemon now holds kept agents' relay tokens in memory, returned only to the app's authenticated connection. Revert is a plain revert; nothing is left on disk.

Known limits:

  • Going back to an older Orca while a bot chat's agent is kept: the older app doesn't serve the front, so that agent's tool calls get the "Orca is restarting" answer until the run is ended and relaunched, or a newer Orca starts again. Retrying alone doesn't recover while the older build runs. New chats in the older build work as before.
  • Past 96 event streams through one front, the next stream is refused until one closes; tool calls are unaffected.
  • The front's descriptor budget is fixed for now, not sized from the daemon's own limit.
  • On Linux without a keyring, a kept Claude chat's agent keeps running through the restart but is replaced at its next turn: Claude checks its tools against a key whose secret is kept only when the system keychain can seal it. Codex chats aren't affected. Keeping that secret in the daemon's memory is a follow-up.
  • Shared command servers are started again by the app at a restart, so a kept agent's next call re-initializes its MCP session (clients do this on their own).

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

…eanup fails, keep locked callers, reattach before app-bound Codex starts, coalesce kept-file writes, dedupe front serving, drop pins
…callers through reattach, only bot callers force app-bound, unlock from botOf, bounded unlock retries, cancel front setup on close, serialize coalesced writes
…in so a locked keyring recovers, keep each kept caller in its own file, cap event streams per front so calls always get a pipe
…voked, locked callers retry in turn, each profile keeps its own grants, a reattached caller's earlier entry goes only once its run is placed, keep cleanup room through a front
…n the keychain, retire a carried caller when its run ends, retry a failed front serve on its own
…leted chat's callers go, a failed handoff write keeps the earlier entry, one file per kept grant owner, revocations tracked only while seals run, stop serve retries for a gone daemon start
…p-alives never hold the daemon pipes cleanup's reserve needs
… memory, not sealed on disk

The daemon start that keeps an agent holds its relay grants and shared-tool caller in memory for exactly as long as the agent's relay runs, received with the agent's spawn and handed back only on the app's authenticated serve. A bot's revoke drops them on every daemon start first. Removes the sealed grant and caller files, the keyring paths and their tests. The front's descriptors count against a budget.
…ler, a token's reach narrows for every token of its owner, refused front sockets are counted and capped, a launch given a front runs under its start or goes app-bound, one serve retry per daemon start, adopted tokens and callers go when their relays do
…t, so pooled, Pi and fallback launches keep the app's address; a kept relay's end drops its handed-back token and caller at once; the front's pipe cap is 128 so its descriptors stay under 400; grants indexed by owner and bots by id; a reconnect keeps its serve retry; startup listing retries on its own
…s, so none outlive a relay that never did; format
…launch's front pin; a relay end that races the serve reply still drops its grants; tool calls through a front wait only for that front's serve; the daemon token is read once per connection, bounded; refusal and revoke records are capped and retired; idle retries stop after a few
…hen the handler asked for keep-alive (an MCP SDK event stream), so it never holds a daemon pipe
…ent that drops an id-less JSON-RPC error fails the call at once and shows the message instead of waiting out its timeout
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status for 947e6b510ecf92274a4fe96d5dcbae8222d486b5: done

Since the previous status (897cf11): CodeRabbit's second batch. When the app closes its end of a tool connection, an answer still queued for a slow agent is now sent before the connection closes (waiting at most 5 s), instead of being cut. There are also two test fixes. All 17 CodeRabbit threads are answered and resolved.

  • Reviews: a fresh code review and a regression audit of this change found no defects. A full performance review of the PR on this head: PASS.
  • QA on Linux, this head (a real Codex bot chat, a shared command server as the tool):
    • Answers through the front: four tool calls, one with a 20,000-character input, all came back whole. Each answer's connection closed within about 1.5 s.
    • Restart: the agent and its background caller kept running. A call made while Orca was down got the plain-text 503 after 30 s. Calls succeeded once Orca was back (133 in total), and the next turn used the tool.
  • Earlier QA on 897cf11, still applying:
    • Updating from main to this branch starts a fresh daemon (protocol 65) beside the old one (64), and both keep their chats running.
    • Deleting a bot makes its token fail (401) at once and after a restart.

r11-long-answer

r11-after-restart

…s-survive-restart

# Conflicts:
#	src/main/acp/session/acp-structured-acquire.ts
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status for 10a27c0280655caed3aaa24e1d255d3b64c0b968: done

Since the previous status (947e6b5): merged main again. The one conflict was ACP chat startup, where main now re-checks the chat's saved account just before the spawn. The resolution keeps that check, and if it fails, drops this launch's shared-tool caller.

  • Reviews:
    • A fresh code review and a regression audit of the merge resolution and of main's new changes against this PR found no defects.
    • A full performance review of the PR on this head: PASS.
  • QA on Linux, this head:
    • Claude: a new Claude bot chat called the tool through the daemon front on its first turn.
    • Codex and restart: a new Codex bot chat called the tool, then went through a graceful restart. The agents and the background caller kept running, and a call made while Orca was down got the plain-text 503 after 30 s. After the restart, 97 calls succeeded, and the next turn used the tool.
    • ACP: a plain OpenCode chat worked, and its agent survived the restart.

A Claude bot chat's tool call, and a Codex bot chat's tool call after a restart:

r12-claude-public

r12-codex-restart-public

…rk, gate on relay requirements

- Never end a newer daemon's unknown-integration relays at listing; they are kept for that Orca.
- No disk work on the relay route unless a newer generation is held; its start ID is read once.
- Connect a newer daemon only when a chat's run names it, so an unused one can still retire.
- ProviderRelayInfo.requires: an app attaches only relays whose every requirement it serves;
  others stay kept and get the newer-Orca refusal.
- Choose that refusal only when the newer daemon couldn't be connected; clear it with the run verdict.
… an unused newer daemon go

- A relay of an integration this build can't reattach is kept-but-unusable: the update refusal.
- A newer daemon that lists a relay but won't attach it gives the update refusal.
- The run gate connects a newer daemon only for its own start; its client disconnects once no relay
  is bound, so the daemon can retire.
- Launch listing doesn't wait on an unconnected newer daemon; its chats ask it themselves.
- Drop an unrelated lockfile change.
Disconnecting a newer daemon's client when its last relay unbound ran before the quit hand-off's
final acks and detach policy, and could cut another chat's listing or a delete's close. Drop it:
only a newer daemon a chat here names is connected, and it stays connected until quit.
…eattached chat reads through

Stopping it would end that chat's agent and drop its unread output; its terminals stay held until
no attached agent reads through it.
… and stops a newer daemon

The bound-relay check alone could race an attach during the stop's process inspection.
… are daemon work, so an idle check or idle shutdown never retires a daemon under them

Once the front alone kept the daemon from retiring, its last call, pipe or grant going re-runs the idle check.
# Conflicts:
#	src/main/daemon/protocol/daemon-provider-relay-protocol.ts
#	src/main/daemon/providers/routing/daemon-newer-protocol-hold.ts
#	src/main/provider-relay/app-provider-relays.ts
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The latest changes appear safe to merge; no new blocking issue was found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge; no new blocking issue was found.

Summary

Bot chats can keep their tools across restarts by using a loopback address held by the daemon. The daemon keeps the agents’ grants in memory and returns them to the app when it reconnects.

  • The daemon keeps a local tool route open while Orca restarts.
  • Kept agents bring their tool grants back when Orca restarts.
  • Supported chats use the front that belongs to their running agent.

Diagram

sequenceDiagram
  participant Agent
  participant Daemon
  participant App
  Agent->>Daemon: Connect to the held tool address
  Daemon->>App: Announce the connection
  App->>Daemon: Open an authenticated connection
  Daemon->>App: Forward the tool request
  App-->>Agent: Check the grant and answer through the daemon
Loading

Reviews (4) · Last reviewed commit: "fix(bots): a daemon client the route dro..." · Reviewed by Greptile

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status for 1d6e5060522bd8da8c9acd3e06421edb198f4ce2: done

Since the previous status (10a27c0): merged main, which now has #51687 (an older Orca may reattach chats kept by a newer daemon).

  • A kept relay whose agent's tools go through the daemon's front is listed with requires: ["toolRelayFront"].

    • An older Orca refuses to reattach that chat and asks the user to update, instead of reattaching it and failing every tool call.
    • This build serves the requirement only on its own daemons and same-protocol daemons, not through a newer daemon's client.
  • The daemon no longer counts itself idle, or retires on an idle-shutdown request, while its tool front holds a call, an open connection or a kept agent's grants.

  • Reviews:

    • A scoped code review and a regression audit of these changes: one must-fix found (accepting the requirement through a newer daemon's client) and fixed; the re-review is clean.
    • A performance review on this head: PASS.
    • New tests cover the idle guard and the requirement check.
  • QA on Linux, 78716c6 (the last commit after it only merges two imports):

    • Codex bot chat restart: the agent and its background caller kept running. A call made while Orca was down got the plain-text 503 after 30 s. Calls succeeded after the relaunch.
    • Reattach: the next turn used the tool on the same agent, so this build reattaches its own kept bot chat with the new requires entry.
    • Daemon while Orca was down: it stayed up, and its relay listing carried requires: ["toolRelayFront"].
    • Claude: a new Claude bot chat called the tool through the daemon front on its first turn.

A Codex bot chat's tool call after a restart:

r13-public

…ts and callers when it disconnects, not only at the next tool launch
…ts and callers when it disconnects, not only at the next tool launch
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status for a5648ba874b59c5006c13122f040354e04b1a599: done

Since the previous status (1d6e506), one change answers Greptile's review thread. When the daemon client of a replaced terminal service disconnects, the app now drops the tool grants, shared-tool callers and listeners it took back from that client right away, instead of at the next tool launch. A client that simply reconnects keeps them.

  • Reviews: a fresh code review and a regression audit of this change found no defects. They checked that a reconnect retires nothing, that no listener leaks, and that retired records can't come back. Performance review on this head: PASS.
  • QA: Linux QA on 78716c6 (Codex and Claude bot chats, restart, relay listing) still applies. The later commits only touch an import and this app-side cleanup.
  • All review threads are resolved.

r13-public

@brennanb2025
brennanb2025 merged commit 3f6e987 into main Nov 29, 2026
73 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