Repository navigation
Description
Short summary
A terminal/session handle obtained at one moment stops matching the current handle of the same object: orca terminal create and orca terminal list return different ids for the same terminal, and a coordinator session's handle changes over the lifetime of one continuous session. As a result, orchestration messages addressed to the handle-at-send-time are not injected into the recipient session (its handle is already different) and land only in inbox; orca terminal send to the previous handle returns terminal_handle_stale.
This surfaced running a multi-agent orchestration pipeline (one coordinator + up to 3 worker agents over many hours). Client-side workaround (never cache a handle, re-resolve via terminal list, sweep inbox every checkpoint) recovers correctness but costs ~2h of cumulative delay across a run and constant polling.
Likely shares a root cause with #9151 (transient loss of a paired handle) but the symptom here is broken message addressing/injection, not completion misclassification.
Environment
- Desktop: macOS (Darwin 24.6.0), arm64
- Orca: v1.4.143
- Multi-agent orchestration (
orca orchestration+orca terminal), local runtime
Repro A — create-handle vs list-handle disagree (deterministic)
$ orca terminal create --title "orca-repro-A" --command "sleep 600" --json
→ terminal.handle = term_efc362c3-7a19-4d3f-8312-9d24048ae5df
$ orca terminal list # same terminal: title "orca-repro-A", same tabId
→ handle = term_257cd493-dde4-4e8c-a47c-ecfe8ba87ee4 # DIFFERENT id
Both handles simultaneously accept terminal send (accepted:true), so one PTY carries at least two ids and it is undefined which is canonical for message addressing. The list handle is stable across repeated list calls but never equals what create returned.
Repro B — coordinator session handle changes over time
One continuous coordinator session held three different handles in sequence:
term_88482859-…— value of envORCA_TERMINAL_HANDLEat startterm_b4eeb794-…— the live--fromhandle (from the[Reply: … --from …]string Orca injects into delivered messages) hours laterterm_9bbe00a1-…— the live handle hours later still
Worker sessions (same worktree, same claude process) likewise changed handle up to 3 times each (e.g. term_f0bb5824 → term_209e6b26 → term_252efcdb for one worktree).
Consequence — undelivered injection (evidence from inbox)
orca orchestration inbox contains worker decision_gate messages addressed to handles that were already stale at delivery time; they were not injected into the coordinator session (only found by periodically sweeping inbox). Example: 4 decision_gate messages from one worker in inbox — two addressed to term_88482859, two to term_b4eeb794 — none injected at send time. This caused a ~50-minute stall on one worker and ~2h cumulative across the run.
Note: orca orchestration ask itself is not implicated — in a controlled repro it returned {"timedOut":true} correctly; earlier runtime_unavailable errors from ask appear to be a separate transient runtime state under load, not part of this bug.
Expected behavior
Any one of:
- A stable per-session id that does not change over the lifetime of a session, used for
orchestrationaddressing andterminal send; or - Injection/delivery follows handle changes (a message addressed to a session is delivered to its current handle, not the one at send time); or
terminal createandterminal listreturn the same canonical handle.
Current client-side workaround (in our orchestrator skill)
- Never cache a handle; re-resolve via
orca terminal list(by worktree + title) before everyterminal send. - Sweep
orca orchestration inboxon every checkpoint and incoming event (injection is not treated as a delivery guarantee). - Duplicate delivery to workers:
orchestration reply(thread) +terminal send(wake).
The workaround holds but the correct fix is server-side canonical/stable addressing.
Activity
bluehansl commentedon Jul 31, 2026
Likely the same root family: we reproduced the exact handle churn described here (same pane,
leafid stable, three differentterm_*handles across consecutiveorca terminal listcalls) — but with a harder failure mode: the claude-teams tmux shim (agentTeams.tmuxCompat) resolves teammate pane splits through a terminal reference stored server-side at registration time, and unlike the general orchestration path (PR #7514) it has no pane-key remint fallback. Once that stored reference goes stale, Claude Code teammate spawning is fully blocked for the session (no client-side workaround — the RPC accepts no handle/pane-key).Details, source analysis, and a suggested fix in #11739.
str0203 commentedon Aug 10, 2026
This is also a hard downstream blocker for Firstmate's Orca backend. Firstmate currently persists the terminal handle for later peek/send/control/cleanup, so handle churn is most damaging exactly after a restart or reconnect—when recovery must prove it is addressing the same worker.
Downstream tracking:
The most useful upstream contract would be:
terminal createandterminal listagree on that canonical identity;resolve canonical-id -> current handleoperation after reconnect;A regression test that creates one terminal, observes handle rotation/restart, then sends and closes through the durable identity would give downstream orchestrators a contract they can safely build on. This is more than a convenience issue for Firstmate: without stable addressing, it cannot safely claim restart-proof supervision or exact cleanup on the Orca backend.
bluehansl commentedon Aug 12, 2026
@str0203 worth noting: the canonical-identity primitives your contract asks for already exist in the runtime —
ORCA_PANE_KEYis a durable pane identity separate from transientterm_*handles, andterminal.resolvePaneis theresolve canonical-id -> current handleoperation (added by PR #7514, but only wired into the general orchestration command path).PR #11742 (awaiting human review) applies exactly that contract to the agent-teams path (
agentTeams.tmuxCompat), which today fails hard on stale handles (#11739): the leader pane key is kept in team state as the durable identity, stale handles are transparently re-resolved through it with a single retry (your item 4), and when the resolver cannot produce a handle the operation fails explicitly instead of letting a stale handle target anything (your item 6).It is scoped to agent-teams rather than the full surface you describe, but it may be useful as a working reference for items 1/3/4/6 of the contract — the pattern and its tests are small and self-contained.
MsCNotes404 commentedon Oct 24, 2026
Additional handle-drift evidence in installed Orca 1.4.239 (macOS), specifically the Run-mailbox automatic-wake path:
After restoring the original coordinator in its original pane, the live pane/terminal handle differs from the old handle still stored in the existing Run. Sending to the current terminal correctly normalizes the message into
run:<id>, and the exact message is durably present. Read and delivered timestamps remain unchanged while the original coordinator can otherwise continue working.Static inspection of installed bundles identifies a routing asymmetry:
XLin out/main/chunks/orcad-migration-source-retention-D7gUOK5z.js) obtains the live terminal pane key and resolves its current Run, so enqueue can succeed despite the stale stored handle.f2n.resolveTerminalHandlein out/main/index.js) usesgetRun(runId).coordinator_handledirectly for Run recipients. Its Dispatch branch has pane-key/current-handle fallback; the Run branch does not. An unknown stored owner resolves to null, so that immediate wake path cannot deliver to the restored terminal.An isolated extraction of the installed resolver with synthetic dependencies returned null for an old stored Run handle despite a current pane mapping; a synthetic current stored owner resolved normally. This was not a live rebinding or integration test.
Please evaluate a source-bound, fail-closed same-owner pane/session fallback in Run wake resolution, with regressions for restored same-owner panes, missing or ambiguous panes, changed ownership/consumer generation, simultaneous coordinators, active permission waits and duplicate deliveries. No fallback should transfer Run authority or bypass delivery/permission gates. Alternatively, document the supported restoration-time binding refresh and its generation/fencing effects.
We did not rebind the live Run, impersonate a coordinator, ACK another consumer's mail, restart the original process or retry blocked terminal input. This update contains no real handles, project contents, client data or credentials.