Skip to content

fix(bin): accept Orca's composite worktree id when tearing down a task - #4677

Merged
kunchenguid merged 3 commits into
kunchenguid:mainfrom
JuanJoseGonGi:fm/orcatd
Sep 16, 2026
Merged

kunchenguid merged 3 commits into
kunchenguid:mainfrom
JuanJoseGonGi:fm/orcatd

Conversation

@JuanJoseGonGi

Copy link
Copy Markdown
Contributor

Intent

Fix the Orca task teardown that firstmate refuses for every Orca-backed task.

bin/fm-teardown.sh refuses with "REFUSED: Orca endpoint metadata for task is malformed or inconsistent; preserving task state." for any task whose backend is orca. Verified by reading bin/fm-backend.sh: in fm_backend_validate_task_endpoint, the orca) branch validates orca_worktree_id with fm_backend_endpoint_atom_valid, which rejects any character outside [A-Za-z0-9._@%+-]. But orca_worktree_id is a composite of the form <uuid>::<absolute-worktree-path> (real example: 411226f7-dc91-4d37-975d-32d412bf97a2::~/orca/workspaces/scrap-services/fm-wtaudit), so its : and / characters make that atom check fail and teardown refuses. Spawn, supervision (fm-peek, fm-crew-state, fm-send) and the work itself all function; only teardown is blocked, so finished Orca tasks cannot be cleaned up and keep triggering the inactive-outcome scan. This blocks using Orca as the fleet backend.

What Changed

  • bin/fm-backend.sh gains fm_backend_orca_worktree_id_valid, which checks the <orca repo id>::<absolute worktree path> shape Orca actually returns: no control characters, a non-empty id before the first ::, and a path starting with / after it. The orca) branch of fm_backend_validate_task_endpoint now validates orca_worktree_id with it instead of fm_backend_endpoint_atom_valid, whose character set excluded : and / and so refused teardown for every Orca-backed task.
  • Orca fixtures across tests/fm-backend-orca.test.sh, tests/fm-control.test.sh and tests/fm-teardown-endpoint-safety.test.sh now carry composite worktree ids everywhere the backend returns or records one, so the assertions match what Orca really emits. tests/fm-teardown-endpoint-safety.test.sh adds test_orca_composite_worktree_id_validates, covering a real-shaped id plus the separatorless and newline-carrying cases.
  • docs/orca-backend.md documents orca_worktree_id= as that composite of repo id and worktree path, explains that cleanup validation requires both halves, and lists the teardown endpoint safety suite among Orca's regression entry points.

Risk Assessment

✅ Low: One validator swap at the shared cleanup-identity boundary, with every downstream use of the id already quoted and no eval, fixtures updated to the shape Orca really returns, and a regression case that exercises the boundary and fails before the fix.

Testing

I stood firstmate up the way an operator runs it, an isolated fleet home with a git-init project, a git worktree standing in for the Orca worktree, and a recording orca on PATH, and drove bin/fm-spawn.sh and bin/fm-teardown.sh directly. The reported bug reproduces at base 9f8ad95 (teardown refuses "Orca endpoint metadata ... is malformed or inconsistent" and preserves the task) and is gone on this branch, where the same record tears down and firstmate hands Orca the composite id verbatim in orca worktree rm --worktree id:&lt;repo id&gt;::&lt;path&gt;. The spawn-to-teardown round trip shows the same story end to end: spawn records the composite id at both commits, only teardown differed. Four malformed id shapes and one identity-mismatch case all refuse before any mutation or Orca call. Against the live Orca runtime, orca worktree list --json returns repoId::path, which is what the docs commit now states, and firstmate both accepts and resolves that real id while the base check rejects it. The change's own regression case and the touched fm-control case pass repeatedly in isolation. Two caveats worth stating plainly: this is a shell CLI change, so the reviewer-visible artifacts are command transcripts rather than screenshots, there is no rendered surface to capture; and the full tests/fm-backend-orca.test.sh suite never completed cleanly on this machine because /usr/bin/perl intermittently exits 139 inside firstmate's realpath helper and aborts the suite at a random case. That flake reproduces at the base commit in this run too, every failure it caused carried the same "task record authorized directory cannot be resolved" signature and no substantive assertion failed, so I drove the scenarios with retries past it and ran the affected cases in isolation instead.

  • Live validation: ✅ go - 8 of 8 scenarios driven live against the product
