Skip to content

feat(bin): opt-in continuous captain input demand on the shared wake owner - #6190

Open
lockhartheavyindustries wants to merge 10 commits into
kunchenguid:mainfrom
lockhartheavyindustries:fm/upstream-captain-input
Open

lockhartheavyindustries wants to merge 10 commits into
kunchenguid:mainfrom
lockhartheavyindustries:fm/upstream-captain-input

Conversation

@lockhartheavyindustries

@lockhartheavyindustries lockhartheavyindustries commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Let an outside channel mark captain input as waiting, so an idle first mate wakes promptly to a new inbox note instead of on the next routine poll.

Today bin/fm-inbox.sh note records a durable note and appends one check wake, but with no work in flight supervision may not be armed at all, and an armed idle watcher only sees the note on its next poll.
That is fine for an occasional note, but it makes a chat-style front end to Firstmate feel unresponsive.
The motivating example is a Slack desk: a small listener, running outside Firstmate as a dedicated bot, receives the captain's messages from a private Slack channel, records each one with fm-inbox.sh note --request-id <message id> (text, source thread, and local paths to downloaded attachments), and the first mate replies in the same Slack thread through that bot, posting new captain-facing asks top-level in the channel.
Before this change such a listener had to run its own waiter and acknowledgement path next to the watcher, which competed with the shared wake owner.

What Changed

  • bin/fm-inbox.sh subscribe | unsubscribe lets only the session-lock owner register or clear continuous input demand for the home, recorded as state/.captain-input.
  • bin/fm-inbox.sh input-receipts prints a body-free, read-only JSON view of each registered note's queue sequence, committed Claude handoff generation, and post-handling acknowledgement.
  • While registered, bin/fm-supervision-lib.sh counts the registration as needed supervision, so the watcher stays armed with no tasks in flight.
  • bin/fm-wake-lib.sh writes a body-free doorbell after an inbox check wake commits, gives registered notes a banner with no user text, and records handoff and acknowledgement receipts under the existing queue lock, waiting briefly for that lock rather than dropping a Stop rewake when it is momentarily busy.
  • bin/fm-watch.sh checks the doorbell between scan units and during otherwise blind idle sleeps, using the new bin/fm-input-wait.py bounded wait; in-progress bounded checks and backend-native event waits keep their existing budgets, and ordinary polling stays the backstop.
  • bin/fm-watch-arm.sh forwards a subscribed input delivery that already names the exact closed cycle in the delivery ledger instead of spending the successor grace window.
  • bin/fm-claude-stop-autoarm.sh adds a one-line handling hint to the rewake banner when input is registered.
  • fm-inbox.sh drain --ack lets only the owning session handle subscribed input and serializes note acknowledgement with the queue lock; its upfront note-id validation applies only while subscribed.
  • bin/fm-wake-drain.sh writes an input acknowledgement receipt only when the owning session acknowledges a handled note, including a note handed off before the owner unsubscribed; a non-session drain actor such as the away/quiet daemon retires input rows exactly as before and writes no receipt.
  • Docs: docs/watcher-continuity.md gains a "Continuous captain input" section, which scopes the prompt wake to the polling watcher and includes a generic Slack desk example, docs/verification/captain-input.md records the native evidence and limits, and docs/scripts.md and docs/verification/supervision.md point at them.

Without state/.captain-input every path keeps its existing behavior; nothing registers demand implicitly, and note itself does not subscribe.
No listener or transport ships with Firstmate: the listener lives outside the home and only captures and relays.
Registration does not authenticate an external human, end away mode, clear quiet, or change daemon or branch ownership.

Risk Assessment

Default-off: the new branches are all guarded by the registration file, and the existing inbox, wake-queue, watcher, arm, and Stop auto-arm suites pass unchanged.
Away/quiet supervision keeps its existing drain authority: the daemon still acknowledges a batch that contains a subscribed inbox row once, leaving the note itself for the session owner.
The doorbell is only a hint written after the durable queue commit; a lost or failed doorbell write leaves ordinary recovery and polling intact.
The prompt wake applies to the polling watcher: a backend blocked in its native event wait, such as Herdr, only sees the doorbell when that wait returns.
The native evidence covers attended Claude only; other harnesses and backend event waits were inspected at their shared integration surfaces but not revalidated live.
Measured idle latency is not better than a separate listener-owned waiter (median about 5.4 s against 2.4 s in a six-input smoke sample); the gain is one shared owner with exactly one handling receipt and zero redundant wakes per input, not speed.
The latency profile and two rejected timing candidates are recorded in docs/verification/captain-input.md.

Testing

  • bin/fm-test-run.sh tests/fm-inbox.test.sh tests/fm-claude-stop-autoarm.test.sh tests/fm-wake-queue.test.sh tests/fm-watch-arm.test.sh tests/fm-watch-recovery-loop.test.sh tests/fm-wake-drain-open-decisions.test.sh tests/fm-wake-drain-open-decisions-cursor.test.sh tests/fm-wake-drain-outcome-backstop.test.sh tests/fm-wake-drain-unread-status.test.sh: FM_TEST_SUMMARY total=9 failed=0 skipped_gate=0 at the final head, after the review and CI fix rounds.
  • New cases cover idle demand without tasks, refusal by an unowned session, a non-session (daemon-style) drain retiring a batch with an unhandled input row and writing no receipt, a receipt that survives unsubscribing after handoff, simultaneous ordinary input, shared queue acknowledgement, concurrent note acknowledgement, a busy bounded check batch, attached-arm delivery, repeated Stop, interrupted arm and re-arm, supersession, and away/quiet ownership and silence.
  • bin/fm-lint.sh (ShellCheck 0.11.0, actionlint 1.7.12) and explicit-path bin/fm-lint.sh over the changed shell files: clean.
  • bin/fm-doc-audience-check.sh: ok.
  • bin/fm-test-run.sh --check-coverage: ok.
  • Native smoke on 2026-09-25 with Claude Code 2.1.282 and claude-haiku-4-5-20251001 in disposable homes, driven by a synthetic mock listener with no chat service or credentials: all seven inputs produced one reader receipt, one committed handoff, one handling receipt, one queue acknowledgement, and zero redundant watcher wakes.

Update 2026-10-09: merged current upstream main into this branch to resolve conflicts; no feature change.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

⏭️ **Rebase** - skipped

Step was skipped.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 9 of 10 scenarios driven live against the product
Scenario Result Live Evidence
Default-off: a note in a home that never subscribed leaves the idle watcher in its 30 s poll sleep and creates no doorbell files ✅ pass live live-captain-input-transcript.txt S1: watcher still asleep 8104 ms after the note; no .captain-input or .captain-input-notify; queue row keeps the existing body-carrying payload; input-receipts shows…
Subscribe is owner-only: a non-owner is refused and writes nothing; the session owner registers and the idle home then demands supervision ✅ pass live live-captain-input-transcript.txt S2; also live-claude-primary-transcript.txt, where a real Claude session was refused before it held the lock and succeeded after bin/fm-lock.sh
Subscribed: an idle watcher in a 30 s poll sleep closes promptly on a new inbox note with a body-free check: captain-input &lt;seq&gt; &lt;id&gt; reason and one queue row ✅ pass live live-captain-input-transcript.txt S3: watcher closed 515 ms after the note against a 30000 ms poll; queue, doorbell and reason line carry no note body
Merge-resolved path: an arm attached to a live watcher forwards the input delivery through cycle_delivered_reason without spending its 20 s successor window ✅ pass live live-captain-input-transcript.txt S4: arm exited rc=0 703 ms after the note, printed check: captain-input 2 &lt;id&gt;, ledger reason=attached-delivered-wake; tests/fm-watch-arm.test.sh exit 0 including…
Adversarial: in a subscribed home an ordinary status-file wake does not take the input shortcut and still closes through upstream's path as signal: ✅ pass live live-captain-input-transcript.txt S7: arm printed signal: .../demo.status, no captain-input line, rc=0
Owner handling: wake acknowledgement is refused until the note is handled, a non-owner cannot handle the note, and after handling there is exactly one input receipt and an empty queue ✅ pass live live-captain-input-transcript.txt S5: 'handle inbox note ... before acknowledging its wake', 'only the owning session may handle subscribed input', then one record with queue_acknowledged true and not…
Daemon-style non-owner drain plus --ack-through on a subscribed home retires the inbox row and writes no input receipt ✅ pass live live-captain-input-transcript.txt S6: non-owner ack succeeded, batch retired, no .input-ack record
Adversarial: after the owner unsubscribes, the next note no longer wakes the idle watcher early ✅ pass live live-captain-input-transcript.txt S8: registration removed; watcher still asleep 8136 ms after the note
Real Claude primary: the session owner subscribes and arms the watcher, an outside note wakes it promptly, and it handles the note leaving one receipt ✅ pass live live-claude-primary-transcript.txt: lock owner pid equals the claude pid; watcher gone about 180 ms after the note; arm output check: captain-input 1 1791563434-fS5N6C; receipts show one record, que…
Native Stop-hook rewake: an idle real Claude primary is given a handling turn by the Stop hook when subscribed input arrives, with the inbox-row guidance line in the banner ⏸️ untested no I started a real Claude primary in a marked lab home from the run worktree and its Stop hooks ran, but bin/fm-claude-stop-autoarm.sh and bin/fm-sessionstart-run.sh exit silently there: fm_primary_scop…
  • bash drive-captain-input.sh &#34;$PWD&#34; (evidence-directory driver: real bin/fm-watch.sh, bin/fm-watch-arm.sh, bin/fm-inbox.sh, bin/fm-wake-drain.sh against bin/fm-lab-home.sh create homes; stub tmux listing no windows; bash-named-claude as session-lock owner) - 8 scenarios, all pass
  • Real claude --model haiku primary in a lab home via pty-primary.py (50x160 pty, env -u NO_MISTAKES_GATE ... FM_HOME=$LAB): bin/fm-lock.sh, bin/fm-inbox.sh subscribe, bin/fm-watch-arm.sh, outside bin/fm-inbox.sh note, bin/fm-wake-drain.sh, bin/fm-inbox.sh drain --ack &lt;id&gt;, bin/fm-wake-drain.sh --ack-through 1 --recovery-generation ..., bin/fm-inbox.sh input-receipts
  • Before the lock was taken, the same real Claude session ran bin/fm-inbox.sh subscribe and was refused with 'only the owning session may change the input subscription'
  • bin/fm-test-run.sh tests/fm-watch-arm.test.sh tests/fm-inbox.test.sh tests/fm-claude-stop-autoarm.test.sh - exit 0
  • Lab teardown: killed the lab Claude process, rm -rf &#34;$LAB&#34;, confirmed git status --short is empty
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Adds continuous input demand to the watcher supervision loop.

