Skip to content

feat(bin): sync fork with upstream firstmate main - #7

Merged
pc-agents-lstutzman[bot] merged 11 commits into
mainfrom
fm/fm-upstream-sync-1012
Oct 13, 2026
Merged

pc-agents-lstutzman[bot] merged 11 commits into
mainfrom
fm/fm-upstream-sync-1012

Conversation

@pc-agents-lstutzman

Copy link
Copy Markdown
Contributor

Intent

Lee asked to check whether this fork of firstmate is behind upstream (https://github.com/kunchenguid/firstmate), check forks for anything worth leveraging, and check the documentation to make sure the setup is optimal; he then approved all five recommended actions: "All 5 please. The Jev powered stuff should allow for a URL in config so we can point to our local Jev is we are going to adopt it". This task is action 2: bring this fork up to date with upstream.

What Changed

  • Merges upstream kunchenguid/firstmate main into the fork. The biggest addition is Forgejo/Gitea forge support through the tea CLI: forge handling in fm-pr-lib.sh, fm-pr-merge.sh, fm-pr-check.sh, fm-pr-poll.sh and fm-project-mode.sh, plus the new docs/forgejo-tea-integration.md. The merge also brings these upstream fixes:
    • Secondmate launches now arm the busy contract.
    • Nested repos are scrubbed from scratch copies before a treehouse return in fm-teardown.sh.
    • Backlog handoff and receive pin the markdown backend.
    • Home-seed registry queries parse whole project names.
    • Fleet contribution snapshots no longer hit argument-size failures.
    • Announced recovery is kept across Codex checkpoints in fm-watch-checkpoint.sh.
  • Fixes retirement of a remote second mate on runtimes that record a busy-state generation. Teardown now skips the busy-state retire step when retirement already removed the home that held the state directory. Host-local retire treats a home path that holds only empty directories as already retired and removes it, so a rerun now finishes; a path that holds files without the home marker is still refused.
  • Adds and extends tests for the merged behavior, including new fm-project-mode, fm-remote-secondmate-retire and fm-secondmate-busy-contract-live-e2e suites and larger fm-pr-merge and fm-teardown coverage. Docs and harness-adapter skill references are updated to match.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: Both merge conflicts were resolved correctly. In fm-pr-merge.sh both the fork's --stack mode and upstream's Forgejo path are kept, and stack mode still refuses non-GitHub providers before any forge call. The scripts.md row combines both features. The Jev resolver files merge cleanly, and the fork-authored retirement fix has behavioural tests that check persisted state. Risk is medium only because the sync brings a large upstream behaviour change into the live fleet's supervision core: the secondmate busy contract, Forgejo support, and the teardown lost-slot exit 4.

Testing

Checked that the fork contains upstream's main tip. Ran the fork's Jev resolver live: real curl against a local fake Jev reached through config/typesafe-base-url. It sent no Authorization header, and the TYPESAFE_API_KEY sentinel never reached the custom URL. Also ran upstream's Forgejo forge binding and its missing-tea refusal live in a disposable fm-lab home. Three more scenarios were covered only by fixture-driven tests or mocks, so they are marked untested here: Forgejo merge, remote second-mate retirement, and fleet-lifecycle internals. Ran about 25 targeted shell suites covering the scripts the merge changed. All pass except two. tests/fm-pr-merge.test.sh's forgejo-merges case fails on this host because the upstream fixture renders invalid JSON under macOS /bin/bash 3.2 brace expansion. tests/fm-control-relaunch.test.sh's Herdr Pi relaunch case fails because pi is not installed, and it would fail at the base commit too. fm-watch-checkpoint failed once while running in parallel with other suites and passed when re-run alone. Nothing here is a product regression.

  • Live validation: ✅ go - 4 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Fork is no longer behind upstream: kunchenguid/firstmate main tip is contained in the branch ✅ pass live git ls-remote upstream main = 20dcbf9; git merge-base --is-ancestor 20dcbf91 HEAD succeeds
Fork's Jev resolver still honours config/typesafe-base-url after the merge: request goes to the local URL, with no Authorization header and no API key sent ✅ pass live jev-local-url-live.txt: POST /v1/systemone to 127.0.0.1:18899, auth=null, model=jev-latest, sentinel occurrences 0, rule_1 resolved at confidence 0.93
Upstream Forgejo binding: a registry line with forge=forgejo resolves to forgejo while the default two-word output is unchanged, and an unbound project resolves to none ✅ pass live forgejo-live.txt: --forge -> forgejo; default -> 'no-mistakes off'; plain --forge -> none
Adversarial: watching a Forgejo PR without tea refuses and arms nothing; the poll emits no wake and never a false merge ✅ pass live forgejo-live.txt: fm-pr-check exits 1 with 'requires tea and jq on PATH', meta unchanged, no check script; fm-pr-poll prints nothing
Forgejo merge verifies open/mergeable/green status and merges bound to the head commit ⏸️ untested no The prior payload did not establish a live result. No Forgejo instance or tea CLI is available on this host, and Docker-based Forgejo is outside the workspace boundary. The real fm-pr-merge was run on…
Fork fix: retiring a remote second mate completes in one run, and a rerun converges ⏸️ untested no The prior payload did not establish a live result. Running a live remote second mate requires an SSH-reachable remote host, and this gate run has none. Only the fixture-driven tests ran: tests/fm-remo…
Upstream backlog handoff/receive, home-seed project-name parsing, busy contract, teardown and watch changes behave as specified ⏸️ untested no The prior payload did not establish a live result. These fleet-lifecycle internals were exercised only by fixture-driven suites, all of which exit 0: fm-backlog-handoff, fm-remote-backlog-handoff, fm-…
Evidence: Live Jev resolver against a local URL (no auth header, key not sent)

Source: Live Jev resolver against a local URL (no auth header, key not sent)

$ FM_HOME=<lab> TYPESAFE_API_KEY=<sentinel> bin/fm-dispatch-resolve.sh brief.md --project pager   # config/typesafe-base-url=http://127.0.0.1:18899/
dispatch-resolve:
  status: escalate
  model: jev-local   latency_ms: 0   tokens: 1/1
  rule: rule_1 (A simple bug fix with a stated root cause.)   confidence: 0.93
  probabilities: rule_1=0.93 default=0.07
  reason: no rankable eligible candidate
  note: rule matched
  candidate: claude:sonnet  provider=claude  -> eligible, unranked: provider claude unmeasured (unknown): disclosed uncertainty
exit=0
--- request received by local Jev server:
{"path":"/v1/systemone","auth":null,"model":"jev-latest","keys":["model","questions","state"]}
sentinel occurrences in request: 0
Evidence: Live Forgejo forge binding + missing-tea refusal in lab home

Source: Live Forgejo forge binding + missing-tea refusal in lab home

# registry: "- my forge app [no-mistakes forge=forgejo] ..." and "- plain - ..."
$ bin/fm-project-mode.sh --forge "my forge app"
forgejo
exit=0
$ bin/fm-project-mode.sh "my forge app"
no-mistakes off
exit=0
$ bin/fm-project-mode.sh --forge plain
none
exit=0
$ PATH=<no tea> bin/fm-pr-check.sh task-x https://localhost/fixture/fixture-repo/pulls/1
error: watching a Forgejo pull request requires tea and jq on PATH
exit=1
task meta unchanged after refusal: yes
armed task-x check script present: 0
$ PATH=<no tea> bin/fm-pr-poll.sh --validated forgejo https://localhost/fixture/fixture-repo/pulls/1 localhost fixture/fixture-repo 1
exit=0
(empty poll output = no wake, never a false 'merged')
Evidence: fm-pr-merge Forgejo merge with valid status fixture (rc=0, head-bound merge)

Source: fm-pr-merge Forgejo merge with valid status fixture (rc=0, head-bound merge)

fm-pr-merge rc=0 (fixture status JSON corrected to the bash-5 rendering)
--- stdout
armed: state/task-x1.check.sh
--- stderr (non-banner)
verified: https://forgejo.example/fixture/fixture-repo/pulls/9 is open and mergeable, with a successful combined status at head cccccccccccccccccccccccccccccccccccccccc
--- tea calls
login list --output json
login list --output json
api --login fm-fixture --repo fixture/fixture-repo /repos/{owner}/{repo}
api --login fm-fixture --repo fixture/fixture-repo /repos/{owner}/{repo}/pulls/9
api --login fm-fixture --repo fixture/fixture-repo /repos/{owner}/{repo}/commits/cccccccccccccccccccccccccccccccccccccccc/status?limit=50&page=1
api --login fm-fixture --repo fixture/fixture-repo /repos/{owner}/{repo}/commits/cccccccccccccccccccccccccccccccccccccccc/status?limit=50&page=2
api --login fm-fixture --repo fixture/fixture-repo -X POST /repos/{owner}/{repo}/pulls/9/merge -f Do=merge -f head_commit_id=cccccccccccccccccccccccccccccccccccccccc
api --login fm-fixture --repo fixture/fixture-repo /repos/{owner}/{repo}/pulls/9
--- meta pr=
pr=https://forgejo.example/fixture/fixture-repo/pulls/9
--- gh-axi calls:        0
  • Evidence: Targeted test suite logs (local file: ~/.no-mistakes/evidence/01M4RZ4CM17S2Z3D7JRNBMDEF5/tests)
Evidence: Upstream tip is an ancestor of HEAD
upstream=20dcbf91520b1816663b81873ad67d0b93b3e4d6
upstream tip IS ancestor of HEAD
- Outcome: ⚠️ 3 issues (1 warning, 2 infos) across 1 run (23m45s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

⚠️ **Test** - 3 issues (1 warning, 2 infos)
  • ⚠️ tests/fm-pr-merge.test.sh:566 - tests/fm-pr-merge.test.sh write_forgejo_status_json (inherited unchanged from upstream) renders invalid JSON under macOS /bin/bash 3.2. The sed replacement {&#34;context&#34;:...,&#34;status&#34;:...} inside "$(...)" is brace-expanded into two printf arguments, so the forgejo-merges case fails locally with 'combined commit status is "unreadable"'. The product is fine: with a valid fixture, fm-pr-merge merges with rc=0. This should be fixed upstream (e.g. build each status entry with printf in a loop) rather than diverging the fork; Linux CI on bash 5 is unaffected.
  • ℹ️ tests/fm-control-relaunch.test.sh:2244 - tests/fm-control-relaunch.test.sh 'Herdr Pi relaunch should complete' fails on this host because the pi executable is not on PATH. Both the test and fm-spawn's executable guard exist unchanged at base ad896d8, so the merge did not cause this.
  • ℹ️ tests/fm-watch-checkpoint.test.sh - tests/fm-watch-checkpoint.test.sh failed 'watch lock pid survived quiet checkpoint timeout' only when run in parallel with other heavy suites. It passed 12/12 when re-run on its own: a timing-sensitive flake, not a regression.
  • Live validation: ✅ go - 4 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Fork is no longer behind upstream: kunchenguid/firstmate main tip is contained in the branch ✅ pass live git ls-remote upstream main = 20dcbf9; git merge-base --is-ancestor 20dcbf91 HEAD succeeds
Fork's Jev resolver still honours config/typesafe-base-url after the merge: request goes to the local URL, with no Authorization header and no API key sent ✅ pass live jev-local-url-live.txt: POST /v1/systemone to 127.0.0.1:18899, auth=null, model=jev-latest, sentinel occurrences 0, rule_1 resolved at confidence 0.93
Upstream Forgejo binding: a registry line with forge=forgejo resolves to forgejo while the default two-word output is unchanged, and an unbound project resolves to none ✅ pass live forgejo-live.txt: --forge -> forgejo; default -> 'no-mistakes off'; plain --forge -> none
Adversarial: watching a Forgejo PR without tea refuses and arms nothing; the poll emits no wake and never a false merge ✅ pass live forgejo-live.txt: fm-pr-check exits 1 with 'requires tea and jq on PATH', meta unchanged, no check script; fm-pr-poll prints nothing
Forgejo merge verifies open/mergeable/green status and merges bound to the head commit ⏸️ untested no The prior payload did not establish a live result. No Forgejo instance or tea CLI is available on this host, and Docker-based Forgejo is outside the workspace boundary. The real fm-pr-merge was run on…
Fork fix: retiring a remote second mate completes in one run, and a rerun converges ⏸️ untested no The prior payload did not establish a live result. Running a live remote second mate requires an SSH-reachable remote host, and this gate run has none. Only the fixture-driven tests ran: tests/fm-remo…
Upstream backlog handoff/receive, home-seed project-name parsing, busy contract, teardown and watch changes behave as specified ⏸️ untested no The prior payload did not establish a live result. These fleet-lifecycle internals were exercised only by fixture-driven suites, all of which exit 0: fm-backlog-handoff, fm-remote-backlog-handoff, fm-…
  • git ls-remote https://github.com/kunchenguid/firstmate refs/heads/main + git merge-base --is-ancestor &lt;upstream-tip&gt; HEAD
  • Live: FM_HOME=&lt;disposable lab&gt; bin/fm-dispatch-resolve.sh brief.md --project pager with config/typesafe-base-url=http://127.0.0.1:18899/ against a local python fake System One (real curl), with TYPESAFE_API_KEY set to a sentinel
  • Live: bin/fm-project-mode.sh --forge &#34;my forge app&#34; / bin/fm-project-mode.sh &#34;my forge app&#34; / bin/fm-project-mode.sh --forge plain against a disposable bin/fm-lab-home.sh create home with a forge=forgejo registry line
  • Live adversarial: PATH=&lt;no tea&gt; bin/fm-pr-check.sh task-x https://localhost/fixture/fixture-repo/pulls/1 and PATH=&lt;no tea&gt; bin/fm-pr-poll.sh --validated forgejo ... in the lab home
  • bash tests/fm-dispatch-resolve.test.sh, tests/fm-forge-detect.test.sh, tests/fm-remote-secondmate-retire.test.sh, tests/fm-remote-secondmate-lifecycle-e2e.test.sh, tests/fm-backlog-handoff.test.sh, tests/fm-remote-backlog-handoff.test.sh, tests/fm-pr-check-security.test.sh, tests/fm-project-mode.test.sh, tests/fm-busy-adapter-wiring.test.sh, tests/fm-crew-state.test.sh, tests/fm-review-diff.test.sh, tests/fm-brief.test.sh, tests/fm-task-delivery.test.sh, tests/fm-secondmate-safety.test.sh, tests/fm-teardown.test.sh, tests/fm-home-summary-refresh.test.sh, tests/fm-turnend-guard.test.sh, tests/fm-secondmate-harness.test.sh, tests/fm-omp-harness.test.sh, tests/fm-spawn-dispatch-profile.test.sh: all exit 0
  • bash tests/fm-watch-checkpoint.test.sh: failed one timing case when run in parallel with other suites, passed 12/12 when re-run on its own
  • bash tests/fm-pr-merge.test.sh: 54 ok, 1 not ok (forgejo-merges); root-caused with a temporary driver (since removed) that ran the same case with the status fixture corrected; fm-pr-merge then merged with rc=0
  • bash tests/fm-control-relaunch.test.sh: one Herdr Pi relaunch case fails because pi is not installed; that test and the guard both exist unchanged at base ad896d8e
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

kesslerio and others added 11 commits October 10, 2026 15:14
…830)

* fix(bin): stage contribution-input JSON via temp files

The contribution-input branch passed the whole canonical backlog document to
jq as a single --argjson argv argument. A large fleet's backlog JSON exceeds
Linux MAX_ARG_STRLEN (128 KiB), so jq fails with E2BIG (Argument list too
long) and the contribution-input snapshot emits empty output, breaking the
bearings contribution path.

Write both the backlog and task documents to a temp directory and hand them
to jq with --slurpfile, matching how the full snapshot path already stages
the same pair. Output is unchanged for any backlog that fits in argv.

* no-mistakes(document): Correct contribution cleanup trap comment
* fix(bin): arm the busy contract on secondmate launches

A tmux-backed secondmate's active-turn gate can only see a busy verdict from the parent home's record, and those launches never armed it.

* no-mistakes(review): Reopen secondmate busy on blocked Claude Stop; drop muse guard

* no-mistakes(review): Make Claude secondmate Stop guard the sole Stop-state writer

* no-mistakes(review): Record live rewake UserPromptSubmit evidence and add regression

* docs: record Claude secondmate Stop guard as busy writer

* no-mistakes(review): Keep Stop idle hook for older secondmate guards

* no-mistakes(document): Correct stale omp secondmate -e rationale in supervision verification

* no-mistakes(document): Fix skill-relative turnend-guard link in Claude harness reference

* no-mistakes(ci): Root cause: in shard 9, the pure-contract-unit family ran two scripts, tests/fm-rovo-harness.test.sh (14712 ms) and tests/fm-omp-harness.test.sh (10335 ms). Those two durations add up exactly to the failing family's 25047 ms. The failing one was tests/fm-omp-harness.test.sh. Its test_secondmate_launch_relies_on_discovery still asserted the old contract: that an omp secondmate launch names no -e and gets no state/<id>.omp-ext.ts. This PR (issue #4268) deliberately changed that. bin/fm-spawn.sh now arms the busy contract for omp secondmates, so their launch names `-e state/<id>.omp-ext.ts` and writes that extension. The primary extensions are still left to auto-discovery. The harness reference docs were updated to match, but the test was not. The fix is test-only and touches just tests/fm-omp-harness.test.sh. The test now asserts that the secondmate launch names exactly one -e and that it points at the parent-home state/sm.omp-ext.ts. Because only one -e is allowed, the tracked .omp/extensions files are not named a second time, which would load them twice. The test also asserts that the extension file exists, and the header comment for contract 3 was updated. The posture overlay, --cwd, marker, and supervision-model assertions are unchanged. Verification: the host's load average was about 140 on 8 cores, and the full script timed out locally after 590 s having finished only its first 2 tests. So I ran the one affected test function on its own through the real fm-spawn path, and it passed (`ok - fm-spawn: a real omp secondmate launch loads only the busy -e and auto-discovers its primary extensions`). The remaining omp tests were not re-run locally. shellcheck on the file reports only existing info-level notices. The change is left uncommitted for the outer executor

* test: keep the secondmate busy stall gate visible after main's liveness probe

The merged watcher treats a window-name inventory miss as a missing endpoint and exits a later checkpoint on the previous quiet run's recovery wake. The fake pane now answers both list-windows formats, and each observation starts without a leftover downtime marker, so a busy mate still defers the stall and an idle mate still surfaces it.

* no-mistakes(review): Align fm-spawn secondmate comments with omp -e and devin refusal

* no-mistakes(document): Document secondmate busy extensions in configuration reference

* no-mistakes(test): Make live busy-contract guard clean up read-only lab dirs

* fix(bin): pass Claude secondmate busy hooks through --settings

Rewriting a persistent mate home's settings.local.json drops the captain's saved permissions. The hooks now live in a parent-state file Claude Code loads for that session only.

* no-mistakes(review): skip busy arm for raw secondmate launch commands

* no-mistakes(review): retire earlier busy arm on raw secondmate respawn

* no-mistakes(review): retire Stop pointer on relaunch, load --settings in live guard

* no-mistakes(document): Document secondmate Claude settings file and raw-launch exception

* no-mistakes(ci): The check "Behavior portable serial 9" failed because of this PR, and I fixed it with a test-only change; `tests/fm-spawn-dispatch-profile.test.sh` now passes locally in full. Cause: the one failing test was "claude secondmate launch settings JSON does not disable Claude attribution" in `tests/fm-spawn-dispatch-profile.test.sh`. This PR makes a claude secondmate launch pass `--settings` as a file path (`state/<id>.claude-settings.json`) instead of inline JSON. The test helper `claude_settings_json_arg` handed that path string to jq as if it were JSON, so jq reported a parse error. The product behavior is correct: the file does carry `feedbackDrafts` and the attribution-off policy. Invariant: a test that checks the Claude launch settings must read the settings Claude would load, whichever form `--settings` takes (inline JSON or a file path). The only place this must hold is `claude_settings_json_arg`, the single reader of the `--settings` value in the tests. Its two callers, `assert_attribution_policy` and `assert_attribution_policy_absent`, both go through it. Fix: `claude_settings_json_arg` now prints the value when it starts with `{` and prints the file contents otherwise. No product code changed. Verification: I ran `bash tests/fm-spawn-dispatch-profile.test.sh` in the worktree. It ended with "all fm-spawn-dispatch-profile tests passed", including the previously failing secondmate case and the crewmate and keep-ai-trailers cases that use the inline form. I did not run the other tests of shard 9; they passed in the CI run and this change touches only this test file. The change is uncommitted in the worktree (one file modified)
…ailures (#7036)

The large-backlog regression already proved the json and secondmate
home-summary modes stay within exec limits. It now also runs the
contribution-input mode on the same 1200-record backlog, which is the
path #6830 moved off argv. With that fix reverted the test fails with
the field error jq Argument list too long at the contribution-input call.
…urn (#5843)

* fix(teardown): scrub nested repos before return

Treehouse return uses git clean -fd, which leaves a nested git
repository in the pool slot. Scout and forced teardown run
git clean -ffdq first. A return that stays dirty names the
lost slot instead of reporting a clean return.

* no-mistakes(review): Report lost pool slots early and scrub forced child copies

* no-mistakes(review): Drop misleading no-rerun clause from lost-slot message

* no-mistakes(document): Note failed status read in teardown dirty-return header

* no-mistakes(ci): I fixed ci-1 and ci-2 in bin/fm-teardown.sh, and I added tests in tests/fm-teardown.test.sh. Invariant (ci-1): a lost-slot finding must only warn. It must never change the teardown exit status. Two places must obey this: the final status block, and the remote success path that a forced remote retirement uses. - The final block no longer runs `exit 1`. When a slot is lost, teardown writes a lost-slot line to stderr instead of the clean "teardown X complete" line. Then backlog_refresh_reminder runs and teardown exits with its normal status. - Before this change, remote_secondmate_teardown discarded the remote output when the remote run succeeded. Now it sends that output to stderr. Without this, the remote lost-slot warning would not reach the operator once the remote side exits 0. - I updated the header comment to match. Invariant (ci-2): after a return that succeeds, teardown must verify every returned copy, or it must warn that it could not. This invariant is enforced inside teardown_note_dirty_return, which both return sites call (the main WT return and the forced-secondmate child return). Before, a copy that was missing or not a readable git worktree caused a silent `return 0`. Now it sets the lost flag and gives the same warning, with the text "cannot verify: the copy is missing or not a readable git worktree after return". Both call sites run only for a copy that existed before the return. The exit status does not change. Tests: - The dirty-return test now expects exit 0 and the warning. - New test (z3d): a forced secondmate teardown whose child return leaves residue. This is the same command that `retire --force` runs on the remote host. The test expects exit 0 and the warning, and it checks that the task record and the home are removed. - New test (z3e): a return that removes the copy's .git. The test expects exit 0, the "cannot verify" warning that names the copy, and no clean completion line. Verification: - I ran the new and updated tests against the old script. Three failed as expected (exit 1, or no warning). With the fix, all of them pass. - The full tests/fm-teardown.test.sh suite passes: 117 ok, 0 not ok. - shellcheck shows no new warnings. - tests/fm-remote-secondmate-lifecycle-e2e.test.sh is still running. It covers the remote success path that now relays output. Up to now it has no failures, but it has not finished, so I cannot report a final result for it

* no-mistakes(ci): I fixed ci-1 and ci-2 as one exit contract, as the user asked. The changes are in bin/fm-teardown.sh, tests/fm-teardown.test.sh, and tests/fm-remote-secondmate-lifecycle-e2e.test.sh. Invariant (ci-1): when a returned slot is dirty or cannot be verified, teardown must finish every cleanup step and then exit with exit code 4. Exit 4 is used for nothing else. It must hold in two places: the final status of a local teardown, and the remote secondmate retirement caller. - Local: the existing lost-slot flag now leads to `exit 4` (TEARDOWN_LOST_SLOT_EXIT). This exit comes after the task record is removed, the warning is printed, and backlog_refresh_reminder runs. A clean return still exits 0. Refusals and errors exit 1, and an invalid request exits 2. The header documents all of these codes. Exit 3 is only an internal "not remote" return. The ssh transport uses 255. - Remote caller: remote_secondmate_teardown treats a remote exit 4 as "retired with a lost-slot warning". It does the full local retirement (route, registry line, reply source, records, summary refresh), prints the normal completion line on stdout, and then returns 4. The remote control script runs fm-teardown.sh as its last command, and fm-on.sh execs ssh, so the remote 4 reaches the local side unchanged. Invariant (ci-2): remote output goes to local stderr only when it is a lost-slot warning. - After a clean remote retirement (exit 0), the caller no longer prints the captured remote output. - After exit 4, the caller forwards only the lost-slot warning header and the remaining-path lines. To make those lines easy to find, teardown_note_dirty_return now indents each remaining path by two spaces. Tests: - The dirty-return (z3), forced-secondmate dirty-child (z3d), and copy-removed (z3e) tests now expect exit 4 after cleanup. The clean scout return (z1) still expects 0. - The final remote retirement in the e2e test now uses a fake-ssh mode, retire-lost-slot. In this mode the real remote retire runs, and then the fake reports a lost child slot with exit 4. The test checks the following: exit 4; the remote home, parent metadata, and route are removed; stdout has "teardown ios complete (remote"; stderr has the warning and the remaining path; and stderr does not contain the remote completion text. The remote side producing exit 4 is covered by z3d. Verification: - tests/fm-teardown.test.sh: 117 ok, 0 not ok. - tests/fm-remote-secondmate-lifecycle-e2e.test.sh: ALL TESTS PASSED. - shellcheck shows the same warning count as before on all three files. - Against the previous script, both suites fail as expected. In the local suite, dirty-return expected 4 but got 0. In the e2e test, the stdout local-completion check fails

* no-mistakes(ci): Both CI failures came from the lost-slot check that this PR added. Shard 3: tests/fm-secondmate-safety.test.sh "force teardown failed to discard child work". Shard 7: tests/fm-teardown-endpoint-safety.test.sh exited 4. The check ran after the return of every copy. Treehouse return removes a copy that is not a pool slot, so the check reported "cannot verify" and teardown exited 4. Before the fix, both failures happened on my machine. Invariant: only a Treehouse pool slot can be lost by the pool, so the check runs only for a copy that was a pool slot before the return. Fix in bin/fm-teardown.sh: both return sites (the main WT return and the forced-secondmate child return) now run fm_treehouse_pool_slot before the return. They call teardown_note_dirty_return only when the copy was a pool slot. teardown_note_dirty_return lost its pool-slot branch and its unused proj argument; the slot label still comes from the path of the copy. Test fix: in tests/fm-teardown.test.sh, the z3d child copy was not a pool slot. It is now a real pool slot (pool/6/repo plus treehouse-state.json), and the test still expects exit 4 and the warning. Verification: endpoint-safety 27 ok, exit 0. secondmate-safety 79 ok, exit 0. fm-teardown 117 ok, 0 not ok. remote-secondmate-lifecycle-e2e ALL TESTS PASSED. shellcheck count is unchanged (17)

---------

Co-authored-by: Nova Agent B <[email protected]>
* fix(tests): keep backlog suites hermetic against a local .tasks.toml

Fixture homes now write the tracked markdown defaults through a
fm_test_tasks_toml helper instead of copying the checkout's .tasks.toml,
which an operator may override with a beads backend at a live backlog.

The backlog handoff and receive moves pin --backend markdown, because they
already name their markdown files and otherwise resolve the backend from the
caller's working directory. The atomicity suite runs from its scratch root so
its direct tasks-axi fixture calls cannot read the checkout config.

* no-mistakes(review): Add decoy-cwd .tasks.toml regressions for handoff and receive

* no-mistakes(lint): Reuse sha256_file helper to fix SC2015 in remote handoff test
…076)

* fix(bin): parse whole project name in home seed registry queries

Parse the full project name after the dash in fm-home-seed.sh registry lookups.

This matches the round-3 bootstrap mirror check parser so spaced names resolve.

Cover both the project-less seed refusal guard and registry line lookups in tests.

* no-mistakes(review): Match registry rows by name prefix plus separator

* no-mistakes(document): Note shared registry row-match rule in fm-home-seed
* fix(codex): preserve announced recovery across checkpoints

* no-mistakes(review): Make announced-recovery checkpoint test reproduce the regression

* no-mistakes(review): Separate 2026-10-07 checkpoint fixture verification from original run

* no-mistakes(test): Defer TERM exit to clean up quiet checkpoint watcher locks

* no-mistakes(document): Update checkpoint recovery and signal documentation

* no-mistakes(ci): Updated both lock-acquire retry loops to honor the watcher’s TERM stop status, so held-marker cleanup exits while retaining stale lock evidence. Set the --stop test’s watcher poll to 1 second to fit its 5-second stop bound. Syntax checks and the full watch-arm suite passed; the targeted held-marker test passed during the triage suite, which timed out after 600 seconds before completing. Did not change or attempt to fix fm-supervision-host.test.sh

* no-mistakes(ci): Removed the cleanup-bound test that incorrectly expected a TERM-stopped watcher to retry a contended lock acquisition. TERM cleanup intentionally stops after the failed attempt; the remaining held-lock test verifies it exits and retains stale lock evidence. The two relevant TERM tests passed, as did shell syntax and diff checks

* Revert "no-mistakes(ci): Updated both lock-acquire retry loops to honor the watcher’s TERM stop status, so held-marker cleanup exits while retaining stale lock evidence. Set the --stop test’s watcher poll to 1 second to fit its 5-second stop bound. Syntax checks and the full watch-arm suite passed; the targeted held-marker test passed during the triage suite, which timed out after 600 seconds before completing. Did not change or attempt to fix fm-supervision-host.test.sh"

This reverts commit 44ce29bfbfa95149a7785efc200f6a00b5bf3a41.

* Revert "no-mistakes(ci): Removed the cleanup-bound test that incorrectly expected a TERM-stopped watcher to retry a contended lock acquisition. TERM cleanup intentionally stops after the failed attempt; the remaining held-lock test verifies it exits and retains stale lock evidence. The two relevant TERM tests passed, as did shell syntax and diff checks"

This reverts commit e1e37067a9369f0c38d7bd1c7a0913b1c54fc28a.

* Revert "no-mistakes(test): Defer TERM exit to clean up quiet checkpoint watcher locks"

This reverts commit 9877bf92134e77414e25cd8e6f122ff4d089473a.

* fix: let checkpoint watcher clean up before timeout

* no-mistakes(review): Scope checkpoint timeout escalation and restore signal docs

* no-mistakes(review): Fix Perl checkpoint timeout escalation

* no-mistakes(document): Clarify checkpoint recovery documentation

* no-mistakes(document): Document isolated checkpoint regression command

* no-mistakes(ci): Tied direct-checkpoint SIGKILL escalation to the effective cleanup bound, preserving the five-second minimum and leaving the supervision-host path unchanged. The targeted checkpoint suite, shell syntax checks, ShellCheck, and diff checks pass. CI was not manually rerun

---------

Co-authored-by: jopo <[email protected]>
* feat(bin): add Forgejo (tea) as a third forge alongside GitHub and GitLab

Extends the existing provider-tagged PR/MR dispatch in fm-pr-lib.sh,
fm-pr-poll.sh, fm-pr-check.sh, and fm-pr-merge.sh with a forgejo arm,
following the same pattern already established for GitLab. tea addresses a
repository by owner/repo slug only and resolves the host through a named
"tea login" rather than a URL, so the login is matched against the PR's host
fresh at arm and merge time. tea's own merge subcommand exposes no
head-binding flag, so the merge itself calls Forgejo/Gitea's REST API
directly via "tea api" with head_commit_id, verified against a real
disposable instance to behave like --match-head-commit/--sha; that same
verification found that "tea api" reports an HTTP-level failure with exit
status 0, so a merge is confirmed only by reading the pull request back
afterward, never by trusting the command's own exit code.

Adds forgejo as a value of the registry's existing forge= binding (the
closed set becomes none|gerrit|forgejo, with its refusals unchanged), so a
generated brief and its direct-PR Definition of done name tea before any PR
exists and bin/fm-spawn.sh's forge agreement and bin/fm-promote.sh carry it
like gerrit. Documents the new value in docs/configuration.md,
docs/architecture.md, and a new maintainer-verification doc mirroring
docs/gitlab-merge-watch.md.

* no-mistakes(review): Redact private Forgejo host/IP from evidence doc

* no-mistakes(review): Fix doc's tea-login JSON shape; dedupe host validators

* no-mistakes(document): Add Forgejo to README doc index and scripts.md forge list

* no-mistakes(lint): {"summary": "fix(bin): drop unused FORGEJO_LOGIN capture in fm-pr-check.sh"}

* fix(bin): refuse --allow-red on Forgejo instead of dropping it silently

The attended --allow-red waiver landed on main while the Forgejo arm was
being written, so its applicability guard only ever classified GitHub and
GitLab. On a Forgejo pull request the flag parsed, and then nothing read
it: forgejo_verify_mergeable requires the head's combined commit status to
be exactly "success", with no per-check name to match a waiver against.

The merge still refused, so no red Forgejo merge was ever possible, but it
refused without saying the waiver had been ignored. Extend the existing
GitLab guard to cover Forgejo for the same reason GitLab has it: both
collapse their checks into a single head verdict, so the green requirement
is absolute and a named waiver cannot apply.

* fix(bin): poll a Forgejo pull request by number through tea api

The merge watch listed the 50 most recent pull requests and filtered to the
watched index, so in a repository with more newer pull requests a merged
watch never fired. Read the one pull request through tea api instead and wake
only on a boolean merged field of true, since tea api exits 0 on HTTP errors.

Share the tea login match as fm_pr_forgejo_login for every sourcing script and
add fm_pr_forgejo_read_record for the state, merged flag, and head. Arming now
also requires jq, which the poll needs to read the record.

* fix(bin): gate a Forgejo merge on every status page and on draft state

The combined-status endpoint computes its state from one page of contexts, so
a failing context past the first page could leave the head reading green. Read
every page until an empty one and require each to be success. Also refuse a
pull request the API reports as a draft.

* fix(bin): prove a Forgejo task landed from its merged pull request at teardown

pr_is_merged read the recorded pr= only through gh, so a Forgejo task always
fell back to the content check and refused landed work whenever that check was
inconclusive, such as when later default-branch commits conflict with the
merged tree. Read a recorded Forgejo URL through fm_pr_forgejo_read_record and
apply the same containment check against its head.

* feat(bin): read Forgejo pull requests in crew-state and review-diff

fm-crew-state reports a terminal passed run's Forgejo pull request as open,
closed, merged, or unknown through fm_pr_forgejo_read_record, and
fm-review-diff resolves a /pulls/<n> URL to the refs/pull/<n>/head ref
Forgejo serves. Document the by-number read, the paged status gate, and the
draft gate, and mark what the evidence instance did not exercise.

* fix(bin): parse tea logins as JSON and close the remaining Forgejo gaps

The tea login match split each line of `tea login list --output json` on
quotes and read field 4, which only works while tea pretty-prints one field
per line. A login printed as one compact object put the login name where the
url belonged, so arming, merging, and polling refused every Forgejo host.
fm_pr_forgejo_login and the static poll's own copy now parse the list with
jq, matching each login's url host with scheme, userinfo, port, and path
stripped, and still refuse zero or several matches.

--allow-missing is now refused on a Forgejo pull request the way --allow-red
already is, instead of being parsed and ignored: the merge already requires
the head's combined commit status to have succeeded.

The forge=forgejo Definition of done read the draft state back with
gh-axi pr view and cleared it with gh-axi pr ready although the PR is opened
with tea; both publishing modes now read the draft state through tea api and
clear Forgejo's work-in-progress title prefix with tea pulls edit.

* no-mistakes(review): Retry Forgejo merge confirmation read before failing

* no-mistakes(document): Document Forgejo draft gate and merge confirmation retry

* fix(bin): merge Forgejo pull requests with the repository's default style

When the caller named no merge method, a Forgejo merge always sent Do=merge,
so a repository that allows only squash or rebase merges refused every
default call. The style now comes from the repository's own
default_merge_style, read live through the same tea login, and a merge is
refused when that value cannot be read or is not a known style rather than
replaced by one chosen here. A method the caller names still wins.

---------

Co-authored-by: dna <dna@local>
… rerun

Retiring a remote second mate launched on a runtime that records a
busy-state generation failed after the host had already closed the pane and
removed the home: the host-local teardown keeps its state directory inside
that home, and the busy-state retire helper refuses a missing state
directory. The parent then kept the route, its task record, and the reply
source.

A rerun could not finish either. Sourcing bin/fm-wake-lib.sh creates
$FM_HOME/state, so the retire command recreated an empty directory at the
retired path and then refused it as an unseeded home, which made the
already-retired answer unreachable.

Teardown now skips the busy-state retirement when a second-mate retirement
removed the home that held the state directory. Host-local retire treats a
home path holding only empty directories as already retired and removes that
tree with rmdir; a path holding any file or symlink without the home marker
is still refused untouched.
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.

6 participants