Scenario Result Live Evidence
An operator tears down a finished Orca task whose record carries Orca's composite worktree id, and teardown completes instead of refusing ✅ pass live bin/fm-teardown.sh orca-live --force on this branch exits 0, prints "teardown orca-live complete", calls orca worktree rm --worktree id:411226f7-...::&lt;path&gt; and removes the task record; see orca-t…
The reported refusal reproduces at the base commit for the same task record, proving the fix is what changed it ✅ pass live The same fixture driven through the base-commit tree's bin/fm-teardown.sh exits 1 with "REFUSED: Orca endpoint metadata for task orca-live is malformed or inconsistent; preserving task state.", no O…
A task spawned on the Orca backend can be cleaned up afterwards: spawn records the composite id and teardown consumes it ✅ pass live bin/fm-spawn.sh ... --backend orca writes orca_worktree_id=411226f7-...::&lt;path&gt; and bin/fm-teardown.sh --force then completes on this branch, while the identical round trip at base spawns fine a…
A malformed Orca worktree id still refuses teardown and leaves the task untouched ✅ pass live Four ids driven through bin/fm-teardown.sh --force on this branch (no :: separator, empty repo-id half, relative path half, tab inside the repo-id half) each exit 1 with the malformed-metadata ref…
A well-shaped id that Orca resolves to a different worktree than the task record is still refused before anything is removed ✅ pass live Teardown calls orca worktree show, sees the mismatch and exits 1 with "resolved to uninspectable path ...; preserving metadata", never reaching worktree rm; see orca-teardown-adversarial.txt
Firstmate accepts and resolves the worktree id the live Orca runtime really returns, which the base commit rejected ✅ pass live Against orca 1.4.204: fm_backend_orca_worktree_id_valid accepts 411226f7-dc91-4d37-975d-32d412bf97a2::~/dev/scrap-services and fm_backend_worktree_path orca resolves it to tha…
The documented id format matches what Orca actually returns ✅ pass live orca worktree list --json returns id 411226f7-...::~/dev/scrap-services with repoId 411226f7-... and path ~/dev/scrap-services, matching the docs line…
Supervision verbs on an Orca task give their real reason instead of the metadata refusal ✅ pass live tests/fm-control.test.sh case test_orca_refuses_an_escape_harness_interrupt passes 3 of 3 in isolation on this branch ("cannot deliver" refusal); the same case run against base code with the compo…
Evidence: Orca teardown before and after the fix, real CLI transcript

Source: Orca teardown before and after the fix, real CLI transcript

Teardown of an Orca-backed task, driven through the real bin/fm-teardown.sh CLI.
The task record carries the composite worktree id Orca really returns:
  <repo id>::<absolute worktree path>

==============================================================
BEFORE the fix (base commit 9f8ad95) - the reported bug
==============================================================
--- task record written by the fleet (state/orca-live.meta) ---
window=fm-orca-live
endpoint_task_id=orca-live
terminal=term-live-1
worktree=<case>/worktree
project=<case>/project
backend=orca
orca_worktree_id=411226f7-dc91-4d37-975d-32d412bf97a2::<case>/worktree
kind=scout
--- running: bin/fm-teardown.sh orca-live --force ---
exit=1
--- stdout ---
--- stderr ---
REFUSED: Orca endpoint metadata for task orca-live is malformed or inconsistent; preserving task state.
--- orca CLI calls firstmate made ---
--- task record still present? ---
state/orca-live.meta PRESERVED

==============================================================
AFTER the fix (this branch) - same task record, same command
==============================================================
--- task record written by the fleet (state/orca-live.meta) ---
window=fm-orca-live
endpoint_task_id=orca-live
terminal=term-live-1
worktree=<case>/worktree
project=<case>/project
backend=orca
orca_worktree_id=411226f7-dc91-4d37-975d-32d412bf97a2::<case>/worktree
kind=scout
--- running: bin/fm-teardown.sh orca-live --force ---
exit=0
--- stdout ---
teardown orca-live complete (window term-live-1, worktree <case>/worktree)
Backlog: orca-live just finished (this home keeps no markdown backlog at /private<case>~/backlog.md). Update /private<case>~/backlog.md - move orca-live 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.
--- stderr ---
--- orca CLI calls firstmate made ---
orca [worktree] [show] [--worktree] [id:411226f7-dc91-4d37-975d-32d412bf97a2::<case>/worktree] [--json]
orca [terminal] [close] [--terminal] [term-live-1] [--json]
orca [worktree] [rm] [--worktree] [id:411226f7-dc91-4d37-975d-32d412bf97a2::<case>/worktree] [--force] [--json]
--- task record still present? ---
state/orca-live.meta REMOVED
Evidence: Spawn to teardown round trip on the Orca backend, base versus branch

Source: Spawn to teardown round trip on the Orca backend, base versus branch

Full Orca task lifecycle driven through the real firstmate CLIs:
bin/fm-spawn.sh --backend orca writes the task record, bin/fm-teardown.sh cleans it up.
Orca is a recording stand-in that answers with the id shape the live runtime returns.

==============================================================
BEFORE the fix (base commit 9f8ad95)
==============================================================
=== 1. spawn: bin/fm-spawn.sh orcaround1 <project> claude --backend orca ===
warning: <case>/data/orcaround1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned orcaround1 harness=claude kind=ship mode=no-mistakes yolo=off window=fm-orcaround1 worktree=<case>/wt
spawn exit=0

=== 2. the task record firstmate wrote ===
window=fm-orcaround1
endpoint_task_id=orcaround1
worktree=<case>/wt
project=<case>/project
harness=claude
kind=ship
mode=no-mistakes
yolo=off
tasktmp=/tmp/fm-orcaround1
model=default
effort=default
busy_gen=g1789595367.61094.28902
spawn_gen=s1789595367.60787.9087
backend=orca
orca_worktree_id=411226f7-dc91-4d37-975d-32d412bf97a2::<case>/wt
terminal=term-round-1

=== 3. teardown: bin/fm-teardown.sh orcaround1 --force ===
REFUSED: Orca endpoint metadata for task orcaround1 is malformed or inconsistent; preserving task state.
teardown exit=0

=== 4. Orca calls teardown made ===
=== 5. task record after teardown ===
state/orcaround1.meta PRESERVED

==============================================================
AFTER the fix (this branch)
==============================================================
=== 1. spawn: bin/fm-spawn.sh orcaround1 <project> claude --backend orca ===
warning: <case>/data/orcaround1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned orcaround1 harness=claude kind=ship mode=no-mistakes yolo=off window=fm-orcaround1 worktree=<case>/wt
spawn exit=0

=== 2. the task record firstmate wrote ===
window=fm-orcaround1
endpoint_task_id=orcaround1
worktree=<case>/wt
project=<case>/project
harness=claude
kind=ship
mode=no-mistakes
yolo=off
tasktmp=/tmp/fm-orcaround1
model=default
effort=default
busy_gen=g1789595377.63256.5552
spawn_gen=s1789595377.62810.10945
backend=orca
orca_worktree_id=411226f7-dc91-4d37-975d-32d412bf97a2::<case>/wt
terminal=term-round-1

=== 3. teardown: bin/fm-teardown.sh orcaround1 --force ===
<case>/project: skipped: no origin remote
teardown orcaround1 complete (window term-round-1, worktree <case>/wt)
Backlog: orcaround1 just finished (this home keeps no markdown backlog at /private<case>/data/backlog.md). Update /private<case>/data/backlog.md - move orcaround1 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.
teardown exit=0

=== 4. Orca calls teardown made ===
orca [worktree] [show] [--worktree] [id:411226f7-dc91-4d37-975d-32d412bf97a2::<case>/wt] [--json]
orca [terminal] [close] [--terminal] [term-round-1] [--json]
orca [worktree] [rm] [--worktree] [id:411226f7-dc91-4d37-975d-32d412bf97a2::<case>/wt] [--force] [--json]
=== 5. task record after teardown ===
state/orcaround1.meta REMOVED
Evidence: Malformed and mismatched worktree ids still refuse, real CLI transcript

Source: Malformed and mismatched worktree ids still refuse, real CLI transcript

Adversarial worktree ids, driven through the real bin/fm-teardown.sh CLI on this branch.
Every one must refuse, run no Orca command, and leave the task record in place.

==============================================================
CASE: no :: separator at all
orca_worktree_id=worktree-9
==============================================================
--- running: bin/fm-teardown.sh orca-live --force ---
exit=1
--- stdout ---
--- stderr ---
REFUSED: Orca endpoint metadata for task orca-live is malformed or inconsistent; preserving task state.
--- orca CLI calls firstmate made ---
--- task record still present? ---
state/orca-live.meta PRESERVED

==============================================================
CASE: empty repo-id half
orca_worktree_id=::@WT@
==============================================================
--- running: bin/fm-teardown.sh orca-live --force ---
exit=1
--- stdout ---
--- stderr ---
REFUSED: Orca endpoint metadata for task orca-live is malformed or inconsistent; preserving task state.
--- orca CLI calls firstmate made ---
--- task record still present? ---
state/orca-live.meta PRESERVED

