Skip to content

Reattach chats kept by a newer Orca's daemon after a downgrade - #51687

Merged
brennanb2025 merged 9 commits into
mainfrom
brennanb2025/kept-claude-unreachable-after-restart
Nov 29, 2026
Merged

brennanb2025 merged 9 commits into
mainfrom
brennanb2025/kept-claude-unreachable-after-restart

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca keeps a chat's agent running in a background helper, so the agent survives when the app restarts. If the app is replaced by an older version, for example when moving from an hourly build to a release, that older app didn't know how to talk to the newer helper. Every message to those chats failed with "Orca can't reach this chat's agent", and nothing fixed it short of updating again. Now the older app can talk to the newer helper well enough to pick its chats back up. When it really can't, it tells you to update Orca.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​34
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​316 $\color{#cf222e}{\Huge{\mathbf{−}}}$​29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​287

What Changed

  • Reaching newer daemons. A downgraded app now opens a relay-only connection to each live newer-protocol daemon.
    • It says hello at that daemon's own version and refuses every request outside the frozen relay set (relayList, relayAttach, relayWrite, relayAck(s), relayDetach, relayClose). It never spawns, sends notifies, routes terminals, or retires or stops the daemon.
    • It connects only when a chat's run names that daemon, and stays connected until quit.
  • Leaving the newer build's agents alone. Listing a newer daemon never ends its relays of agent integrations this build doesn't know. They stay kept for the newer Orca, and their chats get the refusal below.
  • "Reopen terminals" protection. That action no longer stops a newer daemon while an agent this app attached reads through it. Relay attaches there are fenced while the action decides and stops.
  • New ProviderRelayInfo.requires contract. A relay that needs something from its app beyond the relay requests lists it here. An app reattaches only relays whose every entry it supports; the others stay kept and get the refusal below. This build supports no entries. feat(bots): bot chats keep their tools across an Orca restart and update #51086 will add toolRelayFront for relays that hold bot tool grants, so an older app doesn't reattach a bot chat whose tools it can't serve.
  • Honest refusal. When the newer daemon can't be connected, or a relay needs what this build can't serve, the refusal reads: "This chat's agent may still be running under a newer version of Orca, so this version won't start a second one. Update Orca to reconnect to it." A listing that merely timed out keeps the generic message.

Why

The older app connected only to its own daemon and to older generations (createLegacyDaemonAdapters). The chat's run placement names the newer daemon start, so the run gate never found a client for it. That daemon is alive, so it was never proven gone, the gate answered unknown, and every send threw KeptProviderRelayUnreachableError. Terminals already have a newer-protocol hold; kept chats had nothing equivalent.

Semver orders 1.4.281 above 1.4.281-hourly.*, so the updater can make this move on its own.

The alternative was to only reword the refusal. That would still leave chats stuck until an update, and possibly cut a running turn. The relay request set is already frozen and negotiated through hello capabilities, so driving a newer daemon's relays needs no new wire protocol.

Linked Issue

N/A (found live on a maintainer's machine)

Visual Proof

N/A. No UI changes beyond the refusal text; downgrade QA evidence will be posted in a comment.

Testing

  • daemon-newer-protocol-relay-clients.test.ts checks the containment boundary: spawn, terminal and notify requests are refused, a relay request reaches the transport, and the unreachable check matches the newer daemon's start.

  • Remote typecheck, lint and related tests on Linux.

  • Packaged downgrade QA on Linux:

    • A chat kept by a higher-protocol build's daemon reattaches under this build.
    • An unreachable newer daemon shows the new refusal.
    • A plain restart still reattaches.
  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

None, because:

  • With no newer daemon held (the normal case), the relay route returns before touching disk.
  • With one held, each newer generation's start ID is read once during async launch discovery, and a client object is made once per generation.
  • The refusal check is an in-memory lookup.
  • The per-chat refusal flag is cleared with the chat's run verdict on close or delete.
  • No timers or polling are added.

Deferred (follow-up)

  • Newer daemon retirement. A newer daemon that one of this app's chats used stays connected until quit, so it can't retire early. The cost is one extra process per newer protocol generation, and only after a downgrade. Releasing it safely needs in-flight tracking: a first attempt cut the quit hand-off. Tracked in STA-19638.
  • "Reopen terminals" copy. When the action is blocked by an attached chat, it shows the generic "Couldn't reopen" message. Tracked in STA-19639.

Risk

Level: Medium

  • Riskiest part: an older app driving a newer daemon's relays. The daemon accepts one attachment per relay, and a later attach takes over. Two Orca builds share one user data folder and its single-instance lock, so an older and a newer app can't both be attached.
  • If a future daemon changes the relay requests or the hello: the attach fails and the chat gets the new "update Orca" refusal instead of reattaching. The relay protocol comment now states the hello and relay set stay frozen in both directions.
  • Known cost, deferred: after a downgrade, a newer daemon one of this app's chats used stays alive until quit: one extra idle process, about 22 wakeups a minute. Nothing is lost, there is no second writer, and nothing gets stuck. Tracked in STA-19638.
  • Back out with a plain revert.

Merge order

Land this before the next daemon protocol bump (#51086, protocol 65). Then any release still at 64 carries this fix and can reattach chats a 65 daemon kept.

Review

…er a downgrade

An app moved to an older build (for example from an hourly to a release cut before a protocol
bump) only connected to daemons at or below its own protocol, so a chat whose agent a newer
daemon kept was refused on every send as unreachable, with no way out short of updating.

The app now opens a relay-only client to each live newer-protocol daemon (hello at that daemon's
version, frozen relay requests only, never a spawn or a terminal request) and lists it with the
other generations, so the kept chat reattaches. When that daemon still can't be reached, the
refusal says the agent runs under a newer Orca and to update.
…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.
@brennanb2025
brennanb2025 marked this pull request as ready for review November 28, 2026 18:46
… 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.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The changes add relay-only clients for held newer daemon generations and include them in provider relay host client collection. Provider relay requirements and agent reattachability now gate relay placement. Relay inventory preserves specified relays from newer clients. Liveness and kept-relay handling record newer-daemon hold state, update diagnostics, and adjust client connection and cleanup behavior.

Merge Risk: Minimal · up to efd1d

This change lets an older Orca reattach chats held by a newer daemon, and it refuses cleanly with an update prompt when that is not possible. The earlier concerns about connecting unrelated newer daemons and stopping a daemon that an attached chat is using are addressed in the current code. No blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: chats kept by a newer Orca daemon are reattached by an older Orca after a downgrade. The changeset matches this, including the relay-only connection to newer daemons, …
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (marked N/A with a reason), Visual Proof (N/A with a reason), Testing, Performance (filled in with th…
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: chats kept by a newer Orca daemon are reattached by an older Orca after a downgrade. The changeset matches this, including the relay-only connection to newer daemons, the reattach logic in the run gate, and the updated refusal text. The title is concise, specific, and has no file lists or vague terms.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (marked N/A with a reason), Visual Proof (N/A with a reason), Testing, Performance (filled in with the 'None, because' line and reasons), Risk (level Medium, riskiest part, and back-out plan), Merge order, and Review. The AI Disclosure section is empty, which is acceptable for a maintainer. The Agent skill upstream boundary checkbox is not ticked, and the Notes and Checklist sections are not updated. The Linked Issue section says N/A rather than linking an issue, which the template requires for outside contributors. The author appears to be a maintainer, so this is a minor gap.

Resolution

Optional cleanup: tick or address the 'Agent skill upstream boundary' item, confirm the Checklist items, and state the AI Disclosure if applicable. If the author is an outside contributor, link a real issue under Linked Issue.

  • 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: 5a80c241-ad4d-4045-9523-b024ce2c15f6
Commits

Reviewing files that changed from the base of the PR and between 9a6e7f7 and efd1d9c.

Files selected for processing: 2

  • src/main/daemon/providers/lifecycle/daemon-provider-state.ts
  • src/main/daemon/providers/routing/daemon-newer-protocol-hold.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.

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Connect only the newer daemon named by the run. · provider-relay-run-liveness.ts:183-186

src/main/provider-relay/provider-relay-run-liveness.ts:183-186
Minor · Functional Correctness · Quick win

Connect only the newer daemon named by the run.

If a run names instance A, this filter also selects every unanswered newer client for instances B and C. Their hello identities are initially null, although discovery already recorded their instances. ensureConnectedWithin then opens control and stream connections to those unrelated daemons.

The new client collection makes this previously unchanged selector violate the PR's connection scope. Filter newer clients by their recorded instance before connecting. Keep the existing discovery behavior for installed-adapter clients, and still connect the newer client when its instance matches.

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: b14d77e4-4eb6-4f9d-9b7a-5a14f37ed445
Commits

Reviewing files that changed from the base of the PR and between f8d8f9c and 37d0907.

Files ignored due to path filters: 1

  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 11

  • src/main/daemon/protocol/daemon-provider-relay-protocol.ts
  • src/main/daemon/providers/lifecycle/daemon-provider-state.ts
  • src/main/daemon/providers/routing/daemon-newer-protocol-hold.ts
  • src/main/daemon/providers/routing/daemon-newer-protocol-relay-clients.test.ts
  • src/main/daemon/providers/routing/daemon-newer-protocol-relay-clients.ts
  • src/main/provider-relay/provider-relay-kept-rebind.ts
  • src/main/provider-relay/provider-relay-launch-inventory.ts
  • src/main/provider-relay/provider-relay-route.ts
  • src/main/provider-relay/provider-relay-run-liveness.ts
  • src/main/provider-relay/provider-relay-run-verdicts.ts
  • src/main/startup/pty-startup/main-process-pty-startup.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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan — head abc8eb9 — verdict: clean (no findings)

Surfaces: Electron main (provider-relay routing, run gate, launch listing), daemon client transport. No renderer, storage or SQL changes.

Fleet used for pricing: 100+ agents / chats with relayed runs, H = held newer daemon generations on disk (realistically 0–2; one per newer protocol version, does not grow with worktrees, chats or history).

Added work Trigger Population Bound
newerDaemonRelayClients() inside route.all() each run-gate ask and the launch listing H generations returns [] with no allocation when H = 0 (every user who never downgraded); otherwise O(H) map walk, clients created once per generation and reused
Run-gate connect filter (newerDaemonRelayClientInstance) per ask, per unconnected client H O(H); a newer client is connected only when the chat's placement names its daemon start, so chats on other starts pay nothing. ensureConnectedWithin dedupes in-flight connects, capped by the existing connect wait
heldByNewerOrca / newerDaemonUnreachable only on the unknown verdict path H O(H), no I/O; the reconciler's existing 2 s → 5 min backoff still governs retries, and a kept refusal leaves the retry set
requires gate + agent-reattachable check per listed kept relay in a gate ask one relay empty-set membership, constant
Launch listing listOne once per launch (+30 s retry on no answer) H extra clients unconnected newer client returns answered with zero I/O, so it never forces the retry
keep() for a newer daemon launch listing relays on that daemon skips closes: strictly less work than before
Channel idle disconnect last sink leaves a newer daemon's channel one client socket destroy, no timer; reconnect only on the next user send/open or hello-woken ask for that chat
Per-chat refusal flag (underNewerOrca) gate verdicts chats with relayed runs string Set; cleared on gone, idle-forget, close/delete and new run, alongside the existing verdict maps
Launch discovery pid reads once at daemon init, in parallel with legacy adoption H H small async reads, never repeated

Regression classes touched:

  • Fixed-cadence poll / new idle wakeups: no new timers, intervals or subscriptions. A connected newer client has no client-side timer, and the daemon sends events only to attached clients. Idle wakeups/s are unchanged on main, the renderer and the daemon.
  • Expensive code past a gate: the new client only allows the frozen relay request set. notify is refused, so no terminal or spawn path becomes reachable.
  • Per-entity state outlives the entity: the generations map shrinks when a hold is released (client disconnected and deleted), and channels are keyed by a WeakMap. Refusal flags are cleared on every path that clears run verdicts.
  • Unbounded fan-out: Promise.all over clients is bounded by daemon generations, not chats.
  • Startup imports: no new SDK or adapter imports.

Six questions: (1) skip gate before work: yes, the H = 0 early return. (2) ownership: one client per generation, shared across chats. (3) thread: main, O(H) sync with no sync fs. (4) growth: none with fleet or history. (5) host: local-only, the feature is already off on Windows and for remote owners via providerRelayMayKeep. (6) teardown: idle disconnect releases the newer daemon, and a hold release drops the client.

Not measured: no runtime profile was taken. The verdict rests on source-proven counts.

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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head e71584b

Verdict: clean. No findings. Everything the change adds is either bounded by the number of newer daemon generations held at launch (one or two in practice, and never more than the newer protocol numbers left in the runtime dir) or runs on paths and timers that already existed. It adds no new timer, poll or idle wakeup in main, the renderer or the daemon.

What the change adds: trigger, population, bound

Work Trigger / cadence Population Bound and evidence
Launch discovery reads (discoverNewerProtocolHolds) Once per daemon adoption at startup, run in parallel with legacy adapter creation Held newer generations G G async readFile + parse of the pid record, off the event loop. One-time, so it is not a finding. The existing sync readdirSync in listDaemonPidFileProtocols is unchanged.
newerDaemonRelayClients() inside route.all() Each route.all() call: the launch listing (once, retried after 30 s only when a daemon didn't answer) and each run-gate ask G Map walk plus protocols.includes, O(G²) with G ≤ 2. One client per protocol is cached in generations and never recreated per call. A generation removed by reopenNewerDaemonTerminals is disconnected and deleted the next time this runs, so the map can't outgrow the held set.
Launch listing (listOne) Once per launch G more clients An unconnected newer client returns true right away: no connect, no RPC, and no 30 s retry loop. A connected one gets one relayList, and keep() skips its closes.
Run-gate asks (instanceClient) Asks that already existed: chat open, send, restart candidates, and the kept-open reconciler retry (per daemon start, backing off from 2 s to 5 min, one shared timer that exists only while a chat is waiting) Chats waiting on a newer daemon start A newer client is connected only when the chat's run names its pid-record instance (filtered by newerDaemonRelayClientInstance). Concurrent asks share one connectingPromise, capped at CONNECT_WAIT_MS (1 s). That adds one socket connect per retry wave on a timer that already existed, not one per chat. watchProviderRelayClient adds its listener once per client, guarded by a WeakSet.
heldByNewerOrca / newerDaemonUnreachable Only on the unknown verdict branch of decide G O(G) walk plus isConnected(). No I/O.
providerRelayRequirementsMet + providerRelayAgentReattachable Per listed relay in decide The requires array (empty today) Set lookups. Constant.
Per-chat refusal flag (underNewerOrca Set) Set or cleared on each current run-gate verdict Chats whose run is undecided Deleted on forget(), forgetProviderRelayRunVerdict (close, delete, new run) and forgetIdleProviderRelayRunVerdict, the same teardown as unknownRuns. The constructor does one has. It can't outlive the chat.
Connected newer client kept until quit After the first connect G sockets DaemonClient has no keepalive or heartbeat timer, so holding an idle socket adds no wakeups. Relay events go only to the attached client.

Regression classes touched

  • Per-entity state outlives the entity: generations map and underNewerOrca Set. Checked and ruled out: both are deleted in the same teardown as their siblings (held-set shrink, run-verdict forget paths).
  • New wakeups in steady idle / polls that never settle: checked and ruled out. No new setTimeout or setInterval. The only repeated trigger is the existing reconciler backoff (2 s up to 5 min), which ends once no chat is waiting. Idle wakeups/s per process are the same as base: 0 added.
  • Expensive code newly reachable past a gate: listOne previously stopped at a null identity and now connects nothing for newer clients. The run gate connects only the named start. Checked and ruled out.
  • Sync fs on Electron main: the new reads are fs/promises. Checked and ruled out.
  • Unbounded fan-out: Promise.all covers at most G pid reads or G clients. Checked and ruled out.

Six questions

  1. Unused work before the skip gate: reviewed. Unconnected newer clients are skipped before any RPC at launch, and other starts' clients are filtered before connecting.
  2. Ownership multiplying work: reviewed. One client per held protocol, cached. One watcher per client.
  3. Thread and storage: reviewed. Main-process async reads only. No SQLite.
  4. Growth and progress: reviewed. Bounded by G and the existing per-start backoff. The launch listing still settles (an unconnected newer client counts as answered).
  5. Execution host: not applicable. The route is installed on darwin and linux, local only (providerRelayMayKeep requires a local owner and not win32).
  6. Obsolete work stops: reviewed. A generation stopped by reopen is disconnected and dropped on the next route.all(). The refusal flag clears with its verdict. A connected client is kept until quit by design, with G sockets and no timers.

Examined: daemon-newer-protocol-relay-clients.ts, daemon-newer-protocol-hold.ts, daemon-provider-state.ts, provider-relay-run-liveness.ts (decide, instanceClient), provider-relay-launch-inventory.ts (listOne, keep, listKeptProviderRelays), app-provider-relays.ts (reattachListed), provider-relay-kept-rebind.ts, provider-relay-run-verdicts.ts, main-process-pty-startup.ts, daemon-provider-relay-protocol.ts, plus the kept-open reconciler cadence and DaemonClient connect coalescing.

Evidence: source-proven counts only. Nothing was run, and no timing is claimed.

…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.

@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: 1

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: 4b7e5097-9e57-485a-86c5-a7f6a0cd0bc5
Commits

Reviewing files that changed from the base of the PR and between 37d0907 and abc8eb9.

Files selected for processing: 6

  • src/main/daemon/providers/routing/daemon-newer-protocol-relay-clients.ts
  • src/main/provider-relay/app-provider-relays.ts
  • src/main/provider-relay/provider-relay-channel.ts
  • src/main/provider-relay/provider-relay-kept-rebind.ts
  • src/main/provider-relay/provider-relay-launch-inventory.ts
  • src/main/provider-relay/provider-relay-run-liveness.ts

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

… and stops a newer daemon

The bound-relay check alone could race an attach during the stop's process inspection.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: head 9a6e7f7, verdict clean

No findings. Everything this PR adds is gated on a newer-protocol daemon being held at launch. That count is zero for a normal install and at most a couple of protocol versions after a downgrade. None of the new work grows with worktrees, terminals, chats or history, and it adds no timers, polls or idle wakeups.

Work added: trigger, population and bound

Work Trigger Population Bound
route.all() → getProviderRelayHostClients() now also calls newerDaemonRelayClients() each run-gate ask, plus the launch listing held newer generations H (usually 0, at most a few) O(H) map work, no I/O. When H = 0 and the map is empty it returns [] right away. A client is created lazily (no connect) once per held generation and dropped, with disconnect(), when a reopen stops that generation
Run-gate asks (instanceClient) send, open, reconciler, restart-candidate reads (a Promise.all over resume markers that was already there) clients = adapters + H The new filter calls newerDaemonRelayClientInstance (O(H)) for each client that hasn't said hello. A newer client is connected only for a chat whose placement names its daemon start, or when its pid record was unreadable. That connect is capped at 1 s, and concurrent asks share one connectingPromise. If it fails, the next ask makes at most one connect attempt and starts no background reconnect
decide() usability check each ask that finds a kept relay one relay info requires.every(Set.has) plus one Set lookup. Constant
heldByNewerOrca → newerDaemonUnreachable only on the unknown branch, after the process-gone probes H O(H), no I/O
Launch listing (listOne) once per launch, retried after 30 s only when a daemon didn't answer adapters + H A newer client that isn't connected returns true straight away. It is not connected and adds no retry. A connected one is listed once through the existing per-instance listing cache (2 s reuse)
Per-chat refusal flag (underNewerOrca Set) set or cleared on a current ask chats whose run a newer daemon keeps Cleared on forget(), forgetIdleProviderRelayRunVerdict and forgetProviderRelayRunVerdict (close, delete, new run), so entries live no longer than the chat's run verdict. O(1) per write
Launch discovery reads once at daemon provider init H pid files Runs H async readFile calls in parallel through node:fs/promises (no sync fs on main). With H = 0 it reads nothing
Reopen fence (stopping Set, relayingChats check) user's "reopen terminals" H Add and delete in finally, plus a WeakMap lookup and a sinks.size check per generation
keep() on a newer client per listed relay, once per listing relays on that daemon Skips close for newer clients, so it does less work than before

Regression classes touched

  • Per-entity state outlives the entity: checked, no problem. The generations Map is keyed by protocol and pruned when the held list drops a version. stopping is cleared in finally. underNewerOrca is cleared by every verdict-forget path. channels and watched are WeakMap/WeakSet keyed by the client.
  • Expensive code newly reachable past a gate: checked, no problem. The new client only accepts the frozen relay request set. Notify calls are refused. Spawn and terminal RPCs are rejected locally. Launch listing never connects it, and run-gate asks connect it only for a chat whose run names its daemon start.
  • Unbounded fan-out: the restart-candidate Promise.all over markers was already there. This PR adds O(H) work to each item and one shared connect.
  • Idle wakeups: none added. DaemonClient has no reconnect or keepalive timer, and the relay ack batch only arms on scheduled or queued acks. Wakeups/s before and after: main 0 → 0, daemon 0 → 0, renderer untouched.
  • Eager startup imports: the new module and provider-relay-channel are internal and import no SDK. Their only top-level side effect installs a closure.

Six questions

  1. Unused work before the gate: reviewed. With H = 0 it returns early, so a normal install's ask pays one function call.
  2. Ownership multiplying work: reviewed. There is one client per held generation, shared by every chat. Connect is deduped.
  3. Thread and storage: reviewed. All new I/O is async on main: H pid reads at launch and an on-demand socket connect. No SQLite.
  4. Growth and progress: reviewed. Nothing scales with fleet N. The launch listing doesn't add retry debt for a newer client it never connected.
  5. Execution host: not applicable. The route is installed only on darwin and linux and not in serve mode. Local sockets only, no SSH.
  6. Obsolete work stops: reviewed. A stopped generation's client is disconnected and dropped on the next all(). A generation still relaying a chat is kept on purpose, because stopping it would end that chat's agent.

Residual gaps

I ran nothing; the bounds above come from reading the code. I didn't measure the connect latency to an unreachable newer socket. That cost is capped at 1 s per ask, shared by concurrent asks, and happens only for chats placed on that daemon start.

@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: 4c1d2c4c-5f3d-4565-879c-1683360df9ad
Commits

Reviewing files that changed from the base of the PR and between abc8eb9 and 6db509d.

Files selected for processing: 5

  • src/main/daemon/providers/routing/daemon-newer-protocol-hold.ts
  • src/main/daemon/providers/routing/daemon-newer-protocol-relay-clients.test.ts
  • src/main/daemon/providers/routing/daemon-newer-protocol-relay-clients.ts
  • src/main/provider-relay/provider-relay-channel.ts
  • src/main/provider-relay/provider-relay-run-liveness.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready (head 9a6e7f71)

Problem. After Orca was replaced by an older build with a lower daemon protocol, every chat whose agent the newer daemon kept failed on each send with "Orca can't reach this chat's agent". Nothing fixed it short of updating again.

User-facing change.

  • Those chats now reattach under the older build, finishing the turn they were on.
  • When the newer daemon can't be reached, the refusal says the agent may still be running under a newer Orca and to update.

Review.

  • Three review passes, each by a fresh Claude reviewer and a fresh Codex reviewer, plus a blinded regression audit on the merged result. Fixed along the way:
    • a newer daemon's agents of unknown integrations were being ended at listing;
    • sync disk work on the relay route;
    • the refusal flag leaked across chat close and delete, and was chosen on a listing timeout;
    • a disconnect that cut the quit hand-off;
    • "Reopen terminals" could stop a newer daemon an attached chat was using, including a race with a reattach.
  • Added the requires contract on ProviderRelayInfo. feat(bots): bot chats keep their tools across an Orca restart and update #51086 will set toolRelayFront on it, so an older app won't reattach a bot chat whose tools it can't serve.
  • Perf scan on this head: clean (posted above).

Deferred, agreed as follow-ups.

  • A newer daemon one of this app's chats used stays connected until quit, so it can't retire early. A separate confirm review judged this safe to defer: bounded, only after a downgrade, no lost output.
  • When "Reopen terminals" is blocked by an attached chat, it shows the generic "Couldn't reopen" message.

Verified.

  • CI green; remote typecheck, lint and tests pass.
  • Linux packaged-style QA on this head, with a protocol 65 copy of this branch as the "newer" build, a real Claude CLI, and graceful stops:
    1. Before (main): the downgraded app refuses with "can't reach".
    2. After: the chat reattaches mid-turn, the running turn finishes, and follow-ups are answered. It reattaches again after quit and relaunch, and "Reopen terminals" leaves the chat running.
    3. Newer daemon unreachable: the new refusal shows, no second agent starts, and the chat reattaches once the daemon is reachable again.
    4. Plain restart: reattaches.
    5. Single writer: exactly one agent served the chat at every checkpoint.
Before (main) After: reattached and answering Unreachable newer daemon
before after unreachable

Merge order: before #51086.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan: clean (head efd1d9c)

Findings: none. Each new piece of work is bounded by P, the number of newer daemon generations held at launch. P is 0 for anyone who hasn't downgraded and usually 1–2 for someone who has. Nothing new runs on a timer, poll or idle path. Everything is on Electron main.

Surfaces: startup-migration (relay route install in main-process-pty-startup.ts; launch discovery in daemon-newer-protocol-hold.ts).

What the PR adds: trigger → population → bound

Work Trigger Population Bound / evidence
route.all() → getProviderRelayHostClients() + newerDaemonRelayClients() each run-gate ask and the one launch listing current + legacy clients + P newer Returns early with [] when P = 0 and the map is empty. Otherwise it loops G ≤ P map entries with protocols.includes, so O(P²) with P ≤ ~2, plus one array spread. No I/O, and the client is constructed once per protocol and cached in generations.
Run-gate ask (instanceClient) chat open/send, startup candidates, kept-open reconciler retries (existing 2 s → 5 min backoff, one shared timer) per ask newerDaemonRelayClientInstance is O(G) per waiting client. A newer client whose nonce names a different daemon start is filtered out, so it is never connected. At most one connect attempt per matching newer client (≤ 1 s, async). Concurrent asks share the client's connectingPromise, and once connected the client is no longer waiting. Base already did a connect attempt per unconnected client per ask at the same cadence. watchProviderRelayClient is guarded by a WeakSet.
Launch listing (listOne) once per launch P newer clients An unconnected newer client returns early, so it costs 0 relay RPCs and 0 connects at launch. keep() adds one instanceof per channel and skips the close loop for newer daemons, which is less work.
heldByNewerOrca → newerDaemonUnreachable only on an ask's unknown verdict per ask O(P) map walk, no I/O.
requires gate per kept relay found in an ask entries in info.requires Empty set lookup, O(entries). Already-placed relays are unchanged.
Per-chat refusal flag (underNewerOrca Set) set or cleared on a current ask chats with a relayed run One string per chat. It is cleared alongside unknownRuns in forgetProviderRelayRunVerdict / forgetIdleProviderRelayRunVerdict, the ask's forget() and a usable kept verdict. Read only when a refusal error is built.
Launch discovery reads (discoverNewerProtocolHolds) once at daemon init P held protocols One async readFile + parse per held pid file (hundreds of bytes), run in parallel with legacy adoption inside the existing Promise.all. 0 reads when nothing is held.
Relaying check plus stopping fence in "reopen terminals" user action (IPC) P O(1) per protocol. .finally clears the cached promise, so a pass that never awaits can't stay cached.
Relay route install (startup) once n/a One extra closure. The new module's imports (DaemonClient, relay channel, write settlement) are already on the startup graph through app-provider-relays. Its top-level work is one function assignment.

Retention and teardown

generations is keyed by protocol. A generation stopped by reopen is disconnected and deleted on the next all(). A generation whose daemon exits keeps one disconnected client object until quit, at most P objects. Channels live in a WeakMap keyed by client. DaemonClient has no timers and doesn't reconnect on its own, so a connected newer client adds 0 idle wakeups/s. Its ack batch timers run only while acks or relay output are in flight, the same as base relays. Idle wakeups/s on main, renderer and the daemon: 0 before, 0 after.

Regression classes touched

  • Fixed-cadence poll / new idle wakeups: no new timer. The reconciler retry cadence is unchanged and now carries at most one shared connect attempt per instance.
  • Per-entity state outlives entity: the underNewerOrca Set is cleared on the same paths as unknownRuns, and generations is limited to P.
  • Sync fs on main: readDaemonClientToken (existing readFileSync of a small token file) runs once per connect attempt. Attempts happen only when a chat names that daemon and follow the backoff. This is the existing per-client pattern, not new per-event work.
  • Unbounded fan-out: the ask's connect Promise.all is limited by the client count, about P + adapters.
  • Eager startup imports: no new heavy modules.

Six questions

  1. Work paid for before a skip gate? No. Newer clients are listed or connected only when an ask names them; unconnected ones return before any RPC.
  2. Ownership multiplying work? One client per protocol, shared by all chats, with connects shared through connectingPromise.
  3. Which thread pays? Main. The only sync I/O is the existing token read per connect. Discovery is async.
  4. Growth and progress? Nothing grows with chats, worktrees or history beyond one flag string per chat. A kept verdict for an unusable relay ends the reconciler retry, so there's no loop.
  5. Execution host? Darwin and Linux only, local Unix sockets. Windows and serve mode don't install the route.
  6. Obsolete work stops? Reopen drops stopped generations. A connected client is kept until quit on purpose while chats read through it, at zero idle cost.

Evidence and gaps: the counts above are source-proven at the target head. I took no runtime timing, CPU or heap measurements and ran no tests. There are no residual uninspected paths in scope.

@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the previous request for tests covering reopen protection remains non-blocking.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous request for tests covering reopen protection remains non-blocking.

Findings

  1. P2 Reopening protection goes untested ▶

Summary

Lets a downgraded Orca reconnect to chats kept by a newer daemon.

  • Downgraded Orca reconnects chats through the newer daemon that kept them.
  • Unsupported kept chats stay with the newer Orca and point to an update.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Open a kept chat] --> B[Find its recorded daemon start]
  B --> C{Daemon answers?}
  C -->|No| D[Keep the run unknown unless both processes are proven gone]
  C -->|Yes| E{Relay requirements and agent supported?}
  E -->|No| F[Leave relay kept and ask user to update]
  E -->|Yes| G[Bind reader and attach through relay-only client]
  H[Reopen terminals] --> I{Reader bound?}
  I -->|Yes| J[Keep newer daemon]
  I -->|No| K[Fence attaches while stopping daemon]
Loading

Reviews (2) · Last reviewed commit: "fix(daemon): don't cache a reopen pass t..." · Reviewed by Greptile

@brennanb2025

brennanb2025 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

QA round 2 on efd1d9cf: PASS

After the last two review-thread fixes, I reran the downgrade flows on Linux with the same setup as round 1 (a protocol 65 copy as the newer build, a real Claude CLI, graceful stops):

  1. Downgrade reattach: the chat reattaches mid-turn, the running turn finishes, and follow-ups are answered.
  2. Reopen while a chat is attached: the terminal isn't reopened, and the newer daemon and the chat's agent stay alive. The chat keeps answering.
  3. Reopen after the chat's agent ended (the new fix): in the same session, with no restart, the terminal reopens into a working shell and the newer daemon exits.
  4. Single writer: at most one agent at every checkpoint.

Also on efd1d9cf:

  • A blinded audit returned SAFE.
  • A fresh Claude repair check returned READY.
  • The perf scan, now covering startup, is clean.

Follow-ups: STA-19638 (newer daemon retirement), STA-19639 ("Reopen" blocked copy).

Reattached under the older build Reopen while the chat is attached Reopen after the chat ended
reattach (screenshot removed: contained real product data) (screenshot removed: contained real product data)

@brennanb2025
brennanb2025 merged commit bb306fe into main Nov 29, 2026
68 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