Skip to content

feat(bin): add native Orca supervised workers and Secondmates - #5348

Closed
leodiegoo wants to merge 6 commits into
kunchenguid:mainfrom
leodiegoo:fm/orca-native-supervised-x1
Closed

leodiegoo wants to merge 6 commits into
kunchenguid:mainfrom
leodiegoo:fm/orca-native-supervised-x1

Conversation

@leodiegoo

@leodiegoo leodiegoo commented Sep 22, 2026 •

Copy link
Copy Markdown

Intent

Implement all planned phases of the Firstmate + Orca integration in one closed loop, correcting bugs and rerunning tests until the complete migration is finished. The words authorizing this scope were: "you may complete all phases in a closed loop, fixing bugs until completion". The completed capability spike established that Orca 1.4.206 exposes real worker-start, worker-read, worker-abandon, worker-show, worker-list, worker-release, terminal wait, worktree ps, mailbox/ask, and durable Run/Task/Dispatch identities. The final result must make native supervision usable without losing Firstmate\x27s isolation, steering, validation, recovery, delivery, cleanup, and persistent Secondmate guarantees.

What Changed

  • Adds a native Orca supervision adapter (bin/backends/orca-supervised.sh plus a JSON helper). fm-spawn.sh --orca-mode supervised runs the full launch in the task's Orca terminal first, then attaches it with orchestration worker-start --terminal. Before treating the launch as consumed, it checks that the returned Run/Task/Dispatch/worker/worktree identities match and reads a complete worker-read transcript. The mode is capability-gated: agent-context schema 1, the required command shapes, a Claude/Codex/Cursor harness, and a live ORCA_TERMINAL_HANDLE. If any check fails, ordinary ships and scouts fall back to terminal mode.
  • Orca now accepts persistent --secondmate spawns, but only through native supervision bound to an exact existing home workspace from orca worktree ps. A recorded native task never falls back to terminal mode on relaunch or restart: it relaunches in a fresh terminal with --task/--retry-of. Meta records the durable native identities, and routing (fm-backend, fm-peek, fm-send, fm-crew-state, fm-control, fm-classify-lib) goes through dispatch:<id>. It uses transcript-first reads, mailbox doorbells with a terminal fallback, worker-stop/worker-abandon/worker-release control, and it refuses on any identity mismatch.
  • Teardown and recovery settle and release the exact Dispatch before closing the launched terminal. A new cleanup_recovery=orca record, plus orca_retry_dispatch_id for a partial retry, covers attaches or relaunches that cannot settle. The persistent Secondmate home is kept, the Secondmate restart gate and liveness sweep skip recovery records, and the Orca docs, skill, and backend tests are updated to match.

Risk Assessment

⚠️ Medium: The fix round correctly implements the authorized relaunch retry sidecar with no new defect I could substantiate, but the overall branch is a large shell-level lifecycle and recovery change whose retry and abandon semantics are proven only against a fake Orca, so follow-up validation against real Orca 1.4.x is advisable.

Testing

