Skip to content

feat(orca): add agent-state classifier, secondmate spawns, and Escape delivery - #1

Merged
flight505 merged 3 commits into
mainfrom
fm/fm-orca-gaps-s3
Oct 1, 2026
Merged

flight505 merged 3 commits into
mainfrom
fm/fm-orca-gaps-s3

Conversation

@flight505

Copy link
Copy Markdown
Owner

Intent

It would be good to look into these limitations and see if they are easy to fix. A: go. Three easy gaps now, busy signal later.

The limitations are the Orca runtime backend's "Active limits" in docs/orca-backend.md and docs/architecture notes: Firstmate cannot prove an Orca worker stopped, so bin/fm-control.sh <id> exit|relaunch refuse on backend=orca; secondmate spawns are refused on Orca for the same reason; and Escape (interrupt) is unsupported on Orca. The three gaps to close now, on our fork flight505/firstmate (fork main = upstream kunchenguid/firstmate main + our Orca nesting patch):

  1. Stop-state: give backend=orca a real agent-state classifier (alive, dead, missing) using orca terminal show (its connected and agentIdentity fields), as upstream PR fix(backends): implement orca agent-state classifier to unblock secondmate spawns kunchenguid/firstmate#4830 (kunchenguid/firstmate, "fix(backends): implement orca agent-state classifier to unblock secondmate spawns") does, so fm-control.sh exit and relaunch work on Orca.
  2. Secondmates: lift the Orca secondmate-spawn refusal that the missing classifier caused, as the same PR does.
  3. Escape: make fm-control.sh <id> interrupt deliver a real Escape to an Orca terminal (and Ctrl-U where the adapter uses it), as the send_key hunk of upstream PR Orca backend parity: secondmate support, real Escape/Ctrl-U, rendered-screen reads kunchenguid/firstmate#3579 ("Orca backend parity") does; take only that hunk, not the rest of that draft PR.
    Out of scope for now: a native Orca busy signal (orca terminal wait --for tui-idle, orca worktree ps --json, upstream PR feat(bin): add native Orca supervised workers and Secondmates kunchenguid/firstmate#5348), and upstream PR fix: correct Pi wake ownership and processing-turn handling kunchenguid/firstmate#5835, which only matters for a Pi first mate.

Delivered scope for item 1 is the agreed fallback: the classifier is added as upstream PR kunchenguid#4830 does, but fm-control.sh exit and relaunch stay refused on Orca, with the reason stated in the docs. A live probe against Orca 1.4.218 showed that orca terminal show cannot prove an agent stopped while its terminal stays open (connected is the terminal's liveness, and agentIdentity is absent both for a bare shell and for a running agent), and orca worktree ps adds no proof. Upstream PR kunchenguid#4830 itself also leaves exit and relaunch refused. If no sound stop proof exists, exit and relaunch must keep refusing rather than report an unproven stop.

What Changed

  • Added fm_backend_orca_agent_state in bin/backends/orca.sh, and wired it into fm_backend_agent_state in bin/fm-backend.sh. It reads orca terminal show (connected, agentIdentity) and returns alive, ambiguous, dead, missing, or unreadable. Because connected is the terminal's liveness and not the agent's, fm-control.sh exit and relaunch stay refused on Orca (fm_control_backend_state_verified is unchanged). The reason is stated in the code comments and docs.
  • Removed the Orca secondmate-spawn refusal from bin/fm-spawn.sh.
  • Added Escape and Ctrl-U to fm_backend_orca_send_key as raw control bytes sent through orca terminal send --text. fm_control_backend_supports_key now accepts the same keys for Orca as for tmux, herdr, zellij, and cmux, so fm-control.sh <id> interrupt can work on Orca.
  • Updated the Orca, agent-control, architecture, configuration, remote-secondmates, trace-context, and runtime-backends verification docs. Extended tests/fm-backend-orca.test.sh and tests/fm-control.test.sh to cover the new behavior.

Risk Assessment

✅ Low: The fix round matches the decision: only a refused read (exit 2) with a ready runtime gives missing, and every other unproven read gives unreadable. The new tests run the real function against a fake CLI.

Testing

I ran two test files against a fake Orca CLI. All 102 checks passed. I did not drive the real Orca app. That would change the user's live Orca state. So all scenarios are untested live.

  • Live validation: ⚠️ inconclusive - 0 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Agent state classifier: alive, dead, missing, ambiguous; absent connected or bad JSON is unreadable ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
Secondmate spawn on Orca is no longer refused ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
Escape and Ctrl-U on Orca send raw control bytes ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
Liveness sweep respawns dead or missing Orca secondmates and leaves live ones alone ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
fm-control exit and relaunch still refuse on Orca ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
Evidence: orca backend test output

Source: orca backend test output

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: Escape and C-u map to raw --text control bytes
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 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: falls back to --no-parent when the parent selector is refused
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 --backend orca --secondmate: now supported, records metadata, and launches the harness
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-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_backend_orca_agent_state: classifies alive (with and without identity), dead, and ambiguous from connected/agentIdentity
ok - fm_backend_orca_agent_state: a not-found terminal against a ready runtime classifies as missing
ok - fm_backend_orca_agent_state: a failed read against an unready runtime stays unreadable
ok - fm_backend_orca_agent_state: a read without connected, or unparseable, is unreadable even with a ready runtime
ok - fm_backend_agent_state: routes backend=orca to fm_backend_orca_agent_state
ok - sweep: a confirmed-dead Orca secondmate endpoint is closed and respawned through Orca
ok - sweep: an authoritatively missing Orca secondmate endpoint is relaunched without a pre-close
ok - sweep: an already-live Orca secondmate is left untouched, proven by only its liveness probe in the Orca log
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: 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
Evidence: fm-control test output

Source: fm-control test output

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 Devin interrupt: second press only after the armed hint, then busy invalidated without fabricating idle
ok - fm-control Devin interrupt: an idle agent gets one Escape and reports not-running
ok - fm-control Devin exit: a busy record whose turn already ended never opens the revert picker
ok - fm-control Devin interrupt: a revert picker a press opened is closed with Escape, never Enter
ok - fm-control Devin: an open revert picker refuses every typed command
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-lib: only a runtime's own recorded session has a relaunch resume form
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: orca delivers the harness's Escape key as a raw control byte
ok - fm-control: a backend that cannot prove an agent stopped refuses exit and relaunch
ok - fm-control-lib: stop-proving verbs are gated on the backends that really classify agent state
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: 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
- Outcome: ⚠️ 1 warning across 1 run (7m57s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/backends/orca.sh:260 - fm_backend_orca_agent_state reports missing (a recovery-licensing verdict) whenever the show read is not a clean connected=true/false and orca status is ready. That includes a successful read (exit 0) that has connected absent or non-boolean (connected=unknown) and unparseable JSON (exit 1). A live terminal whose show output lacks the field gets classed as gone. The liveness sweep (fm-watch.sh:1747/1764, fm-spawn.sh:3431 via fm_backend_agent_alive, which maps missing to dead) can then respawn a duplicate secondmate. The comment claims this never gives a false dead/missing, which does not hold for these two shapes. Narrower form: only treat exit 2 (ok:false / command failure) as authoritative absence and return unreadable for exit 0 with unknown connected and for exit 1.

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

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 5 scenarios were driven live against the product); untested: Agent state classifier: alive, dead, missing, ambiguous; absent connected or bad JSON is unreadable, Secondmate spawn on Orca is no longer refused, Escape and Ctrl-U on Orca send raw control bytes, Liveness sweep respawns dead or missing Orca secondmates and leaves live ones alone, fm-control exit and relaunch still refuse on Orca
  • Live validation: ⚠️ inconclusive - 0 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Agent state classifier: alive, dead, missing, ambiguous; absent connected or bad JSON is unreadable ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
Secondmate spawn on Orca is no longer refused ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
Escape and Ctrl-U on Orca send raw control bytes ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
Liveness sweep respawns dead or missing Orca secondmates and leaves live ones alone ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
fm-control exit and relaunch still refuse on Orca ⏸️ untested no Only run against a fake Orca CLI. The prior payload did not drive the real Orca app, so it set no live result. A real run would change the user's live Orca state.
  • bash tests/fm-backend-orca.test.sh (61 ok, 0 failed, fake Orca CLI)
  • bash tests/fm-control.test.sh (41 ok, 0 failed, fake Orca CLI)
✅ **Document** - passed

✅ No issues found.

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

✅ No issues found.

… delivery

Give backend=orca a recovery-grade agent-state classifier built on
`orca terminal show`'s connected and agentIdentity fields, as upstream
kunchenguid#4830 does, and lift the Orca secondmate-spawn refusal
that the missing classifier caused.

Deliver Escape and Ctrl-U to an Orca terminal as raw control bytes through
`orca terminal send --text`, the send_key hunk of upstream
kunchenguid#3579, so `fm-control.sh <id> interrupt` works for
Escape harnesses on Orca.

`fm-control.sh exit` and `relaunch` stay refused on Orca. Live readings
against Orca 1.4.218 show connected is the terminal's liveness, and that
agentIdentity is absent both for a bare shell and for a running agent, so
neither field can prove an agent stopped inside an open terminal. The
evidence is recorded in docs/verification/runtime-backends.md.
@flight505 flight505 closed this Oct 1, 2026
@flight505 flight505 reopened this Oct 1, 2026
@flight505
flight505 merged commit 28b7f2f into main Oct 1, 2026
19 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