Skip to content

feat(bin): deliver verified document snapshots in secondmate --doc reports - #8243

Closed
tiago-peixoto wants to merge 5 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/up-fork114-doc-snapshot
Closed

tiago-peixoto wants to merge 5 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/up-fork114-doc-snapshot

Conversation

@tiago-peixoto

@tiago-peixoto tiago-peixoto commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Keep the fork-only change and open an upstream PR for it: deliver verified document snapshots with secondmate --doc reports. The --doc report helper must capture reviewed non-secret Markdown or plain text from data/ into a content-addressed snapshot, preserve source host, home, and document-path provenance, and verify the exact bytes at the receiving home before delivering the correlated report. Local delivery verifies the snapshot before appending the report. Remote delivery withholds the correlated answer and leaves the captured delta retryable when the snapshot is missing or corrupt, then succeeds when the exact snapshot arrives. Support snapshots up to 1 MiB. Open one upstream PR against kunchenguid/firstmate. There is no upstream issue to close.

What Changed

  • Added bin/fm-document-snapshot.sh with two subcommands. capture copies a reviewed .md/.txt file under data/ into a content-addressed data/report-snapshots/<sha256>.md snapshot. receive verifies the exact bytes against the digest and byte count at the receiving home. Both enforce a 1 MiB limit and refuse symlinks, hardlinks, hidden or credential paths, non-UTF-8 or control bytes, and recognizable credential content. A content refusal exits with status 3.
  • fm-secondmate-report.sh --doc now captures a snapshot and writes a report line that carries report=, source-host=, source-home=, source-document=, and document-bytes=. On a local parent route, it receives and verifies the snapshot in the parent home before it appends the report.
  • fm-procevent-remote-reply.sh now treats a data/report-snapshots/<sha256>.md pointer as required, with a 1 MiB fetch limit. If the snapshot is missing or does not verify, ingest stops and the delta stays uncommitted for retry, so the correlated answer is withheld. A malformed digest or a content refusal still fails open like other refusals. The docs, the secondmate-provisioning skill, and the tests for local receipt, symlinked homes, and the remote withhold-then-retry flow were updated to match.

Risk Assessment

✅ Low: The change matches the stated intent and the earlier fixes hold: capture and receive are confined and checked against the digest, local delivery verifies the parent copy before it appends the report, and remote ingest withholds the delta and keeps it retryable when the snapshot is missing or corrupt. Fixed refusals (a bad digest name or a content refusal) let the stream continue with a note, the symlinked-home path resolves, and exit code 3 now has its own name, SNAPSHOT_CONTENT_REFUSED.

Known limits

The content check rejects carriage returns, so Markdown files using CRLF line endings cannot be captured. The receiver repeats the credential-content check after verifying the byte count and digest, so different policy versions can reject a snapshot the source accepted.

Testing

I ran the two test files named in the verification plan, and both passed. They drive the real remote adapter, fm-on.sh and fm-remote-file.sh, with only SSH replaced by a fake. Those runs covered remote missing and corrupt snapshots, retry after the snapshot comes back, replay without a duplicate answer, and refusals that fail open. Next, I drove the real fm-secondmate-report.sh --doc CLI by hand in disposable local parent and mate homes. The parent copy was byte-identical by sha256, including a trailing blank line. The status line carried source-host, source-home and source-document. An exactly 1 MiB document was delivered. A document one byte over the limit, a path outside data/, a symlinked document and a hardlinked destination were each refused, and no report line was appended. A 1 MiB remote offer also read back fully through fm-remote-file.sh. This change has no UI, so the evidence is CLI transcripts and test logs.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Local mate runs fm-secondmate-report.sh --doc on data/x/report.md, and the parent home gets a byte-identical content-addressed snapshot plus a correlated line with host, home and document-path provena… ✅ pass live local-doc-delivery-transcript.txt: sha256 of source and parent snapshot match, cmp identical, status line has source-host/source-home/source-document/document-bytes
Local delivery verifies before appending: a hardlinked (unsafe) parent snapshot destination makes --doc fail and no report line is appended ✅ pass live local-doc-delivery-transcript.txt: 'snapshot destination is unsafe' rc=1, and the parent status still has exactly 2 lines
Size boundary: an exactly 1048576-byte doc is delivered and a 1048577-byte doc is refused with no report ✅ pass live local-doc-delivery-transcript.txt boundary sections; remote-1mib-offer-transcript.txt shows the 1 MiB remote offer reads back fully
Capture guards: a doc outside data/ and a symlinked doc are refused ✅ pass live local-doc-delivery-transcript.txt adversarial sections, each rc=1
Remote delivery: a missing or corrupt snapshot holds back the correlated answer and leaves the cursor in place, a restored snapshot then delivers the exact bytes with provenance, and a replay does not… ✅ pass live bash tests/fm-remote-reply.test.sh -> remote-reply.log exit=0
Deterministic refusals (invalid digest name, credential content) fail open with a note instead of blocking the mate's reply stream ✅ pass live remote-reply.log: 'deterministic snapshot refusals fail open instead of blocking the stream'
Evidence: Local --doc delivery and guard transcript

Source: Local --doc delivery and guard transcript

schema=fm-secondmate-parent.v1
route=local
parent_home=/tmp/fm-docsnap.AyTTFL/parent
$ FM_HOME=mate fm-secondmate-report.sh --doc done $CORR data/x/report.md "see report"
rc=0
--- parent status line:
done [corr=0123456789abcdef] [at=1794062015]: see report (report=data/report-snapshots/c9b74676bbcdde0cab750bf093c8d2b44a497d18272a26ab96a3099e43cc101f.md source-host=firstmate-hz source-home=/tmp/fm-docsnap.AyTTFL/mate source-document=data/x/report.md document-bytes=38 via-helper)
--- parent snapshot:
c9b74676bbcdde0cab750bf093c8d2b44a497d18272a26ab96a3099e43cc101f.md
c9b74676bbcdde0cab750bf093c8d2b44a497d18272a26ab96a3099e43cc101f  /tmp/fm-docsnap.AyTTFL/mate/data/x/report.md
c9b74676bbcdde0cab750bf093c8d2b44a497d18272a26ab96a3099e43cc101f  /tmp/fm-docsnap.AyTTFL/parent/data/report-snapshots/c9b74676bbcdde0cab750bf093c8d2b44a497d18272a26ab96a3099e43cc101f.md
bytes identical (incl. trailing blank line)

=== adversarial: 1048577-byte doc
error: cannot deliver document snapshot: document exceeds the 1048576-byte safety bound
rc=1
=== boundary: exactly 1048576-byte doc
rc=0
=== adversarial: doc outside data/
error: cannot deliver document snapshot: document must be a non-hidden path under this home's data directory
rc=1
=== adversarial: symlinked doc
error: cannot deliver document snapshot: [Errno 40] Too many levels of symbolic links: 'link.md'
rc=1
=== adversarial: parent snapshot destination corrupted (hardlink) before local receive
error: cannot deliver document snapshot: snapshot destination is unsafe
rc=1
--- parent status line count (expect 2: report + max):
2
done [corr=0123456789abcdef] [at=1794062015]: see report (report=data/report-snapshots/c9b74676bbcdde0cab750bf093c8d2b44a497d18272a26ab96a3099e43cc101f.md source-host=firstmate-hz source-home=/tmp/fm-
done [corr=0123456789abcdef] [at=1794062016]: max (report=data/report-snapshots/9bc1b2a288b26af7257a36277ae3816a7d4f16e89c1e7e77d0a5c48bad62b360.md source-host=firstmate-hz source-home=/tmp/fm-docsnap
--- mate source docs unmodified:
c9b74676bbcdde0cab750bf093c8d2b44a497d18272a26ab96a3099e43cc101f  /tmp/fm-docsnap.AyTTFL/mate/data/x/report.md
Evidence: Remote 1 MiB snapshot offer transcript

Source: Remote 1 MiB snapshot offer transcript

report rc=0
done [corr=0123456789abcdef] [at=1794062024]: max remote (report=data/report-snapshots/e56ec8dc1862be6c09c53620cbc0f00f639de2a51c882745fbbc4e144714b3c2.md source-host=firstmate-hz source-home=/tmp/fm-docsnap.GWXBY4/r sou
remote-file get rc=0 bytes=1048576
Evidence: tests/fm-remote-reply.test.sh log

Source: tests/fm-remote-reply.test.sh log

ok - default delta reader waits 0.5 seconds then delivers a non-destructive complete-line delta
ok - override delta reader waits 0.07 seconds then delivers a non-destructive complete-line delta
ok - remote reply adapter leaves no temporary path or lifecycle lock behind on any exit
ok - transport failures and non-schema diagnostics stay out of captured results
ok - a blocking non-destructive remote delta reaches durable process-event capture
ok - a captured delta is applied, acknowledged, and re-armed without a handler
ok - ingest appends one validated line, fetches its document, and advances the cursor
ok - replayed capture has one deduplicated append and one durable handling identity
ok - later generations cannot invalidate an unacknowledged ingested result
ok - the remote status and decision model mirrors and the cursor advances
ok - a remote mate's new decision folds open exactly as a local mate's does
ok - a replayed mirrored delta is idempotent in both the stream and the cursor
ok - transported control bytes are normalized in place and never stop the stream
ok - payload protocol-field names cannot collide with transport metadata
ok - NUL bytes are normalized in place before shell line processing
ok - local document storage failures remain retryable until delivery succeeds
ok - a structured pointer must end at its token boundary
ok - adjacent pointers are fetched while malformed tokens remain unchanged
ok - a rejected candidate never gives the following text a false leading boundary
ok - nested remote reports relay while an undeliverable foreign pointer fails open
ok - the reported incident raises no standing decision and still delivers the report
ok - an undeliverable structured offer fails open with one note and never a decision
ok - a remote refusal surfaces its own reason without opening a decision
ok - a failed pointer extraction never commits a partial delta
ok - a failed mirror write never drops status content or advances the cursor
ok - source-line identity survives commit failure and cursor-loss recapture
ok - a mirrored reserved-key line cannot squat or clear the parent's own decision
ok - a reply that arrives after escalation resolves it and clears the open decision
ok - a remote reply listener stays owned across empty waits and a delta
ok - a failed remote read exits instead of relistening
ok - persistent ingestion failure leaves exactly one durable capture
ok - a preempted reply poll reports a closed window without publishing channel freshness
ok - a preempted reply poll keeps its listener and reconcile launches nothing
ok - a quiet reply window publishes the caught-up watermark the reply guard reads
ok - a cursor-loss whole-log recapture is acknowledged quietly with no duplicate wake
ok - truncation is detected, escalated once, and not silently rebased
ok - a repeated continuity break after an operator resolve appends nothing
ok - remote reply retirement quiesces and refuses unhandled captured results
ok - a later continuity break after repair and re-advance opens the decision again
ok - an old-format continuity line does not swallow the next break
ok - a later continuity break after the cursor moves without retirement opens the decision again
ok - a continuity break after retirement and an identical restore opens the decision once
ok - a failed cursor removal does not increase the retirement count
ok - a retirement that stops after removing the cursor leaves the old count
ok - deterministic snapshot refusals fail open instead of blocking the stream
ALL TESTS PASSED
exit=0
Evidence: tests/fm-classify-corr-token.test.sh log

Source: tests/fm-classify-corr-token.test.sh log

ok - captain regex overrides preserve timed and legacy relevance and event bytes
ok - malformed event times stay ordinary line bytes without hiding the event
ok - malformed event times never open or close a decision
ok - optional event time preserves parsing and legacy unknown time
ok - a correlation token between the verb and the key breaks neither opening nor closing
ok - the token is read through before the key, after it, doubled, bracketed, and unkeyed
ok - the untokened opener/closer pair behaves exactly as before
ok - prose, malformed, wrong-length and unknown name=value tokens stay non-transitions
ok - a token-first line cannot impersonate any opening or closing verb
ok - untokened captain-relevance, pause, terminal-verb and captain-held verdicts are unchanged
ok - captain-relevance, terminal-verb, pause and captain-held all read through the token
ok - the daemon and crew-state verb case arms read through the token
ok - reading through the token does not weaken the reserved-key namespace rule
ok - the cursor-backed fold and the whole-file fold agree on every correlated transition
ok - a cursor persisted under the previous reading is discarded and refolded
ok - both real correlation-token writers produce lines this classifier reads through
exit=0

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 warning
  • ⚠️ bin/fm-procevent-remote-reply.sh:681 - A missing or refused data/report-snapshots/* pointer kills the whole ingest. The intent asks only to withhold "the correlated answer". This change withholds every line in the delta. Because the cursor stays put, it also withholds every later delta from that mate: other corr answers, new decisions, and progress lines. Failures that can never succeed on retry go down the same path. Example: a mate echoes a plain status line with report=data/report-snapshots/notes.md. fetch_document (line 467) returns 'invalid required snapshot digest' with rc=1, and the ingest stops at the die on line 683. The same happens when the snapshot is permanently gone, for example after the remote home is pruned or recreated. It also happens when receive's check_content refuses the bytes at the parent but not at the mate, which version skew between the remote root and the parent root can cause. Each case blocks the mate's reply stream until someone runs retire --force. The firstmate does see the unhandled capture, so this is not silent. Remedy: let a deterministic refusal (bad digest name or content refusal) fall back to the fail-open note, and keep the retryable stop only for transport-level or missing-file cases. Another option is to withhold only the correlated line. Any remedy that needs new skip or escalation state extends the design, so it needs the author's decision. The remedy is what needs authorization, not the defect.
  • ⚠️ bin/fm-document-snapshot.sh:69 - The credential-content heuristic in check_content refuses ordinary technical prose, and the caller has no way to override it. For example, these patterns match 'Authorization: Bearer header is required', 'token: the corr id', 'secret: none' and 'api_key = see vault'. The control-byte check refuses carriage returns (\x0d), so any CRLF Markdown file is rejected with 'contains control bytes'. The path regex on line 131 refuses names such as data/tokenizer-plan.md or data/x.keynote.md. receive (line 159) runs the same content check again at the parent. So if the two machines' firstmate versions disagree on the patterns, a snapshot the mate already captured can never be received. That feeds the stream block in the snapshot-head-of-line-wedge finding. The intent says callers deliver reviewed non-secret documents. It does not require automated credential scanning. Simplification remedy: drop the content and path credential heuristics, or at least drop the content check from receive, where the digest already pins the reviewed bytes. Alternatively, narrow them to high-precision patterns such as private-key headers and AKIA/ghp_/sk- prefixes.
  • ℹ️ bin/fm-document-snapshot.sh:126 - capture computes os.path.relpath(path, realpath(FM_HOME)) without resolving the absolute document path's directory. If FM_HOME contains a symlink component (for example a homes/ symlink or macOS /tmp -> /private/tmp), passing "$FM_HOME/data/x.md" turns into '../..' and is refused as 'non-hidden path under this home's data directory'. fm-secondmate-report.sh passes the unresolved FM_HOME as HOME_DIR, so callers naturally build such paths. Fix: resolve os.path.dirname(path) with realpath before computing relpath, and keep the final component unresolved so O_NOFOLLOW still applies.

🔧 Fix applied.
3 issues (2 warnings, 1 info) still open:

  • ⚠️ bin/fm-procevent-remote-reply.sh:681 - A missing or refused data/report-snapshots/* pointer kills the whole ingest. The intent asks only to withhold "the correlated answer". This change withholds every line in the delta. Because the cursor stays put, it also withholds every later delta from that mate: other corr answers, new decisions, and progress lines. Failures that can never succeed on retry go down the same path. Example: a mate echoes a plain status line with report=data/report-snapshots/notes.md. fetch_document (line 467) returns 'invalid required snapshot digest' with rc=1, and the ingest stops at the die on line 683. The same happens when the snapshot is permanently gone, for example after the remote home is pruned or recreated. It also happens when receive's check_content refuses the bytes at the parent but not at the mate, which version skew between the remote root and the parent root can cause. Each case blocks the mate's reply stream until someone runs retire --force. The firstmate does see the unhandled capture, so this is not silent. Remedy: let a deterministic refusal (bad digest name or content refusal) fall back to the fail-open note, and keep the retryable stop only for transport-level or missing-file cases. Another option is to withhold only the correlated line. Any remedy that needs new skip or escalation state extends the design, so it needs the author's decision. The remedy is what needs authorization, not the defect.
  • ⚠️ bin/fm-document-snapshot.sh:69 - The credential-content heuristic in check_content refuses ordinary technical prose, and the caller has no way to override it. For example, these patterns match 'Authorization: Bearer header is required', 'token: the corr id', 'secret: none' and 'api_key = see vault'. The control-byte check refuses carriage returns (\x0d), so any CRLF Markdown file is rejected with 'contains control bytes'. The path regex on line 131 refuses names such as data/tokenizer-plan.md or data/x.keynote.md. receive (line 159) runs the same content check again at the parent. So if the two machines' firstmate versions disagree on the patterns, a snapshot the mate already captured can never be received. That feeds the stream block in the snapshot-head-of-line-wedge finding. The intent says callers deliver reviewed non-secret documents. It does not require automated credential scanning. Simplification remedy: drop the content and path credential heuristics, or at least drop the content check from receive, where the digest already pins the reviewed bytes. Alternatively, narrow them to high-precision patterns such as private-key headers and AKIA/ghp_/sk- prefixes.
  • ℹ️ bin/fm-procevent-remote-reply.sh:504 - The round-1 fix gave exit status 3 opposite meanings in two places. In fm-document-snapshot.sh, 3 means a permanent content refusal, so the adapter fails open. In the adapter, SNAPSHOT_UNVERIFIED=3 means a retryable stop. fetch_document compares the helper's status against a bare literal 3 (line 504) and then returns SNAPSHOT_UNVERIFIED, which is also 3. The behavior is correct today. A later edit that writes -ne &#34;$SNAPSHOT_UNVERIFIED&#34; here because it looks consistent would silently swap fail-open and retry. Fix: name the helper's status in the adapter, for example SNAPSHOT_CONTENT_REFUSED=3, and compare against that name.

🔧 Fix applied.
1 warning still open:

  • ⚠️ bin/fm-document-snapshot.sh:69 - The credential-content heuristic in check_content refuses ordinary technical prose, and the caller has no way to override it. For example, these patterns match 'Authorization: Bearer header is required', 'token: the corr id', 'secret: none' and 'api_key = see vault'. The control-byte check refuses carriage returns (\x0d), so any CRLF Markdown file is rejected with 'contains control bytes'. The path regex on line 131 refuses names such as data/tokenizer-plan.md or data/x.keynote.md. receive (line 159) runs the same content check again at the parent. So if the two machines' firstmate versions disagree on the patterns, a snapshot the mate already captured can never be received. That feeds the stream block in the snapshot-head-of-line-wedge finding. The intent says callers deliver reviewed non-secret documents. It does not require automated credential scanning. Simplification remedy: drop the content and path credential heuristics, or at least drop the content check from receive, where the digest already pins the reviewed bytes. Alternatively, narrow them to high-precision patterns such as private-key headers and AKIA/ghp_/sk- prefixes.

🔧 No changes applied.
1 warning still open:

  • ⚠️ bin/fm-document-snapshot.sh:69 - The credential-content heuristic in check_content refuses ordinary technical prose, and the caller has no way to override it. For example, these patterns match 'Authorization: Bearer header is required', 'token: the corr id', 'secret: none' and 'api_key = see vault'. The control-byte check refuses carriage returns (\x0d), so any CRLF Markdown file is rejected with 'contains control bytes'. The path regex on line 131 refuses names such as data/tokenizer-plan.md or data/x.keynote.md. receive (line 159) runs the same content check again at the parent. So if the two machines' firstmate versions disagree on the patterns, a snapshot the mate already captured can never be received. That feeds the stream block in the snapshot-head-of-line-wedge finding. The intent says callers deliver reviewed non-secret documents. It does not require automated credential scanning. Simplification remedy: drop the content and path credential heuristics, or at least drop the content check from receive, where the digest already pins the reviewed bytes. Alternatively, narrow them to high-precision patterns such as private-key headers and AKIA/ghp_/sk- prefixes.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Local mate runs fm-secondmate-report.sh --doc on data/x/report.md, and the parent home gets a byte-identical content-addressed snapshot plus a correlated line with host, home and document-path provena… ✅ pass live local-doc-delivery-transcript.txt: sha256 of source and parent snapshot match, cmp identical, status line has source-host/source-home/source-document/document-bytes
Local delivery verifies before appending: a hardlinked (unsafe) parent snapshot destination makes --doc fail and no report line is appended ✅ pass live local-doc-delivery-transcript.txt: 'snapshot destination is unsafe' rc=1, and the parent status still has exactly 2 lines
Size boundary: an exactly 1048576-byte doc is delivered and a 1048577-byte doc is refused with no report ✅ pass live local-doc-delivery-transcript.txt boundary sections; remote-1mib-offer-transcript.txt shows the 1 MiB remote offer reads back fully
Capture guards: a doc outside data/ and a symlinked doc are refused ✅ pass live local-doc-delivery-transcript.txt adversarial sections, each rc=1
Remote delivery: a missing or corrupt snapshot holds back the correlated answer and leaves the cursor in place, a restored snapshot then delivers the exact bytes with provenance, and a replay does not… ✅ pass live bash tests/fm-remote-reply.test.sh -> remote-reply.log exit=0
Deterministic refusals (invalid digest name, credential content) fail open with a note instead of blocking the mate's reply stream ✅ pass live remote-reply.log: 'deterministic snapshot refusals fail open instead of blocking the stream'
  • bash tests/fm-classify-corr-token.test.sh (exit 0)
  • bash tests/fm-remote-reply.test.sh (exit 0, ALL TESTS PASSED, including 48-byte and 300000-byte snapshot missing/corrupt/retry/replay and the deterministic-refusal fail-open block)
  • Manual local-route drive: disposable parent and mate homes with route=local, FM_HOME=mate bin/fm-secondmate-report.sh --doc done &lt;corr&gt; data/x/report.md, then sha256/cmp of source vs parent snapshot and inspection of parent state/pinned.status
  • Manual local-route guard cases: 1048577-byte doc, exactly 1048576-byte doc, path outside data/, symlinked doc, hardlinked parent snapshot destination
  • Manual remote-route offer: 1048576-byte doc via fm-secondmate-report.sh --doc on a route=remote home, then fm-remote-file.sh get &lt;snapshot&gt; 1048576 read-back
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

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

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (1) · Last reviewed commit: "no-mistakes(lint): Quote done verb in sy..." · Reviewed by Greptile

@tiago-peixoto

Copy link
Copy Markdown
Contributor Author

Speaking as Tiago's agent... Closing this one for now: it adds a new feature without a triaged issue behind it, which does not fit how this lane's other changes have moved, and the branch stays available if an issue for verified document snapshots is opened and marked ready-for-pr first.

tiago-peixoto added a commit to tiago-peixoto/firstmate that referenced this pull request Nov 18, 2026
…t-PR branch PRs (#120)

* fix(bin): treat a declared wait as a standing declaration, not the log's last event

`state/<id>.status` is an append-only event log, and every declared-wait
gate read it last-event-wins. A worker that appended `paused: <external
wait>` kept its wedge-alarm suppression only until the next line landed,
from anyone: its own armed background reporter, a pipeline step notice, a
firstmate note. That line became the newest event, current state flipped
away from the declaration, the possible-wedge ladder restarted from zero,
and nothing reported that the suppression had been voided.

`status_standing_wait_line` in `bin/fm-classify-lib.sh` folds the log the
way keyed decisions are already folded: a `paused:` or `captain-held:` line
declares the wait, and only a line the worker writes to say its situation
changed - `done`, `needs-decision`, `blocked`, `failed`, `resolved`, or a
replacing declaration - retracts it. `working:`, `note:` and free-text
prose leave it standing. A `resolved` line retracts a pause only when it
carries the pause's own phase key, where a keyless line is its own phase
distinct from a stated `[key=default]`, matching upstream's
`status_declared_wait_line`; a captain hold is retracted by any `resolved`
line because the hold waits on firstmate's answer. Every declared-wait
gate reads that fold: `fm-crew-state.sh`, `fm-watch.sh`,
`fm-supervise-daemon.sh`, and `fm-push-transition-lib.sh`'s Herdr fast
path. The re-surface throttle is scoped to the declaration line rather
than the status-log signature. The daemon's captain-relevance and terminal
reads, and the watcher's wedge wait evidence, keep upstream's
`status_declared_wait_line` read.

Fork patch F6. Tracks kunchenguid#2713 (open); upstream PR
kunchenguid#4811 proposes a narrower cadence fix for the same
issue. Rebuilt on upstream a8572f6, whose 5587 introduced
`status_declared_wait_line` at these gates; each conflicting gate keeps
the standing fold on top of upstream's surrounding change.

Upstream issue: kunchenguid#2713 (open)
Upstream PR: kunchenguid#4811 (open)
(cherry picked from commit 4bfc53c)

* feat(spawn): lease Treehouse copies for the task lifetime

A process-bound `treehouse get` hold lapses when no process remains in
the copy, so a later `get` could be handed a live task's recorded
worktree while that task was merely idle between turns. Its next
relaunch, teardown, or worktree read then pointed at someone else's work.

Fresh ship and scout Treehouse spawns now acquire the copy with
`treehouse get --lease --lease-holder <task-id>` from the spawning
project instead of opening a process-bound subshell in the pane. A
leased worktree is never handed out by a later `get` and never removed by
prune, even with no process running inside it, until `treehouse return` -
and teardown returns it only after the landed-work test passes.

After acquiring, spawn refuses a copy that another live task in this home
or any locally registered home already records, including pre-lease tasks
whose hold has lapsed; a relaunch of the same task reuses the copy its own
record names. The pane is then seated with a top-level `cd` into the
leased path and polled until two consecutive reads agree on it. The
pool-slot ownership claim is kept alongside the lease, because that
marker is what teardown reads to leave a reassigned slot untouched.
Upstream spawn fixtures are taught the lease so tests added after this
patch keep passing.

The occupancy walk reuses upstream's fm_local_firstmate_state_dirs, the
same local-home set teardown reads, and a spawn that aborts before any
lease was armed skips the lease return.

Fork patch. Tracks kunchenguid#2754, kunchenguid#1924 and kunchenguid#947 (all
open); the upstream PR that carried this design, kunchenguid#2760, was closed by
its own author on 2026-09-21, not declined by the maintainer.

Upstream issue: kunchenguid#2754 (open); also kunchenguid#1924 and kunchenguid#947 (open)
Upstream PR: kunchenguid#2760 (closed unmerged by its author; the open issues above still track the defect)
(cherry picked from commit eacfbf4)

* fix(bin): lease a secondmate's worktree from its own clone (#64)

* fix(bin): lease a secondmate's worktree from its own clone

Treehouse names a pool by directory name and origin URL, not by clone
path, so a secondmate home's clone of a project shares the pool of the
main home's clone of the same origin. A spawn from the secondmate home
was handed a copy linked to the main home's clone, and Claude trust
pre-registration refused it ("is not a worktree of project"), so no
claude worker could start there.

Acquisition now holds such a copy leased while it retries, so Treehouse
cannot hand it out again and creates a copy from the spawning clone,
then returns the held copies. The trust refusal is unchanged for fresh
spawns. A relaunch of a task already recorded in another clone's copy
of the same origin registers trust against that clone, so existing work
can move to claude; an unrelated repository's copy is still refused.

Refs kunchenguid#4348

* test(pi): stop a killed fork from deleting the dead-lock fixture

The free-or-dead-lock case made its dead pid with `sleep 30 &` followed
at once by `kill`. A TERM that reaches the forked child before it drops
the suite's TERM trap runs fm_test_cleanup there, and the child shares
the suite's cleanup registry, so it deleted the fixture root while the
test kept running. CI saw the second extension load fail with
ERR_MODULE_NOT_FOUND. A child that exits on its own yields a dead pid
without sending any signal.

Upstream issue: kunchenguid#4348 (open)
Fork PR: #64
(cherry picked from commit 8cef12e)

* fix(bin): refresh the watcher beacon between slow poll phases (#65)

* fix(bin): refresh the watcher beacon between slow poll phases

A round of checks can outlast the liveness grace while the watcher is
still moving, so a live watcher is reported dead.
kunchenguid#5408

* fix(bin): treat a beacon generation change as the next poll

Mid-cycle liveness touches moved the beacon mtime during a slow round, so a cycle wait reaped the watcher before wedge classification.

Upstream issue: kunchenguid#5408 (open)
Fork PR: #65
Includes the wedge-suite fixture correction from fork PR #100 (fork commit 44a9daa), which reads a completed watcher poll from the beacon's generation rather than its modification time, because this carry refreshes that time between slow phases.
(cherry picked from commit c01eae6)

* fix(bin): carry the machine-capacity rule in every ship and scout brief (#76)

* fix(bin): carry the machine-capacity rule in every ship and scout brief

Ship and scout briefs said nothing about the heavy-run slots that every
Firstmate home on a machine shares, so each home hand-wrote its own copy
of the rule. One copy named a slot by a bare suffix, which two lanes
resolved to two different paths: each held a genuine lock and both ran
heavy suites at once.

fm-brief.sh now emits one "# Machine capacity" section in ship and scout
briefs. It spells each of this home's slot paths in full, in claim order,
states the 1-minute load bar, and sends every claim through the new
bin/fm-heavy-slot.sh. The helper claims a slot by one atomic mkdir of its
full path, records the task and a pid that lives for the whole heavy
command, and releases only the task's own slot. The slot list and load
bar come from config/heavy-suite-slots and config/heavy-suite-load.

* fix(bin): leave a project's own slot-claiming suite script unwrapped

A project on this server runs its full suite through its own script,
which claims a heavy slot by itself. Wrapped in fm-heavy-slot.sh as the
brief directed, that script would wait on the slot its own wrapper
already holds. The capacity rule now tells the worker to run such a
script as the project says instead.

Upstream issue: kunchenguid#4453 (open; a full-check limit for parallel workers on one machine)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #76
(cherry picked from commit d6d65e4)

Current successor: kunchenguid#8006 (open).

* fix(bin): serve heavy-slot waiters in arrival order and show live holders (#77)

Heavy-slot admission was bare mkdir contention, so a home whose tasks
released and retook a slot faster than another home polled could keep
it indefinitely. A waiter could not tell that starvation from honest
queuing behind working holders either: the owner pid was its only
liveness evidence, and a suite's short-lived processes leave any one pid
dead while the suite still works.

fm-heavy-slot.sh now refreshes the owner file's time while the command
runs, so its age shows a working holder even between a suite's
processes. Waiters keep a refreshed ticket in a queue beside the slots,
and a free slot goes to the longest live waiter that may use it. The new
status subcommand reads each slot as working, between commands, idle, or
stale, and the brief escalates only a holder not shown to be working.

Upstream issue: kunchenguid#4453 (open)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #77
(cherry picked from commit 27b3cc2)

Current successor: kunchenguid#8006 (open).

* fix(bin): let firstmate clear an abandoned heavy slot only on positive evidence (#78)

* test(heavy-slot): end fake suites when a failed test removes their directory

Two fake suites in tests/fm-heavy-slot.test.sh wait for a "go" file that
only the passing path creates. When a test failed first, the test root was
removed but the suite kept polling for a file that could no longer appear,
so it ran until someone killed it and held any pipe on the test's output
open. Each loop now also ends once its case directory is gone.

* fix(bin): let firstmate clear an abandoned heavy slot only on positive evidence

Nothing could tell an abandoned heavy slot from one whose suite still ran.
The owner pid is the launcher's, and a wrapper killed outright leaves its
suite running under other pids, so a sweep keyed on a dead pid would clear
a live slot and start a second suite beside it. Slots on this machine also
came in older shapes, plain files and bare-pid owner lines, that status
lumped together as unreadable.

fm-heavy-slot.sh run now exports FM_HEAVY_SLOT_HELD=<slot>:<task> into the
heavy command, so every process the suite starts carries the claim's mark.
The new clear subcommand is for firstmate only and removes one slot only
when the record is past its bound, no recorded pid is alive, no live
process carries the mark, and no no-mistakes pipeline step runs. It checks
the record's age last, so a slot claimed again during the scans is left
alone. Status now names plain-file claims and legacy owner lines, and the
brief tells workers that only firstmate clears a slot.

* fix(bin): refuse to clear a heavy slot the helper did not mark

clear derived a claim's mark from its owner line, so a claim written by
hand in that shape, or one with no pid at all, looked as if no process
carried its mark and cleared on age alone. All three slots live on this
machine today are hand-made claims, and one records no pid, so a suite
running under it would have been invisible to every check.

Every claim fm-heavy-slot.sh makes now holds a mark file, and run exports
that file's line as the mark. clear trusts only that file; any other claim
is refused unless firstmate passes --owner-ended after confirming the
owning task has ended, and the recorded-pid, pipeline-step, and age checks
still apply.

Upstream issue: kunchenguid#4453 (open)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #78
(cherry picked from commit 9430517)

Current successor: kunchenguid#8006 (open).

On macOS, clear refuses occupied slots even with --owner-ended because ps can hide a live process environment. The protected-process regression fails before this guard and passes afterward. Ordinary claim, run, and owner release are unchanged.

* fix(bin): relaunch a gone herdr worker into its own presentation space (#79)

When fm-control relaunch re-created a worker whose Herdr pane was gone,
fm-spawn always used the flat per-home container. A second mate runs
fm-control from its own pane, so the replacement tab landed inside the
second mate's own workspace instead of a presentation space of its own.

The rebind now follows the fresh-spawn placement rules in the recorded
session: the projected create moves into spawn_herdr_projection_create,
shared by both paths. A journal whose token workspace is positively gone
is retired first; a space that is still present or unreadable is left
untouched and the replacement falls back flat with a warning. A projected
replacement also gets the projection's abort cleanup.

tests/fm-control-relaunch.test.sh reproduces the defect against a
stateful stand-in Herdr. tests/fm-control-herdr-relaunch-space-e2e.test.sh
checks the same placement against real Herdr where a default session
exists, and skips elsewhere.

Upstream PR: kunchenguid#6700 (closed unmerged by its author; re-create a rebound herdr endpoint in its own presentation space)
Upstream issue: kunchenguid#5356 (open)
Fork PR: #79
Includes the Herdr fixture correction from fork PR #100 (fork commit 42f55e0): the inert opencode stand-in answers upstream's --version probe.
(cherry picked from commit 38b19bf)

* fix(bin): tell the no-mistakes validation handoff from the finished report (#86)

A no-mistakes worker was told to append done at commit time and again when
its pull request was green, so one status line could not say which event it
reported, and the handoff sentence did not name who starts the validation run.

The handoff line now opens with the fixed words 'ready for validation, not
pushed', and the instructions say that firstmate sends the /no-mistakes
instruction and the worker starts the run only then. A secondmate home no
longer publishes that handoff to its parent as finished work.

A bare done: {summary} from a worker launched on older instructions stays an
ungated handoff, as before.

Refs kunchenguid#7251

Upstream issue: kunchenguid#7251 (open)
Fork PR: #86
(cherry picked from commit 1e01205)

* fix: match Pi Codex quota accounts by recorded sign-in source (#92)

Upstream issue: kunchenguid#7483 (open)
Fork PR: #92
(cherry picked from commit 5b55c4a)

* fix(bin): read a green PR waiting on a merge as held, not finished (#75)

* fix(bin): read a green PR waiting on a merge as held, not finished

A secondmate home summary counted every in-flight child that
fm-crew-state.sh reads as done as terminal_in_flight. A no-mistakes ship
whose run passed reads done while its PR is still open and waiting on a
maintainer, so Bearings reported those homes as having unreconciled
books and the parent queued a reconcile request for each of them.

A done child whose run-step reading shows its PR still open is now a
child-state hold. Merged, closed, unknown, and status-log done readings
still count as terminal_in_flight, so a finished task that was never
cleaned up still reads as a mismatch.

* ci: expect the added Bearings regression test in the stock Bash count

The stock macOS Bash job pins the number of Bearings tests it must see.
The parked-PR regression test makes that 61.

Upstream PR: kunchenguid#7493 (open; same job), also kunchenguid#6565 (open)
Upstream issue: kunchenguid#3941 (open; related)
Fork PR: #75
(cherry picked from commit 5876427)

* fix(bin): require a handoff or disposition receipt to acknowledge a review with findings (#109)

Upstream issue: kunchenguid#8046

* fix(bin): keep a correlated reply distinct from the child's completion (#110)

Upstream issue: kunchenguid#8047

* fix(status): validate status event writes (#111)

Upstream issue: kunchenguid#8048

* fix(bin): refresh the watcher beacon between pane-scan windows (#113)

One pane scan reads every recorded window in turn. A pane seen stable for
the first time costs a current-state read, which can spend its whole
no-mistakes bound, so many windows together outlast the beacon grace while
the watcher is still working. The arm then refuses a live watcher with
"lock held by live pid ... but heartbeat is stale".

Refresh the beacon at the start of each window, as the check loop already
does between checks. One window whose reads hang past the grace still reads
stale.

Upstream issue: kunchenguid#8095

* feat(bin): deliver verified document snapshots with secondmate --doc reports (#114)

Capture document bytes before publishing a report and bind the report to their digest.
Verify remote bytes before making the snapshot available to the parent.
Preserve upstream interrupt cleanup for remote download temporary files.

Upstream PR: kunchenguid#8243
Fork PR: #114

* fix(bin): reuse unchanged pending-reply decisions within a tick (#115)

Reuse one decision fold while task status identity, contents, kind, and classification settings remain unchanged within a tick. Invalidate the cached verdict on changed evidence and keep calls outside a tick uncached.

Upstream PR: kunchenguid#8241

Fork PR: #115

* fix(bin): preserve Claude worker local settings during spawn and relaunch (#119)

* fix: preserve Claude worker settings during spawn and relaunch

* no-mistakes(test): Seed Claude worker settings from the primary clone

* no-mistakes(document): Document that local Claude settings seed workers

* fix(contributions): wake on an unanswered inline comment from an app bot

A GitHub App reviewer such as CodeRabbit posts inline findings as a Bot
account with no repository association, so the observer dropped them unless a
home listed the bot. Admit such an inline comment while its thread has no later
reply from the contribution author, and key it without the edit time so the
bot rewriting its own comment does not wake again.

* fix(pr-health): record a direct-PR ship's branch PR when no ready line names it

A direct-PR worker that reports readiness in other words, or only through a
paused merge wait, leaves no done line that a PR registration path reads, so the
task never records pr= and never arms a merge poll. The monitor already finds
the open PR on each live task copy's branch; record it through fm-pr-check.sh
for a direct-PR ship that has none. Other modes open their PR before the work
is ready, so they keep relying on their ready report.

Document both this and the app-bot inline comment admission in the
configuration reference, the script index and the ship-landing skill.

* fix(pr-health): never re-arm a merge poll on a PR whose merge was reported

After a merge the watcher retires the poll but keeps pr=, and the contribution
record can stay non-final for a pass, so branch registration skipped a PR the
merge poll already reported, as fm-pr-check.sh scan does. Also correct the
registration-scan section, which said pr= could only come from a manual run.

* ci: trigger checks after Actions were re-enabled on the fork

* no-mistakes(document): docs: state full direct-PR registration rule
tiago-peixoto added a commit to tiago-peixoto/firstmate that referenced this pull request Nov 25, 2026
…t-PR branch PRs (#120)

* fix(bin): treat a declared wait as a standing declaration, not the log's last event

`state/<id>.status` is an append-only event log, and every declared-wait
gate read it last-event-wins. A worker that appended `paused: <external
wait>` kept its wedge-alarm suppression only until the next line landed,
from anyone: its own armed background reporter, a pipeline step notice, a
firstmate note. That line became the newest event, current state flipped
away from the declaration, the possible-wedge ladder restarted from zero,
and nothing reported that the suppression had been voided.

`status_standing_wait_line` in `bin/fm-classify-lib.sh` folds the log the
way keyed decisions are already folded: a `paused:` or `captain-held:` line
declares the wait, and only a line the worker writes to say its situation
changed - `done`, `needs-decision`, `blocked`, `failed`, `resolved`, or a
replacing declaration - retracts it. `working:`, `note:` and free-text
prose leave it standing. A `resolved` line retracts a pause only when it
carries the pause's own phase key, where a keyless line is its own phase
distinct from a stated `[key=default]`, matching upstream's
`status_declared_wait_line`; a captain hold is retracted by any `resolved`
line because the hold waits on firstmate's answer. Every declared-wait
gate reads that fold: `fm-crew-state.sh`, `fm-watch.sh`,
`fm-supervise-daemon.sh`, and `fm-push-transition-lib.sh`'s Herdr fast
path. The re-surface throttle is scoped to the declaration line rather
than the status-log signature. The daemon's captain-relevance and terminal
reads, and the watcher's wedge wait evidence, keep upstream's
`status_declared_wait_line` read.

Fork patch F6. Tracks kunchenguid#2713 (open); upstream PR
kunchenguid#4811 proposes a narrower cadence fix for the same
issue. Rebuilt on upstream a8572f6, whose 5587 introduced
`status_declared_wait_line` at these gates; each conflicting gate keeps
the standing fold on top of upstream's surrounding change.

Upstream issue: kunchenguid#2713 (open)
Upstream PR: kunchenguid#4811 (open)
(cherry picked from commit 4bfc53c)

* feat(spawn): lease Treehouse copies for the task lifetime

A process-bound `treehouse get` hold lapses when no process remains in
the copy, so a later `get` could be handed a live task's recorded
worktree while that task was merely idle between turns. Its next
relaunch, teardown, or worktree read then pointed at someone else's work.

Fresh ship and scout Treehouse spawns now acquire the copy with
`treehouse get --lease --lease-holder <task-id>` from the spawning
project instead of opening a process-bound subshell in the pane. A
leased worktree is never handed out by a later `get` and never removed by
prune, even with no process running inside it, until `treehouse return` -
and teardown returns it only after the landed-work test passes.

After acquiring, spawn refuses a copy that another live task in this home
or any locally registered home already records, including pre-lease tasks
whose hold has lapsed; a relaunch of the same task reuses the copy its own
record names. The pane is then seated with a top-level `cd` into the
leased path and polled until two consecutive reads agree on it. The
pool-slot ownership claim is kept alongside the lease, because that
marker is what teardown reads to leave a reassigned slot untouched.
Upstream spawn fixtures are taught the lease so tests added after this
patch keep passing.

The occupancy walk reuses upstream's fm_local_firstmate_state_dirs, the
same local-home set teardown reads, and a spawn that aborts before any
lease was armed skips the lease return.

Fork patch. Tracks kunchenguid#2754, kunchenguid#1924 and kunchenguid#947 (all
open); the upstream PR that carried this design, kunchenguid#2760, was closed by
its own author on 2026-09-21, not declined by the maintainer.

Upstream issue: kunchenguid#2754 (open); also kunchenguid#1924 and kunchenguid#947 (open)
Upstream PR: kunchenguid#2760 (closed unmerged by its author; the open issues above still track the defect)
(cherry picked from commit eacfbf4)

* fix(bin): lease a secondmate's worktree from its own clone (#64)

* fix(bin): lease a secondmate's worktree from its own clone

Treehouse names a pool by directory name and origin URL, not by clone
path, so a secondmate home's clone of a project shares the pool of the
main home's clone of the same origin. A spawn from the secondmate home
was handed a copy linked to the main home's clone, and Claude trust
pre-registration refused it ("is not a worktree of project"), so no
claude worker could start there.

Acquisition now holds such a copy leased while it retries, so Treehouse
cannot hand it out again and creates a copy from the spawning clone,
then returns the held copies. The trust refusal is unchanged for fresh
spawns. A relaunch of a task already recorded in another clone's copy
of the same origin registers trust against that clone, so existing work
can move to claude; an unrelated repository's copy is still refused.

Refs kunchenguid#4348

* test(pi): stop a killed fork from deleting the dead-lock fixture

The free-or-dead-lock case made its dead pid with `sleep 30 &` followed
at once by `kill`. A TERM that reaches the forked child before it drops
the suite's TERM trap runs fm_test_cleanup there, and the child shares
the suite's cleanup registry, so it deleted the fixture root while the
test kept running. CI saw the second extension load fail with
ERR_MODULE_NOT_FOUND. A child that exits on its own yields a dead pid
without sending any signal.

Upstream issue: kunchenguid#4348 (open)
Fork PR: #64
(cherry picked from commit 8cef12e)

* fix(bin): refresh the watcher beacon between slow poll phases (#65)

* fix(bin): refresh the watcher beacon between slow poll phases

A round of checks can outlast the liveness grace while the watcher is
still moving, so a live watcher is reported dead.
kunchenguid#5408

* fix(bin): treat a beacon generation change as the next poll

Mid-cycle liveness touches moved the beacon mtime during a slow round, so a cycle wait reaped the watcher before wedge classification.

Upstream issue: kunchenguid#5408 (open)
Fork PR: #65
Includes the wedge-suite fixture correction from fork PR #100 (fork commit 44a9daa), which reads a completed watcher poll from the beacon's generation rather than its modification time, because this carry refreshes that time between slow phases.
(cherry picked from commit c01eae6)

* fix(bin): carry the machine-capacity rule in every ship and scout brief (#76)

* fix(bin): carry the machine-capacity rule in every ship and scout brief

Ship and scout briefs said nothing about the heavy-run slots that every
Firstmate home on a machine shares, so each home hand-wrote its own copy
of the rule. One copy named a slot by a bare suffix, which two lanes
resolved to two different paths: each held a genuine lock and both ran
heavy suites at once.

fm-brief.sh now emits one "# Machine capacity" section in ship and scout
briefs. It spells each of this home's slot paths in full, in claim order,
states the 1-minute load bar, and sends every claim through the new
bin/fm-heavy-slot.sh. The helper claims a slot by one atomic mkdir of its
full path, records the task and a pid that lives for the whole heavy
command, and releases only the task's own slot. The slot list and load
bar come from config/heavy-suite-slots and config/heavy-suite-load.

* fix(bin): leave a project's own slot-claiming suite script unwrapped

A project on this server runs its full suite through its own script,
which claims a heavy slot by itself. Wrapped in fm-heavy-slot.sh as the
brief directed, that script would wait on the slot its own wrapper
already holds. The capacity rule now tells the worker to run such a
script as the project says instead.

Upstream issue: kunchenguid#4453 (open; a full-check limit for parallel workers on one machine)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #76
(cherry picked from commit d6d65e4)

Current successor: kunchenguid#8006 (open).

* fix(bin): serve heavy-slot waiters in arrival order and show live holders (#77)

Heavy-slot admission was bare mkdir contention, so a home whose tasks
released and retook a slot faster than another home polled could keep
it indefinitely. A waiter could not tell that starvation from honest
queuing behind working holders either: the owner pid was its only
liveness evidence, and a suite's short-lived processes leave any one pid
dead while the suite still works.

fm-heavy-slot.sh now refreshes the owner file's time while the command
runs, so its age shows a working holder even between a suite's
processes. Waiters keep a refreshed ticket in a queue beside the slots,
and a free slot goes to the longest live waiter that may use it. The new
status subcommand reads each slot as working, between commands, idle, or
stale, and the brief escalates only a holder not shown to be working.

Upstream issue: kunchenguid#4453 (open)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #77
(cherry picked from commit 27b3cc2)

Current successor: kunchenguid#8006 (open).

* fix(bin): let firstmate clear an abandoned heavy slot only on positive evidence (#78)

* test(heavy-slot): end fake suites when a failed test removes their directory

Two fake suites in tests/fm-heavy-slot.test.sh wait for a "go" file that
only the passing path creates. When a test failed first, the test root was
removed but the suite kept polling for a file that could no longer appear,
so it ran until someone killed it and held any pipe on the test's output
open. Each loop now also ends once its case directory is gone.

* fix(bin): let firstmate clear an abandoned heavy slot only on positive evidence

Nothing could tell an abandoned heavy slot from one whose suite still ran.
The owner pid is the launcher's, and a wrapper killed outright leaves its
suite running under other pids, so a sweep keyed on a dead pid would clear
a live slot and start a second suite beside it. Slots on this machine also
came in older shapes, plain files and bare-pid owner lines, that status
lumped together as unreadable.

fm-heavy-slot.sh run now exports FM_HEAVY_SLOT_HELD=<slot>:<task> into the
heavy command, so every process the suite starts carries the claim's mark.
The new clear subcommand is for firstmate only and removes one slot only
when the record is past its bound, no recorded pid is alive, no live
process carries the mark, and no no-mistakes pipeline step runs. It checks
the record's age last, so a slot claimed again during the scans is left
alone. Status now names plain-file claims and legacy owner lines, and the
brief tells workers that only firstmate clears a slot.

* fix(bin): refuse to clear a heavy slot the helper did not mark

clear derived a claim's mark from its owner line, so a claim written by
hand in that shape, or one with no pid at all, looked as if no process
carried its mark and cleared on age alone. All three slots live on this
machine today are hand-made claims, and one records no pid, so a suite
running under it would have been invisible to every check.

Every claim fm-heavy-slot.sh makes now holds a mark file, and run exports
that file's line as the mark. clear trusts only that file; any other claim
is refused unless firstmate passes --owner-ended after confirming the
owning task has ended, and the recorded-pid, pipeline-step, and age checks
still apply.

Upstream issue: kunchenguid#4453 (open)
Upstream PR for the same job: kunchenguid#7614 (closed unmerged; superseded)
Fork PR: #78
(cherry picked from commit 9430517)

Current successor: kunchenguid#8006 (open).

On macOS, clear refuses occupied slots even with --owner-ended because ps can hide a live process environment. The protected-process regression fails before this guard and passes afterward. Ordinary claim, run, and owner release are unchanged.

* fix(bin): relaunch a gone herdr worker into its own presentation space (#79)

When fm-control relaunch re-created a worker whose Herdr pane was gone,
fm-spawn always used the flat per-home container. A second mate runs
fm-control from its own pane, so the replacement tab landed inside the
second mate's own workspace instead of a presentation space of its own.

The rebind now follows the fresh-spawn placement rules in the recorded
session: the projected create moves into spawn_herdr_projection_create,
shared by both paths. A journal whose token workspace is positively gone
is retired first; a space that is still present or unreadable is left
untouched and the replacement falls back flat with a warning. A projected
replacement also gets the projection's abort cleanup.

tests/fm-control-relaunch.test.sh reproduces the defect against a
stateful stand-in Herdr. tests/fm-control-herdr-relaunch-space-e2e.test.sh
checks the same placement against real Herdr where a default session
exists, and skips elsewhere.

Upstream PR: kunchenguid#6700 (closed unmerged by its author; re-create a rebound herdr endpoint in its own presentation space)
Upstream issue: kunchenguid#5356 (open)
Fork PR: #79
Includes the Herdr fixture correction from fork PR #100 (fork commit 42f55e0): the inert opencode stand-in answers upstream's --version probe.
(cherry picked from commit 38b19bf)

* fix(bin): tell the no-mistakes validation handoff from the finished report (#86)

A no-mistakes worker was told to append done at commit time and again when
its pull request was green, so one status line could not say which event it
reported, and the handoff sentence did not name who starts the validation run.

The handoff line now opens with the fixed words 'ready for validation, not
pushed', and the instructions say that firstmate sends the /no-mistakes
instruction and the worker starts the run only then. A secondmate home no
longer publishes that handoff to its parent as finished work.

A bare done: {summary} from a worker launched on older instructions stays an
ungated handoff, as before.

Refs kunchenguid#7251

Upstream issue: kunchenguid#7251 (open)
Fork PR: #86
(cherry picked from commit 1e01205)

* fix: match Pi Codex quota accounts by recorded sign-in source (#92)

Upstream issue: kunchenguid#7483 (open)
Fork PR: #92
(cherry picked from commit 5b55c4a)

* fix(bin): read a green PR waiting on a merge as held, not finished (#75)

* fix(bin): read a green PR waiting on a merge as held, not finished

A secondmate home summary counted every in-flight child that
fm-crew-state.sh reads as done as terminal_in_flight. A no-mistakes ship
whose run passed reads done while its PR is still open and waiting on a
maintainer, so Bearings reported those homes as having unreconciled
books and the parent queued a reconcile request for each of them.

A done child whose run-step reading shows its PR still open is now a
child-state hold. Merged, closed, unknown, and status-log done readings
still count as terminal_in_flight, so a finished task that was never
cleaned up still reads as a mismatch.

* ci: expect the added Bearings regression test in the stock Bash count

The stock macOS Bash job pins the number of Bearings tests it must see.
The parked-PR regression test makes that 61.

Upstream PR: kunchenguid#7493 (open; same job), also kunchenguid#6565 (open)
Upstream issue: kunchenguid#3941 (open; related)
Fork PR: #75
(cherry picked from commit 5876427)

* fix(bin): require a handoff or disposition receipt to acknowledge a review with findings (#109)

Upstream issue: kunchenguid#8046

* fix(bin): keep a correlated reply distinct from the child's completion (#110)

Upstream issue: kunchenguid#8047

* fix(status): validate status event writes (#111)

Upstream issue: kunchenguid#8048

* fix(bin): refresh the watcher beacon between pane-scan windows (#113)

One pane scan reads every recorded window in turn. A pane seen stable for
the first time costs a current-state read, which can spend its whole
no-mistakes bound, so many windows together outlast the beacon grace while
the watcher is still working. The arm then refuses a live watcher with
"lock held by live pid ... but heartbeat is stale".

Refresh the beacon at the start of each window, as the check loop already
does between checks. One window whose reads hang past the grace still reads
stale.

Upstream issue: kunchenguid#8095

* feat(bin): deliver verified document snapshots with secondmate --doc reports (#114)

Capture document bytes before publishing a report and bind the report to their digest.
Verify remote bytes before making the snapshot available to the parent.
Preserve upstream interrupt cleanup for remote download temporary files.

Upstream PR: kunchenguid#8243
Fork PR: #114

* fix(bin): reuse unchanged pending-reply decisions within a tick (#115)

Reuse one decision fold while task status identity, contents, kind, and classification settings remain unchanged within a tick. Invalidate the cached verdict on changed evidence and keep calls outside a tick uncached.

Upstream PR: kunchenguid#8241

Fork PR: #115

* fix(bin): preserve Claude worker local settings during spawn and relaunch (#119)

* fix: preserve Claude worker settings during spawn and relaunch

* no-mistakes(test): Seed Claude worker settings from the primary clone

* no-mistakes(document): Document that local Claude settings seed workers

* fix(contributions): wake on an unanswered inline comment from an app bot

A GitHub App reviewer such as CodeRabbit posts inline findings as a Bot
account with no repository association, so the observer dropped them unless a
home listed the bot. Admit such an inline comment while its thread has no later
reply from the contribution author, and key it without the edit time so the
bot rewriting its own comment does not wake again.

* fix(pr-health): record a direct-PR ship's branch PR when no ready line names it

A direct-PR worker that reports readiness in other words, or only through a
paused merge wait, leaves no done line that a PR registration path reads, so the
task never records pr= and never arms a merge poll. The monitor already finds
the open PR on each live task copy's branch; record it through fm-pr-check.sh
for a direct-PR ship that has none. Other modes open their PR before the work
is ready, so they keep relying on their ready report.

Document both this and the app-bot inline comment admission in the
configuration reference, the script index and the ship-landing skill.

* fix(pr-health): never re-arm a merge poll on a PR whose merge was reported

After a merge the watcher retires the poll but keeps pr=, and the contribution
record can stay non-final for a pass, so branch registration skipped a PR the
merge poll already reported, as fm-pr-check.sh scan does. Also correct the
registration-scan section, which said pr= could only come from a manual run.

* ci: trigger checks after Actions were re-enabled on the fork

* no-mistakes(document): docs: state full direct-PR registration rule
Upstream issue: maps to kunchenguid#8753 (app-bot inline comments)
Upstream issue: maps to kunchenguid#8754 (direct-PR branch PR record)
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