==============================================================
CASE: relative path half
orca_worktree_id=411226f7-dc91-4d37-975d-32d412bf97a2::orca/relative/wt
==============================================================
--- running: bin/fm-teardown.sh orca-live --force ---
exit=1
--- stdout ---
--- stderr ---
REFUSED: Orca endpoint metadata for task orca-live is malformed or inconsistent; preserving task state.
--- orca CLI calls firstmate made ---
--- task record still present? ---
state/orca-live.meta PRESERVED

==============================================================
CASE: tab character inside the repo-id half
orca_worktree_id=411226f7	dc91::@WT@
==============================================================
--- running: bin/fm-teardown.sh orca-live --force ---
exit=1
--- stdout ---
--- stderr ---
REFUSED: Orca endpoint metadata for task orca-live is malformed or inconsistent; preserving task state.
--- orca CLI calls firstmate made ---
--- task record still present? ---
state/orca-live.meta PRESERVED

==============================================================
CASE: well-shaped id that Orca resolves to a DIFFERENT worktree than
      the one on the task record (the identity guard behind the shape check)
==============================================================
--- running: bin/fm-teardown.sh orca-live --force ---
exit=1
--- stdout ---
--- stderr ---
REFUSED: Orca worktree id 411226f7-dc91-4d37-975d-32d412bf97a2::~/orca/workspaces/other/fm-other resolved to uninspectable path ~/orca/workspaces/other/fm-other; preserving metadata.
--- orca CLI calls firstmate made ---
orca [worktree] [show] [--worktree] [id:411226f7-dc91-4d37-975d-32d412bf97a2::~/orca/workspaces/other/fm-other] [--json]
--- task record still present? ---
state/orca-live.meta PRESERVED
Evidence: The id shape against the live Orca runtime, and firstmate resolving it

Source: The id shape against the live Orca runtime, and firstmate resolving it

The id shape against the live Orca runtime (orca 1.4.204), read-only.

$ orca worktree list --json   (first worktree, trimmed to the identity fields)
{
  "id": "411226f7-dc91-4d37-975d-32d412bf97a2::~/dev/scrap-services",
  "repoId": "411226f7-dc91-4d37-975d-32d412bf97a2",
  "path": "~/dev/scrap-services"
}

That is exactly what docs/orca-backend.md now documents: <orca repo id>::<absolute worktree path>.

Firstmate on this branch, handed that real id:
$ fm_backend_orca_worktree_id_valid "411226f7-dc91-4d37-975d-32d412bf97a2::~/dev/scrap-services"
  -> accepted

$ fm_backend_worktree_path orca "411226f7-dc91-4d37-975d-32d412bf97a2::~/dev/scrap-services"   (resolved through the running Orca)
  -> ~/dev/scrap-services

The same real id at the base commit 9f8ad95, which is what teardown used to check:
$ fm_backend_endpoint_atom_valid "411226f7-dc91-4d37-975d-32d412bf97a2::~/dev/scrap-services"
  -> REJECTED (this is why teardown refused every Orca task)
Evidence: Key before/after lines from the teardown transcript
BASE 9f8ad95, orca_worktree_id=411226f7-dc91-4d37-975d-32d412bf97a2::<case>/worktree
$ bin/fm-teardown.sh orca-live --force
exit=1
REFUSED: Orca endpoint metadata for task orca-live is malformed or inconsistent; preserving task state.
(no Orca command ran) state/orca-live.meta PRESERVED

