Skip to content

feat: add attended supervision to the non-Pi host - #5631

Closed
kunchenguid wants to merge 55 commits into
mainfrom
fm/fm-supervision-host-attended-r1
Closed

kunchenguid wants to merge 55 commits into
mainfrom
fm/fm-supervision-host-attended-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Intent

Standing words for this AFK revamp:

  • "2 should be done by opus crewmates"
  • "this is a major architectural revamp so i want it to do very careful live validation including regression in isolated live environments with some real complex sessions before calling it done. it's ok to use my real llm tokens here"
  • End state: "non-afk mode gains pi-like supervision session which offloads main session work. in afk mode it activates a different posture where everything goes to supervision session"

Context: this task is rung 3c of the approved AFK revamp plan. Rung 3c is the attended posture and /quiet on the non-Pi supervision host: the dialog mirror writers, a BRANCH OUTCOMES section in the wake drain for unprocessed captain-verdict rows with the mark-processed acknowledgement, the broken-session latch and cooldown copied from the Pi policy, and /quiet becoming a statement that the attended host already is quiet. Rungs 3a (host core plus Claude away, #5488) and 3b (Cursor, OpenCode, omp, Grok, and Codex arm owners running the host under the flag while away, #5503) are merged on main, and 3b has a dated live-validation record.

What the approved plan says rung 3c is, in substance:

  • The host is bin/fm-supervision-host.sh park, launched by each harness's own arm owner in place of the arm command, still gated behind the default-off presence flag config/supervision-host. On each actionable watcher close it computes eligibility with the same rules the Pi branch uses (one owner, reused through the dispatch CLI rather than re-implemented), starts the successor watcher cycle, runs one headless engine turn on the claimed rows, and requires a durable report before it counts the wake handled. It exits only when main is needed, and its exit reason line is what the harness's existing wake path delivers.
  • Attended posture (no away record): a stored captain-verdict outcome makes the host exit with "branch-outcome: seq N"; main is woken natively, drains, sees the unprocessed captain rows, acts, and acknowledges with bin/fm-branch-outcome.sh mark-processed. A stored routine outcome causes no exit and no main turn; routine rows live in the store and surface in the next drain rather than as transcript notes. Rows the session may not claim (attended main-only classes) exit with today's reason line, unchanged. When the session declined, errored twice, or the scan was unsafe, the host exits with today's reason line, the same no-acceptor fallback the Pi dispatcher already has; a watcher failure exits with the failure line. Away posture keeps its 3a/3b behavior: captain rows accumulate for the return brief with no exit.
  • The dialog mirror: away needs nothing, but attended needs the captain's dialog. The same code-owned turn-end surfaces that arm the watcher (Stop or stop hooks, plugin and extension message events) append captain and assistant text, never tool traffic, to state/.host-mirror.jsonl, and the host feeds unread lines ahead of the wake. If a harness cannot supply text, that harness runs attended with no acceptor (every wake to main, as today) until it can.
  • The broken-session latch and cooldown copy the Pi policy: two provider errors latch the session, followed by bounded probes.
  • /quiet becomes the attended host posture, where routine outcomes never reach main; on Pi this is already true.
  • The host ships with the Claude engine only; Pi keeps its in-process supervision branch, with no change to the Pi host, dispatcher, or extension beyond shared neutral wording. No pane injection, no new authority beyond what the Pi branch has.
  • The host adds no delivery machinery: its fallback is always to exit with today's reason line.

What Changed

  • Let the opt-in supervision host handle eligible attended wakes, keeping routine outcomes off main while handing main-only wakes and failures back through the existing wake path.
  • Mirror captain and assistant dialog from verified Claude, Cursor, and Codex turn surfaces; present captain outcomes in the wake drain until main acknowledges them with mark-processed.
  • Add a broken-session cooldown and probe policy, and make /quiet use the already-quiet attended posture where it is available.

Risk Assessment

⚠️ Medium: The reviewed implementation has no substantiated blocker, but the attended host adds several interacting state transitions and some changed tests remain unreviewed.

Testing

Targeted behavioral tests passed. Two real Claude turns completed in isolated labs, but neither produced a session lock or dialog mirror, so quiet-check correctly declined readiness and the attended host could not be exercised. No reviewer-visible artifact was captured; this CLI/TUI check yielded only transient pane and state observations.

  • Live validation: ⚠️ inconclusive - 1 of 5 scenarios driven live against the product
Scenario Result Live Evidence
A captain uses /quiet after a real attended Claude turn and sees the host report readiness ⏸️ untested no The real primary did not run the project hook path that establishes the session lock and mirror. Provide an isolated lab primary with those hooks active, then rerun the readiness check.
A captain requests quiet readiness without a usable dialog mirror and the CLI refuses to claim it ✅ pass live After a real Claude turn in each opted-in disposable lab, FM_HOME="$LAB" bin/fm-afk-launch.sh quiet-check exited 1 while the mirror was absent.
An attended host handles a routine watcher close without waking main, but delivers captain outcomes and unsafe closes to main ⏸️ untested no The isolated real primary never established its hook-owned session lock or mirror, and no real worker close was generated. Provide a hook-active lab primary and actionable worker task.
An away host handles successive real-engine wakes without consuming attended dialog and hands a failed turn to main ⏸️ untested no No isolated real-engine watcher session with actionable worker closes was stood up; provide that lab scenario for a live check.
Installed harness hooks mirror real captain and assistant dialog, including a Codex mid-turn prompt ⏸️ untested no The isolated Claude primary did not fire the project mirror hooks, and Codex was not driven interactively. Provide hook-active isolated primaries for the installed harnesses.
  • Outcome: ⚠️ 1 warning across 2 runs (27m23s)

Validation notes

The pipeline's own test phase could not stand up real primaries, so its live verdict above is inconclusive; live validation was driven separately on the real Claude engine and real harnesses, in disposable lab homes with config/supervision-host naming claude, each primary on its own private tmux server, with real Pi workers on a small lab repository (2026-09-24 and 2026-09-25):

  • Attended (Claude primary): routine outcomes stayed off main with no host exit and an unchanged main pane; a finished worker became a captain outcome, the host exited with branch-outcome, and main drained BRANCH OUTCOMES, landed the work, and acknowledged it with mark-processed.
  • Away: the engine handled wakes with no away daemon; an injected engine failure reached main as the away session could not take this wake: the engine turn failed; a worker finishing while away became a per your away instructions captain outcome that the return brief named; away wakes carry no mirror and leave its cursor alone, and after the return the next attended wake carried the away window's dialog.
  • Broken-session latch: two injected failures latch with a 300-second cooldown; /quiet in the real primary reported the session paused with its next retry time until a probe succeeded, then recovered.
  • Dialog mirror: the opt-in live guard proved the Claude, Codex (including a message typed during a running turn), and Cursor writers; a missing, unreadable, or malformed mirror hands the attended wake to main without moving the cursor; a Codex message whose mirror write was refused was recorded in order once the mirror was writable; a deleted and recreated mirror keeps numbering past the committed and staged cursors; every mirror file the real writers recorded passes the final validator.
  • Readiness: quiet-check refuses with the engine executable missing or a malformed mirror, and the live host passed an attended wake to main with the claude engine executable is missing.
  • Grok and OpenCode: attended wakes pass through to main (no verified dialog mirror) while away wakes run on the engine.
  • Not driven live: the away-to-attended posture race and an unreadable lock-holder identity; both are covered by behavioral tests through the host entrypoint.

Accepted limits (documented in docs/supervision-host.md):

  • If the captain leaves and returns while an attended engine turn is running, and the host is terminated before its branch-outcome wake is delivered, no immediate wake reaches main; the captain outcome stays durable and the next drain's BRANCH OUTCOMES section presents it until it is acknowledged.
  • A captain prompt whose own hook write fails (refused permission on its state file or a full disk) is not mirrored, so the engine may judge the next attended wake without it; Codex's transcript reader retries at its next hook, while Claude and Cursor have no later source.

Pipeline steps skipped in the final validation run:

  • Rebase: the PR branch still held the head pushed before an earlier run rebased itself onto newer main; this branch already contained that work and was ahead of origin/main, so rebasing onto the old pushed head could only conflict and re-apply work already present.
  • Document: the document step ran and was reviewed in the three earlier runs, with its last edits accurate; its post-review edits were the only tree changes the push guard refused.

Follow-ups, not in this PR:

  • Capturing the first captain prompt on Grok and OpenCode, which would reintroduce their mirror writers and let them run the attended posture; omp still has no verified writer.
  • The Codex attended checkpoint returns to main at each 180-second boundary, so main still takes a turn per boundary.
  • tests/fm-host-mirror-live-e2e.test.sh should keep the pane after a harness exits and fail at once, naming the harness and its last output, when the harness never reaches its prompt.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

⏭️ **Rebase** - skipped

Step was skipped.

⚠️ **Review** - medium risk

✅ No issues found.

✅ No issues found.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 4 scenarios were driven live against the product); untested: A captain enters /quiet on an opted-in non-Pi primary and sees whether attended supervision is ready, including malformed-mirror and latch boundaries, An attended primary handles a routine wake without opening a main turn, but hands captain outcomes and unsafe closes to main for drain and acknowledgement, An away primary handles successive wakes without consuming attended dialog and hands a failed engine turn to main, Installed harness hooks mirror captain and assistant dialog while excluding injected or tool traffic, including a Codex mid-turn prompt
  • Live validation: ⚠️ inconclusive - 0 of 4 scenarios driven live against the product
