Skip to content

feat: act on captain's away words during AFK supervision - #5076

Merged
kunchenguid merged 5 commits into
mainfrom
fm/fm-afk-words-execute-r1
Sep 20, 2026
Merged

kunchenguid merged 5 commits into
mainfrom
fm/fm-afk-words-execute-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

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:

  • Slice 2 model: "W: words as the record; plain-sentence read-back; the session acts on the words by judgment under existing authority; no clause fields, ids, or clause log"
  • What stays mechanical while away: "Any green merge while the away record exists; the session's reading of the words decides which; task-id grant list retired"
  • Go: "Slice 2: go"

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

  • Replace structured clauses and task-specific merge grants with a version 2 AFK record that preserves the captain’s words verbatim while remaining compatible with version 1 records.
  • Teach away supervision to interpret those words at each wake, act through existing guarded authority, and report instruction-driven actions in the return brief.
  • Allow any green, synchronous merge while the away record is active, retain red-merge protections, and permit dispatch of queued work filed directly from the recorded instructions.

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.

  • Live validation: ⚠️ inconclusive - 4 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Captain enters multiline words with trailing blank lines and receives a plain-language read-back before confirmation ✅ pass live AFK live product transcript, scenario 1; persisted byte dump ends in 0a 0a and the confirmation announces hold-for-return behavior.
Damaged v2 and legacy v1 words tails fail validation, and damaged v2 state cannot be archived ✅ pass live AFK live product transcript, scenario 2; both versions report invalid words block, and archive exits nonzero while retaining the record.
Legacy v1 records remain readable while clause and grant sections are ignored ⏸️ untested no The prior payload cited only 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…
Return brief reproduces the captain's words and accounts only outcomes carrying the exact canonical action marker ✅ pass live AFK live product transcript, scenario 3; the exact-colon outcome appears under the action account while the colonless near miss does not.
Real Pi away mode records posture without a daemon or pane injection and gates return until remediation ✅ pass live FM_AFK_PI_HERDR_E2E=1 tests/fm-afk-pi-herdr-return-e2e.test.sh in a guarded non-default Herdr lab.
While an away record exists, any green synchronous merge can proceed, but red, allow-red, asynchronous, unlocked, or unreadable-record paths refuse ⏸️ untested no The prior payload cited only tests/fm-pr-merge.test.sh with isolated fixtures, which did not establish a live product result. Exercise the merge matrix through the real public merge entrypoint with…
Away supervision receives the verbatim words tail and the emitted branch prompt remains byte-stable ⏸️ untested no The prior payload cited only branch extension and supervision test scripts, which did not establish a live product result. Run an actual away-supervision flow and capture the received words tail and e…
Retired clause fields, grants, and related subcommands are rejected through public entrypoints ⏸️ untested no The prior payload cited only contract and launch test scripts, which did not establish a live product result. Invoke the retired fields, grants, and subcommands through the real public product entrypo…
Evidence: Real Pi/Herdr away-return lifecycle
ok - real Pi primary: the away posture is recorded with no daemon launched
ok - real Pi/Herdr: nothing injects into the captain pane under the away posture
ok - real unmarked Pi return renders the brief, opens catch-up, and reports that posture through Bearings while the blocker stays Firstmate's to remediate
ok - resolved return catch-up allows Bearings and a clean idempotent away re-entry
herdr=0.9.0 pi=0.85.1
Evidence: AFK live product transcript

Source: AFK live product transcript

SCENARIO 1 — captain enters verbatim away words and confirms the plain-language read-back
$ fm-afk-contract.sh propose --words-file words.txt --expected-return 2026-09-21T08:00Z --spend 2
Away posture read-back (proposed, not yet confirmed):
  entered: 2026-09-20T21:34:37Z
  expected return: 2026-09-21T08:00Z
  spend cap: 2 concurrent workers
  reach: hold-for-return only. No phone channel is configured; anything that needs you waits for your return.
  your words (verbatim):
    merge the windows fix when green, then cut a prerelease
    
Say go to confirm; restate your instructions first if this reading is not what you meant.

$ fm-afk-contract.sh confirm
Away posture confirmed at 2026-09-20T21:34:37Z: hold-for-return only. No phone channel is configured; anything that needs you waits for your return. Your away instructions are recorded verbatim; the away session will carry them out where it can, and anything it is unsure of, or that needs you, waits for your return. Destructive, irreversible, and security-sensitive actions are never pre-authorizable, whatever the words say. Expected return: 2026-09-21T08:00Z. Spend cap: 2 concurrent workers.

Persisted words bytes (od -An -tx1; final 0a 0a proves both trailing newlines):
           6d  65  72  67  65  20  74  68  65  20  77  69  6e  64  6f  77
           73  20  66  69  78  20  77  68  65  6e  20  67  72  65  65  6e
           2c  20  74  68  65  6e  20  63  75  74  20  61  20  70  72  65
           72  65  6c  65  61  73  65  0a  0a                            


SCENARIO 2 — damaged v2 and v1 words tails are rejected rather than silently truncated
$ fm-afk-contract.sh validate  # damaged v2
fm-afk-contract: record ~/.no-mistakes/worktrees/016d88035d58/01M3092XBFQFWA9M1TXSEBEPNJ/.test-afk-live-39216/state/.afk-contract has an invalid words block: the line after the stored words is neither a stored line nor a section this record version ends the block at: hold B until I return
exit=1
$ fm-afk-contract.sh archive   # damaged v2
fm-afk-contract: record ~/.no-mistakes/worktrees/016d88035d58/01M3092XBFQFWA9M1TXSEBEPNJ/.test-afk-live-39216/state/.afk-contract has an invalid words block: the line after the stored words is neither a stored line nor a section this record version ends the block at: hold B until I return
fm-afk-contract: confirmed away-posture record at ~/.no-mistakes/worktrees/016d88035d58/01M3092XBFQFWA9M1TXSEBEPNJ/.test-afk-live-39216/state/.afk-contract is invalid; refusing to archive
exit=1
$ fm-afk-contract.sh validate  # damaged v1 before recognized clauses section
fm-afk-contract: record ~/.no-mistakes/worktrees/016d88035d58/01M3092XBFQFWA9M1TXSEBEPNJ/.test-afk-live-39216/state/.afk-contract has an invalid words block: the line after the stored words is neither a stored line nor a section this record version ends the block at: hold B until I return
exit=1

SCENARIO 3 — return brief shows verbatim instructions and only exact action-marker outcomes
$ fm-afk-return.sh begin
fm-afk-launch: away-posture record archived at ~/.no-mistakes/worktrees/016d88035d58/01M3092XBFQFWA9M1TXSEBEPNJ/.test-afk-live-39216/state/afk-contracts/1789940078.afk-contract
fm-afk-launch: away mode stopped; daemon terminal torn down, .afk cleared, and the posture record archived
=== Return brief (away 2026-09-20T21:34:38Z -> 2026-09-20T21:34:39Z, 1s) ===
Supervisor health:
  - supervision ran through the away window with no detected gap (watcher beat 0s old at return)
Your instructions:
  your words at entry:
    merge the windows fix when green, then cut a prerelease
    
  the away session acted on them:
    - windows: per your away instructions: merged the windows fix after checks went green
Waiting on you:
  (nothing)
Tried and failed, or could not be fixed:
  (nothing)
Handled while away:
  2 outcome(s) handled by the away session (2 routine, 0 escalated above)
  2 routine outcome(s) recorded; the latest:
    - windows: per your away instructions were unclear, so I held
    - windows: per your away instructions: merged the windows fix after checks went green
Cost: 2 supervision outcome(s) recorded (2 routine, 0 captain); 0 task(s) live at return.
catch-up health: supervision ran through the away window with no detected gap (watcher beat 0s old at return)
fm-afk-return: catch-up clear; ordinary captain work may proceed
- Outcome: ⚠️ 1 warning across 1 run (20m18s)

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 as deploy A\n\n reach the away session as deploy A, altering the whole mandate it must judge. Preserve rendered.stdout unchanged; 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 exact per your away instructions: marker contract. For example, a non-action summary per your away instructions were unclear, so I held is 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 B is parsed as only merge 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.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (4 of 8 scenarios were driven live against the product); untested: Legacy v1 records remain readable while clause and grant sections are ignored, While an away record exists, any green synchronous merge can proceed, but red, allow-red, asynchronous, unlocked, or unreadable-record paths refuse, Away supervision receives the verbatim words tail and the emitted branch prompt remains byte-stable, Retired clause fields, grants, and related subcommands are rejected through public entrypoints
  • Live validation: ⚠️ inconclusive - 4 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Captain enters multiline words with trailing blank lines and receives a plain-language read-back before confirmation ✅ pass live AFK live product transcript, scenario 1; persisted byte dump ends in 0a 0a and the confirmation announces hold-for-return behavior.
Damaged v2 and legacy v1 words tails fail validation, and damaged v2 state cannot be archived ✅ pass live AFK live product transcript, scenario 2; both versions report invalid words block, and archive exits nonzero while retaining the record.
Legacy v1 records remain readable while clause and grant sections are ignored ⏸️ untested no The prior payload cited only 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…
Return brief reproduces the captain's words and accounts only outcomes carrying the exact canonical action marker ✅ pass live AFK live product transcript, scenario 3; the exact-colon outcome appears under the action account while the colonless near miss does not.
Real Pi away mode records posture without a daemon or pane injection and gates return until remediation ✅ pass live FM_AFK_PI_HERDR_E2E=1 tests/fm-afk-pi-herdr-return-e2e.test.sh in a guarded non-default Herdr lab.
While an away record exists, any green synchronous merge can proceed, but red, allow-red, asynchronous, unlocked, or unreadable-record paths refuse ⏸️ untested no The prior payload cited only tests/fm-pr-merge.test.sh with isolated fixtures, which did not establish a live product result. Exercise the merge matrix through the real public merge entrypoint with…
Away supervision receives the verbatim words tail and the emitted branch prompt remains byte-stable ⏸️ untested no The prior payload cited only branch extension and supervision test scripts, which did not establish a live product result. Run an actual away-supervision flow and capture the received words tail and e…
Retired clause fields, grants, and related subcommands are rejected through public entrypoints ⏸️ untested no The prior payload cited only contract and launch test scripts, which did not establish a live product result. Invoke the retired fields, grants, and subcommands through the real public product entrypo…
  • tests/fm-afk-contract.test.sh
  • tests/fm-afk-return.test.sh
  • tests/fm-pr-merge.test.sh
  • bash tests/fm-pi-branch-extension.test.sh
  • bash tests/fm-branch-supervision.test.sh
  • tests/fm-afk-launch.test.sh rerun from a detached neutral tmux session; the direct invocation inherited Pi ancestry and correctly refused daemon-only cases
  • FM_AFK_PI_HERDR_E2E=1 tests/fm-afk-pi-herdr-return-e2e.test.sh
  • bash tests/fm-contributions.test.sh
  • bash tests/fm-pr-check-security.test.sh
  • Manual isolated product flow through bin/fm-afk-contract.sh, bin/fm-branch-outcome.sh, and bin/fm-afk-return.sh capturing entry, corruption refusal, archival refusal, and return rendering
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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.
@kunchenguid
kunchenguid merged commit dee119b into main Sep 20, 2026
19 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-afk-words-execute-r1 branch September 20, 2026 22:22
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