Repository navigation
Description
Summary
FirstMate's experimental Orca backend records terminal=<handle> in task metadata and documents that value as a stable handle used for capture, send, current-state reads, and teardown. Orca now has a reproducible open bug where terminal/session handles change across create/list calls and runtime restarts (stablyai/orca#9163), making cached handles stale and breaking message addressing.
Make the FirstMate Orca adapter treat the recorded handle as a hint, re-resolve the current terminal identity before every consequential operation, and fail closed when it cannot prove the replacement refers to the same task terminal.
Current mismatch
FirstMate docs/orca-backend.md currently says:
terminal=carries the stable Orca terminal handle that backend operations use.
stablyai/orca#9163 demonstrates that:
orca terminal createandorca terminal listcan return different handles for the same tab/PTY;- a continuous coordinator or worker session can receive several handles over its lifetime;
- old handles eventually return
terminal_handle_staleor fail to receive injected messages.
This invalidates the adapter's persistence assumption, particularly after Orca restart/reconnect—the exact point where FirstMate recovery needs reliable identity.
Proposed behavior
- Persist stable identity fields in addition to the transient handle: Orca worktree id, tab id, pane key/leaf id, terminal title/alias, and PTY id where the supported CLI exposes them.
- Before peek/send/state/close, list terminals within the recorded Orca worktree and resolve exactly one candidate using stable identity.
- Update local metadata atomically when a replacement handle is proven.
- Refuse destructive close/teardown on zero or multiple candidates; preserve the worktree and report the ambiguity.
- Reconcile handles at FirstMate session start and after any
terminal_handle_staleresponse. - Keep Orca #9163 as the upstream product fix; this issue is the adapter's defensive compatibility behavior.
Acceptance criteria
- A fake-Orca test changes the terminal handle after spawn while preserving stable pane/tab identity; peek and send re-resolve and succeed.
- A restart/reconnect recovery test updates metadata to the current handle.
- Ambiguous duplicate candidates fail closed without sending input or closing anything.
- Teardown never trusts a stale handle to identify the terminal being destroyed.
- Documentation stops calling runtime-issued handles stable.
Related upstream: stablyai/orca#9163
Prepared with AI assistance from current FirstMate/Orca documentation and the upstream reproduction. Reporter: @ericjung.
Activity
str0203 commentedon Aug 10, 2026
The upstream side of this dependency is now explicitly linked from stablyai/orca#9163, and the supervised-worker migration is tracked in #1813.
I suggest preserving two implementation horizons here:
Immediate adapter defense
terminal_handle_staleor session start, re-resolve within the recorded worktree using supported stable fields.Durable identity migration
The restart smoke proposed in #2084 should exercise both modes: rotate the terminal handle after spawn, verify non-destructive read/send recovery, then verify ambiguous duplicates refuse cleanup. This keeps the current adapter safe without blocking on the upstream canonical-identity fix, while giving a clean deletion path once supervised-worker identity is adopted.
kunchenguid commentedon Aug 24, 2026
Speaking as Kun's firstmate: inspected on current
main7b88520c0554.VISION.md (each rule):
Evidence:
docs/orca-backend.mdstill saysterminal=is the stable handle.bin/backends/orca.shstill records and usesterminal-handlewith no re-resolve-before-send. Defect still present. Related #1813. Labelingready-for-pr.kunchenguid commentedon Aug 24, 2026
Speaking as Kun's firstmate:
VISION.md read in full from current main
7b88520c055408a18f1476ecce08be60b2885fc9. Per-rule, inspectedbin/backends/orca.shsend/read/close,bin/fm-spawn.shterminal=persistence,docs/orca-backend.md,tests/fm-backend-orca.test.sh, thread + #1813:Contributor report (e-jung): Orca handles change across create/list and runtime restarts (stablyai/orca#9163). Firstmate records
terminal=and uses it as a stable handle for capture, send, current-state, and teardown. Proposed: persist additional identity fields; re-resolve to exactly one candidate before peek/send/state/close; atomically update metadata when proven; refuse destructive close on 0 or N>1; reconcile at session start and onterminal_handle_stale. str0203 (2026-08-10): keep two horizons — immediate adapter defense here, durable dispatch identity once #1813 lands; #2084 should exercise both.Inspected current main
7b88520c055408a18f1476ecce08be60b2885fc9:bin/fm-spawn.sh:758-759,2686-2688: spawn writesterminal=$ORCA_TERMINALas durable metadata.docs/orca-backend.md:38-44still namesterminal=(withorca_worktree_id=) as backend authority for operation and cleanup.bin/backends/orca.sh:157-205,256-290:terminal create/read/send/closetake the recorded handle as--terminalwith no list-and-re-resolve, noterminal_handle_stalehandling, no candidate proof, no metadata refresh.fm_backend_orca_json_getstill extracts onlyresult.terminal.handle.tests/fm-backend-orca.test.sh: no re-resolve fixture, no restart/reconnect handle rotation, no ambiguous-duplicate fail-closed case (0 hits forre-resolve).Still present. Constraints for a patch: treat the recorded handle as a hint; re-resolve within the recorded worktree using supported stable fields before peek/send/state/close; replace metadata only when exactly one candidate is proven; zero or multiple candidates refuse send/control/teardown and preserve the worktree; keep Orca #9163 as the upstream product fix. Fake-Orca tests: handle rotates after spawn, peek/send succeed; restart updates metadata; duplicates fail closed; teardown never trusts a stale handle.
ready-for-pris a queue label, not a merge vote.devin-ai-integration commentedon Sep 24, 2026