Skip to content

Start a fresh terminal host after an update so chats keep running across restarts - #51160

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/daemon-relay-keep-protocol-bump
Nov 28, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/daemon-relay-keep-protocol-bump

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

After an update, Orca keeps using the terminal host that the previous version started, so open terminals keep running. Some hosts from earlier builds of the same version could not keep a chat's agent alive across a restart. Orca picked one of those up, and every Claude chat and every chat with other agents that connect the same way then quietly started outside it and died on the next quit or crash. Now the updated app starts its own fresh host for new terminals and chats. The old host keeps the terminals it already runs until they end.

What Changed

  • PROTOCOL_VERSION 63 → 64, and 63 joins PREVIOUS_DAEMON_PROTOCOL_VERSIONS, so the v63 daemon is adopted as a previous generation (its terminals and kept relays stay reachable) and new sessions go to a fresh v64 daemon. PROVIDER_RELAY_PROTOCOL_VERSION stays 63: a v63 daemon still serves the relay RPCs, and its kept relays must stay reattachable.
  • The build compatibility contract (local-build-compatibility-contract.json / .ts) moves to 64; a test now checks it against PROTOCOL_VERSION, since packaging says hello to the built daemon with the contract's version.
  • PROVIDER_RELAY_CAPABILITIES_BY_PROTOCOL pins the relay capabilities each protocol's daemon advertises (v63: providerRelay; v64: plus providerRelayKeep, providerRelayAcks). The daemon's hello now derives its relay flags from this table, and a test pins its rows, so adding a capability means a new row with a protocol bump.
  • launchRelayedProviderProcess: when a chat falls back to a direct launch because the daemon lacks providerRelay or providerRelayKeep, it records a provider-relay.direct-fallback trace span (and a console warning) once per daemon start and capability, with the daemon's appVersion.

Other paths an older same-version daemon degrades silently

These v63 additions had no capability flag. On a v64 daemon they are all guaranteed; on an adopted v63 daemon they still degrade as listed:

  • relayAcks (gated by providerRelayAcks): falls back to one relayAck per relay. Costs only requests.
  • daemonInstance echo in spawn and list replies: placement falls back to the hello launchNonce, and the inventory accepts a listing without it.
  • relaySpawn.policy and relayDetach.policy (detached idle stop): ignored, so a detached agent runs until closed.
  • relaySpawn.agent, relayAttach.kept, keep spec requests / replies / note: ignored.
  • relayAck.cutKeys without cut, savedThrough, held, and reply ackedThrough / truncatedThrough: ignored or absent, so the app falls back to its older cut accounting.
  • Spawning for another bundle's app: refused by daemons older than that change, so the chat launches direct.

Why

Adopting a same-version daemon is how terminals survive updates, so any capability added without a protocol bump is invisible to the bundles that adopt an older daemon. Bumping is the existing versioned-hosts model. A per-protocol table makes the next capability addition force a bump instead of relying on memory.

Linked Issue

N/A

Visual Proof

N/A: no UI change.

Testing

  • daemon-protocol-bump.test.ts pins the relay capability table and checks the build compatibility contract matches PROTOCOL_VERSION.

  • Packaged upgrade on Linux, from a build before the keep capability existed (protocol 63) to this PR's build, on the same user data:

    • A v64 daemon started beside the running v63 one.
    • The old build's terminal stayed attached to the v63 daemon, still printing.
    • A new Claude chat ran under the v64 daemon, not the app. It kept the same agent process through a quit and relaunch, and it remembered the earlier turn.
    • No direct-launch fallback was traced.
    • With the old build, the Claude chat had launched direct and ended at quit.
  • 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

Performance

None: one extra daemon starts after an update (the normal path for a protocol bump), and the trace runs at most once per daemon start and capability.

Risk

Level: Medium. After updating, users run two daemons until the old one's terminals end, as with every protocol bump. A revert or downgrade to a v63 build can't attach terminals or kept chats on a v64 daemon until that daemon exits, the same as every earlier bump.

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

Windows doesn't relay chats (the route is macOS and Linux only), so it only sees the protocol bump. SSH and mobile are unaffected.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I stated the risk
  • N/A with reason for visuals
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

An app adopts any running daemon of its own protocol, so a v63 daemon from a
bundle that predates providerRelayKeep kept every Claude and ACP chat on a
direct launch. v64 guarantees keep and batched acks; the advertised relay
capabilities now come from a pinned per-protocol table, and a launch that
falls back for a missing capability traces it once per daemon start.
…d test it follows the bump

Packaging says hello to the built daemon with the contract's version, so a
stale contract fails every mac and AppImage packaging check.
@brennanb2025
brennanb2025 marked this pull request as ready for review November 27, 2026 23:02
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The daemon protocol version advances to 64. Protocol-specific relay capabilities are advertised by the daemon and checked during client-side relay setup, with fallback tracing when a capability is missing. Both local-build compatibility contracts include version 64. Spool cleanup now caches owner liveness checks and skips filenames that do not match the spool naming pattern.

Merge Risk: Minimal · up to 1c8a9

This change bumps the daemon protocol to 64 and gates relay capabilities by protocol version, with a traced direct-launch fallback. No concrete defect was found in the changed code, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: after an update, the app starts a fresh terminal host so chats keep running across restarts. The changeset bumps PROTOCOL_VERSION from 63 to 64, adds relay capability …
Description check Passed The description follows the repository template and covers every required section: ELI5, What Changed, Why, Linked Issue (N/A), Visual Proof (N/A with reason), Testing, Performance, Risk with level, a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: after an update, the app starts a fresh terminal host so chats keep running across restarts. The changeset bumps PROTOCOL_VERSION from 63 to 64, adds relay capability tables and a fallback trace, and updates the build compatibility contract. The title describes the user-facing purpose rather than the protocol bump, but it stays on-topic and specific.

Full details: Description check

Explanation

The description follows the repository template and covers every required section: ELI5, What Changed, Why, Linked Issue (N/A), Visual Proof (N/A with reason), Testing, Performance, Risk with level, and Checklist. It explains the mechanism (protocol bump, previous-version adoption, relay capability table), the degraded behaviors on an adopted v63 daemon, and the manual Linux upgrade test. Gaps: the Linked Issue section says N/A, although the template requires an issue for outside contributors; the Testing section does not list the platforms beyond Linux; and the lint, typecheck, test, and build checklist item is unchecked. The PR objectives also raise open performance concerns (idle v63 daemon retirement, Windows synchronous staging, and spool liveness probing) that the Performance section does not address. The 'AI Disclosure' section is left as the template placeholder.

Resolution

Consider these items before merge: state the linked issue or justify N/A for an outside contributor; name the platforms tested for the manual upgrade test; and either run or record the pnpm lint, typecheck, test, and build results. The Performance section should address the raised concerns about idle v63 daemon retirement, Windows mirror staging on the main process, and per-file owner liveness probes.

  • Autofix · 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

Recent 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: 7e380be8-1725-473c-8d52-a8cc06f6d037
Commits

Reviewing files that changed from the base of the PR and between 20f3a16 and 1c8a95d.

Files selected for processing: 10

  • src/main/daemon/protocol/daemon-protocol-bump.test.ts
  • src/main/daemon/protocol/daemon-protocol-version.ts
  • src/main/daemon/protocol/daemon-provider-relay-protocol.ts
  • src/main/daemon/provider-relay/daemon-provider-relays.ts
  • src/main/daemon/provider-relay/provider-relay-directory.ts
  • src/main/provider-relay/app-provider-relays.ts
  • src/main/provider-relay/provider-relay-capability-fallback.ts
  • src/main/provider-relay/provider-relay-spawn-request.ts
  • src/shared/remote-runtime/orcad-distribution/local-build-compatibility-contract.json
  • src/shared/remote-runtime/orcad-distribution/local-build-compatibility-contract.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan — FAIL

P1 · The v63 daemon stays connected and keeps polling after its last terminal or chat ends. The bump starts v64 at a new endpoint. Startup opens an authenticated control/stream pair to the surviving v63 daemon for its inventory. Terminal exit removes the session route and relay settlement releases the relay, but neither releases the legacy connection. The daemon cancels its initial adoption timer on authentication and its automatic idle exit waits for the final client disconnect or endpoint loss. The v64 endpoint leaves v63’s endpoint intact. An old daemon with zero work can therefore live until the app disconnects. Protocol bump · Legacy adoption · Exit routing · Relay removal · Idle lifecycle · Idle predicate

  • Idle cost per upgraded profile. On the healthy v63 adoption path the base has one daemon; the head has two processes and two socket pairs while the old lease remains. The extra process contributes a terminal-policy tick every 3 s where file-backed policy applies (read up to 1 KiB), a process-growth tick every 30 s (no process-table read at zero PTYs), a ledger tick every 60 s (refreshes a published record), and on macOS/Linux one synchronous socket stat every 30 s. Those are about 0.42 additional scheduled callbacks/s on POSIX or 0.38 on Windows with file-backed policy and ledger; macOS GUI login watching adds a healthy probe about every 120 s. The base has zero work from a second daemon. These counts are independent of 750 or 7,500 worktrees, 300 or 3,000 PTYs, and 100 or 1,000 agents. The app’s main process and renderer gain no periodic callback or frame from hello or the fallback trace. Policy · Growth monitor · Ledger · Ownership watch · Login watcher cadence
  • Cost while both generations serve terminals. With default enforcement and PTYs on both, the growth monitors independently read the full host process table, so one read per steady 30 s cadence becomes two, or one per 5 s per daemon during recent automatic work or growth confirmation. For a table of P rows this is up to 2P visits per period versus P when both run at the same cadence, at reference and 10× load. Linux uses one ps per sample, macOS can use libproc with a ps fallback, and Windows uses the native table when available. Once v63 is empty, its table read stops and its other ticks continue. An old ledger record also costs up to two additional synchronous record reads and PID probes per successful terminal admission attempt, for the initial census and reservation check. Sampling gate · Default enforcement · POSIX process table
  • Regression check. Adopt a healthy v63 with a retained PTY and relay, start v64, then drain v63 while the app stays open. Count connections, children, policy reads and ownership ticks through idle. Require v63 to stay until the final retained PTY or unread relay is released, retire with both sockets closed and no further ticks, and leave v64 able to spawn. Repeat with an already-empty v63 and with a second authenticated client that must survive.

Work by trigger

Trigger Population, work and bound
First launch after update or current-host recovery One current endpoint per profile across macOS/Linux/Windows. Healthy v63 adoption becomes a v64 endpoint miss and one winning fresh start. Existing cold paths can stage a signed macOS image and bootstrap launchd, wait up to 8 s for Linux AppImage preparation, or stage the Windows host and fork. Work is per bundle/image, independent of worktrees or transcripts. Fork readiness defaults to 10 s, macOS budgets 10 s each for bootstrap and readiness, and existing gates cap the first-window wait at 12 s and local provider readiness wait at 60 s. Respawn admission allows five attempts per 60 s window. Launcher · macOS launch · Readiness gates
Legacy discovery and terminal ownership Once per provider initialization, prior protocol candidates go from 62 to 63. One sequential socket probe per candidate (1 s if a connect stalls); on a miss, one async PID-file read, at most one signal-zero check, and up to two synchronous stale-file unlinks on proof. A reachable v63 yields one extra adapter and an inventory from each reachable generation. Shared inventory uses a 2 s request deadline and indexes the returned PTY rows once per acquisition. Fresh PTYs go to current, known IDs keep their owner, and unresolved ownership or full-list callers can query all connected generations again. The retained PTY population is partitioned across hosts; it is not replicated on both. Discovery · Inventory and sharing · Routing
Daemon construction and hello One capability lookup per supported daemon start, checking two rows and writing at most three booleans. Each fresh client pair has two authenticated request/reply exchanges, with one stored control identity and no periodic hello. v64 carries the same three fields as the capable v63 build. A v63 daemon still supplies its actual flags. Framing limits hello to 16 MiB, and temporary listeners and deadlines end on settlement. Capability table · Server hello · Client hello
New local chat or kept-chat reopen Eligible Codex, Claude and ACP launch callers share the current daemon client; reattach-only calls skip the fresh-spawn path. The run gate verifies the recorded owner and kept inventory, then fresh launch checks one identity. Capability failure skips environment construction, cwd probe, relay spawn and attach. Success copies the launch environment once and adds one macOS cwd probe (1.5 s), one spawn (30 s request deadline) and one attach (10 s). The agent starts once on the normal success path. Windows and serve mode do not install the app chat relay route. Relay route and startup gate · Launch · Spawn spec · RPC deadlines
Capability fallback Main builds one key and looks it up per capability miss. First occurrence for a daemon nonce and missing capability emits one warning and at most one three-attribute span to the existing bounded sink; no timer of its own. The set retains keys for app lifetime. Normal production spawns use current local v64, which advertises both required flags, and v63 recovery uses the reattach path. The guard has one additional shared key for a missing identity. Fallback trace · Current and legacy client selection · Trace sink
First relay spawn in each daemon One shared preparation promise, one directory creation, two permission stats, lazy imports and one directory listing. For S entries, U distinct other owners and K dead-owner files, the sweep does S name checks, at most U signal-zero probes (previously one per matching file), and K serial unlinks. With 100 or 1,000 primary spools from one surviving v63, that is 100 or 1,000 names, one probe and zero unlinks. It reads no spool content. Completion is bounded by actual directory entries and deletion I/O, with no entry-count cap. Preparation failure resets the promise for the next launch. Directory preparation · Shared preparation
Kept relay inventory and active output Launch shares one listing pass; one relayList RPC per capable generation (3 s), proportional to its relays, with one close per unsupported detached relay. Failed launch listing is retried on demand after 30 s; same-instance reads share in-flight work and reuse successful results for 2 s. Active output goes to one keyed sink per event. ACKs use a demand-driven 1 s tick and 25 ms flush per client, capped at 1,024 entries per wire batch; a v63 without ACK batching gets one RPC per due ACK. At 100 or 1,000 due entries in one flush on v64, one RPC on that connection. Idle without output owes zero stream and ACK frames. Kept inventory · Sink and teardown · ACK batching
Terminal event routing The multi-generation router installs one data, exit and identity listener per adapter, plus one IPC background-stream and write-unavailable binding on each. A source event reaches its usual main binding once, then the existing renderer dispatchers (PTY dispatch for data/exit/write availability and resource inventory for exit); temporary close listeners live for one shutdown. Each PTY still sends through its one owning adapter and the existing listener registrations. The added path emits 0 frames/s at idle and 0 duplicate/no-change frames at the same input rate under load. Fanout · IPC binding · Renderer dispatch · Resource inventory
Quit, loss, restart and deliberate retirement Quit/aborted adoption disconnects adapters in parallel, with final checkpoints for active PTYs (up to four workers per adapter) and one 250 ms connect/idle-shutdown budget per adapter. The server fences retirement on no PTYs, relays, in-flight create or competing transports. Lost legacy endpoints with active PTYs get one reconnect chain per adapter (0.5/2/5 s then 30 s while unproved); inventory drops a proven-dead POSIX adapter and its subscriptions. Manual restart normally swaps current and keeps the legacy adapters. Managed idle retirement inventories each adapter and asks each empty daemon to stop. Uninstall extends its known protocol list from 63 to 64; macOS keeps in-use helper copies and sweeps other candidates on a fresh launch with one 5 s lsof budget each. Disconnect · Idle RPC · Loss retry · Router retirement · Uninstall · macOS bundle collection
Packaged compatibility check Both compatibility payloads add one entry (63 → 64) and set the built daemon’s expected hello to 64. Packaging still verifies one daemon with two hello roles. Runtime activation checks advertised live protocols against the 64-entry list. Packaged check · Compatibility check

Scan questions. Admission and payload construction, ownership and fanout, process/thread and storage placement, growth and retries, platform branches, and teardown were reviewed. The touched recurring classes are idle timers and obsolete owners (P1), startup work made reachable by a version change (one cold launch per transition), and repeated reads or process probes (spool probes now deduped by PID; host sampling is duplicated as described above). Missing-capability work exits before environment or RPC work. Scope covers desktop and local daemon use on managed hosts, including Windows/WSL terminal teardown; mobile and SSH clients add no local launch owner or timer here.

Source comparison used origin/main...1c8a95d4 (merge base 6e8f10ccd01f). Counts are derived from source. Cold startup timing, platform-specific process exit, and worst-case leftover spool cleanup time were unmeasured. The protocol and packaging assertions were inspected without execution.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status: ready, Brennan merges (performance waiver).

Problem: after an update, the app kept using a still-running terminal host from an older build of the same protocol. That host couldn't keep chat agents alive, so every Claude chat (and other agents that connect the same way) launched outside it and ended at the next quit.

Change: the host protocol moves to 64, so an updated app starts a fresh host for new terminals and chats. The old host keeps its existing terminals until they end. A test-pinned table now ties each relay capability to a protocol version, and a launch that falls back records one trace per host start.

Verified:

  • Packaged Linux upgrade from a build before the capability to this build:
    • A v64 host started beside the v63 one, and the old terminal stayed on v63.
    • A new Claude chat ran under the new host and kept the same agent across a quit and relaunch.
  • Windows timing of the fresh-host start: about 1.5 s cold and 84 ms warm on the main thread.
  • The checks gate and CI.

Deferred: two costs that every protocol bump already carries.

  • An emptied older host stays connected until quit. It uses about 107 MiB and close to zero CPU. Retiring it is the next PR.
  • Windows host-file staging runs on the main thread. That will be its own PR.

Perf waiver (Brennan): "/ref-oss up to you" (2026-11-27), delegated; the decision was to ship now, with retiring an emptied older host as the next PR and Windows staging as its own PR. #51160 (comment)

@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA (packaged Linux build of this PR): a Claude chat runs under the terminal host and survives the app quitting.

Before quitting, the chat is asked to remember a word:

Chat before quit

After a quit and relaunch, the same chat answers from the earlier turn, with no restart. The agent process was the same one throughout (same pid, parented to the v64 host):

Same chat after relaunch

@brennanb2025
brennanb2025 merged commit 339594e into main Nov 28, 2026
104 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