Scenario Result Live Evidence
A captain enters /quiet on an opted-in non-Pi primary and sees whether attended supervision is ready, including malformed-mirror and latch boundaries ⏸️ untested no bin/fm-lab-home.sh is absent, preventing the runbook-required disposable primary; provide that helper and rerun in an isolated lab.
An attended primary handles a routine wake without opening a main turn, but hands captain outcomes and unsafe closes to main for drain and acknowledgement ⏸️ untested no bin/fm-lab-home.sh is absent, so a real primary and Claude engine could not be driven under the required lab contract; provide the helper.
An away primary handles successive wakes without consuming attended dialog and hands a failed engine turn to main ⏸️ untested no bin/fm-lab-home.sh is absent, so the required isolated real-primary lab could not be started; provide the helper.
Installed harness hooks mirror captain and assistant dialog while excluding injected or tool traffic, including a Codex mid-turn prompt ⏸️ untested no bin/fm-lab-home.sh is absent, preventing a runbook-compliant real primary with installed hooks; provide the helper to run the credentialed hook check.
  • tests/fm-afk-launch.test.sh (also retried without inherited PI_* variables; fixture detected the Pi ancestor and failed its Claude/daemon cases)

  • bash tests/fm-host-mirror.test.sh

  • tests/fm-supervision-host.test.sh

  • bash tests/fm-branch-supervision.test.sh

  • ls bin/fm-lab-home.sh (required lab-home helper absent)

  • ⚠️ live validation verdict: inconclusive (1 of 5 scenarios were driven live against the product); untested: A captain uses /quiet after a real attended Claude turn and sees the host report readiness, An attended host handles a routine watcher close without waking main, but delivers captain outcomes and unsafe closes to main, An away host handles successive real-engine wakes without consuming attended dialog and hands a failed turn to main, Installed harness hooks mirror real captain and assistant dialog, including a Codex mid-turn prompt

  • Live validation: ⚠️ inconclusive - 1 of 5 scenarios driven live against the product

