Repository navigation
feat(bin): add opt-in continuous captain input subscription - #6190
lockhartheavyindustries wants to merge 20 commits into
Conversation
[Medium impact] The PR appears safe to merge; the latest update addresses the outstanding note-ownership finding. Reviews (10) · Last reviewed commit: "no-mistakes(ci): Result: ci-4 is fixed a..." · Reviewed by Greptile |
|
Speaking as Kun's firstmate: triage on HEAD contract-class: opt-in. Continuous captain input demand is gated on explicit 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 ( Waiting on: CI to finish. If green + mergeable → squash-merge candidate (opt-in). |
|
Speaking as Kun's firstmate: thanks @lockhartheavyindustries for bringing this up to date with main and re-raising it. The attestation now matches head I compared head What I checked: every new path is gated on CI: this is a fork contribution whose runs were waiting on approval. I reviewed the diff first: Contract-class: opt-in. An unconfigured home runs exactly as before. Continuous input demand starts only after an explicit owner VISION.md, rule by rule
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. |
|
Merged upstream main ( All nine inbox, wake, watcher, and Stop auto-arm suites passed locally with zero skips. ShellCheck 0.11.0 passed on all ten changed shell files, and the documentation audience check passed. |
|
Speaking as Kun's firstmate: thanks @lockhartheavyindustries for bringing this onto main Waiting on you for two things:
Diff review of Contract class: opt-in, unchanged. Continuous input demand starts only after an explicit owner |
|
Speaking as Kun's firstmate: thanks @lockhartheavyindustries, both asks are done on Gates: the attestation now binds this head with Diff review of the delta since Contract class: opt-in (continuous captain input stays off until a home subscribes). VISION: all rules align. I'm adding |
|
Speaking as Kun's firstmate: as promised, I've added |
|
Speaking as Kun's firstmate: thanks @lockhartheavyindustries. New head One thing is waiting on you: the attestation in the body binds Contract class: opt-in (unchanged). Because it changes the wake path for homes that subscribe, a clean head goes to Kun for his word rather than auto-merging. |
b0329cb to
a0f3b30
Compare
|
Speaking as Kun's firstmate: thanks @lockhartheavyindustries for the clean re-raise. Head Gates on this head: the attestation binds Contract class: opt-in (unchanged). Because it changes the wake path for homes that subscribe, it goes to Kun for his word now rather than auto-merging. Nothing is waiting on you. |
… Slack desk example
…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
… 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
…e no longer cancels the Claude Stop rewake. The fix is in the working tree, not committed. Smoke-tested: red before the fix, green after. Invariant: once the ledger records outcome=rewake, the hook must exit 2 with its normal wake. Only a ledger, ownership or marker failure may cancel it, never a receipt write. The handoff receipt already followed this rule. The .input-commit receipt was the only site that broke it; it is written in one place, `_fm_autoarm_write_owned_locked` in bin/fm-wake-lib.sh. Fix (bin/fm-wake-lib.sh): the `.input-commit` directory creation and the per-generation write are now best effort: `{ mkdir -p ... && printf ... > .../$gen; } 2>/dev/null || true`. These paths are unchanged: - the ledger write failure (return 1) - the ownership and identity refusals (return 2) - the marker write (return 2) - the handoff call The reader in fm-inbox.sh `input-receipts` already treats a missing commit file as uncommitted (OSError leads to an empty commit), so no consumer changes were needed. Regression (tests/fm-claude-stop-autoarm.test.sh, next to the existing subscribed-input cases): it runs the real hook in a subscribed, actionable disposable home. It covers two failure cases: - a regular file at state/.input-commit, so the directory cannot be created - a read-only state/.input-commit directory, so the per-generation write fails For each case it asserts: - exit 2 - the "firstmate watcher wake" output - outcome=rewake retained in .claude-autoarm-epoch - the .input-handoff/commit-1 receipt still written Verification: - Red before the fix: the directory case failed with "expected exit 2, got 0". In a scratch copy of HEAD running only the generation case, the per-generation case failed the same way. - Green after the fix: the full tests/fm-claude-stop-autoarm.test.sh passed (EXIT=0), including the new "a failed generation commit receipt does not cancel the rewake". - `shellcheck -x` is clean on both changed files
eda360a to
6af2283
Compare
… finding was that a session that does not own the home could run `drain --ack <id>` after `unsubscribe` and mark a handed-off note handled before the owner read it. Not true yet: the fix is in the working tree only. It is not committed or pushed. Invariant: a note handed off while subscribed stays owner-only after unsubscription. That covers a note with a saved handoff record and a note whose handoff is still deferred. Places this rule must hold: - `cmd_drain --ack` in bin/fm-inbox.sh. This is the only place that marks a note handled, and it is the only place changed. - `fm_input_ack_locked` already keeps receipts for handed-off notes after unsubscribe (an earlier ci-1 fix). It needed no change. - `cmd_subscription` is already owner-only. Fix (bin/fm-inbox.sh, `cmd_drain --ack`): - Default-off homes are unchanged. If there is no `.captain-input`, no `.input-handoff` directory, no `.input-handoff-pending` file and no `.input-handoff-pending.*.rows` sidecar, the command takes no lock and loads no library. - If any of those exist, it first checks every note id. It then takes `.wake-queue.lock` and replays any deferred handoffs under that lock. - Owner-only handling applies if any of these is true: - the home is still subscribed - a requested note has an `.input-handoff/<id>` record - a requested note is still listed (field 2) in `.input-handoff-pending` or a sidecar - A non-owner is refused, and the queue lock is released before the command exits. - A note queued after unsubscribe was never handed off, so any session can still handle it. - One side change: a subscribed non-owner now waits for the queue lock before it is refused. Before, it was refused without waiting. The result is the same. Tests (tests/fm-inbox.test.sh): - In the subscribed-then-off case, a non-owner's `drain --ack` after unsubscribe is refused. The note stays queued, is not marked handled, and the queue lock is not left held. - In the same case, a note queued after unsubscribe can be handled by a non-owner. - New deferred-then-off case: - Setup: the handoff is deferred through the real `_fm_input_handoff_defer`, and `.input-handoff` is blocked so the replay keeps the row pending. - Expected: a non-owner is refused and the lock is released, and the owner can still handle the note. Verification: - Red before the fix: with the HEAD version of bin/fm-inbox.sh, the suite failed with "not ok - non-owner must not handle a handed-off note after unsubscribe". - Green after: `bash tests/fm-inbox.test.sh` passed (exit 0). - `bash tests/fm-claude-stop-autoarm.test.sh` passed (exit 0, 84 ok). - `bin/fm-lint.sh bin/fm-inbox.sh tests/fm-inbox.test.sh` is clean (ShellCheck 0.11.0, exit 0). Not touched, as told: bin/fm-backend.sh, tests/fm-watch-meta-index.test.sh, and the ignored ci-1, ci-2 and ci-3 checks
|
Speaking as Kun's firstmate: thanks @lockhartheavyindustries. New head Diff review of the new change ( CI is running on this head with Contract class: opt-in (unchanged). Once the suite is green it goes to Kun for his word because it changes the wake path for subscribed homes. Nothing is waiting on you. |
|
Rebased onto upstream
|
|
Speaking as Kun's firstmate: thanks @lockhartheavyindustries. The labelled full suite on head Contract class: opt-in (unchanged; a home with no |
Intent
Refresh #6190 ("feat(bin): add opt-in continuous captain input subscription", lockhartheavyindustries fork, branch fm/upstream-captain-input) so it no longer conflicts with upstream main. Captain 2026-11-30 chose "a": refresh PR 6190 on upstream main (rebase and push to the captain's PR; one-task upstream consent).
Context: Kun's firstmate triaged head eda360a on 2026-11-30 19:21Z (a rebase onto main plus one fix): diff review safe, no P1, attestation binds the head, full suite green, merged cleanly; contract class opt-in, waiting on Kun's word. Upstream main has moved since (now including 8bfcc88 "perf(bin): index window lookups once per watcher cycle"), and GitHub now reports the PR as conflicting.
Substance of #6190: adds opt-in continuous captain input subscription via bin/fm-inbox.sh subscribe | unsubscribe | input-receipts (session-lock owner-only registration in state/.captain-input, keeping supervision armed with no work in flight in bin/fm-supervision-lib.sh, and read-only fm-input-receipts.v1 JSON without note bodies), body-free .captain-input-notify doorbell plus durable input handoff, deferred lock-busy sidecar replay, and best-effort generation commit and handled-note ack receipts in bin/fm-wake-lib.sh and bin/fm-wake-drain.sh (with array locals named input_sources and input_deferred), bounded doorbell waits via bin/fm-input-wait.py and input_checkpoint in bin/fm-watch.sh, immediate cycle-receipt forwarding in bin/fm-watch-arm.sh, Stop autoarm guidance in bin/fm-claude-stop-autoarm.sh, documentation in docs/watcher-continuity.md, docs/scripts.md, docs/documentation-audiences.json, docs/verification/captain-input.md, and docs/verification/supervision.md, and regression coverage in tests/fm-inbox.test.sh, tests/fm-claude-stop-autoarm.test.sh, and tests/fm-watch-arm.test.sh. Unsubscribed homes keep existing behavior unchanged.
What Changed
bin/fm-inbox.shadds three commands:subscribe,unsubscribeandinput-receipts.subscribeandunsubscribeset or clearstate/.captain-inputunder the wake-queue lock, and only the session-lock owner may run them.input-receiptsis read-only and printsfm-input-receipts.v1JSON with queue, handoff, commit and ack status, but no note bodies. In a subscribed home,drain --ackalso requires the session-lock owner and takes the queue lock.bin/fm-supervision-lib.shcounts the registration as a reason to keep supervision armed even when no work is in flight.bin/fm-wake-lib.shandbin/fm-wake-drain.shadd the subscribed input path. It has a.captain-input-notifydoorbell that holds no note body and a durable input handoff. When the lock is busy, handoffs go to sidecar files that are replayed later under the lock. Generation commit receipts and handled-note ack receipts are best effort, so a failed receipt write never cancels the Claude Stop rewake.bin/fm-watch.shadds aninput_checkpointthat waits on the doorbell for a bounded time through the newbin/fm-input-wait.py.bin/fm-watch-arm.shforwards a deliveredcaptain-inputcycle right away instead of waiting out the successor grace window.bin/fm-claude-stop-autoarm.shadds guidance for the Stop autoarm hook. Homes that never subscribe behave as before.docs/watcher-continuity.md,docs/scripts.md,docs/documentation-audiences.jsonanddocs/verification/supervision.md, and addeddocs/verification/captain-input.md. Tests: added regression cases totests/fm-inbox.test.sh,tests/fm-claude-stop-autoarm.test.shandtests/fm-watch-arm.test.sh. One of the new cases checks that a failed generation commit receipt does not cancel the rewake.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The rebase conflict in bin/fm-watch.sh was resolved correctly: upstream's per-cycle meta index build and its clear on cleanup are both kept, and the input checkpoint sits after the build. Diffing eda360a against 82eb1e6 shows that, in bin/, only upstream-owned files and bin/fm-watch.sh changed, and in bin/fm-watch.sh only upstream hunks differ (meta index, review-park pending). Every unsubscribed path is still gated on state/.captain-input, so homes that never subscribe behave as before.
Testing
I confirmed the rebase base and that the upstream meta-index calls are still there. I then re-ran tests/fm-watch-arm.test.sh by itself, without the parallel load that caused the round-1 failure. It exited 0, and all 42 cases passed, including the input cycle-receipt forwarding and arm-start cases. The round-1 logs for the inbox, Claude Stop autoarm and watch-meta-index suites show zero failures. Each suite runs the real firstmate scripts in disposable homes. I did not start a tmux or Herdr lab primary, because these suites already drive the changed scripts end to end. Overall result: go.
Evidence: watch-arm suite run alone (round 2)
Source: watch-arm suite run alone (round 2)
Evidence: inbox suite log
Source: inbox suite log
Evidence: Claude Stop autoarm suite log
Source: Claude Stop autoarm suite log
Evidence: watch meta-index suite log
Source: watch meta-index suite log
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
🔧 **Rebase** - 1 issue found → auto-fixed ✅
bin/fm-watch.sh- merge conflict rebasing onto origin/main🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Review** - passed
✅ No issues found.
tests/fm-watch-arm.test.sh- tests/fm-watch-arm.test.sh exited 1. After 13 passing cases, the case 'arm did not start a watcher: watcher: FAILED - no live watcher with a fresh beacon' failed. It ran in parallel with three other suites, so load may have caused it, but that is not confirmed. Re-run it alone to tell a real fault from a flaky failure.git merge-base --is-ancestor 8bfcc883 HEADcheck that bin/fm-watch.sh keeps fm_backend_meta_index_build/clear and input_checkpointbash tests/fm-inbox.test.shbash tests/fm-claude-stop-autoarm.test.sh(stopped before it finished)bash tests/fm-watch-arm.test.shbash tests/fm-watch-meta-index.test.sh🔧 No changes applied.
1 warning still open:
tests/fm-watch-arm.test.sh- tests/fm-watch-arm.test.sh exited 1. After 13 passing cases, the case 'arm did not start a watcher: watcher: FAILED - no live watcher with a fresh beacon' failed. It ran in parallel with three other suites, so load may have caused it, but that is not confirmed. Re-run it alone to tell a real fault from a flaky failure.git merge-base --is-ancestor 8bfcc8832d002f6d864d0ecd1454b2ee41f96808 HEAD(base preserved)grep fm_backend_meta_index_build|clear bin/fm-watch.sh(upstream index calls retained)bash tests/fm-watch-arm.test.shrun alone (EXIT=0, 42 ok, 0 not ok)bash tests/fm-inbox.test.sh(round 1, EXIT=0, 0 not ok)bash tests/fm-claude-stop-autoarm.test.sh(round 1, 0 not ok, including the generation-commit receipt failure case)bash tests/fm-watch-meta-index.test.sh(round 1, EXIT=0, 0 not ok)✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.