THIS BRANCH, same task record, same command
$ bin/fm-teardown.sh orca-live --force
exit=0
teardown orca-live complete (window term-live-1, worktree <case>/worktree)
orca [worktree] [show] [--worktree] [id:411226f7-dc91-4d37-975d-32d412bf97a2::<case>/worktree] [--json]
orca [terminal] [close] [--terminal] [term-live-1] [--json]
orca [worktree] [rm] [--worktree] [id:411226f7-dc91-4d37-975d-32d412bf97a2::<case>/worktree] [--force] [--json]
state/orca-live.meta REMOVED

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ℹ️ bin/fm-control.sh:302 - Blast radius is wider than the intent states, and the change is right to fix it at the shared boundary. The intent says "Spawn, supervision (fm-peek, fm-crew-state, fm-send) and the work itself all function; only teardown is blocked", but fm_backend_validate_task_endpoint is also the gate for the control plane (bin/fm-control.sh:302, so interrupt/exit/relaunch refused every Orca task with the same message), for relaunch metadata (bin/fm-spawn.sh:1474) and for the secondmate liveness read (bin/fm-update.sh:127). The single validator swap unblocks all of them. The only one worth checking for a behavior flip is fm-update.sh: an Orca record now passes validation and reaches fm_backend_agent_state, which has no orca arm and returns "unverified", so the routing outcome is identical to the previous refusal. Nothing to change; recorded so the author's mental model of what this fix reaches is accurate.
  • ℹ️ bin/fm-backend.sh:391 - The comment above the new validator describes the format as &lt;orca id&gt;::&lt;absolute worktree path&gt; while commit 134ee25 deliberately renamed that same format in docs/orca-backend.md to &lt;orca repo id&gt;::&lt;absolute worktree path&gt;, because the uuid half identifies the repository and not the worktree (the live-runtime evidence shows one uuid shared by two worktrees of the same repo). Naming it "orca id" in the source leaves the one comment a reader hits first vaguer than the doc the change just corrected. Mechanical wording fix, no behavior involved.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 8 of 8 scenarios driven live against the product
Scenario Result Live Evidence
An operator tears down a finished Orca task whose record carries Orca's composite worktree id, and teardown completes instead of refusing ✅ pass live bin/fm-teardown.sh orca-live --force on this branch exits 0, prints "teardown orca-live complete", calls orca worktree rm --worktree id:411226f7-...::&lt;path&gt; and removes the task record; see orca-t…
The reported refusal reproduces at the base commit for the same task record, proving the fix is what changed it ✅ pass live The same fixture driven through the base-commit tree's bin/fm-teardown.sh exits 1 with "REFUSED: Orca endpoint metadata for task orca-live is malformed or inconsistent; preserving task state.", no O…
A task spawned on the Orca backend can be cleaned up afterwards: spawn records the composite id and teardown consumes it ✅ pass live bin/fm-spawn.sh ... --backend orca writes orca_worktree_id=411226f7-...::&lt;path&gt; and bin/fm-teardown.sh --force then completes on this branch, while the identical round trip at base spawns fine a…
A malformed Orca worktree id still refuses teardown and leaves the task untouched ✅ pass live Four ids driven through bin/fm-teardown.sh --force on this branch (no :: separator, empty repo-id half, relative path half, tab inside the repo-id half) each exit 1 with the malformed-metadata ref…
A well-shaped id that Orca resolves to a different worktree than the task record is still refused before anything is removed ✅ pass live Teardown calls orca worktree show, sees the mismatch and exits 1 with "resolved to uninspectable path ...; preserving metadata", never reaching worktree rm; see orca-teardown-adversarial.txt
Firstmate accepts and resolves the worktree id the live Orca runtime really returns, which the base commit rejected ✅ pass live Against orca 1.4.204: fm_backend_orca_worktree_id_valid accepts 411226f7-dc91-4d37-975d-32d412bf97a2::~/dev/scrap-services and fm_backend_worktree_path orca resolves it to tha…
The documented id format matches what Orca actually returns ✅ pass live orca worktree list --json returns id 411226f7-...::~/dev/scrap-services with repoId 411226f7-... and path ~/dev/scrap-services, matching the docs line…
Supervision verbs on an Orca task give their real reason instead of the metadata refusal ✅ pass live tests/fm-control.test.sh case test_orca_refuses_an_escape_harness_interrupt passes 3 of 3 in isolation on this branch ("cannot deliver" refusal); the same case run against base code with the compo…
  • Real CLI: bin/fm-teardown.sh &lt;id&gt; --force on an Orca-backed task whose record carries 411226f7-dc91-4d37-975d-32d412bf97a2::&lt;worktree path&gt;, run against this branch and against a git archived copy of base commit 9f8ad95
  • Real CLI round trip: bin/fm-spawn.sh &lt;id&gt; &lt;project&gt; claude --mode no-mistakes --backend orca then bin/fm-teardown.sh &lt;id&gt; --force, on this branch and at base
  • Real CLI adversarial ids through bin/fm-teardown.sh: worktree-9 (no separator), ::&lt;path&gt; (empty repo-id half), &lt;uuid&gt;::orca/relative/wt (relative path half), &lt;id-with-tab&gt;::&lt;path&gt;
  • Real CLI boundary: well-shaped id that the Orca stand-in resolves to a different worktree than the task record
  • Live Orca runtime (orca 1.4.204, read-only): orca worktree list --json, then fm_backend_orca_worktree_id_valid and fm_backend_worktree_path orca &lt;real id&gt; from bin/fm-backend.sh, plus fm_backend_endpoint_atom_valid on the same id at base
  • tests/fm-teardown-endpoint-safety.test.sh cases test_supported_backend_endpoint_records_validate and test_orca_composite_worktree_id_validates, run in isolation 5 times, green every run
  • tests/fm-control.test.sh case test_orca_refuses_an_escape_harness_interrupt, run in isolation 3 times on this branch and once against base code with the branch's composite-id fixture
  • tests/fm-backend-orca.test.sh full suite, 5 attempts
