Skip to content

[Bug]: Terminal/session handle instability breaks orchestration message addressing and injection #9163

Open

Description

@mtarvos

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 env ORCA_TERMINAL_HANDLE at start
  • term_b4eeb794-… — the live --from handle (from the [Reply: … --from …] string Orca injects into delivered messages) hours later
  • term_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:

  1. A stable per-session id that does not change over the lifetime of a session, used for orchestration addressing and terminal send; or
  2. Injection/delivery follows handle changes (a message addressed to a session is delivered to its current handle, not the one at send time); or
  3. terminal create and terminal list return 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 every terminal send.
  • Sweep orca orchestration inbox on 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

  1. added
    bug
    on Jul 27, 2026
  2. bluehansl commented on Jul 31, 2026

    @bluehansl

    Likely the same root family: we reproduced the exact handle churn described here (same pane, leaf id stable, three different term_* handles across consecutive orca terminal list calls) — 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.

  3. str0203 commented on Aug 10, 2026

    @str0203

    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:

    1. expose one canonical, durable session/worker identity separate from transient connection handles;
    2. make terminal create and terminal list agree on that canonical identity;
    3. provide a supported resolve canonical-id -> current handle operation after reconnect;
    4. route orchestration messages to the canonical identity so handle rotation is transparent;
    5. require destructive close/release to bind to the canonical identity and proven ownership;
    6. return an explicit ambiguous/unknown result rather than allowing a stale handle to target anything.

    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.

  4. bluehansl commented on Aug 12, 2026

    @bluehansl

    @str0203 worth noting: the canonical-identity primitives your contract asks for already exist in the runtime — ORCA_PANE_KEY is a durable pane identity separate from transient term_* handles, and terminal.resolvePane is the resolve canonical-id -> current handle operation (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.

  5. MsCNotes404 commented on Oct 24, 2026

    @MsCNotes404
    Contributor

    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:

    • Recipient normalization (XL in 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.
    • Automatic wake owner resolution (f2n.resolveTerminalHandle in out/main/index.js) uses getRun(runId).coordinator_handle directly 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.
    • Other pane-based live-idle/settlement paths exist, and idle/ownership/writable/outstanding-delivery gates still apply. This is not a claim that every possible delivery path is impossible, or that a null delivered timestamp alone proves this cause.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions