Repository navigation
feat: act on captain's away words during AFK supervision - #5076
Merged
Merged
Conversation
Retire the clause fields, verb list, never-set scan, refused records, and the per-task merge-grant list from the away-posture record. The record is now version 2: the captain's words verbatim plus expected return, spend cap, and reach line; a version 1 record still validates, reads, and archives so a live away window is never broken by the upgrade. The supervision branch reads the words at the tail of every wake and acts on them by its own judgment through the guarded scripts under standing authority, never by analogy, holding for the return on doubt, and opens each such outcome summary with "per your away instructions:" so the return brief can render the words beside the session's account. While the record exists any green merge runs under away authority (ledger tag "away"); red merges, --allow-red, asynchronous and queued merges, and local-only landing stay refused. The branch may file a backlog item the words explicitly call for before dispatching it under the spend cap. Tests drive fm-afk-contract.sh, fm-afk-launch.sh, fm-afk-return.sh, and fm-pr-merge.sh as commands: version 2 written, version 1 read, retired flags and subcommands refused by name, green merges landing under the record, red and waived-red refused, the record lock still closing the authority-read window, and the Pi away tail carrying the words.
dscott98
added a commit
to Simplifying-Cloud/firstmate
that referenced
this pull request
Sep 21, 2026
* fix(bin): preserve Claude lock ownership after helper recycling (kunchenguid#4894) * fix(bin): let a background Claude session keep owning its session lock Session-lock ownership was decided by process ancestry alone. Under an unattended Claude session the model loop runs in a transient bg-spare bridged to the front-end by a shared daemon; when that bridge is recycled the contiguous claude-named ancestry from a hook to the recorded owner breaks while the owner pid stays alive, so the Stop auto-arm stood down as a foreign live owner, the turn-end guard ended every turn with its read-only diagnostic, and fm-lock.sh refused - a self-sustaining outage until restart. Ownership is now ancestry membership OR a trusted same-session id, never id-first: - fm-session-lock-lib.sh accepts CLAUDE_CODE_SESSION_ID only when CLAUDE_PID is a Claude-shaped member of the current contiguous run, compares it against the id recorded in state/.lock-session, and requires the recorded pid to still be a live harness. No id, no sidecar, an untrusted id, a different id, or a dead recorded pid leaves the ancestry verdict unchanged. Ids are never read from ps argv. - fm-lock.sh accepts a same-session holder at both refusal sites, writes, refreshes, and clears the sidecar only under its claim lock (including the early already-mine exit, skipped only while the deferred startup sweep leases that lock), keeps it byte-identical across a same-session confirmation, records CLAUDE_PID on lock line 1 for a session with a trusted id so a shared daemon or front-end that outlives the session never keeps a dead session's lock alive, never rewrites a live line 1 on a same-session confirmation, and names the recorded id in the live-owner refusal. - The .lock line-1 format is unchanged, so every reader that takes the whole first line as the pid keeps working; the guard's foreign-owner exit is unchanged and inherits the fix through the shared predicate. Tests: the ancestry suite drives the ancestry and id signals apart in a deterministic process table (asserting the divergence) and runs a real orphaned front-end/daemon/pty-host/spare tree through six phases with the real lock, auto-arm, and guard scripts; the foreign-owner repro keeps its negative control and adds a same-id positive control. Disclosure: no live unattended Claude background session ran on the verifying machine. The topology is documented by the real process listings in kunchenguid#3902, kunchenguid#2314, kunchenguid#3398, and kunchenguid#4066; coverage is the structural predicate plus the executable fixtures, not a live pass. Residual: bin/fm-sessionstart-nudge.sh keeps its own private ancestry walk (it only decides whether to print a nudge) and may nudge on a resume
Intent
Rework AFK away-mode so the captain's away words are the whole mandate: recorded verbatim, restated back in plain sentences at entry, and acted on by the away supervision session's own judgment at the moment an event makes them relevant - instead of the current clause/grant apparatus. This is slice 2 of the captain-approved AFK revamp, decided on a Lavish review board on 2026-09-20.
The captain's verbatim decisions that shape this task:
The full, authoritative design is in data/fm-afk-slices23-plan-s1/report.md (this file survived the plan scout's teardown). Section 4 is the slice-2 spec, 4.2 is the file-by-file change, 4.4 is the one engineering default described below, 4.6 is the non-goals, and 7 is the test strategy. Read it before starting; treat it as the acceptance shape for this task.
The substance of the referenced report sections, in the captain's terms:
Section 4 principle: the away words are the whole mandate. Words in, words out: /afk records the words verbatim, firstmate restates them back in plain sentences (its own reading) so the captain can catch a misreading before saying go; no verbs, no fields, no ids, no refusals; plain /afk with no words stays a valid entry with no mandate. Judgment at execution: on every wake under the record the session reads the words at the tail, decides whether the moment has come, acts through the authority it already has, and holds with verdict captain when unsure; a mirrored captain sentence still authorizes nothing new once the record exists. Mechanical only where words are not needed: a script keeps enforcing exactly what it can check without reading words - green at the live head and head-bound, synchronous merge only under the record lock, the spend cap for fresh spawns, the never-set, no --allow-red while away, local-only landing never relocated. The task-id merge-grant list is retired: while the record exists any green PR may merge, and which one the words meant is the session's reading.
Section 4.2, file by file, one PR: bin/fm-afk-contract.sh retires --action/--object/--when/--stop, the verb list, the never-set scan, clauses: and refused: records, merge_grants: and --grant, and the clauses, flags, refused, grants subcommands; keeps words, expected_return, spend_max_concurrent_workers, reach_, confirmed, validate, readback (now the words verbatim plus the spend cap, expected return, and reach line), archive, the proposal flow, and the cross-subsystem lock; bumps to version 2 while a v1 record still validates and reads with its clause and grant sections ignored, so a live away window is never broken by an upgrade; header rewritten: the record is the words, execution is the session's judgment. bin/fm-afk-launch.sh propose takes only --words-file/--words, --expected-return, --spend. The afk skill: entering records the words, runs propose, relays firstmate's own plain-sentence restatement (not a numbered field list), confirms on go; while away the session acts on the words; announcement is hold-for-return, no phone, "your instructions are recorded and the away session will carry them out where it can; anything it is unsure of, or that needs you, waits for your return"; remove "recorded clauses are not executed". bin/fm-branch-prompt.sh Postures section replaces "a recorded clause is a fact, not authority" with the execution rules: the words are the captain's explicit instruction given before leaving; act on them through the guarded scripts under standing authority; a merge the words call for proceeds when green; work the words call for is dispatched; a run the words say to abort is steered; a decision the words pre-answer is answered through --resolve-key under ask-user-authority; never by analogy; hold on doubt with verdict captain; the never-set is absolute; the words die at archive; log every action taken under the words in the outcome summary ("per your away instructions: ..."). bin/fm-pr-merge.sh removes require_away_merge_grant and the grant read; require_current_away_authority keeps the record lock, the synchronous-only rule, the --allow-red refusal, and the queue refusal; the ledger tag becomes away instead of away-grant/yolo. bin/fm-afk-return.sh: the clause section becomes "your instructions" (the words verbatim) followed by the session's account: every outcome-store row from the window whose summary cites the instructions, then what is waiting, failed, handled, cost, unchanged. bin/fm-lease-lib.sh: no change. docs/pi-supervision-branch.md Postures, docs/architecture.md, and the AGENTS.md section 8 stub: wording; reword the three "deferred to phase 4" comments to "deferred, no owner". Tests: the contract test (v2 record, v1 still validates, no clause subcommands), the launch test, the return test, the merge test (the away matrix becomes record-present-and-green merges, record-present-and-red refuses, --allow-red refused, archive restores attended), the Pi branch extension test (the tail carries the words), the branch supervision prompt byte-identity test, and the pr-check-security and contributions grant fixtures.
Section 4.4 engineering default (the recommended option): the away session may file a backlog work item when the words explicitly call for that work (for example "cut a prerelease after the merge"), writing the brief's intent from the words for that step, then dispatch it under the spend cap; fm-spawn's queued-only rule for the branch becomes "queued, or filed by the branch from the away words", a one-line relaxation plus a backlog note citing the words. Filing the item the captain explicitly asked for is not inventing work.
Section 4.6 non-goals: no parser, tokenizer, classifier, or grammar over the words; no fields, verbs, ids, or clause log; no named-check red merge while away, no local-only landing relocation, no discard, no phone reach; no fm_lease_justify, --clause, --posture, --citation, fm-afk-alarm.sh; no change to bin/fm-lease-lib.sh; no mechanical gate that tries to tell a never-set decision from an ordinary one; the three "phase 4" deferrals in landed comments (archive-chain identity, same-second session identity, per-blocker decision provenance in the return gate) are not adopted, and the PR rewords those comments so the code stops naming a task that will not exist.
Section 7 test strategy: behavioral, through public entrypoints only, per the repo rule against source-text tests. Drive fm-afk-contract.sh and fm-afk-return.sh as commands and assert records and rendered output (v2 written, v1 still read); drive fm-pr-merge.sh with the existing forge mocks for the record-present matrix (green merges, red refuses, --allow-red refused, archive restores attended); pin the prompt through the existing byte-identity test and the Pi extension's tail test.
What Changed
Risk Assessment
✅ Low: The approved authority-model change is consistently implemented across record parsing, wake delivery, merge gating, return reporting, documentation, and behavioral tests, with the prior fix-round regressions correctly addressed.
Testing
Live evidence supports multiline entry, corruption refusal, return accounting, and the real Pi/Herdr away-return lifecycle. The remaining four scenarios were supported only by automated tests in the prior payload, not live product interaction, so the overall result is inconclusive.
0a 0aand the confirmation announces hold-for-return behavior.invalid words block, and archive exits nonzero while retaining the record.tests/fm-afk-contract.test.sh, which did not establish a live product result. Drive a legacy v1 record through the real public product entrypoint and capture its rendere…FM_AFK_PI_HERDR_E2E=1 tests/fm-afk-pi-herdr-return-e2e.test.shin a guarded non-default Herdr lab.tests/fm-pr-merge.test.shwith isolated fixtures, which did not establish a live product result. Exercise the merge matrix through the real public merge entrypoint with…Evidence: Real Pi/Herdr away-return lifecycle
Evidence: AFK live product transcript
Source: AFK live product transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (3) ✅
.pi/extensions/fm-branch-supervision.ts:1448- Intent requires the wake tail to carry the captain's words verbatim, but.trim()removes trailing spaces and blank lines from the rendered read-back. For example, words recorded asdeploy A\n\nreach the away session asdeploy A, altering the whole mandate it must judge. Preserverendered.stdoutunchanged; the remedy needs confirmation because this contradicts the authoritative verbatim requirement.🔧 Fix applied.
1 warning still open:
bin/fm-afk-return.sh:395- The return brief accepts a case-insensitive prefix without the required colon, exceeding the exactper your away instructions:marker contract. For example, a non-action summaryper your away instructions were unclear, so I heldis incorrectly reported as an action. The unnecessary case-insensitive alias is also encoded at tests/fm-afk-return.test.sh:401. Remove the alias and match the complete canonical marker exactly.🔧 Fix applied.
1 error still open:
bin/fm-afk-contract.sh:256- A damaged multi-line words block can validate while silently dropping the rest of the captain's mandate. For example, if the stored second line loses its two-space prefix,words: |-\n merge A\nhold Bis parsed as onlymerge A: the generic top-level match exits successfully once one line was read, so validation passes and the truncated read-back reaches the away session at .pi/extensions/fm-branch-supervision.ts:1448. This can omit a hold or condition before an otherwise mechanically permitted merge. Make the boundary version-aware (only recognized v1 legacy sections may terminate v1 words; v2 words run to EOF) and reject every other unprefixed line. Related changed paths also suppress word-reader failures with a sentinel and must propagate them: bin/fm-afk-contract.sh:328, bin/fm-afk-contract.sh:342, and bin/fm-afk-return.sh:380.🔧 Fix applied.
✅ Re-checked - no issues remain.
0a 0aand the confirmation announces hold-for-return behavior.invalid words block, and archive exits nonzero while retaining the record.tests/fm-afk-contract.test.sh, which did not establish a live product result. Drive a legacy v1 record through the real public product entrypoint and capture its rendere…FM_AFK_PI_HERDR_E2E=1 tests/fm-afk-pi-herdr-return-e2e.test.shin a guarded non-default Herdr lab.tests/fm-pr-merge.test.shwith isolated fixtures, which did not establish a live product result. Exercise the merge matrix through the real public merge entrypoint with…tests/fm-afk-contract.test.shtests/fm-afk-return.test.shtests/fm-pr-merge.test.shbash tests/fm-pi-branch-extension.test.shbash tests/fm-branch-supervision.test.shtests/fm-afk-launch.test.shrerun from a detached neutral tmux session; the direct invocation inherited Pi ancestry and correctly refused daemon-only casesFM_AFK_PI_HERDR_E2E=1 tests/fm-afk-pi-herdr-return-e2e.test.shbash tests/fm-contributions.test.shbash tests/fm-pr-check-security.test.shManual isolated product flow throughbin/fm-afk-contract.sh,bin/fm-branch-outcome.sh, andbin/fm-afk-return.shcapturing entry, corruption refusal, archival refusal, and return rendering✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.