I ran the three targeted regression suites for this change with the live flag set: tests/fm-backend-orca.test.sh, tests/fm-control.test.sh and tests/fm-secondmate-restart.test.sh. All passed; they cover the fake-Orca lifecycle, the recovery records and partial receipts. I then set up a throwaway Orca lab: a scratch repo already registered in Orca, a coordinator worktree and terminal, and isolated Firstmate state/data/config under /tmp. In it I ran the real Firstmate CLIs against the running Orca app. The capability gate accepted native mode only inside a real Orca terminal; a missing or stale handle fell back, and Pi was excluded. A persistent Secondmate refused outside Orca and refused a raw launch, with no mutation. A raw-launch scout asking for supervised mode fell back to the terminal adapter on a real Orca worktree and terminal, and was peeked and torn down, which released the worktree. Forged native records and cleanup_recovery=orca records were refused by peek, crew-state, send and teardown, and every record was kept. A native spawn run inside the Orca coordinator hit a real agent_unconfigured refusal; spawn closed the launched terminal, released the worktree, wrote no record, and left no Dispatch in the Run. The one remaining gap is a successful attach, which needs a real logged-in agent. The lab was torn down afterwards. There is no UI change, so there are no screenshots; the evidence is CLI transcripts.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Inside a live Orca terminal, the native capability gate accepts Claude and Codex (schema 1, required commands present) and excludes Pi ✅ pass live gate-inside-orca.txt: gate[claude]=native schema=1 commands=236, gate[codex]=native, gate[pi]=terminal-fallback reason=agent-pi-not-supported
Outside Orca, or with a stale ORCA_TERMINAL_HANDLE that real Orca rejects, the gate reports no-orca-sender-terminal and falls back instead of claiming native support ✅ pass live gate-outside-orca.txt: both the no-handle and stale-handle contexts give terminal-fallback reason=no-orca-sender-terminal
A persistent Orca Secondmate spawned outside Orca (no handle, stale handle, or raw launch command) refuses before any mutation and keeps its home ✅ pass live secondmate-outside-orca-refusal.txt: 'native Orca supervision is required ... preserving the home' exit=1 (twice), raw-launch refusal exit=1; Orca worktrees 23 before and after; no state record; home…
An ordinary scout requesting --orca-mode supervised with a raw launch falls back to the terminal adapter on a real Orca worktree and terminal, can be peeked, and tears down cleanly ✅ pass live scout-raw-supervised-fallback-spawn.txt (notice + orca_mode=terminal meta with real orca_worktree_id/terminal), scout-terminal-peek.txt (FM_LIVE_RAW_AGENT_UP visible), scout-terminal-teardown.txt (tea…
Adversarial: a native supervised record whose Run/Task/Dispatch real Orca doesn't know fails closed across peek, crew-state, send and teardown, and the durable record is kept ✅ pass live forged-native-records-fail-closed.txt: peek 'Dispatch ... could not be inspected; output identity is unknown' exit=1; crew-state unknown/native-worker; teardown 'REFUSED: native Orca Dispatch ... is n…
Adversarial: a cleanup_recovery=orca record holding only a Dispatch id that can't be proven to belong to its workspace is refused by teardown, and the record is kept ✅ pass live forged-native-records-fail-closed.txt: 'REFUSED: native Orca recovery Dispatch ... is not proven to belong to its recorded workspace; preserving its durable records.' and the meta is still present
A fresh native spawn inside a real Orca coordinator whose worker-start attach Orca refuses closes the launched terminal, releases the worktree, writes no record, and leaks no Dispatch ✅ pass live native-spawn-inside-orca.txt ('worker-start did not attach supervision ... closing the launched terminal and releasing its unrecorded resources', exit=1, no meta); afterwards the launched terminal exi…
Successful native attach with a real agent: worker-start --terminal, first-turn worker-read transcript proof, mailbox steer, worker-stop/release on teardown, native relaunch with --retry-of, and nativ… ⏸️ untested no Orca attaches only to a recognized, logged-in Claude/Codex agent in the terminal. Proving it live needs the captain to authorize running a real logged-in agent (spending tokens) in the live Orca app,…
Evidence: Native gate inside a live Orca terminal

Source: Native gate inside a live Orca terminal

context: inside-orca-terminal ORCA_TERMINAL_HANDLE=term_54367c64-a62d-4202-97f1-4270a72485f3
orca --version: 1.4.207
gate[claude]=native schema=1 commands=236
gate[codex]=native schema=1 commands=236
gate[pi]=terminal-fallback reason=agent-pi-not-supported
Evidence: Native gate outside Orca (no handle / stale handle)

Source: Native gate outside Orca (no handle / stale handle)

context: outside-orca-no-handle ORCA_TERMINAL_HANDLE=<unset>
orca --version: 1.4.207
gate[claude]=terminal-fallback reason=no-orca-sender-terminal
gate[codex]=terminal-fallback reason=no-orca-sender-terminal
gate[pi]=terminal-fallback reason=agent-pi-not-supported

context: outside-orca-stale-handle ORCA_TERMINAL_HANDLE=term_00000000-dead-beef-0000-000000000000
orca --version: 1.4.207
gate[claude]=terminal-fallback reason=no-orca-sender-terminal
gate[codex]=terminal-fallback reason=no-orca-sender-terminal
gate[pi]=terminal-fallback reason=agent-pi-not-supported
Evidence: Persistent Secondmate refusal outside Orca

Source: Persistent Secondmate refusal outside Orca

--- fm-spawn.sh smlive1 <home> --harness claude --backend orca --secondmate  (no ORCA_TERMINAL_HANDLE)
error: native Orca supervision is required for persistent secondmate smlive1 (no-orca-sender-terminal); preserving the home
exit=1
--- fm-spawn.sh smlive1 <home> --harness claude --backend orca --secondmate  (ORCA_TERMINAL_HANDLE=term_00000000-dead-beef-0000-000000000000)
error: native Orca supervision is required for persistent secondmate smlive1 (no-orca-sender-terminal); preserving the home
exit=1
--- raw/custom launch for a persistent Secondmate
error: raw/custom launch commands cannot start a persistent Orca Secondmate; use a canonical harness for native supervision
exit=1
orca worktrees before=23 after=23
state dir: .last-watcher-beat 
home still present: yes
Evidence: Raw-launch scout supervised→terminal fallback spawn

Source: Raw-launch scout supervised→terminal fallback spawn

notice: native Orca supervision does not accept raw/custom launch commands; using the tested terminal adapter
spawned fmlivescout1 harness=bash kind=scout window=fm-fmlivescout1 worktree=~/orca/workspaces/proj/fm-fmlivescout1
exit=0
Evidence: Terminal-mode scout peek

Source: Terminal-mode scout peek

--- fm-peek.sh fmlivescout1 (terminal-mode fallback task)
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

fm-fmlivescout1 [ fm-fmlivescout1]


fm-fmlivescout1 [ fm-fmlivescout1]


fm-fmlivescout1 [ fm-fmlivescout1]


fm. '/tmp/fm-fmlivescout1+b82dae5b817739f668545ecd54491cbd032b114b295705e0d0b01571b47dfc61/launch.s1790117531.9557.7623.sh'
FM_LIVE_RAW_AGENT_UPexit=0
--- fm-crew-state.sh fmlivescout1
state: unknown · source: pane · harness state unavailable (unknown missing)
Evidence: Terminal-mode scout teardown and Orca release

Source: Terminal-mode scout teardown and Orca release

--- fm-captain-hold.sh complete fmlivescout1 --none
complete: fmlivescout1 captain-call inventory reviewed
--- fm-teardown.sh fmlivescout1
teardown fmlivescout1 complete (window term_cee6ce4e-a575-46e0-be24-df1cdf83ed7f, worktree ~/orca/workspaces/proj/fm-fmlivescout1)
Backlog: fmlivescout1 just finished (this home keeps no markdown backlog at /private/tmp/fm-live-native/data/backlog.md). Update /private/tmp/fm-live-native/data/backlog.md - move fmlivescout1 to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
exit=0
meta present: no
worktree dir present: no
orca worktree row: released
orca terminal show: still present
Evidence: Forged native and recovery records fail closed

Source: Forged native and recovery records fail closed

=== forged native record (complete identities that real Orca does not know), same real worktree+terminal as fmlivescout1
--- fm-peek.sh fmlivenative1
error: native Orca Dispatch dispatch-forged-0001 could not be inspected; output identity is unknown
exit=1
--- fm-crew-state.sh fmlivenative1
state: unknown · source: native-worker · native Orca Dispatch unavailable
--- fm-send.sh fmlivenative1 'hello'
error: FM_HOME is not set; fm-send refuses to resolve targets without an explicit firstmate home
exit=1
--- fm-teardown.sh fmlivenative1
teardown: reaping leaked worktree process(es) for fmlivenative1: 10587 11025 13293
REFUSED: native Orca Dispatch for task fmlivenative1 is not proven owned; preserving its durable records.
exit=1
=== forged cleanup_recovery=orca record (Dispatch id only)
--- fm-teardown.sh fmliverecov1
REFUSED: native Orca recovery Dispatch for task fmliverecov1 is not proven to belong to its recorded workspace; preserving its durable records.
exit=1
=== aftermath
meta fmlivenative1 present: yes
meta fmliverecov1 present: yes
real worktree dir present: yes
orca worktree row: present liveTerminalCount=0
Evidence: Forged native record steer keeps durable inbox

Source: Forged native record steer keeps durable inbox

--- fm-send.sh fmlivenative1 (forged native record)
fm-send: native Orca steering was not enqueued; falling back to the terminal doorbell
fm-send: doorbell did not reach dispatch:dispatch-forged-0001; the steer is durably recorded at /tmp/fm-live-native/state/fmlivenative1.inbox/001.msg and the watcher will re-ring
exit=0
fmlivenative1.inbox/
/tmp/fm-live-native/state/fmlivenative1.inbox/001.msg
--- fm-peek.sh fmlivescout1 after forged teardown
exit=0
Evidence: Native spawn inside Orca: refused attach abort cleanup

Source: Native spawn inside Orca: refused attach abort cleanup

coordinator ORCA_TERMINAL_HANDLE=term_54367c64-a62d-4202-97f1-4270a72485f3
error: native Orca worker-start did not attach supervision to terminal term_f04e2954-3600-4f3c-b5d2-ecdb02f96f2e; closing the launched terminal and releasing its unrecorded resources
spawn exit=1
--- state/fmlivenat1.meta:
cat: /tmp/fm-live-native/state/fmlivenat1.meta: No such file or directory
NATIVE_SPAWN_DONE
Evidence: Direct worker-start attach probe (agent_unconfigured, 0 workers)

Source: Direct worker-start attach probe (agent_unconfigured, 0 workers)

probe terminal=term_92e17b89-65c0-4132-a14d-794b46ec5b45
--- terminal tail before attach
Welcome to fish, the friendly interactive shell,Type help for instructions on how to use fish,,fmlab-coord [ fmlab-coord],  env CLAUDE_CONFIG_DIR=/tmp/fm-live-native/cchome claude,Error: Input must be provided either through stdin or as a prompt argument when using --print,,fmlab-coord [ fmlab-coord]
--- worker-start --terminal
{"ok":false,"error":{"code":"agent_unconfigured","message":"Terminal term_92e17b89-65c0-4132-a14d-794b46ec5b45 is not running a recognized agent. Orchestration mutation request ID: b17ee9e3-38c0-4001-b618-87708b497307."}}
workers in run: 0
probe terminal closed
ATTACH_PROBE_DONE
Evidence: Targeted regression suites log

Source: Targeted regression suites log

=== tests/fm-backend-orca.test.sh
FM_TEST_BEGIN 2026-09-22T22:49:12Z tests/fm-backend-orca.test.sh family=orca expected_gate_skip=optional-binary
ok - native Orca capability probe gates schema and required command shapes
ok - native Orca capability gate keeps unverified Pi on the tested terminal adapter
ok - native Orca capability gate refuses a caller outside an Orca terminal
ok - native Orca capability gate refuses a stale inherited Orca terminal handle
ok - native Orca worker-start and transcript-first worker-read project stable identities
ok - native Orca worker-start: incomplete receipts retain identities for abort reconciliation
ok - native Orca worker-read marks terminal or clipped output as non-authoritative evidence
ok - native Orca state projection rebinds transient terminal evidence only after exact identity checks
ok - native Orca adapter parses real Orca 1.4.207 worker-show and worker-read shapes
ok - native Orca state mapping preserves unknown outcomes
ok - native Orca stop and source-change evidence keep lifecycle and cursor semantics explicit
ok - native Orca release requires owned settled identity while recovery uses worker-abandon
ok - fm_backend_orca_capture: parses result.terminal.tail and calls terminal read
ok - fm_backend_orca_capture: falls back to result text fields
ok - fm_backend_orca_capture: fails closed on Orca read error JSON
ok - fm_backend_orca_runtime_check: accepts reachable ready runtime
ok - fm_backend_orca_runtime_check: fails closed when runtime is not ready
ok - fm_backend_orca_send_text_submit: verifies empty composer after Enter with one bounded read
ok - fm_backend_orca_send_text_submit: a borderless claude composer confirms delivery (the missing #2029 shape)
ok - fm_backend_orca_composer_state: a stale startup banner cannot outrank the live composer row
ok - fm_backend_orca_send_text_submit: retries Enter while composer remains pending
ok - fm_backend_orca_composer_state: a slash-command popup's argument-hint placeholder still reads pending
ok - fm_backend_orca_composer_state: a bare dead-shell prompt reads unknown (unsafe-for-injection), never empty
ok - fm_backend_orca_send_text_submit: a slash-command popup's placeholder fill on Enter #1 does not short-circuit as submitted; Enter #2 is retried and lands it
ok - fm_backend_orca_send_literal: sends text without submitting
ok - fm_backend_orca_send_text_submit: reports send-failed when Orca send fails
ok - Orca send helpers: fail closed on ok:false JSON
ok - fm_backend_orca_send_key: Enter maps to empty enter, C-c maps to interrupt
ok - fm_backend_orca_send_key: refuses unsupported keys loudly
ok - fm_backend_orca_send_key: refuses Escape instead of mapping it to interrupt
ok - fm_backend_orca_kill: calls terminal close and stays best-effort
ok - fm_backend_orca_kill: a close its missing CLI never attempted reports the failure instead of a success
ok - fm_backend_orca_remove_worktree: refuses empty worktree ids
ok - fm_backend_orca_remove_worktree: fails closed on ok:false JSON
ok - fm_backend_orca_worktree_path: resolves an Orca worktree id to its path
ok - fm_backend_orca_existing_worktree: refuses duplicate workspace identities for one path
ok - fm-backend dispatcher: accepts orca and routes capture through bin/backends/orca.sh
ok - fm_backend_orca_json_get: ignores undocumented terminal id shapes
ok - Orca lifecycle helpers: register repo, create worktree, create terminal, parse stable ids
ok - fm_backend_orca_worktree_create: removes created worktree when path is missing
ok - fm-spawn.sh --backend orca: preserves metadata when pathless cleanup fails
ok - fm-spawn.sh --backend orca: reuses implicit terminal, records metadata, launches harness
ok - fm-spawn.sh --orca-mode supervised: capability failure falls back to terminal supervision
ok - fm-spawn.sh --orca-mode supervised: raw launch commands use the tested terminal fallback intact
ok - fm-spawn.sh --orca-mode supervised: runs the full launch contract, then attaches worker-start --terminal
ok - fm-spawn.sh --orca-mode supervised: canonical harness launch keeps permission, prompt, and brief framing
ok - fm-spawn.sh native Orca relaunch: relaunches the full contract in a fresh terminal, then retries the Dispatch
ok - fm-spawn.sh --orca-mode supervised: a refused attach closes the launched terminal and releases its worktree
ok - fm-spawn.sh --orca-mode supervised: an unsettled fresh Dispatch keeps a recovery record that teardown stops and releases
ok - fm-spawn.sh native Orca relaunch: a refused attach keeps the prior identities so the task relaunches again
ok - fm-spawn.sh native Orca relaunch: a partial retry receipt keeps the prior record and relaunch or teardown abandons the retry Dispatch
ok - fm-teardown.sh: a partial native receipt recovery record abandons its Dispatch and releases the worktree
ok - fm-teardown.sh: a recovery record missing its Task id still abandons its Dispatch
ok - fm-teardown.sh: a native Secondmate recovery record abandons its Dispatch and keeps the persistent home
ok - fm-spawn.sh native Orca relaunch: a failed capability probe refuses instead of downgrading the record
ok - fm-spawn.sh native Orca Secondmate relaunch: rebinds one manager in its persistent home
ok - fm-spawn.sh --backend orca --secondmate: launches the full manager contract, then supervises its exact home natively
ok - fm-spawn.sh refuses terminal fallback for persistent Orca Secondmates
ok - fm-teardown.sh native Orca Secondmate retirement: release precedes persistent-home removal
ok - fm-spawn.sh --backend orca: refuses before mutation when Orca runtime is not ready
ok - fm-spawn.sh --backend orca: refuses non-isolated worktrees and closes implicit terminals
ok - fm-spawn.sh --backend orca: removes worktree when terminal creation fails
ok - fm-spawn.sh --backend orca: preserves metadata when abort cleanup fails
ok - fm-spawn.sh --backend orca: releases terminal and worktree on later aborts
ok - fm-peek/fm-send/fm-crew-state route through backend=orca metadata and its durable inbox
ok - fm-crew-state: projects native Orca worker state from exact Dispatch identity
ok - native Orca state targets reverse-resolve without masquerading as terminals
ok - fm-send: durable Firstmate inbox plus native Orca mailbox steering
ok - fm-send: native Orca key delivery rebinds to the terminal target
ok - fm-send: native Orca mailbox failure falls back through the terminal target
ok - fm-peek/fm-crew-state: Orca read error JSON fails closed
ok - fm_backend_target_exists: Orca ok:false read JSON is not live
ok - fm-teardown.sh native Orca: proves stop before release and preserves Dispatch ownership
ok - fm-teardown.sh backend=orca: scout report gate then helper-backed worktree removal
ok - fm-teardown.sh backend=orca: scout teardown refuses id/path mismatches
ok - fm-teardown.sh backend=orca: releases terminal/worktree when path is absent
ok - fm-teardown.sh backend=orca: preserves metadata on remove ok:false JSON
ok - fm-teardown.sh backend=orca: scout report gate precedes pathless helper cleanup
ok - fm-teardown.sh backend=orca: ship teardown fails closed when worktree path is missing
ok - fm-teardown.sh backend=orca: ship teardown requires a matching Orca id path
ok - fm-teardown.sh backend=orca: ship teardown fails closed when id resolution fails
ok - fm-teardown.sh backend=orca: ship teardown refuses id/path mismatches
ok - fm-teardown.sh backend=orca: refuses missing worktree ids before cleanup
ok - fm-teardown.sh backend=orca: refuses incomplete worktree-only endpoint metadata before runtime dispatch
ok - fm-teardown.sh --force: settles native Orca children before worktree removal
ok - fm-teardown.sh --force: removes Orca secondmate children through Orca
ok - fm-teardown.sh --force: refuses Orca child id/path mismatches
ok - fm-teardown.sh --force: refuses partial Orca secondmate children before runtime dispatch
skip: live: not inside a live Orca terminal
FM_TEST_END 2026-09-22T22:55:57Z tests/fm-backend-orca.test.sh exit=0 duration_ms=405468 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=405677
FM_TEST_SUMMARY_FAMILY family=orca count=1 duration_ms=405468 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-backend-orca.test.sh duration_ms=405468
exit=0
=== tests/fm-control.test.sh
FM_TEST_BEGIN 2026-09-22T22:55:57Z tests/fm-control.test.sh family=backend-dispatch expected_gate_skip=none
ok - fm-control exit: every verified harness gets its own verified exit command
ok - fm-control interrupt: every verified harness gets its own verified key and repeat count
ok - fm-control interrupt: opencode needs a double Escape, claude a single one
ok - fm-control: a harness with no verified control mechanics is refused, not guessed at
ok - fm-control-lib: a recorded harness resolves to its verified adapter without guessing
ok - fm-control: prefixed recorded harnesses reach interrupt and exit mechanics
ok - fm-control-lib: the backend key matrix matches each adapter's real send-key surface
ok - fm-control-lib: adapter capability is per task kind, not per adapter alone
ok - fm-control interrupt: a backend that cannot deliver the harness's key refuses instead of sending another
ok - fm-control: a backend that cannot prove an agent stopped refuses exit and relaunch
ok - fm-control-lib: native Orca state proof requires supervised mode
ok - fm-control: a legacy window label is refused and the exact task id is named
ok - fm-control: an explicit backend endpoint is never a control target
ok - fm-control: an unrecorded task id is refused
ok - fm-control: a record whose endpoint identity names another task is refused
ok - fm-control: a remotely placed secondmate is refused by placement, not by a metadata complaint
ok - fm-control: interrupt and exit lock before task-state resolution
ok - fm-control: the verb list is closed - no raw keys, arbitrary text, or clear verb
ok - fm-control: resume is refused with the determinism reason and the alternative
ok - fm-control: profile and note flags belong to relaunch only
ok - fm-control exit: an already-stopped agent is idempotent success with no bytes sent
ok - fm-control exit: an unprovable tmux endpoint refuses instead of claiming the agent stopped
ok - fm-control interrupt: refuses when no agent is running rather than keying a shell
ok - fm-control exit: an endpoint whose process cannot be attributed refuses
ok - fm-control exit: a busy agent receives interrupt delivery before the exit command
ok - fm-control exit: an idle agent goes straight to its exit command
ok - fm-control interrupt: unconfirmed delivery preserves observed busy state
ok - fm-control interrupt: muse confirms cancellation from its session log
ok - fm-control interrupt: postconditions are revalidated after acknowledgement polling
ok - fm-control exit: an interrupt-stopped agent satisfies the gone-state postcondition
ok - fm-control exit: a stubborn agent reports delivered input and an unconfirmed exit
ok - fm-control interrupt: grok reports delivery without claiming cancellation
ok - fm-control interrupt: grok's idle footer does not confirm cancellation
ok - fm-control native Orca: exits only after owned Dispatch stop reaches dead
ok - fm-control native Orca: abandons only an unknown owned Dispatch
ok - fm-control: a lifecycle command to a secondmate is unmarked and opens no reply expectation
ok - fm-control's arrival leaves fm-send's from-firstmate marking untouched
FM_TEST_END 2026-09-22T22:56:57Z tests/fm-control.test.sh exit=0 duration_ms=59416 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=59568
FM_TEST_SUMMARY_FAMILY family=backend-dispatch count=1 duration_ms=59416 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-control.test.sh duration_ms=59416
exit=0
=== tests/fm-secondmate-restart.test.sh
FM_TEST_BEGIN 2026-09-22T22:56:57Z tests/fm-secondmate-restart.test.sh family=secondmate expected_gate_skip=none
ok - T1 persist is a gate, and asks for open records and task status only
ok - T2 the mate persists before anything is stopped
ok - T2b an arrived persist answer is resolved before timeout
ok - T2c a reply between the preliminary scan and timeout decision wins
ok - T3 a runtime that cannot prove a restart falls back to the re-read message
ok - T4 every named mate is accounted for, including one this home does not know
ok - T5 a refused restart leaves the mate running and reports an unknown outcome
ok - T8 a local restart re-resolves this home's pin and reports the runtime that came up
ok - native Ultra survives local restart and the remote restart transport
ok - T6 a remote mate restarts through the host-local control plane over the fm-on hop
ok - T7 an unreachable host is reported honestly instead of claimed as reloaded
ok - T9 the persist gate retains its explicitly allocated correlation
ok - T10 pending persist answers are polled as one fleet
ok - T11 post-stop restart failure is never misreported as a nudge
ok - T12 relaunch waits do not block fleet persistence polling
ok - T13 a dead restart worker cannot hang the parent
ok - T14 a result published during reaping is honored
ok - T15 an already-current live mate is named by the update pass and genuinely restarted
ok - T16 an already-current mate with an unprovable runtime keeps the honest nudge path
ok - native Orca Secondmate restart capability preserves supervised mode
# all fm-secondmate-restart tests passed
FM_TEST_END 2026-09-22T22:58:27Z tests/fm-secondmate-restart.test.sh exit=0 duration_ms=89657 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=89762
FM_TEST_SUMMARY_FAMILY family=secondmate count=1 duration_ms=89657 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-secondmate-restart.test.sh duration_ms=89657
exit=0
- Outcome: ⚠️ 1 info across 1 run (11m40s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 5 issues found → auto-fixed ✅
  • ⚠️ bin/backends/orca-supervised.sh:185 - The native attach loses the Dispatch identity on any failed or outcome_unknown worker-start. out=$(&#34;${args[@]}&#34;) || return 1 (and then fm_backend_orca_json_ok ... || return 1) returns before fm_backend_orca_supervised_set_from_json runs. orca orchestration worker-start --help says 'Failed or outcome_unknown exits 1 and JSON includes stage/failedStage, setup, effects, residualResources'. So when Orca creates the Dispatch and then reports outcome_unknown, FM_ORCA_SUPERVISED_DISPATCH_ID stays empty and fm-spawn.sh:5153-5160 copies nothing. The abort trap sees no ORCA_DISPATCH_ID and skips orca_supervised_abort_reconcile. It closes the terminal and, on a fresh ship, removes the worktree with no cleanup_recovery=orca record. The Dispatch then leaks untracked. The spawn comment at fm-spawn.sh:5162-5165 ('A nonzero receipt is not proof that no worker was created. The abort trap reconciles any Dispatch it did return') says the opposite of what happens, and the user asked to 'verify no Dispatch leak'. Fix: capture the exit status, run fm_backend_orca_supervised_set_from_json &#34;$out&#34; start whenever stdout is parseable JSON (ok:false included), then return 1, so the existing trap and recovery-record path see the Dispatch.
  • ⚠️ bin/fm-spawn.sh:5162 - When worker-start returns a different terminal handle, the abort trap closes that handle and leaves the terminal Firstmate launched running. fm_backend_orca_supervised_worker_start stores the receipt's handle in FM_ORCA_SUPERVISED_TERMINAL and only then returns 1 on [ &#34;$FM_ORCA_SUPERVISED_TERMINAL&#34; = &#34;$terminal&#34; ] (orca-supervised.sh:192). Line 5162 still copies that value into ORCA_TERMINAL. The trap then runs fm_backend_kill orca &#34;$ORCA_TERMINAL&#34;, and orca_abort_recovery_record writes it as terminal=, so teardown's recovery path closes it a second time. The launched terminal $T keeps its harness running outside task control, which is the case the new 'close the launched terminal' contract is meant to prevent. The terminal that does get closed was never verified as Firstmate's; it could be any handle Orca put in the receipt, including another task's terminal or the coordinator's. Now that spawn passes --terminal &#34;$T&#34;, $T is authoritative. Fix: drop the ORCA_TERMINAL assignment from the receipt at line 5162 (or assign it only after the equality check passes).
  • ⚠️ bin/fm-spawn.sh:1306 - A failed native relaunch can still leave a record that no lifecycle command accepts. On --relaunch, suppose worker-start returns a retry Dispatch D2 but omits terminalIncarnation or paneKey. worker_start returns 1 at orca-supervised.sh:193-194, and lines 5153-5160 copy D2 and the other returned ids while ORCA_PANE_KEY/ORCA_TERMINAL_INCAR stay empty (they are initialized empty, not from the prior record). If orca_supervised_abort_reconcile then fails, the trap reaches the elif at 1306 because SPAWN_FRESH_COMMIT_PENDING=0 on relaunch. The reconcile fails when the worker is ambiguous and gets abandoned (rc 2), or when the stop/poll doesn't reach dead within FM_ORCA_EXIT_POLLS. orca_supervised_meta_publish then writes orca_pane_key= / orca_terminal_incarnation= with empty values and no cleanup_recovery key. fm_backend_validate_task_endpoint (fm-backend.sh:546-551) refuses that record, so relaunch, teardown, fm-control and procevent all lock out, and D2 is left unsettled. This is the relaunch sibling of the round-5 and round-6 findings. Any honest remedy needs a policy decision: a recovery-typed relaunch record must not let teardown's ship recovery branch delete preserved relaunch work, and keeping the prior identities would leave D2 untracked. That remedy, not the defect, is what needs authorization.
  • ⚠️ bin/fm-spawn.sh:3316 - A native relaunch opens replacement terminal T2 here, but ORCA_ABORT_CLEANUP stays 0 until line 5134. The published relaunch record also names the prior terminal (terminal=${ORCA_PRIOR_TERMINAL:-...} at 4671). Any exit between 3316 and 5134 therefore leaves T2 open in the task workspace, and no record, trap or teardown will ever close it. Such exits include harness hook install failures, record publish failures, and the launch-dir/launch-file refusals at 5026-5050. A second relaunch opens another terminal on top of it. There is a related gap: when attach succeeds and records T2, and then worker-show or the first-turn proof fails, the trap closes T2 but never closes the prior T1. The record no longer names T1, so it is orphaned too. Fix: have the trap close ORCA_TERMINAL when ORCA_PRIOR_TERMINAL is set and differs from it, for example by arming a relaunch-only cleanup flag right after T2 is created, and close ORCA_PRIOR_TERMINAL once the record has moved to T2.
  • ℹ️ bin/fm-teardown.sh:436 - This commit deletes FM_LOCK_LOG_PREFIX=teardown, which has nothing to do with the Orca work. fm-teardown.sh still sources bin/fm-lock-lib.sh (line 299), and fm_lock_log prints ${FM_LOCK_LOG_PREFIX:-fm-lock}: .... Teardown's stale-lock diagnostics now come out as fm-lock: instead of teardown:, so they no longer identify their caller the way fm-lock-lib documents ('so each caller's output stays recognizable'). No intent requirement needs this change. Restore the line.

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Test** - 1 info
  • ℹ️ bin/fm-teardown.sh:3591 - Observed live: for an ordinary native supervised task, teardown runs reap_task_worktree_processes (and detaches or deletes the branch) before settle_native_orca_meta proves Dispatch ownership. When ownership can't be proven, teardown prints 'preserving its durable records', but it has already killed the processes in that worktree (live run: 'reaping leaked worktree process(es) ... 10587 11025 13293', then REFUSED). A later teardown rerun can still settle a real Dispatch, so nothing leaks, but the refusal isn't side-effect free. Informational only; the ordering predates this change for other backends.
  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Inside a live Orca terminal, the native capability gate accepts Claude and Codex (schema 1, required commands present) and excludes Pi ✅ pass live gate-inside-orca.txt: gate[claude]=native schema=1 commands=236, gate[codex]=native, gate[pi]=terminal-fallback reason=agent-pi-not-supported
Outside Orca, or with a stale ORCA_TERMINAL_HANDLE that real Orca rejects, the gate reports no-orca-sender-terminal and falls back instead of claiming native support ✅ pass live gate-outside-orca.txt: both the no-handle and stale-handle contexts give terminal-fallback reason=no-orca-sender-terminal
A persistent Orca Secondmate spawned outside Orca (no handle, stale handle, or raw launch command) refuses before any mutation and keeps its home ✅ pass live secondmate-outside-orca-refusal.txt: 'native Orca supervision is required ... preserving the home' exit=1 (twice), raw-launch refusal exit=1; Orca worktrees 23 before and after; no state record; home…
An ordinary scout requesting --orca-mode supervised with a raw launch falls back to the terminal adapter on a real Orca worktree and terminal, can be peeked, and tears down cleanly ✅ pass live scout-raw-supervised-fallback-spawn.txt (notice + orca_mode=terminal meta with real orca_worktree_id/terminal), scout-terminal-peek.txt (FM_LIVE_RAW_AGENT_UP visible), scout-terminal-teardown.txt (tea…
Adversarial: a native supervised record whose Run/Task/Dispatch real Orca doesn't know fails closed across peek, crew-state, send and teardown, and the durable record is kept ✅ pass live forged-native-records-fail-closed.txt: peek 'Dispatch ... could not be inspected; output identity is unknown' exit=1; crew-state unknown/native-worker; teardown 'REFUSED: native Orca Dispatch ... is n…
Adversarial: a cleanup_recovery=orca record holding only a Dispatch id that can't be proven to belong to its workspace is refused by teardown, and the record is kept ✅ pass live forged-native-records-fail-closed.txt: 'REFUSED: native Orca recovery Dispatch ... is not proven to belong to its recorded workspace; preserving its durable records.' and the meta is still present
A fresh native spawn inside a real Orca coordinator whose worker-start attach Orca refuses closes the launched terminal, releases the worktree, writes no record, and leaks no Dispatch ✅ pass live native-spawn-inside-orca.txt ('worker-start did not attach supervision ... closing the launched terminal and releasing its unrecorded resources', exit=1, no meta); afterwards the launched terminal exi…
Successful native attach with a real agent: worker-start --terminal, first-turn worker-read transcript proof, mailbox steer, worker-stop/release on teardown, native relaunch with --retry-of, and nativ… ⏸️ untested no Orca attaches only to a recognized, logged-in Claude/Codex agent in the terminal. Proving it live needs the captain to authorize running a real logged-in agent (spending tokens) in the live Orca app,…
  • FM_ORCA_SUPERVISED_LIVE=1 bin/fm-test-run.sh tests/fm-backend-orca.test.sh (exit 0)
  • bin/fm-test-run.sh tests/fm-control.test.sh (exit 0)
  • bin/fm-test-run.sh tests/fm-secondmate-restart.test.sh (exit 0)
  • Live gate probe via fm_backend_orca_supervised_capability_check for claude/codex/pi inside a real Orca coordinator terminal (sent with orca terminal send)
  • Live gate probe outside Orca with ORCA_TERMINAL_HANDLE unset and with a stale handle
  • fm-spawn.sh smlive1 &lt;home&gt; --harness claude --backend orca --secondmate outside Orca (no handle and stale handle), plus a raw-launch Secondmate; Orca worktree count checked before and after
  • fm-spawn.sh fmlivescout1 &lt;proj&gt; --scout --harness &#39;bash -c ...&#39; --backend orca --orca-mode supervised against real Orca, then fm-peek.sh and fm-crew-state.sh
  • Forged orca_mode=supervised record and forged cleanup_recovery=orca record on a real Orca worktree: fm-peek.sh, fm-crew-state.sh, fm-send.sh, fm-teardown.sh
  • fm-captain-hold.sh complete fmlivescout1 --none then fm-teardown.sh fmlivescout1; Orca worktree row and terminal state checked afterwards
  • fm-spawn.sh fmlivenat1 &lt;proj&gt; --scout --harness claude --backend orca --orca-mode supervised run inside the real Orca coordinator terminal; then orca orchestration worker-list --run &lt;lab run&gt;, orca worktree ps, orca terminal show
  • Direct orca orchestration worker-start --terminal probe to name the attach refusal (agent_unconfigured)
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

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