⚠️ **Document** - 1 info
  • ℹ️ bin/fm-backend.sh:391 - Left alone deliberately, flagging it so the decision is visible rather than silent. The new helper's comment calls the composite &lt;orca id&gt;::&lt;absolute worktree path&gt; while docs/orca-backend.md, after the previous document round, calls the first half the Orca repo id. "orca id" is not wrong but it can be misread as the worktree's own id, which is the whole value. I did not touch it because it is a shell file rather than a documentation surface, the wording is imprecise rather than stale, and editing bin/ here would re-open the lint and test phases for a single word. If someone is already touching that file, changing &lt;orca id&gt; to &lt;orca repo id&gt; would match the owner document.
⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

Teardown refused every Orca-backed task because the endpoint validator
checked orca_worktree_id with the simple-atom rule meant for tmux-style
window names, which rejects any character outside [A-Za-z0-9._@%+-]. Orca
returns that id as `<orca id>::<absolute worktree path>`, so the colon and
slashes in every real value made validation fail and finished Orca tasks
could never be cleaned up.

Validate the field as the composite it is: both halves of the first `::`
split present, the path half absolute, and no embedded newline, carriage
return, or tab. The terminal field keeps the atom check, which is correct
for it, and no other backend's validation changes.

The existing Orca fixtures recorded ids like `wt-teardown`, a shape Orca
never returns, which is why the suite passed a check the real value fails.
They now carry the composite form, so the tests exercise the real value.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

