Skip to content

fix(afk): gate the away entry on the fleet lock and name its live holder - #7624

Open
kesslerio wants to merge 15 commits into
kunchenguid:mainfrom
kesslerio:fix/7034-afk-fleet-lock-entry
Open

kesslerio wants to merge 15 commits into
kunchenguid:mainfrom
kesslerio:fix/7034-afk-fleet-lock-entry

Conversation

@kesslerio

@kesslerio kesslerio commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • fm-afk-launch.sh enter now refuses to write an away record when the session is read-only, i.e. inspection proves another live session holds the fleet lock, naming that holder's pid, live process start time, and age; quiet entries are settled first and never take the check, and stopping the holder is never automatic.
  • The check lives in the record writer (bin/fm-afk-contract.sh), which holds the fleet lock's acquisition boundary (state/.lock.acquire) across the check and the write, so a concurrent acquisition cannot overtake the verdict; bin/fm-session-lock-lib.sh now owns that boundary path and the may-record/holder-naming helpers, and bin/fm-lock.sh reads the path from it.
  • bin/fm-session-start.sh names the live lock holder in its read-only digest and offers the two choices (stop that session yourself, or keep this one read-only), with matching updates in the afk skill and docs/configuration.md, docs/architecture.md, docs/scripts.md.

Risk Assessment

✅ Low: The change is bounded, serializes away-entry authorization against lock acquisition, and preserves the explicitly accepted ownership and quiet-mode rules; no material defects were substantiated.

Testing

Drove the real product end-to-end in throwaway marked lab homes and through the changed paths' behavior suites. A live foreign session-shaped process recorded in state/.lock makes bin/fm-afk-launch.sh enter --words ... and a direct bin/fm-afk-contract.sh enter refuse with the holder's pid, live process start time, and age, leaving no away record; the same holder leaves the quiet entry free to record quiet mode; a dead pid in state/.lock does not block the away entry; a standing away record keeps its own mode and its away write is refused under the holder. The acquisition-boundary serialization and the fail-closed holder-summary cases were driven by the suite tests that execute the real contract script against a synthetic acquisition actor and a stubbed holder summary, and the read-only session-start digest (real bin/fm-session-start.sh with a synthetic process table) names the live holder and offers both choices while naming nothing for this session's own lock. Two failures in suites I ran are host-bound and pre-existing: the pty reparent-to-pid-1 e2e in fm-session-lock-ancestry.test.sh and the Windows-tagged supervision-host case in fm-supervision-host-park.test.sh; both reproduce from the base-commit tree, so they are not attributable to this change. One observed edge worth knowing, though consistent with the entry-wide refusal the docs describe: a no-words refresh (readback) of a standing away record is also refused while a foreign live holder holds the lock; the record is untouched and its mode unchanged. No UI surface exists for this CLI change, so the reviewer-visible artifacts are CLI transcripts and test logs.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
A read-only session's away entry (fm-afk-launch.sh enter --words) is refused while another live session holds the fleet lock, the refusal names that holder's pid, live process start time and age, an… ✅ pass live live-afk-entry-transcript.log: another live firstmate session holds the lock (pid 2507554, started Mon Nov 9 20:00:56 2026, age 00:01) ..., rc=1, record present: no; afk-launch-test.log `ok - ente…
A quiet entry still succeeds for a read-only session while another live session holds the fleet lock, recording quiet mode rather than being refused ✅ pass live live-afk-entry-transcript.log (launcher run with FM_AFK_MODE=quiet under the same live holder: rc=0, recorded mode: quiet, recorded words: quiet down); afk-launch-test.log `ok - enter: quiet mode…
The record writer itself refuses an away mandate when called directly (bypassing the launcher) while a live foreign session holds the fleet lock ✅ pass live live-afk-entry-transcript.log: direct bin/fm-afk-contract.sh enter --words 'bypass the launcher' prints the holder refusal, rc=1, record present: no; afk-launch-test.log `ok - enter: the record wr…
A lock with no proven live holder (stale pid, free or unclassifiable lock) never blocks the away entry ✅ pass live live-afk-entry-transcript.log: state/.lock = 999999 after the holder exited, enter --words 'merge it when green' rc=0, record present, recorded mode: away; afk-launch-test.log `ok - enter: a sta…
An away entry that starts while another session is inside a fleet-lock acquisition waits for the acquisition boundary and then refuses, naming the holder it acquired behind (check and write are one cr… ✅ pass live afk-launch-test.log ok - away write: an entry started on a free lock waits for the acquisition in flight instead of writing the mandate and `ok - away write: the entry refuses once the serialized ac…
A held lock whose holder details cannot be produced still refuses the away write instead of failing open ✅ pass live afk-launch-test.log ok - away write: a held lock is refused even when holder details cannot be produced with the message `another live firstmate session holds the lock (pid win:123, started unknown;…
A read-only session start names the live lock holder with pid, process start time and age, offers the two choices (stop that session and start a new one, or keep this session read-only), and stops not… ✅ pass live session-start-test2.log ok - a read-only session names the live lock holder with its pid, start time, and age, and offers the two choices (test_read_only_session_names_the_live_lock_holder; asserts…
A read-only session start does not name its own live lock as another session's holder, so the digest never tells the operator to stop their own process ✅ pass live session-start-test2.log ok - a read-only session does not name its own live lock as another session's holder (test_read_only_session_does_not_name_its_own_lock_as_another_session)
A standing away record keeps its own mode for a quiet caller, and that away write is refused under a live foreign holder (existing refresh/mode rules preserved) ✅ pass live afk-launch-test.log ok - enter: a quiet-mode caller on a home holding an away record still writes an away mandate, so the live lock holder refuses that write too; live-afk-refresh-transcript.log sho…
Evidence: Live CLI transcript: away refusal, quiet entry with the same live holder, direct record-writer refusal, stale-lock allow (marked disposable lab homes)

Source: Live CLI transcript: away refusal, quiet entry with the same live holder, direct record-writer refusal, stale-lock allow (marked disposable lab homes)

== lab home: /tmp/fm-lab.kWD8qQ (marked disposable)
== foreign live lock holder pid: 2507554
== state/.lock content: 2507554
== ps of the holder: Mon Nov 9 20:00:56 2026 00:00

$ bin/fm-afk-launch.sh enter --words 'merge it when green'   # away entry, live foreign holder
another live firstmate session holds the lock (pid 2507554, started Mon Nov 9 20:00:56 2026, age 00:01); this session does not own the fleet lock, so it must not record a mandate it cannot carry out. Stopping the holder is a decision for the operator, never for this script.
rc=1
record present: no

$ bin/fm-afk-launch.sh enter --words 'quiet down'  (FM_AFK_MODE=quiet)   # same live holder
Quiet mode recorded at 2026-11-10T04:00:59Z: you are present, so nothing waits for your return: every action you ask for, a local landing or a merge included, proceeds now under ordinary attended authority, and quiet mode changes only which updates reach this conversation. Only an explicit /quiet off ends it.
Quiet mode (recorded):
  entered: 2026-11-10T04:00:59Z
  holds: none - you are present, so nothing waits for your return: every action you ask for, a local landing or a merge included, proceeds now under ordinary attended authority, and quiet mode changes only which updates reach this conversation.
  your words (verbatim):
    quiet down
rc=0
record present: yes
recorded mode: quiet
recorded words: quiet down

$ bin/fm-afk-contract.sh enter --words 'bypass the launcher'   # direct record write, live holder
another live firstmate session holds the lock (pid 2507554, started Mon Nov 9 20:00:56 2026, age 00:02); this session does not own the fleet lock, so it must not record a mandate it cannot carry out. Stopping the holder is a decision for the operator, never for this script.
rc=1
record present: no

$ bin/fm-afk-launch.sh enter --words 'merge it when green'   # stale lock, no live holder
Away posture recorded at 2026-11-10T04:01:00Z: 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: not given. Spend cap: 4 concurrent workers.
Away posture (recorded):
  entered: 2026-11-10T04:01:00Z
  expected return: not given
  spend cap: 4 concurrent workers
  reach: hold-for-return only. No phone channel is configured; anything that needs you waits for your return.
  your words (verbatim):
    merge it when green
rc=0
record present: yes
recorded mode: away
recorded words: merge it when green

== done; lab homes removed by the EXIT trap
Evidence: Live CLI transcript: no-words and quiet refreshes over a standing away record under a foreign live holder (record untouched, mode away)

Source: Live CLI transcript: no-words and quiet refreshes over a standing away record under a foreign live holder (record untouched, mode away)

== lab home: /tmp/fm-lab.AwQLpN (marked disposable)
== stage a standing away record while no other session holds the lock
record present: yes
recorded mode: away
== foreign live lock holder pid: 2520897

$ bin/fm-afk-launch.sh enter   (no words: refresh over the standing away record)
another live firstmate session holds the lock (pid 2520897, started Mon Nov 9 20:03:20 2026, age 00:00); this session does not own the fleet lock, so it must not record a mandate it cannot carry out. Stopping the holder is a decision for the operator, never for this script.
rc=1
record unchanged by the refresh: yes
recorded mode after: away

$ FM_AFK_MODE=quiet bin/fm-afk-launch.sh enter   (quiet refresh over the standing away record)
another live firstmate session holds the lock (pid 2520897, started Mon Nov 9 20:03:20 2026, age 00:01); this session does not own the fleet lock, so it must not record a mandate it cannot carry out. Stopping the holder is a decision for the operator, never for this script.
rc=1
record unchanged by the quiet refresh: yes
recorded mode after: away

== done; lab home removed by the EXIT trap
Evidence: fm-afk-launch.test.sh: fleet-lock refusal, quiet exception, serialization, and fail-closed holder-summary units pass

Source: fm-afk-launch.test.sh: fleet-lock refusal, quiet exception, serialization, and fail-closed holder-summary units pass

ok - clear-stale: removes escalations buffer, sidecar, wedge marker, and unknown-wake acknowledgements
ok - clear-stale: leaves the durable wake-queue intact (no pending work dropped)
ok - enter: one call writes the record with the words, expected return, and spend cap, reads it back without asking for a go, and launches no daemon
ok - enter: the retired --grant flag is refused by name and leaves the standing record alone
ok - enter: refuses while the prior return catch-up is pending
ok - enter: refuses while another live session holds the fleet lock, names that holder's pid, start time, and age, and writes no record
ok - enter: quiet mode still enters for a read-only session while another live session holds the fleet lock
ok - enter: a quiet-mode caller on a home holding an away record still writes an away mandate, so the live lock holder refuses that write too
ok - enter: the record writer itself refuses an away mandate while another live session holds the fleet lock
ok - enter: a stale lock with no live holder does not block the away entry
ok - away write: an entry started on a free lock waits for the acquisition in flight instead of writing the mandate
ok - away write: the entry refuses once the serialized acquisition completes, naming the holder it acquired behind
ok - away write: a held lock is refused even when holder details cannot be produced
ok - propose: the retired wait-for-go step is refused by name, writes nothing, and releases the launcher lock
ok - confirm: the retired wait-for-go step is refused by name, writes nothing, and releases the launcher lock
ok - pi: start refuses to launch the daemon and writes no state
ok - pi: start-native refuses to prepare a daemon
ok - pi-signed: start refuses to launch the daemon and writes no state
ok - pi-signed: start-native refuses to prepare a daemon
ok - FM_TEST_HARNESS seam is inert without the test marker
ok - pi enter stop: reports that no daemon terminal was running
ok - daemon entry: no daemon lifecycle starts without the away-posture record
ok - daemon entry: enter then start-native run back to back with no confirmation between them
ok - failed start: preserves the posture record enter wrote
ok - stop: clears the away flag and archives the posture record under its entry time
ok - launcher paths: relative home and state ignore CDPATH before daemon command construction
ok - launcher paths: absolute symlink spellings are preserved
ok - launcher paths: unresolved relative FM_HOME fails loudly
ok - launcher paths: unresolved relative FM_STATE_OVERRIDE fails loudly
ok - refresh: daemon already alive - stale artifacts preserved (current session's buffer kept)
ok - mode: a fresh entry with FM_AFK_MODE=quiet writes quiet
ok - mode: a fresh entry with FM_AFK_MODE unset defaults to away
ok - mode: a bare refresh (FM_AFK_MODE unset) of an already-running quiet daemon preserves quiet, never resets to away
ok - start: an unset-mode quiet refresh preserves the quiet record and flag
ok - start: /afk over a running quiet daemon refreshes the flag to away
ok - start-native: an unset-mode quiet refresh preserves the quiet record and flag
ok - start-native: /afk over a running quiet daemon refreshes the flag to away
ok - mode: an empty (legacy pre-mode) flag reads as away
ok - mode: a bare-epoch-timestamp (legacy pre-mode) flag reads as away
ok - mode: unrecognized content falls back to away
ok - mode: a missing flag reads as away
ok - stop-ordering: daemon SIGTERM'd while .afk still present (flush is not a no-op)
ok - stop-ordering: .afk cleared last
ok - stop-ordering: daemon-terminal record removed
ok - stop identity: stale lock cannot signal an unrelated live process
ok - failed start: away flag and delivery artifacts roll back
ok - concurrent start: one serialized daemon terminal remains tracked
ok - launcher lock: incomplete publication receives initialization grace
ok - launcher signal: TERM exits and releases the lifecycle lock
fm-afk-launch: daemon launched in non-visible herdr workspace ws-partial (pane lab:pane-exact), supervising lab:captain
ok - herdr create: malformed response recovers durable exact ownership
fm-afk-launch: herdr create failed after returning exact ids; closing lab:pane-exact
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - herdr create error: unconfirmed exact id is persisted for reconciliation
fm-afk-launch: failed to run daemon in herdr pane lab:pane-exact; closing it
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - herdr run failure: unconfirmed exact id remains reconcilable
ok - herdr daemon terminal: runs with the captain's primary harness
ok - tmux daemon terminal: runs with the captain's primary harness
fm-afk-launch: failed to persist daemon terminal record; closing tmux:exact-session
ok - record failure: newly created terminal is closed by exact id
fm-afk-launch: daemon did not become ready; closing tmux:exact-session
ok - readiness failure: exact terminal and durable record roll back
fm-afk-launch: daemon did not become ready; closing tmux:exact-session
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - readiness failure: unconfirmed terminal retains its reconciliation id
ok - tmux absence: clean missing differs from transport probe failure
ok - native lifecycle: launcher owns state with no terminal
ok - native lifecycle: uniform stop clears state without closing a terminal
ok - supervision host: away start-native on a claude home (config file: -) refuses the daemon and keeps the record
ok - supervision host: away start-native on a claude home (config file: empty) refuses the daemon and keeps the record
ok - supervision host: quiet start-native and a plain refresh of the quiet daemon still prepare the daemon
ok - supervision host: config/supervision-host-off keeps the away daemon on a claude home
ok - supervision host: away mode on an opted-in cursor, opencode, omp, grok, codex, or agy home launches no daemon
ok - supervision host: enter names a missing engine on an opted-in home and says nothing otherwise
ok - quiet entry: the daemon-backed quiet record announces a present captain with nothing held for a return
ok - quiet entry: a later /afk entry turns the quiet record into the away posture, which holds for the return
ok - supervision host: /quiet is a statement where the attended host runs, and a quiet enter writes nothing there
ok - supervision host: quiet-check says the supervision session is paused while its latch holds, and starts nothing
ok - supervision host: quiet-check names what the attended host lacks
ok - supervision host: an unready host's quiet entry records its mode, which carries the daemon start
ok - supervision host: /quiet under a live away record refuses and names it until the return
ok - supervision host: /quiet under a live away record over a fallback quiet daemon refuses until the return
ok - supervision host: a failed quiet start archives its quiet record so the present captain is not parked
ok - supervision host: a failed away start keeps its away record
ok - native entry: launcher-prepared lifecycle state is not rewritten
fm-afk-launch: reconciling leaked daemon terminal tmux:exact-session
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - teardown failure: exact terminal record is preserved
ok - record publication: failed atomic rename preserves the complete prior record
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
ok - record read: malformed record fails closed without acting on a partial id
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
fm-afk-launch: malformed daemon terminal record; refusing to stop away mode
ok - stop: malformed terminal record preserves away state and fails closed
fm-afk-launch: failed to create detached tmux daemon session 'fm-afk-daemon-1047136617-1359606-25443-1794281909'
ok - tmux launch: planned exact target is recorded before creation and removed on failure
fm-afk-launch: failed to create detached tmux daemon session 'fm-afk-daemon-2240372183-1359641-9814-1794281909'
ok - tmux launch: unique names eliminate collision teardown
ok - stop validation: malformed record causes no daemon or state side effects
ok - launcher lock: incomplete metadata fails acquisition and releases lock
fm-afk-launch: failed to clear away-mode flag
fm-afk-launch: away mode stopped; terminal teardown or the record archive remains recorded for retry
ok - stop state: away-flag removal failure is surfaced
fm-afk-launch: away-mode daemon did not exit after SIGTERM; preserving lifecycle state
ok - stop liveness: captured live daemon preserves lifecycle state after lock release
fm-afk-launch: an away-posture record is required; run enter before starting the daemon
fm-afk-launch: an away-posture record is required; run enter before starting the daemon
ok - refresh record: malformed terminal identity fails closed
fm-afk-launch: an away-posture record is required; run enter before starting the daemon
ok - clear failure: native entry aborts and restores prior state
fm-afk-launch: reconciling leaked daemon terminal tmux:exact-session
fm-afk-launch: terminal close command failed, but exact absence was confirmed
ok - confirmed absence: cleanup succeeds and removes the stale record
fm-afk-launch: rollback restoration incomplete; backup retained at /tmp/fm-afk-restore-fail.XHCgua/state/.afk-launch-backup.pjYcuf
ok - rollback restore: incomplete restoration retains its recovery backup
fm-afk-launch: an away-posture record is required; run enter before starting the daemon
ok - flag failure: lifecycle aborts without active state
ok - herdr e2e: captain tab pane count unchanged after start (no split)
ok - herdr e2e: daemon launched in a separate non-visible workspace
ok - herdr e2e: daemon pane is NOT in the captain's tab
ok - herdr e2e: daemon terminal scoped to the lab session
ok - herdr e2e: captain tab pane count restored after stop
ok - herdr e2e: daemon workspace removed by exact id on stop
ok - herdr e2e: record + .afk cleared on stop
ok - tmux e2e: captain window pane count unchanged after start (no split-window)
ok - tmux e2e: daemon launched in a separate detached session
ok - tmux e2e: captain window pane count unchanged after stop
ok - tmux e2e: daemon session killed by exact id on stop
ok - tmux e2e: record + .afk cleared on stop
skip: rex CLI not found at $REX_BIN_DIR, on PATH, or at the server bundle path
skip: Rex CLI or jq unavailable (rex e2e)
EXIT=0
Evidence: fm-session-start.test.sh: read-only digest names the live holder with pid/start/age and offers the two choices

Source: fm-session-start.test.sh: read-only digest names the live holder with pid/start/age and offers the two choices

ok - context digest distinguishes ABSENT, empty-but-present, and populated files
ok - a lock refusal prints a loud read-only banner, skips every mutating step, and still completes the digest
ok - session start stays read-only when lock ownership cannot be published
ok - locked session start freezes trace context and lock refusal leaves it unchanged
ok - concurrent session-lock acquisition admits exactly one live harness
ok - digest sections are ordered safety-preamble first, live fleet state before curated memory
ok - the read-once contract is stated once, ahead of the sources it governs
ok - session start: configured and auto-detected Herdr homes never require tmux
ok - session start: an absent recorded tmux window relaunches its Pi secondmate exactly once, off the blocking path
ok - session start: a deferred relaunch is always reported, so the digest's stale endpoint record cannot stand
ok - session start: inactive reconciliation runs after the digest and retains its durable wake
ok - session start: an unreachable host delays a reported check, not the digest
ok - session start: a deferred result the digest outran still reaches the agent as a wake
ok - session start: a read-only session declares its skipped network checks rather than dropping them
ok - session start: the tasks-axi compatibility verdict is computed once and reused
ok - session start: an existing ambiguous Pi process prevents duplicate recovery
ok - session start: transient tmux unreadability never licenses a relaunch
ok - session start: the proven bare-shell recovery path remains intact
ok - session start: a confirmed Herdr husk is closed and relaunched
ok - status tail is bounded to the configured line count, with the full log path always printed
ok - status tail lines are capped with a truncation marker while the full log stays reachable
ok - orphan status logs are printed once with bounded tails
ok - tmux endpoint liveness is reported per task: alive for a live window, dead for a gone one
ok - herdr endpoint liveness is reported per task: alive, dead for exit 1, dead for any other probe status
_: line 4: 2030118 Killed                     "$@"
ok - a killed per-task endpoint read becomes that task's error line and the digest completes
ok - a hung per-task endpoint read hits its configured bound, reports the task, and leaves nothing stuck
Terminated                 env FM_ROOT_OVERRIDE="$FM_ROOT" FM_HOME="$FM_HOME" FM_STATE_OVERRIDE="$STATE" FM_DATA_OVERRIDE="$DATA" FM_CONFIG_OVERRIDE="$CONFIG" FM_PROJECTS_OVERRIDE="$PROJECTS" "$SCRIPT_DIR/fm-fleet-snapshot.sh" --secondmate-home-summary > "$HOME_SUMMARY_TMP" 2> "$HOME_SUMMARY_ERR_TMP"
ok - a padded-zero per-read bound falls back to the 10s default instead of removing the bound
ok - the perl timeout fallback reports a signal death as a nonzero status
Terminated                 "$@"
ok - a digest child killed mid-stage is bannered by the parent, which still exits 0
ok - fm-session-start.sh composes the real fm-lock.sh, fm-bootstrap.sh, and fm-wake-drain.sh output verbatim
ok - locked Pi session start replays leading routine outcomes, preserves the captain barrier, and sweeps only dead leases
ok - non-Pi session start neither sweeps nor replays Pi branch state
ok - session start seeds an existing outcome store's absent display tail copy while away, moving no marker
ok - compatible tasks-axi backlog rendering drops done rows and keeps every in-flight, held, and blocked row
ok - the startup backlog bound cuts only dispatchable queued rows and discloses the remainder exactly
ok - manual backlog rendering drops done rows, keeps every held or blocked title line, and bounds the rest
ok - unavailable or incompatible tasks-axi falls back to compact manual backlog rendering
ok - an empty fleet reports (none) for in-flight tasks and an absent AFK flag
ok - session start emits X-mode cadence guidance in the harness supervision block
ok - next step delegates watcher ownership to the AFK daemon
ok - next step delegates watcher ownership to the daemon in quiet mode, distinctly from away mode
ok - the AFK digest reads a quiet record as a present captain holding nothing, and an away record as hold-for-return
ok - a legacy empty .afk flag (written before mode existed) still reads as away mode
ok - session start emits exactly one detected harness block and reports Pi extension load state
ok - session start preserves pi-signed primary identity while applying Pi extension guarantees
ok - session start rejects stale Pi loaded markers
ok - session start rejects a Pi watcher generation left in handoff
ok - session start accepts current Pi markers written before lock acquisition
ok - session start emits the omp block and reports omp extension load state
ok - omp diagnostic keeps today's wording for the checkout home and names the establishable cause
ok - session start accepts current omp markers written before lock acquisition
ok - session start rejects Pi sessions missing the turn-end guard marker
ok - session start rejects Pi loaded markers from previous sessions
ok - the pure-Bash watchdog bounds session start, kills its hung grandchild, and emits the truncation contract
ok - the portable timeout path force-kills a command that ignores TERM
ok - a session start inside its budget prints no truncation banner
ok - the runtime bound leaves enough ancestry headroom for a deeply nested session to take the lock
ok - --reemit reprints the digest without repeating startup's mutating sweeps and still drains queued wakes
ok - --reemit puts its read cue in the first 2000 characters and a normal start omits it
ok - true-start AGENTS baselines stay immutable while every drifted Pi compact re-emits the current contract
ok - a read-only session names the live lock holder with its pid, start time, and age, and offers the two choices
ok - a read-only session does not name its own live lock as another session's holder
ok - read-only Pi compact refreshes against the rebuilding session identity without mutation
ok - Codex reset sources do not claim an unavailable instruction-refresh channel
ok - instruction baselines require SHA-256 and successful startup completion
ok - --reemit re-verifies lock ownership and keeps repair ownership with whoever holds it
# fm-session-start.test.sh: all assertions passed
EXIT=0
Evidence: fm-supervision-host-park.test.sh on the change: the ported enter_away_in_session fixture test passes; one Windows-tagged test fails

Source: fm-supervision-host-park.test.sh on the change: the ported enter_away_in_session fixture test passes; one Windows-tagged test fails

1..20
ok - host: two engine errors latch the session, main keeps every away wake in the cooldown, a failed probe doubles it up to its cap, and a report recovers it silently
ok - host: an attended close in a latched session reaches main as the arm printed it and leaves the latch as it was, and a home that opted out with off never reads it
ok - host: attended, two engine errors latch the session, main keeps every close unchanged in the cooldown, a failed probe doubles it up to its cap, and a routine probe's recovery stays in the ledger, off main
ok - host: an engine turn is bounded, and tool processes outside its process group are reaped
ok - host: a restarted host stops, by recorded identity, the cycle a killed predecessor left running
ok - host: an idle engine conversation is compacted once across hosts
ok - host: a conversation the next turn would not resume is not compacted
ok - host: a compaction abandoned at the park boundary is not marked done
ok - host: the park ends itself with a boundary wake and a stopped watcher
ok - host: waiting closes cannot carry the park past its boundary
ok - host: a close whose margin runs out while the successor starts reaches main at the boundary without a turn
ok - host: the park's test clock is inert without the test marker
ok - host: a park at or beyond the Stop-hook registration falls back to the default boundary
ok - host: an owner's later park limit lets a turn outlive the boundary, and no other limit does
ok - host: the first cycle's status streams once, --restart replaces a stale watcher, and an owner predecessor makes a handling successor
ok - host: an unchanged held outcome reaches the captain once across cadences, and a later decision on the task still does
ok - host: a home naming an unverified engine hands every away wake to main with the reason
ok - host: a host outside the session-lock owner stands down without arming
not ok - tagged: the host never started a watcher cycle: supervision-host stood down: this session does not own supervision
EXIT=1
Evidence: Same supervision-host-park suite from the base-commit tree: the identical Windows-tagged failure, so it pre-exists this change

Source: Same supervision-host-park suite from the base-commit tree: the identical Windows-tagged failure, so it pre-exists this change

1..20
ok - host: two engine errors latch the session, main keeps every away wake in the cooldown, a failed probe doubles it up to its cap, and a report recovers it silently
ok - host: an attended close in a latched session reaches main as the arm printed it and leaves the latch as it was, and a home that opted out with off never reads it
ok - host: attended, two engine errors latch the session, main keeps every close unchanged in the cooldown, a failed probe doubles it up to its cap, and a routine probe's recovery stays in the ledger, off main
ok - host: an engine turn is bounded, and tool processes outside its process group are reaped
ok - host: a restarted host stops, by recorded identity, the cycle a killed predecessor left running
ok - host: an idle engine conversation is compacted once across hosts
ok - host: a conversation the next turn would not resume is not compacted
ok - host: a compaction abandoned at the park boundary is not marked done
ok - host: the park ends itself with a boundary wake and a stopped watcher
ok - host: waiting closes cannot carry the park past its boundary
ok - host: a close whose margin runs out while the successor starts reaches main at the boundary without a turn
ok - host: the park's test clock is inert without the test marker
ok - host: a park at or beyond the Stop-hook registration falls back to the default boundary
ok - host: an owner's later park limit lets a turn outlive the boundary, and no other limit does
ok - host: the first cycle's status streams once, --restart replaces a stale watcher, and an owner predecessor makes a handling successor
ok - host: an unchanged held outcome reaches the captain once across cadences, and a later decision on the task still does
ok - host: a home naming an unverified engine hands every away wake to main with the reason
ok - host: a host outside the session-lock owner stands down without arming
not ok - tagged: the host never started a watcher cycle: supervision-host stood down: this session does not own supervision
EXIT=1
Evidence: fm-session-lock-ancestry.test.sh: pre-existing pid-1 pty-reparent e2e failure at base

Source: fm-session-lock-ancestry.test.sh: pre-existing pid-1 pty-reparent e2e failure at base

ok - session-lock: a version-named Claude Code session is identified from its install path and argv[0]
ok - session-lock: a harness that is pid 1 of its own namespace is examined, not skipped
ok - session-lock: ordinary script paths under a harness directory are not harness processes
ok - session-lock: ownership stops at the first non-harness gap above the contiguous run
ok - session-lock: a live version-named session holding the lock is not mistaken for a stale owner
ok - session-lock: a trusted same-session id keeps owning a recycled background chain, and nothing weaker does
ok - session-lock: a trusted id anchors the lock on the model-loop process, anything else on the outermost pid
ok - session-lock: a Windows session is identified from its published pid across the severed parent link
ok - session-lock: a published Windows pid is confirmed against the process table before it is trusted
ok - session-lock: a tagged Windows pid is never resolved against the Cygwin process table
ok - session-lock: a published identity is accepted by every gate that reads the lock
ok - session-lock: a live tagged lock holder is a live foreign owner to a second Windows session
ok - session-lock: fm-lock.sh protects valid tagged owners and reclaims dead or malformed records
ok - session-lock: a published Windows Claude pid is accepted only with its session id
ok - session-lock: a Windows /clear keeps the lock and re-keys its session id
ok - session-lock: a Windows-tagged lock stays inert off Windows
ok - session-lock: a task lease follows a live tagged lock holder and goes stale when it exits
ok - session-lock: a harness in the local process table resolves untagged when ps has no -o option
ok - session-lock e2e: a version-named session claims the home and arms supervision
ok - session-lock e2e: a session parented by a harness-named daemon claims the home and arms supervision
ok - session-lock e2e: a version-named session under a harness-named daemon keeps its own lock
not ok - the pty-host was not reparented to init after the daemon ended
Evidence: fm-afk-contract.test.sh and fm-afk-return.test.sh: away/quiet record schema and return-brief regressions pass

Source: fm-afk-contract.test.sh and fm-afk-return.test.sh: away/quiet record schema and return-brief regressions pass

ok - the read-back renders the words verbatim beside the expected return, spend cap, and reach line
ok - words preserve their final newline shape in storage and read-back
ok - one enter call writes a version 2 record, announces hold-for-return only, reads it back without asking for a go, and every read subcommand reflects it
ok - entry without --spend records the live worker count, never below the default floor, and an explicit --spend still wins
ok - the retired propose, confirm, and --proposal inputs are refused by name and write nothing
ok - enter removes a proposal an older version left behind and records only the new words
ok - a same-turn entry records never-set words verbatim, adds no authority field, and restates the never-set
ok - a plain entry records no mandate in one step, and a refresh leaves the standing record untouched
ok - new words archive the old words and keep the session start
ok - a failed replacement keeps the standing posture live
ok - a failed final replacement publication rolls back its superseded archive
ok - validation and archive refuse damaged words blocks
ok - a words line that lost its record prefix fails validate, read, read-back, and archive instead of truncating the mandate
ok - archive keys the record by its entry time, empties the posture, and is idempotent
ok - malformed inputs and foreign record versions are refused rather than guessed
ok - retired clause fields, --grant, and the clause and grant subcommands are refused by name
ok - a version 1 record validates, reads its words and scalars with the clause and grant sections ignored, refreshes untouched, and archives
ok - new words over a live version 1 record archive it and write version 2 with the same session start
ok - enter and archive refuse while the record is locked, and proceed once it clears
ok - a quiet record announces, refreshes, and reads back as a present captain holding nothing, while an away record keeps hold-for-return
ok - an away entry over quiet mode records away, and a quiet entry never masks a standing away record
EXIT=0
Evidence: fm-session-lock ps-denied and Windows-consumer suites pass

Source: fm-session-lock ps-denied and Windows-consumer suites pass

ok - untagged lock values: the session-pid helpers answer exactly as fm_pid_identity and fm_pid_alive do
ok - supervision host: a win:<pid> session lock yields the main-session key only while that Windows process lives
ok - auto-arm: a claim pins a win:<pid> lock holder and reads open only while that holder lives
ok - auto-arm: mid-turn health accepts a rewake bound to a live win:<pid> holder and drops it when that holder exits

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
A read-only session's away entry (fm-afk-launch.sh enter --words) is refused while another live session holds the fleet lock, the refusal names that holder's pid, live process start time and age, an… ✅ pass live live-afk-entry-transcript.log: another live firstmate session holds the lock (pid 2507554, started Mon Nov 9 20:00:56 2026, age 00:01) ..., rc=1, record present: no; afk-launch-test.log `ok - ente…
A quiet entry still succeeds for a read-only session while another live session holds the fleet lock, recording quiet mode rather than being refused ✅ pass live live-afk-entry-transcript.log (launcher run with FM_AFK_MODE=quiet under the same live holder: rc=0, recorded mode: quiet, recorded words: quiet down); afk-launch-test.log `ok - enter: quiet mode…
The record writer itself refuses an away mandate when called directly (bypassing the launcher) while a live foreign session holds the fleet lock ✅ pass live live-afk-entry-transcript.log: direct bin/fm-afk-contract.sh enter --words &#39;bypass the launcher&#39; prints the holder refusal, rc=1, record present: no; afk-launch-test.log `ok - enter: the record wr…
A lock with no proven live holder (stale pid, free or unclassifiable lock) never blocks the away entry ✅ pass live live-afk-entry-transcript.log: state/.lock = 999999 after the holder exited, enter --words &#39;merge it when green&#39; rc=0, record present, recorded mode: away; afk-launch-test.log `ok - enter: a sta…
An away entry that starts while another session is inside a fleet-lock acquisition waits for the acquisition boundary and then refuses, naming the holder it acquired behind (check and write are one cr… ✅ pass live afk-launch-test.log ok - away write: an entry started on a free lock waits for the acquisition in flight instead of writing the mandate and `ok - away write: the entry refuses once the serialized ac…
A held lock whose holder details cannot be produced still refuses the away write instead of failing open ✅ pass live afk-launch-test.log ok - away write: a held lock is refused even when holder details cannot be produced with the message `another live firstmate session holds the lock (pid win:123, started unknown;…
A read-only session start names the live lock holder with pid, process start time and age, offers the two choices (stop that session and start a new one, or keep this session read-only), and stops not… ✅ pass live session-start-test2.log ok - a read-only session names the live lock holder with its pid, start time, and age, and offers the two choices (test_read_only_session_names_the_live_lock_holder; asserts…
A read-only session start does not name its own live lock as another session's holder, so the digest never tells the operator to stop their own process ✅ pass live session-start-test2.log ok - a read-only session does not name its own live lock as another session&#39;s holder (test_read_only_session_does_not_name_its_own_lock_as_another_session)
A standing away record keeps its own mode for a quiet caller, and that away write is refused under a live foreign holder (existing refresh/mode rules preserved) ✅ pass live afk-launch-test.log ok - enter: a quiet-mode caller on a home holding an away record still writes an away mandate, so the live lock holder refuses that write too; live-afk-refresh-transcript.log sho…
  • bash tests/fm-afk-launch.test.sh (exit 0; unit_away_entry_refuses_while_another_live_session_holds_the_fleet_lock, unit_away_entry_serializes_against_lock_acquisition, unit_away_guard_refuses_when_holder_summary_fails, plus herdr/tmux terminal-topology e2e)
  • bash tests/fm-afk-contract.test.sh (exit 0)
  • bash tests/fm-afk-return.test.sh (exit 0)
  • FM_TEST_BASE_PATH=/run/current-system/sw/bin:/usr/bin:/bin bash tests/fm-session-start.test.sh (exit 0; test_read_only_session_names_the_live_lock_holder, test_read_only_session_does_not_name_its_own_lock_as_another_session)
  • bash tests/fm-supervision-host-park.test.sh (19/20 ok; the ported enter_away_in_session fixture test passes; test_tagged_lock_holder_reaches_the_engine_whole fails, and fails identically when the same suite runs from the base-commit tree)
  • bash tests/fm-session-lock-ancestry.test.sh, tests/fm-session-lock-ps-denied.test.sh, tests/fm-session-lock-windows-consumers.test.sh (ps-denied and windows-consumers exit 0; ancestry fails only at its pid-1 reparent e2e, identical on the base-commit tree)
  • Manual live drive /tmp/fm-live-afk-entry.sh: marked lab homes + a live foreign session-shaped holder, running bin/fm-afk-launch.sh enter and bin/fm-afk-contract.sh enter for away refusal, quiet entry, direct-writer refusal, and stale-lock allow
  • Manual live drive /tmp/fm-live-afk-refresh.sh: no-words and quiet refreshes over a standing away record while a foreign holder holds the lock (record unchanged, mode stays away)
⚠️ **Document** - 1 info
  • ℹ️ bin/fm-startup-network.sh:552 - The new acquisition-boundary section in fm-session-lock-lib.sh calls fm_session_lock_claim_path 'the one owner of the path', and this script already sources that library, but it still hardcodes $STATE/.lock.acquire here, at line 557, and at line 589 for its startup-network lease. The same path therefore has a second definition that can drift from the owner and silently break the boundary the away-entry check now relies on. Converting those three uses to fm_session_lock_claim_path is a behavior-preserving follow-up; I did not make it here because this rebase is scoped to patch-equivalent preservation and the edit is executable code, not documentation.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Thank you @kesslerio. Splitting this into a restore commit and a new-default commit, as the #7034 triage asked, really helps, and settling quiet mode before the check is exactly right.

I read head 87383ef3 against main bd866530, including your last push, which already passes the entry guard as an executable plus an argument instead of through sh -c. Thank you, that's the right fix for checkout paths with spaces. Closes #7034 matches the issue, which is labelled ready-for-pr.

Where it stands: waiting on you:

  • The no-mistakes check fails. The body has no ## Pipeline section and no attestation, and the required check reports "This PR was not raised through no-mistakes." Once your pushes settle, please re-raise with git push no-mistakes so the attestation binds the final head.
  • One small review point before the re-raise: the header of bin/fm-afk-contract.sh now has the FM_AFK_CONTRACT_ENTER_GUARD paragraph twice, and the POSTURE. paragraph got split around the second copy.
  • CI on the new head hasn't finished yet. I'll read it next pass.

My read of the diff. The away-entry guard runs under the record's own mutation lock and only refuses when another live session holds the lock. An owned lock, a stale lock and the other read-only reasons all still pass, and quiet mode is untouched. The holder summary reads ps -o lstart= -o etime= live and falls back to "unknown". Nothing is ever stopped automatically. No .github changes, and I have no security concerns.

Contract-class: new-default for the PR as a whole (my own read). The away-entry refusal on its own is a restore, since session start already says a read-only session must not arm. But this PR also adds the holder-naming block and the two-choice offer to the default session-start digest, and that's new presentation on the unconfigured path. So it won't auto-merge. Once it's attested and green, it goes to Kun as a merge-or-leave decision. If you'd rather the restore land on its own, split it into its own PR and it can follow the restore path.

VISION: One captain aligns (a vague read-only state becomes a named decision) · Authority aligns (a read-only session can't take an away mandate, and stopping the holder stays the operator's call) · Scripts aligns · Restart aligns · Delegation pending the attestation and CI · Vendor aligns (portable ps read with an unknown fallback; macOS is proven by the hosted job) · Scope aligns.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @kesslerio. Moving the check into fm-afk-contract.sh so it applies to every writer of the record, not only the launcher's, is a nice tightening, and it clears the duplicated header paragraph too.

I read head bb25e8ec against main df9eb03a.

Where it stands: still waiting on you:

  • CI is red on this head (run 39711996123), and the failures look real, not flakes:

    • serial 2: not ok - fixture: could not record the away posture again
    • serial 6: not ok - could not confirm the first mandate
    • parallel 1: not ok - telemetry did not count the changed root's source directives

    The first two are away-entry fixtures that now hit the in-contract fleet-lock guard. The third matches the new fm-session-lock-lib.sh source line in fm-afk-contract.sh. Please take a look.

  • The no-mistakes check still fails. There's no ## Pipeline section or attestation. Once the fix settles, please re-raise with git push no-mistakes so the attestation binds the final head.

Contract-class: new-default (my own read, unchanged). The away-entry refusal is a restore. The holder-naming block and two-choice offer on the default session-start digest are new presentation on the unconfigured path. So once it's attested and green, this goes to Kun as a merge-or-leave decision rather than auto-merging. VISION.md: unchanged from my 02:18Z note; Authority aligns more strongly now that every writer is guarded. No security concerns.

@kesslerio
kesslerio force-pushed the fix/7034-afk-fleet-lock-entry branch from bb25e8e to e712a87 Compare October 24, 2026 04:23
@kesslerio kesslerio changed the title fix(afk): refuse the away entry while another live session holds the fleet lock fix: block away entry when another session holds the fleet lock Oct 24, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @kesslerio. Re-raising through no-mistakes was the missing piece, and the attestation now binds head e712a87e. Rebased onto main d22640f4, the obsolete FM_AFK_CONTRACT_ENTER_GUARD header text is gone, and the live refusal evidence (launcher and direct writer both refusing while a real Claude session held the lock, without stopping it) is clear.

Where it stands: waiting on you. Three things:

  1. The open review error. Your own pipeline's review left one error open and rates the risk High: the away guard checks the lock under the record's mutation lock, but not against fm-lock.sh acquisition, so a session can see a free lock and record an away mandate just as another session takes state/.lock. Could you either serialize the check through the record write against the shared .lock.acquire boundary, or explain why that window is acceptable? The PID-reuse note on holder naming and the R6 telemetry pin (5 vs 6 in tests/fm-lint.test.sh) are also still open. A short note on each would do.
  2. Live validation of the startup digest. The one untested scenario is a read-only session starting while another session holds the lock, with its digest naming the holder and offering the two choices. That's the new captain-facing part of this PR. Could you drive it live (pre-trusting the lab folder in the harness should get past the trust prompt) and post the evidence here, or re-raise through git push no-mistakes with it covered?
  3. CI on this head (run 40062142610). Behavior portable serial 1 was cancelled at its 30-minute limit. That's inherited from main right now and won't count against you. Behavior portable serial 4 failed in tests/fm-watch-wedge-cap.test.sh ("the wedge behind the released provably-working-nonterminal cap stayed silent"). This PR doesn't touch the watcher, so it looks unrelated, and I'll re-check it on your next head. Heads-up: this PR edits tests/fm-supervision-host.test.sh, which an open fix for the serial 1 cap (fix(test): split fm-supervision-host so serial shards fit the job cap #7706) splits into two files, so a rebase may be needed if that lands first.

Contract-class: new-default (my own read, unchanged). On its own, the away-entry refusal is a restore. The holder-naming block and the two-choice offer in the default session-start digest are new presentation on the unconfigured path. VISION.md: One captain aligns · Authority aligns, but only once the check-then-write window is closed or explained, because "a read-only session must not record an away mandate" is the authority promise this PR keeps · Scripts aligns · Restart aligns · Delegation pending the digest live evidence · Vendor aligns · Scope aligns. No security concerns.

Once those are settled and CI is green, this goes to Kun as a merge-or-leave decision, not back to you.

@kesslerio kesslerio changed the title fix: block away entry when another session holds the fleet lock fix(bin): refuse the away entry while another live session holds the fleet lock Oct 31, 2026
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new issue was established.

Reviews (3) · Last reviewed commit: "no-mistakes(document): Dedupe away-entry..." · Reviewed by Greptile

Comment thread docs/configuration.md Resolved
@kesslerio

Copy link
Copy Markdown
Contributor Author

Addressed the Greptile P2 on quiet-mode wording in 6cd97830.

  • docs/configuration.md no longer claims quiet mode spawns nothing; it keeps the read-only quiet exception and points at quiet's single owner (docs/supervision-host.md#quiet-mode and the quiet skill), which describes both paths.
  • bin/fm-afk-launch.sh (header and enter) and the matching tests/fm-afk-launch.test.sh comments describe both: nothing where attended supervision already does what quiet asks, the quiet daemon otherwise.
  • The pipeline's document step also records the session-lock lib as the fleet lock's acquisition-boundary owner.

Verification: tests/fm-afk-launch.test.sh 104 ok (includes the fleet-lock and quiet units), tests/fm-supervision-host.test.sh 82 ok, bin/fm-lint.sh and bin/fm-doc-audience-check.sh clean.

Separate note: the base branch moved (main split tests/fm-supervision-host.test.sh), so the PR reports a conflict. That predates this fix and is untouched here.

@kesslerio

Copy link
Copy Markdown
Contributor Author

Round on the three open items. Attested head: 6cd97830777604619ec4d79f7ec38a1c66e65f4c.

1. The check-then-write window is closed, not narrowed

You were right that the record's mutation lock was the wrong boundary: it excludes other record writers, not bin/fm-lock.sh acquisitions. The away entry now takes state/.lock.acquire, the boundary fm-lock.sh publishes state/.lock under, and holds it across the lock check and the record write.

That makes the verdict authoritative rather than merely fresh. fm-lock.sh writes state/.lock only while it holds that boundary, so while the entry holds it no other session can publish a new lock: "no live session holds the lock" cannot go stale before the mandate lands, and a session already inside an acquisition forces the entry to wait, re-check, and refuse.

The path gained one owner: fm_session_lock_claim_path in bin/fm-session-lock-lib.sh, called by bin/fm-lock.sh (the publisher) and bin/fm-afk-contract.sh (the reader), so a reader cannot serialize on a different file than the publisher writes under. bin/fm-afk-contract.sh's header owns the mechanism; docs/configuration.md carries the one-line behavior; docs/scripts.md records the library's added role.

Lock ordering stays acyclic. The record lock is taken first and the boundary second, and the only two boundary holders (fm-lock.sh and bin/fm-startup-network.sh's sweep lease) never take the record lock. The boundary acquire is bounded at 120s like the record lock: a session mid-startup-sweep produces a refusal that says nothing changed and to retry, never a wedge.

Regression test (tests/fm-afk-launch.test.sh, unit_away_entry_serializes_against_lock_acquisition). The fixture holds the boundary with the lock still free, starts a real fm-afk-contract.sh enter, and asserts the entry neither writes nor returns; then it publishes state/.lock and releases the boundary, and asserts the entry refuses by name. With the boundary hold removed, the same test catches exactly the reported bug, the entry recording the mandate while another session is mid-acquisition:

not ok - away write: the entry finished while another session was still inside its
acquisition, so it decided from a snapshot of a free lock: Away posture recorded at
2026-10-31T06:20:51Z: hold-for-return only. ... Spend cap: 4 concurrent workers.

So the test fails on the old behavior and passes on the new one, rather than asserting that a helper exists.

Not changed, deliberately: an ownerless session that sees no proven live holder can still enter, which docs/configuration.md documents as the rule (including a session that started read-only while a holder was live and is asked to enter after that holder exited). Requiring lock ownership to record would also refuse the ordinary case where no session holds the lock at all. The invariant this PR keeps is "a live foreign holder refuses the write", and that is now atomic.

2. PID reuse in holder naming

Agreed, and it is a documented limit rather than an oversight. state/.lock line 1 holds only a pid, and every other reader takes that first line as the pid, so capturing a start-time identity at acquisition would be a durable format change to shared state, not a local fix. What the summary does instead is read the process live: pid, start time, and age, with started unknown; age unknown when the process cannot be inspected. The header section --- naming a live lock holder --- in bin/fm-session-lock-lib.sh states that it cannot establish whether a process reusing the pid acquired the lock, and docs/configuration.md says the same to operators. What bounds the failure: the digest and the refusal name the start time and age, so the operator can tell a recycled pid from their own session, and nothing is ever stopped automatically. A held lock is also refused when holder details cannot be produced at all (unit_away_guard_refuses_when_holder_summary_fails), so a missing summary can never turn into an allowed write. Main's #7746 separately taught the other tagged-pid consumers fm_session_pid_alive / fm_session_pid_identity.

3. The R6 telemetry pin: 5 is the accurate count

assert_grep $'source_directives\t5' (tests/fm-lint.test.sh:657) is unchanged from main, and 5 is what bin/fm-afk-launch.sh actually carries: 5 # shellcheck source= directives before this PR, 5 after. The 6 in the earlier round came from a # shellcheck source=bin/fm-session-lock-lib.sh line added to the launcher; that import was correctly removed once the guard moved into the record writer, because the launcher calls no fm_session_lock_* function. Restoring it to satisfy a 6 would re-add a directive that does nothing, so I kept the semantically correct 5 and pinned it with a comment naming why. If you would rather the R6 decision read 5 explicitly, that is a one-line record change on your side; the test should keep asserting what the source actually has.

4. Live validation of the read-only startup digest

Driven end to end with bin/fm-live-lab.sh from this branch (--harness claude, no mate or worker, so the digest is the unconfigured default path):

  • primary in the lab home took the lock: ok primary: claude pid 1236116 in <lab>/home, fm-lock.sh status -> lock: held by live harness pid 1236116
  • the lab home was pre-trusted by up, so the second session hit no trust prompt
  • a second, read-only Claude session (v2.1.314) started in that same lab home while the lock was live
  • its session-start digest named the holder and offered the two choices; asked to quote it, the read-only session replied:
●  Another live firstmate session holds the fleet lock:
●    pid 1236116, started Fri Oct 30 23:24:40 2026, age 08:42
●  Choose one:
●    - stop that session yourself, then start a new session, or
●    - keep this session read-only.
●  Nothing is stopped automatically.
  • nothing was stopped and nothing was taken over: after the exchange the holder was still running (claude --setting-sources project,local --model sonnet ...), state/.lock still named 1236116, the read-only session never wrote state/.session-start-complete (its mtime stayed at the primary's 23:24:48), and no state/.afk-contract existed
  • fm-live-lab.sh down removed the lab, its Claude trust entries, and its temp dirs, and reported no worker-pool or Pi trust-store change

That closes the gap: 6 of 6 live scenarios now have a passing run.

Local verification

tests/fm-afk-launch.test.sh (104 ok), tests/fm-afk-contract.test.sh (21 ok), tests/fm-afk-return.test.sh (33 ok), bin/fm-lint.sh clean on the changed files and in changed-file mode, bin/fm-doc-audience-check.sh clean, git diff --check clean.

Four suites have one failing case each on this host, and I reproduced every one byte-identically at the pre-change head e712a87e (checked out separately), so they are inherited, not from this change:

  • tests/fm-lint.test.sh: the fallback attempts lost per-root RSS reporting: unavailable
  • tests/fm-session-lock-ancestry.test.sh: the pty-host was not reparented to init after the daemon ended
  • tests/fm-session-start.test.sh: a locked session start did not publish the home summary ledger
  • tests/fm-supervision-host.test.sh: tagged: the host never started a watcher cycle

Serial 4 fm-watch-wedge-cap and the serial 1 cancel are the ones you already acknowledged as unrelated.

State of this head

The attestation binds 6cd97830. The PR is CONFLICTING with main because main moved past the base you reviewed on 10-24, and the two conflicted files are bin/fm-session-lock-lib.sh and tests/fm-supervision-host.test.sh. Per your note I left the merge resolution to you rather than publishing a rebase: I stopped the CI repair round that had started rewriting the supervision-host fixtures around main's split, so no rebased head goes out from here. The visible consequence is that GitHub creates no pull_request workflow runs for a head whose merge ref cannot be built, which is why the required Behavior and Lint checks are absent on 6cd97830 rather than red; Greptile Review passed. Once you resolve the two files, the 77db01c0..6cd97830 documents steps are the only commits after d918dfff, and the change itself is that one commit plus the test.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @kesslerio, this round answers all three points from my 10-24 note. The away entry now holds state/.lock.acquire across both the lock check and the write, so a session that saw a free lock can't be overtaken by an acquisition before its mandate lands. Your regression test fails on the old behavior and passes on the new. The PID-reuse limit is documented rather than claimed away, and the digest names the start time and age. The R6 count of 5 is the right one. And the live lab run shows the read-only digest naming the holder, offering the two choices and stopping nothing. Thanks also for fixing Greptile's quiet-mode wording.

I read head 6cd97830 against main 095db3bc. The no-mistakes attestation binds this head with every step run, and Greptile is 5/5 with its thread resolved. The branch conflicts with main in bin/fm-session-lock-lib.sh and tests/fm-supervision-host.test.sh, so GitHub hasn't run CI on this head. That conflict is ours to fix if Kun says to merge, and it isn't on you.

Contract-class: new-default, unchanged. The away-entry refusal on its own is a restore. The holder-naming block and the two-choice offer in the default session-start digest are new on the unconfigured path. VISION: One captain aligns (a vague read-only state becomes a named decision) · Authority aligns (a live foreign holder now refuses the away write atomically, and stopping it stays the operator's call) · Scripts aligns · Restart aligns · Delegation aligns (live evidence now covers 6 of 6 scenarios) · Vendor aligns (portable ps read with an unknown fallback) · Scope aligns.

Next step: this now waits on Kun's merge-or-leave decision, not on you. If he says merge, we resolve the conflict, run the full suite on the merged head and land it.

The lint telemetry assertion pinned the source-directive count of
bin/fm-afk-launch.sh at five, so the away entry's new session-lock source
broke it for a reason that says nothing about the telemetry. Derive the
expectation from the file with the counter's own predicate, and keep the
assertion non-vacuous.

Two fixtures recorded the away posture from outside the session that holds
the fleet lock, which the record writer now refuses on purpose: the return
suite hand-copied the record writer without its new session-lock library,
and the supervision-host latch case needs the lock-owning session to record
its own mandate. Copy the dependency, and stage the entry inside that
session.
A read-only session must not record an away mandate it cannot carry out, but
the record's mutation lock only excludes other record writers.
An entry could inspect a free fleet lock and then write the record after
bin/fm-lock.sh published state/.lock, so the invariant held only by luck.

The check and the write it authorizes now run while the entry holds
state/.lock.acquire, the boundary bin/fm-lock.sh publishes state/.lock under.
bin/fm-session-lock-lib.sh owns that path, so a reader can never serialize on
a different file than the publisher writes under.

The regression test drives the window itself: with the boundary held and the
lock still free, an entry must neither write nor return, and it must refuse by
name once the acquisition completes.
Removing the hold makes it record the mandate, which is the bug.
The away-authority docs and the entry contract said quiet mode spawns
nothing. That is only the ready-supervision path: where attended
supervision is unavailable, a quiet entry records its mode and the quiet
daemon starts. Say both, keeping the read-only exception that a quiet
entry never takes the fleet-lock check.

Addresses the Greptile P2 on kunchenguid#7624.
@kesslerio
kesslerio force-pushed the fix/7034-afk-fleet-lock-entry branch from 6cd9783 to db865c8 Compare November 10, 2026 04:25
@kesslerio kesslerio changed the title fix(bin): refuse the away entry while another live session holds the fleet lock fix(afk): gate the away entry on the fleet lock and name its live holder Nov 10, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @kesslerio for bringing this up to date with main. The branch no longer conflicts.

I read head db865c86 against main 913bb7a7 (15 files). It's the same change I reviewed at 6cd97830:

  • The away entry holds state/.lock.acquire across both the live-holder check and the record write.
  • Quiet entries skip the check.
  • The read-only digest names the holder (pid, start time and age) and offers the two choices.
  • Nothing is stopped automatically.

There are no workflow, network or credential changes. The no-mistakes attestation binds this head with every step completed, the required check passes, and so do the coverage guard and repo invariants. Greptile is 5/5, and its thread is resolved.

One small thing, waiting on you: the re-raise dropped the Closes #7034 line from the description, so GitHub no longer links the issue. Could you add it back? Editing the description is enough, and you don't need to push again.

Optional, and not blocking: your pipeline's document step noticed that bin/fm-startup-network.sh still hardcodes $STATE/.lock.acquire in three places instead of calling fm_session_lock_claim_path. That would be a good follow-up.

Contract-class: new-default (my own read, unchanged). The away-entry refusal on its own is a restore, but the holder-naming block and the two-choice offer in the default session-start digest are new on the unconfigured path. VISION: every rule aligns.

After the Closes line is back, the next steps are ours. We run the full suite once main's CI is green again (an unrelated upstream break is holding every PR right now), and then this goes to Kun as a merge-or-leave decision.

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.

2 participants