The PR appears safe to merge; no outstanding findings or new issues remain.

Reviews (3) · Last reviewed commit: "no-mistakes(ci): I fixed the one failure..."

Comment thread bin/fm-wake-lib.sh Resolved
Comment thread docs/watcher-continuity.md Resolved
…t fails without the code fix and passes with it. ci-1: the input receipt was lost after unsubscribing. - Rule that must hold: a note handed off while subscribed gets exactly one acknowledgement receipt when it is handled, even if the owner unsubscribes before acking. - Where it applies: only fm_input_ack_locked writes receipts, and fm-wake-drain.sh --ack-through is its only caller. - Code fix (bin/fm-wake-lib.sh): a row now counts if the home is still subscribed or the note already has a .input-handoff/<id> record. - The function still exits straight away when neither state/.captain-input nor the .input-handoff folder exists, so homes that never subscribed behave exactly as before. - The owner-only check, the handled-note check and the away/quiet daemon skip are unchanged. - Test (tests/fm-inbox.test.sh): subscribes, queues a note, records a handoff, unsubscribes; the owner then handles and acks the note, and the test checks that the wake is retired and exactly one receipt exists. ci-2 (docs only): docs/watcher-continuity.md now says the prompt wake applies to the polling watcher. A backend blocked in its own event wait, such as Herdr, only sees the doorbell when that wait returns. It is one sentence on its own line. Checks run: - tests/fm-inbox.test.sh passes, including the new case. - With the code fix removed, it fails with "handed-off input keeps one receipt (expected '1', got '0')". - tests/fm-claude-stop-autoarm.test.sh and all six tests/fm-wake*.test.sh suites pass. - shellcheck -x reports nothing on the changed shell files
@lockhartheavyindustries lockhartheavyindustries changed the title feat(bin): let subscribed captain input wake an idle first mate through the shared wake owner feat(bin): opt-in continuous captain input demand on the shared wake owner Sep 30, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: triage on HEAD 1b950745ab20e7d1269af5780a3c4ddc7aa7adb2.

contract-class: opt-in. Continuous captain input demand is gated on explicit bin/fm-inbox.sh subscribe → state/.captain-input. Tests assert an idle default-off home does not demand supervision; note itself does not subscribe. Unconfigured path unchanged. Auto-merge eligible when otherwise ready (green CI, NM, attestation MATCH, mergeable).

VISION (brief): One captain/interface aligns (outside listener stays outside; shared wake owner). Authority aligns (explicit subscribe by session-lock owner). Scripts/agents aligns. Restart aligns (durable registration + receipts). Delegation N/A. Fleet-outlives-vendor aligns (harness-agnostic demand; Claude evidence scoped). Scope aligns (command-layer inbox/wake, no shipped Slack bot). Align: opt-in peace-of-mind for chat-style fronts without new default noise.

Attestation: MATCH. workflow-zero: yes. CI: fork runs approved this pass (36675265551, 36674200992, 36674201031); CI/NM queued after approval.

Waiting on: CI to finish. If green + mergeable → squash-merge candidate (opt-in).

… 2". It came from the test file this PR adds, not from the product code. tests/fm-inbox.test.sh stopped at "not ok - owner registration failed" with "only the owning session may change the input subscription". The other 22 scripts in the shard passed or were skipped by design. Cause: the test's owned() helper runs a fake `claude` harness, which is a symlink to /bin/bash. It runs `bash -c 'printf $$ > state/.lock; "$@"'`. Newer bash (the Linux runner, and bash 5.3 locally) replaces its own process with the last command in a -c string instead of starting a child. So the fake harness process whose pid is in .lock disappears. fm_session_lock_owned_by_self then no longer finds that pid among the running command's parent processes and refuses. macOS /bin/bash 3.2 does not do this, which is why the test passed locally before. Rule that must hold: the process named in state/.lock must stay alive as a parent of every command owned() runs. owned() is the only place that sets this up, and all of the test's owner-side commands go through it (subscribe and unsubscribe, drain --ack, fm-wake-drain.sh --ack-through). So one change covers all of them. Fix (test only, tests/fm-inbox.test.sh): the -c string is now `...; "$@"; exit`. Because `"$@"` is no longer the last command, bash cannot replace the harness process. A bare `exit` keeps the command's exit status, so the checks that expect a refusal (for example the refused --ack-through at line 583) still work. I added a two-line comment explaining why the exit is there. Checks run: - With the fake harness pointed at bash 5.3 and without the fix, the test fails exactly as in CI ("owner registration failed"). - With the fix, it passes on bash 5.3 and on macOS /bin/bash 3.2: exit 0, no "not ok" lines. - `shellcheck -x tests/fm-inbox.test.sh` reports nothing
@lockhartheavyindustries lockhartheavyindustries changed the title feat(bin): opt-in continuous captain input demand on the shared wake owner feat(bin): wake an idle first mate promptly on subscribed captain input Oct 9, 2026
@lockhartheavyindustries lockhartheavyindustries changed the title feat(bin): wake an idle first mate promptly on subscribed captain input feat(bin): opt-in continuous captain input demand on the shared wake owner Oct 9, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @lockhartheavyindustries for bringing this up to date with main and re-raising it. The attestation now matches head d40ad698, and live validation is a go (9 of 10, including a real Claude primary).

I compared head d40ad698 against main b75658b6. Since my 09-30 look, the changes are your CI fix (2f0a791c) and the two merges from main.

What I checked: every new path is gated on state/.captain-input, which only fm-inbox.sh subscribe writes, and only the session-lock owner can run that. Without it, fm_supervision_status, the wake append, the Stop-hook hint, the arm shortcut, input_wait, and input_checkpoint all behave exactly as main does. fm_input_ack_locked also runs while .input-handoff/ exists, but that directory only ever comes from an earlier subscription. note never subscribes. fm-input-wait.py only polls a home-local file with a bound, so there's no network, no process signalling, and no note body in any banner or doorbell. Nothing touches AGENTS.md.

CI: this is a fork contribution whose runs were waiting on approval. I reviewed the diff first: bin/, docs, and tests, with no workflow, secret, or network surface. Then I approved CI 37959884688 and Require no-mistakes 37959884652, 37959932484, and 37960808752.

Contract-class: opt-in. An unconfigured home runs exactly as before. Continuous input demand starts only after an explicit owner subscribe.

VISION.md, rule by rule

  • One captain, one interface: aligns. Any outside listener stays outside, and the existing wake owner delivers.
  • Authority is explicit and never inferred: aligns. Demand is an explicit, owner-only opt-in, and a non-owner drain writes no input receipt.
  • Scripts own the mechanics, agents own the judgment: aligns. The doorbell, receipts, and acknowledgement are exact and scripted.
  • A restart is a non-event: aligns. The registration, handoff, and ack records are durable, and the queue stays the authority.
  • Delegation with a spine: aligns. Acknowledgement is refused until the note is actually handled.
  • The fleet outlives any vendor: aligns. Demand works with any harness, and the Claude-specific handoff record is scoped as such.
  • Scope: aligns. This is command-layer inbox and wake plumbing, and it ships no Slack bot.

Next step: waiting on CI. If CI and Require no-mistakes come back green and it's still mergeable, this is an opt-in change I can merge on a later pass. Nothing is needed from you right now.

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