First look on HEAD 0409f6916a43403f196e7a1726d5b78ddc86dee9 (fork JuanJoseGonGi). Full thread + full tip diff reviewed. No .github/** edits. Authors not on blocked list. Workflow approval this pass: yes — CI 35155153415 (was action_required; now in progress) + Require no-mistakes 35155153526 (approved → queued).

Attestation: MATCH (body head_sha binds tip; intent/rebase/review/test/document/lint/push completed; ci pending).

Contract-class: restore — Orca-backed teardown on tip was refusing every well-formed live Orca task because fm_backend_orca_worktree_id_valid rejected the composite <orca repo id>::<absolute worktree path> shape Orca actually returns. Tip swaps the validator to that documented composite, updates fixtures/docs, keeps malformed/mismatch refuse paths. Concrete existing Orca cleanup path was specified and broken; unconfigured non-Orca teardown unchanged.

VISION.md per-rule

  • One captain, one interface: aligns — removes false refuse noise on Orca teardown; no new captain surface.
  • Authority explicit: aligns — still refuses malformed / mismatched worktree ids; no widened destructive authority.
  • Scripts own mechanics: aligns — validator + teardown identity check in bin/fm-backend.sh with tests.
  • Restart is a non-event: aligns — cleanup can finish so task records do not linger forever behind a false malformation refuse.
  • Delegation with a spine: aligns — refuse-to-discard on real mismatch preserved.
  • Fleet outlives vendors: aligns — binds to Orca's real worktree id semantics, not a guessed simple name.
  • Scope: aligns — backend cleanup contract only.

Checks: CI 35155153415 in progress; NM 35155153526 queued after approval. mergeable=MERGEABLE / UNSTABLE.

Outcome: waiting-ci. Auto-merge candidate as restore once CI+NM green on this tip. Firstmate flag no while CI open.

@kunchenguid
kunchenguid merged commit 795e5e4 into kunchenguid:main Sep 16, 2026
14 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @JuanJoseGonGi — really appreciate you taking the time on this.

andrewesweet added a commit to andrewesweet/firstmate that referenced this pull request Sep 17, 2026
…fixes (#19)

* fix(bin): clear parent pending-replies on local secondmate retirement (kunchenguid#4680)

* fix(bin): clear parent pending-replies on local secondmate retirement

Local secondmate teardown left resolved parent pending-reply records behind
after home removal (seen after papa-hdds / pxmx retirement). Refuse non-forced
retirement while any reply for that id is still unresolved, and delete every
matching record plus its delivery confirmation after a successful local or
remote retirement, matching the remote cleanup path.

* no-mistakes(document): Align secondmate retirement docs with pending-reply cleanup

* no-mistakes(review): Lokale Pending-replies-Sicherheitsprüfung vor Home-Entfernung

* no-mistakes(review): Pending-replies-corr_id auf 16-Hex absichern

* no-mistakes(review): Pending-replies Basename und corr_id abgleichen

* no-mistakes(document): Clarify forced retirement pending-reply cleanup

---------

Co-authored-by: ladwein <[email protected]>

* fix(bin): accept Orca's composite worktree id when tearing down a task (kunchenguid#4677)

* fix(bin): accept Orca's composite worktree id at teardown

Teardown refused every Orca-backed task because the endpoint validator
checked orca_worktree_id with the simple-atom rule meant for tmux-style
window names, which rejects any character outside [A-Za-z0-9._@%+-]. Orca
returns that id as `<orca id>::<absolute worktree path>`, so the colon and
slashes in every real value made validation fail and finished Orca tasks
could never be cleaned up.

Validate the field as the composite it is: both halves of the first `::`
split present, the path half absolute, and no embedded newline, carriage
return, or tab. The terminal field keeps the atom check, which is correct
for it, and no other backend's validation changes.

The existing Orca fixtures recorded ids like `wt-teardown`, a shape Orca
never returns, which is why the suite passed a check the real value fails.
They now carry the composite form, so the tests exercise the real value.

* no-mistakes(document): name Orca's repo id in the composite worktree id

* no-mistakes(document): list teardown endpoint safety suite in Orca regression entry points

* feat(bin): add opt-in typed dispatch resolution (kunchenguid#4692)

* feat(bin): add opt-in typed dispatch resolution through typesafe.ai

Add bin/fm-dispatch-resolve.sh, which resolves one concrete crewmate or
scout profile from a written brief with typesafe.ai's System One model:
one Choice question over the rules' `when` texts, then the confidence
floor, the rule's `approval` and `floor`, each profile's `provider` and
`floor`, one quota-axi snapshot, and the spendPriority argmax all in code.
It is off unless TYPESAFE_API_KEY is in the environment or the home's
gitignored .env; off means one stderr line, exit 0, and no network call,
so firstmate dispatches exactly as before. The key reaches curl on a file
descriptor, never argv.

Extract fmx_env_get into bin/fm-env-lib.sh as the one .env accessor and
the harness-to-provider table into bin/fm-quota-axi-lib.sh so the new
tool and bin/fm-quota-choose.sh share one owner each. Bootstrap validates
the four new optional dispatch fields. Document the schema, the operator
contract, the AGENTS.md intake step, and the live and benchmark evidence.

* no-mistakes(review): Harden typed dispatch resolution and quota bounds

* no-mistakes(review): Validate dispatch floors and ranking evidence

* no-mistakes(review): Tighten dispatch response and floor evidence

* no-mistakes(review): Neutralize none matching and resolve defaults locally

* no-mistakes(review): Preserve providerless profiles outside typed resolution

* no-mistakes(review): Validate response usage and reject duplicate profiles

* no-mistakes(review): Escalate unverifiable floors and validate probabilities

* no-mistakes(review): Validate probability mass and unknown profile floors

* no-mistakes(review): Simplify resolver interface and preserve fallback routing

* no-mistakes(review): Fix constants and rank partial quota evidence

* no-mistakes(review): Add authoritative provider mapping and enforce explicit providers

* no-mistakes(review): Declare provider for documented Pi profile

* no-mistakes(review): Validate provider identifiers and support Gemini dispatch

* no-mistakes(review): Strictly anchor provider identifiers

* no-mistakes(review): Validate selectors and preserve fallback candidate evidence

* no-mistakes(review): Gate typed validation and harden resolver evidence

* no-mistakes(review): Preserve opt-in routing and harden candidate evidence

* no-mistakes(review): Prioritize known exhaustion over quota uncertainty

* no-mistakes(review): Isolate API secrets and preserve no-key diagnostics

* no-mistakes(review): Fallback safely when dispatch rules are absent

* no-mistakes(review): Prioritize quota vetoes and isolate bootstrap secrets

* no-mistakes(document): Document typed dispatch safety and fallback behavior

* fix(bin): read the latest status event so buried declarations and open decisions aren't lost (kunchenguid#3753)

* test: reproduce buried status declarations in shared readers

* fix: share status event reads and preserve open blockers

* fix: retain terminal scout and ship status declarations

* no-mistakes(review): Fix status chronology, legacy completions, and reader performance

* no-mistakes(review): Share terminal decision reconciliation across fleet snapshots

* no-mistakes(review): Unify terminal supersession across cached folds and consumers

* no-mistakes(review): Filter per-key status history while preserving terminal chronology

* no-mistakes(test): Preserve parent lock ownership in Bash 3.2 subshells

* no-mistakes(review): Anchor legacy status tokens so prose cannot hide pauses

* no-mistakes(document): Document latest-event status read and kind-scoped fold cursor

* no-mistakes(lint): Quote literal done in test for-lists for SC1010

* ci: expect 19 snapshot/fleet-view tests

This branch adds a fleet-snapshot regression, so the stock macOS Bash
lane's hardcoded guard of 18 'ok - ' lines fails on the new count.
Bump the guard and its message to 19.

* no-mistakes(review): Restore multiline child outcome reporting

* no-mistakes(review): Select ledger terminal events through bounded shared reader

* no-mistakes(review): Report newest open decision instead of preferring blocked

* no-mistakes(review): Require colon before ship/scout terminal supersession in fold

* no-mistakes(review): Gate socket-down override on latest event; drop lock matrix

* no-mistakes(review): Fold only colon-bearing or keyed lines as decision transitions

* no-mistakes(review): Pre-select candidate lines before per-key closing-verb fold

* no-mistakes(test): Update fleet-view expectations to newest-open-decision rule

* no-mistakes(document): Align status-read docs with fold-resolved crew state

* no-mistakes(document): Correct status-reader contracts in classify-lib and crew-state headers

* no-mistakes(ci): Greptile P1 (bin/fm-crew-state.sh:729, "Stale socket blocker survives") was a real defect introduced by commit b7c2183 on this branch, and is fixed. Root cause: the daemon-socket-down override took its verb check from `last_status_line "$LOG"` but its evidence and emitted detail from `$LOG_LINE` (status_current_line = the fold's newest still-open decision). Those are different lines whenever a later recognized `blocked:` event is one the decision fold declines. Reproduced by sourcing bin/fm-classify-lib.sh on `blocked: no-mistakes daemon socket is missing` followed by `blocked [key=pending-reply-t3]: still waiting on the answer` (reserved-namespace key whose note does not speak that vocabulary, so _fm_decision_key_transition_allowed rejects it): open set still holds the socket blocker, last_status_line returns the newer line, its verb is blocked, so the gate passed and the stale daemon-down evidence overrode a healthy attributed run. Fix (bin/fm-crew-state.sh): capture LOG_LATEST=$(last_status_line "$LOG") once and read verb, socket-down evidence, and the emitted note all off that same line, so the override fires only while the socket-down declaration is itself the log's latest recognized event — preserving the narrow override the prior round's user instruction asked for. Comment updated to state that contract. No new machinery; the two-line conflation was removed rather than papered over. Regression: extended tests/fm-crew-state.test.sh:test_socket_refusal_override_expires_when_the_crew_moves_on with the reproduced sequence, asserting the run-step reading (state: working, source: run-step) and absence of the override detail. It fails before the fix ("not ok - a later unfolded blocked event also hands the reading back to the run (missing: 'state: working')") and passes after. Verified locally: tests/fm-crew-state.test.sh, tests/fm-fleet-snapshot-view.test.sh, tests/fm-classify-decision-key.test.sh, tests/fm-watch-triage.test.sh, tests/fm-captain-hold-lifecycle.test.sh all pass; bin/fm-lint.sh (shellcheck 0.11.0 + actionlint) exits 0. Changes left uncommitted in the worktree

* test: fold terminal-cleanup snapshot coverage into the completed-scout case

Keep the ship/scout/secondmate supersession assertions without adding a
nineteenth top-level fleet-view test, so CI can stay at the upstream suite count.

* no-mistakes(document): Clarify socket-down override expiry in architecture doc

* ci: retrigger flaky contribution check

---------

Co-authored-by: Sebastian <[email protected]>
Co-authored-by: ladwein <[email protected]>
Co-authored-by: Juan José González Giraldo <[email protected]>
Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Tiago <[email protected]>
rega10 added a commit to rega10/firstmate that referenced this pull request Sep 17, 2026