Scenario Result Live Evidence
A captain uses /quiet after a real attended Claude turn and sees the host report readiness ⏸️ untested no The real primary did not run the project hook path that establishes the session lock and mirror. Provide an isolated lab primary with those hooks active, then rerun the readiness check.
A captain requests quiet readiness without a usable dialog mirror and the CLI refuses to claim it ✅ pass live After a real Claude turn in each opted-in disposable lab, FM_HOME="$LAB" bin/fm-afk-launch.sh quiet-check exited 1 while the mirror was absent.
An attended host handles a routine watcher close without waking main, but delivers captain outcomes and unsafe closes to main ⏸️ untested no The isolated real primary never established its hook-owned session lock or mirror, and no real worker close was generated. Provide a hook-active lab primary and actionable worker task.
An away host handles successive real-engine wakes without consuming attended dialog and hands a failed turn to main ⏸️ untested no No isolated real-engine watcher session with actionable worker closes was stood up; provide that lab scenario for a live check.
Installed harness hooks mirror real captain and assistant dialog, including a Codex mid-turn prompt ⏸️ untested no The isolated Claude primary did not fire the project mirror hooks, and Codex was not driven interactively. Provide hook-active isolated primaries for the installed harnesses.
  • tests/fm-host-mirror.test.sh initially failed to execute directly (permission denied); reran with bash.
  • bash tests/fm-host-mirror.test.sh && bash tests/fm-afk-launch.test.sh && bash tests/fm-supervision-host.test.sh
  • Launched Claude twice in a disposable marked lab home on a private tmux socket, submitted a real prompt, inspected the pane and lab state, and ran FM_HOME="$LAB" bin/fm-afk-launch.sh quiet-check; removed each lab afterward.
⏭️ **Document** - skipped

Step was skipped.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

