Skip to content

Orca backend parity: secondmate support, real Escape/Ctrl-U, rendered-screen reads - #3579

Draft
1yian wants to merge 5 commits into
kunchenguid:mainfrom
1yian:1yian/feat-orca-backend-parity
Draft

1yian wants to merge 5 commits into
kunchenguid:mainfrom
1yian:1yian/feat-orca-backend-parity

Conversation

@1yian

@1yian 1yian commented Sep 3, 2026

Copy link
Copy Markdown

Summary

Brings the experimental Orca runtime backend substantially closer to parity with the tmux/herdr reference backends. Every underlying Orca CLI behavior was verified live against a real runtime (Orca 1.4.x); every code path is covered by fake-CLI unit/integration tests.

What's now covered

Secondmate spawns on Orca (the headline gap). Orca can only open a terminal inside an Orca-managed worktree, so a secondmate home is created as an Orca worktree of the firstmate repo, placed outside the repo via the project's worktree-base-path so the existing "a secondmate home may not live inside the firstmate repo" safety invariant is preserved (not relaxed).

  • bin/fm-home-seed.sh: on the Orca backend the leased (-) home is created with orca worktree create instead of a treehouse lease; rollback releases it with orca worktree rm. An explicit home path is refused (Orca cannot adopt an arbitrary checkout).
  • bin/fm-spawn.sh: the backend=orca && --secondmate refusal is removed; the secondmate reuses the seeded home worktree (resolves its id from the path, creates the terminal via terminal create --worktree path:) and never creates a second worktree.
  • bin/fm-teardown.sh: an Orca secondmate home is released via orca worktree rm --worktree path: under all the existing landed-work/in-flight guards.

Full key parity — real Escape. --interrupt is Ctrl-C, which for 8 of 9 harnesses is not the interrupt key (they cancel a turn with Escape). Orca now delivers Escape and Ctrl-U as their raw control bytes through terminal send --text (verified live: an ESC byte reaches cat -v as ^[, a Ctrl-U performs the tty line-kill). fm-control and fm-send key tables updated accordingly.

Rendered-screen captures. Captures/composer reads switched to terminal read --screen. Orca's default stream mode stacks TUI repaints into fragments (its own docs call it "unsuitable for verifying rendered output"), which was garbling every composer classification and steer confirmation.

Bug fixes surfaced by real-Orca verification

  • Teardown validation rejected real Orca worktree ids. A real id is <repo-id>::<absolute-path>, which the strict endpoint-atom validator rejects (://). This meant all real Orca teardown (ship/scout/secondmate) would have been refused; only simplified test ids ever passed. Added an Orca-specific worktree-id validator.
  • Base-path idempotency check crashed. An illegal top-level return in a node -e snippet made the "is the base path already set?" check always fail, so it rewrote config on every home creation. Fixed.

What is NOT covered (honest limits)

  • Native busy/idle signal — Orca's agent-status surface depends on Orca's own agent-status hooks, which firstmate does not install; unverifiable for firstmate crews, so worker state still comes from each harness adapter's lifecycle.
  • Native push events — Orca's CLI exposes no terminal event stream; the watcher's poll fallback remains.
  • Recovery-grade agent-state — Orca has no agent-process classifier, so a dead Orca secondmate is not auto-respawned at session start; recover it explicitly with fm-spawn.sh <id> --secondmate (documented).
  • Auto-detection — intentionally never auto-detected (Orca also owns the worktree).

Verification

  • Live: worktree create at an external base-path, terminal create/read --screen, path→id resolution, worktree rm, raw ESC + Ctrl-U byte delivery, and the full new adapter functions end to end (with cleanup).
  • Tests (all green): fm-backend-orca (57), fm-backend (28), fm-control (35), fm-control-relaunch (46), fm-teardown (58), fm-teardown-endpoint-safety (7), fm-secondmate-safety (77), fm-secondmate-lifecycle-e2e (6), fm-secondmate-sync (21), fm-secondmate-liveness (15), fm-bootstrap (28), fm-send-secondmate-marker (8). shellcheck-clean.

Remaining (manual, out of CI scope)

A full end-to-end smoke of a live secondmate agent running a supervision loop inside an Orca home (same manual-smoke posture as herdr's, recorded in docs/verification/runtime-backends.md). All plumbing is unit/integration tested with the fake-CLI harness and every Orca primitive is verified live.

@1yian
1yian force-pushed the 1yian/feat-orca-backend-parity branch from 7e68dd6 to 4780dc8 Compare September 3, 2026 03:31
Yian added 5 commits September 2, 2026 22:48
…creen reads

- Secondmate spawns on Orca: the home is created as an Orca-managed worktree
  outside the repo (project worktree-base-path), seeded, given a terminal via
  'terminal create --worktree path:', and released with 'orca worktree rm' at
  teardown. Home-isolation and unlanded-work safety invariants preserved.
- Full key parity: Escape and Ctrl-U delivered as raw --text control bytes
  (--interrupt is Ctrl-C and is not a substitute); Enter/C-c unchanged.
- Captures/composer reads use 'terminal read --screen' (rendered), replacing
  the default stream mode that garbled TUI reads.
- Fix: teardown validation now accepts real Orca worktree ids
  (<repo-id>::<abs-path>), which the strict atom validator rejected.
- Fix: setup base-path idempotency check (illegal top-level return in node -e).
- Docs + fake-CLI tests for every new path.
- busy_state: correlate the task terminal to Orca's agent status
  (worktree ps agents[].state = working|done|blocked, the vocabulary from
  Orca's own hook source); working->busy, done/blocked->idle, unattributed
  ->unknown (falls back to the harness lifecycle). Trusted for BUSY in
  fm-busy-lib alongside herdr.
- agent_state: recovery-grade classifier from terminal orphaned/connected/
  agentIdentity + worktree ps state -> alive/dead/missing/ambiguous. Only
  dead/missing license recovery; a connected terminal with no attributable
  agent stays ambiguous. Wires Orca into fm_backend_agent_state and marks it
  state-verified, so secondmate auto-recovery and fm-control exit/relaunch now
  work on Orca.
- Fake-CLI unit tests for both classifiers; control/state-verified tests updated.
  Verified live against the running fleet (alive/idle for a live agent, missing
  for a bogus handle).
@1yian
1yian force-pushed the 1yian/feat-orca-backend-parity branch from 4780dc8 to 2a8cfdb Compare September 3, 2026 03:49
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is a draft — waiting on the author to mark ready when you want full triage-for-merge.

Reviewed body + file list + shared backend/busy/control/send hunks vs main d3fcdfa548f5.

Security: clean. No .github/** / workflow / pull_request_target changes. Author 1yian not blocked. Cross-repo fork.

Contract-class: opt-in. Changes deepen the experimental Orca backend (secondmate home-as-Orca-worktree, Escape/Ctrl-U via --text, rendered-screen reads, composite worktree id validator). Unconfigured tmux/herdr captains keep prior behavior; Orca is a selected backend.

VISION:

  1. One captain, one interface — aligns.
  2. Authority explicit — aligns (backend choice; no assumed consent widen).
  3. Scripts own mechanics — aligns.
  4. Restart non-event — aligns.
  5. Delegation with a spine — aligns (secondmate/control parity under Orca).
  6. Fleet outlives vendor — aligns (session-manager adapter parity, not lock-in).
  7. Scope — aligns (runtime backend, not forge/merge).

Workflow approval this pass (tip action_required after diff review):

  • CI 33712746981
  • Require no-mistakes 33712746860

Attestation: MISSING on tip 2a8cfdb80398948684d9e46dd0eb686f79b15150. When you leave draft, raise via no-mistakes so body SHA matches tip, and ensure CI/NM green before merge consideration.

No auto-merge from draft. Not a captain hold — waiting on you.

flight505 added a commit to flight505/firstmate that referenced this pull request Oct 1, 2026
… delivery (#1)

* feat(orca): add agent-state classifier, secondmate spawns, and Escape 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.

* no-mistakes(review): Orca classifier: unproven reads are unreadable, not missing

* no-mistakes(document): Fix stale Orca classifier and cmux docs
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.

2 participants