@kunchenguid
kunchenguid force-pushed the fm/fm-supervision-host-attended-r1 branch from f34f758 to 1c49412 Compare September 25, 2026 07:49
@kunchenguid kunchenguid changed the title feat: supervise attended wakes on non-Pi hosts feat: add attended supervision to the non-Pi host Sep 25, 2026
The non-Pi supervision host now takes the attended wakes the Pi branch would
take, behind the same default-off config/supervision-host flag:

- The Pi watcher's offer rule moves into the dispatch module
  (branchOfferForWake), and the host asks it through fm-branch-dispatch.mjs
  offer, so a close reaches main off Pi exactly when it would on Pi.
- bin/fm-host-mirror.sh owns a dialog mirror that each primary's prompt and
  turn-end surfaces write (Claude, Codex, Grok, Cursor hooks and the OpenCode
  plugin); the host feeds it at the head of each wake.
- A handled attended wake with a captain outcome exits with one
  branch-outcome line; the drain's BRANCH OUTCOMES section presents every
  unprocessed captain outcome until bin/fm-branch-outcome.sh mark-processed.
- The Pi branch's broken-session latch and cooldown apply to the host.
- /quiet enters nothing where the attended host runs.

The host still adds no delivery path: its fallback is the close's own reason
line through the owner's existing wake path.
…utcomes once

The live Claude lab showed a finished local-only task the captain had called
routine reported as routine, which left it invisible to main, the only actor
that may land it while attended. The branch prompt now makes such work a
captain outcome, and the drain lists routine host outcomes once for awareness,
as the Pi branch's routine notes reach main's transcript without a turn.
In the live Claude lab the engine reported a rebased local-only branch as
routine four times, reasoning that main already knew it would land it. The
verdict rule now says that anything main must act on is a captain outcome,
even when an earlier outcome told main, because a routine outcome reaches main
only at its next wake.
The live Claude lab showed each host handback's rewake mirrored as captain
text, because Claude submits a Stop-hook rewake through UserPromptSubmit with
only its <task-notification> wrapper to tell it apart. The mirror drops a
prompt that opens with that wrapper, and the live guard now drives a real
rewake and fails if it is mirrored.
A supervising Codex main stays inside one turn across its foreground
checkpoints, so the live Codex lab's mid-turn captain messages fired no prompt
or Stop hook and never reached the mirror. Codex's hooks, now including
PostToolUse, read the session's rollout transcript instead, and the live guard
types a real mid-turn steer and requires it in the mirror.
The live Grok lab showed slow drains; the BRANCH OUTCOMES section made three
validated store reads per main drain. The store now owns one locked present
call that prints what is unread or unprocessed and advances the cursor, and
the drain checks its cheap gates before it asks which harness is primary.
The live Grok lab mirrored every background-task completion notice, which
Grok submits as a prompt inside <system-reminder>, as captain text. The mirror
drops that wrapper too, and the live guard now runs a real Grok background
task and requires its completion turn to stay out of the captain's words.
The quiet check also covered Pi, which changed /quiet on Pi homes that never
opted into the supervision host. It now answers only for a home whose attended
host runs, so a home without the flag behaves as before.
Its stub turns run the real drain, report, and acknowledgement, which took
about 13 seconds each at a load average near 20, so a 3-second turn bound and a
20-second park failed as a fixture while the behavior held.
…t-review re-check

A later documentation pass described the removed Grok and OpenCode writers as
still registered. Restore the accurate wording in the mirror header, the host
doc, and the verification record, note the away-ledger line a primary without
a mirror logs as follow-up, and record the live re-check of the attended,
away, latch, and mirror cases after review.

Move the recreated-mirror regression into the existing mirror suite, where its
fixtures already live, so it no longer builds a temporary tree inside the
checkout.
…their payload rows

A late documentation pass again described the removed Grok and OpenCode
writers as still installed. Restore the accurate wording in the mirror header,
the host doc, and the verification record, and drop the Grok and OpenCode rows
from the record's table of captured writer payloads, which only described
writers this branch removed.
@kunchenguid
kunchenguid force-pushed the fm/fm-supervision-host-attended-r1 branch from 1c49412 to 021853f Compare September 25, 2026 08:10
… directives, but the changed script has six. The test now checks that telemetry reports a positive numeric count without depending on the script’s exact contents. `bash tests/fm-lint.test.sh` passes
@kunchenguid

Copy link
Copy Markdown
Owner Author

Superseded by a re-cut into smaller PRs from this branch's final validated tree:

The repeated-escalation fix that surfaced during this work ships separately as its own PR. Closing this one in favour of those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant