Repository navigation
feat(bin): let the local Jev classifier absorb routine wakes behind a go-live gate - #47
Merged
Merged
Conversation
added 5 commits
September 28, 2026 01:07
config/jev-absorb (off by default) lets bin/fm-watch.sh skip queuing, and waking the supervising session for, a wake at exactly two allowlisted call sites: a routine working/paused signal whose crew is not provably working, and a declared-pause recheck. Activation requires the local Rizzo Flow backend specifically, a calibrated confidence threshold (config/jev-absorb- threshold, never below 0.9), and either bin/fm-jev.sh's new absorb-gate (zero wrongly absorbable, >=90% agreement, a minimum sample) or an explicit captain override; needs-decision, blocked, done, failed, merge/check results, heartbeats, captain inbox notes, secondmate routed replies, Relay, process-event wakes, and any task with an open decision are never eligible. Every absorbed wake is appended, masked, to a durable digest that bin/fm-wake-drain.sh surfaces on the next real wake or heartbeat, so nothing is lost silently. Any doubt anywhere in the chain falls through to today's behavior.
…erial 2": `tests/fm-remote-job.test.sh`, check "the worker kept serving after its state root was deleted". This PR doesn't touch the remote-job code, but the failure comes from a real race in the worker, so it's a code fix, not a rerun. **Cause:** the worker's serve loop refreshes its heartbeat and then calls `fm_remote_job_reap_stale`. That sweep called `fm_remote_job_prepare_state`, which creates any missing state directories. If the state root was moved away in the short gap after the heartbeat write succeeded, the sweep silently recreated it. Every later heartbeat then succeeded, so the worker kept serving an unowned queue with no lock, and the test's 10-second tripwire fired. It only happens when the move lands in that gap, which is why it's intermittent. **Fix (smallest root-cause change):** - `bin/fm-remote-job-lib.sh`: `fm_remote_job_reap_stale` no longer re-prepares the state tree. It sweeps only the jobs directory the worker already prepared at startup, and returns 1 if that directory is missing or a symlink. Its only caller is the worker loop, which ignores the return code (`|| true`). The next heartbeat then fails and the worker exits for its supervisor to restart, which is the intended behaviour. - `bin/fm-remote-job-worker.sh`: updated one comment that said the sweep re-prepares the tree. - `tests/fm-remote-job.test.sh`: added a deterministic regression check. It prepares a state root, moves it away, runs the stale sweep, and asserts the sweep fails and doesn't recreate the root. It lives next to the live-worker tripwire, which only hits the gap occasionally. **Verification:** - `bash tests/fm-remote-job.test.sh` → ALL TESTS PASSED, including the tripwire and the new check. - Running the same steps against the pre-fix lib (`git show HEAD:bin/fm-remote-job-lib.sh`): the sweep returned 0 and recreated the deleted root. With the fix it returns 1 and leaves the root absent, so the new check fails before the fix and passes after. - `tests/fm-remote-job-orphan-reap.test.sh` and `tests/fm-remote-doctor.test.sh` pass. - `shellcheck -x` is clean on all three changed files. **Remaining gap:** a much smaller window of the same kind remains. `fm_remote_job_reap`, which the sweep calls once per stale completed job, still prepares state itself. It only matters when stale completed jobs exist at the moment the root is deleted, and I left it alone to keep the fix narrow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Implement gated wake absorption ("junk cleaning") on top of bin/fm-jev.sh's local shadow classifier. Off by default. Refuses to activate until the shadow report meets go-live criteria (0 wrongly absorbable, >=90% agreement, a minimum sample of ~300 classified wakes, no default confidence threshold below 0.9, calibrated) or an explicit captain override. Strict allowlist: only a routine working/paused signal wake whose crew is not provably working, and a declared-pause recheck; never needs-decision, blocked, done, failed, merge/check results, heartbeats, captain inbox notes, Relay, process-event wakes, secondmate routed replies, or any task with an open decision. Durable digest of every absorbed wake (masked), surfaced with the next real wake or heartbeat, never lost silently. Fall-through to today's behavior on any doubt, timeout, server error, or classifier error, adding no latency beyond the existing per-request classify timeout. Tests for every refusal class and the gate. Docs in docs/configuration.md 'Jev shadow wake triage' and the AGENTS.md config line list. Local Rizzo Flow backend only (never OpenRouter) since absorption changes real behavior. Source comments max 3 lines. Never add an agent co-author trailer.
What Changed
bin/fm-jev.shadds an opt-in wake absorption path that only runs against the local backend.absorb-trydecides per wake, andabsorb-gatechecks that the shadow report shows zero wrongly absorbable wakes, at least 90% agreement, and at least 300 scored wakes. The gate result is cached. Absorption stays off unlessconfig/jev-absorbsayson, and it needs either the gate to pass or anoverrideline.config/jev-absorb-thresholddefaults to 0.9 and values below that are rejected. A wake is absorbed only when the Rizzo native/v1/decisionsanswer isok,absorbable, and at or above the threshold. Anything else falls through to the existing behavior, including an ineligible wake, an unmet gate, a timeout, an error, or a low-confidence answer.statusnow reports the absorption setting, the threshold, and whether the gate is met.bin/fm-watch.shcalls absorption at exactly two places:Everything else always surfaces as before: needs-decision, blocked, done, failed, merge/check results, heartbeats, inbox notes, Relay, process-event wakes, secondmate routed replies, and tasks with an open decision.
Each absorbed wake is written, masked, to
state/jev/absorbed.jsonl.bin/fm-wake-drain.shprints that digest on every non-afk drain, so it shows up with the next real wake or heartbeat. The digest is held while away mode is active. New tests intests/fm-jev.test.shandtests/fm-watch-triage.test.shcover each refusal class, the gate, the override, and the digest.docs/configuration.md(a "Gated wake absorption" subsection),docs/scripts.md, and theAGENTS.mdconfig/state entries are updated to match.Risk Assessment
Testing
Both suites passed, 0 failures: the Jev suite and the full watcher-triage suite, which was run in full because its shared helper changed. That covers the new unit tests for gate, refusal and digest behaviour and the real-watcher tests for signal and pause-recheck absorption, the dead-agent guard and the captain-held guard. I also drove the CLI by hand against the real local Rizzo Flow server. Every refusal class fell through with no digest. The real model labelled routine working and paused lines
firstmatebelow 0.9, so nothing was absorbed there, which is the fail-safe outcome. A loopback stub returning Rizzo-format "absorbable" answers showed the full positive path: masked digest written, held during away mode, surfaced once by the next drain and never repeated, and a hung classifier falling through within the per-request timeout. The CLI transcripts and test logs are saved as artifacts. The worktree was left clean.Evidence: Positive path: absorb-try, masked digest, afk hold, drain surfaces ABSORBED once, hung-server timeout
Source: Positive path: absorb-try, masked digest, afk hold, drain surfaces ABSORBED once, hung-server timeout
Evidence: Real Rizzo Flow e2e: off by default, gate NOT met, override, threshold floor, ineligible verbs, OpenRouter refused, classifier down/hung fall-through
Source: Real Rizzo Flow e2e: off by default, gate NOT met, override, threshold floor, ineligible verbs, OpenRouter refused, classifier down/hung fall-through
Evidence: Drain output surfacing the absorbed-wake digest
Evidence: Demo scripts (reproducible)
Source: Demo scripts (reproducible)
Evidence: Demo script against the real local Rizzo Flow server
Source: Demo script against the real local Rizzo Flow server
Evidence: tests/fm-jev.test.sh output
Source: tests/fm-jev.test.sh output
Evidence: tests/fm-watch-triage.test.sh output
Source: tests/fm-watch-triage.test.sh output
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 10 issues found → auto-fixed (2) ✅
bin/fm-watch.sh:504- The new Jev branch in handle_paused_stale can absorb a declared-pause recheck whose agent is dead. The surrounding contract says "A recheck that finds the agent dead is never absorbed, so an exited worker keeps surfacing on every PAUSE_RESURFACE_SECS recheck", and the existing quiet-absorb branch enforces it withcase $now_sit in *' agent=dead '*) false. The Jev branch has no such guard. Example: a worker writespaused: waiting on upstreamand then its process exits. On the first recheck prev_sit is empty, so the reason sent to the classifier never mentions liveness; on later unchanged rechecks it only says "unchanged since the last recheck". Rizzo answers absorbable at 0.95, so the dead worker is absorbed, the throttle and surfaced markers are re-stamped, and it goes quiet indefinitely, visible only as digest lines. Fix: skip jev_stale_absorbed when now_sit contains ' agent=dead ', and add a watcher test for it.bin/fm-jev.sh:976- This contradicts the intent criterion "Fall-through to today's behavior on any doubt ... adding no latency beyond the existing per-request classify timeout". When absorption is requested without override and the 300s gate cache is missing or stale, jev_absorb_gate_cached runs the wholeabsorb-gate --jsonscan synchronously inside fm-watch's loop, bounded only by JEV_ABSORB_GATE_TIMEOUT=10s. That time is added on top of the classify timeout. So an eligible signal or recheck can block the watcher for about 10s plus jev-timeout once every 5 minutes. docs/configuration.md says the opposite. Keeping the wake path at classify-timeout-only would mean moving the gate refresh off that path (for example into the detached observe-drain, with absorb-try only reading the cache and falling through when it is missing). That adds background work, so the remedy needs the author's sign-off.bin/fm-jev.sh:188- At realistic volume the go-live gate can never be met, so in practice only the captain override activates absorption. JEV_JQ_ROWS joins every presented wake against every event in the whole shadow log (quadratic), and it does this before the 30-day window filter. The shadow log is append-only and never rotated. Measured here: the live ~/firstmate shadow.jsonl (~215 wakes/day) replicated to 30 days (25,860 events, 6,439 wakes) took 157s forfm-jev.sh absorb-gate, against a 10s JEV_ABSORB_GATE_TIMEOUT. After a few days of logging every recompute times out, cachesfail, and absorption stays inactive for good (while still paying the 10s stall above). That fails closed, but the measured gate the intent requires stops working. Possible fixes: pre-filter or index events before the join, bound the scanned log, or compute the gate incrementally. Each of these changes how the gate measures, so this needs the author.bin/fm-jev.sh:143- The intent requires "Source comments max 3 lines." Many new comment blocks are longer. Examples: the new absorption block in the fm-jev.sh header (~33 lines, 143-175), the cmd_absorb_try header (9), jev_dial_local (10), jev_absorb_gate_cached (7), JEV_JQ_ROWS/JEV_JQ_ABSORB_GATE (5 each). In fm-jev-lib.sh: fm_jev_absorb_try (12) and fm_jev_absorb_digest_surface (7). In fm-watch.sh: jev_signal_absorbed (8), jev_stale_absorbed (6), and the inline signal-branch comment (6). The fm-wake-drain.sh digest comment is 5 lines, and the new test-file comments run 5-7 lines.tests/fm-jev.test.sh:614- The intent requires "Tests for every refusal class and the gate" and names "timeout, server error, or classifier error" as fall-through classes. None of those are tested for absorb-try: no curl timeout (rc 28), non-2xx HTTP, transport error, or unreadable body. Also untested: an invalid (non-loopback) config/jev-endpoint, ablocked:verb, the watcher refusing a batch that coalesces more than one task, the dead-agent recheck, and the real activation path where absorb-try passes via a met gate (jev_absorb_gate_cached and its cache) with no override. Only the override path is ever exercised end to end.bin/fm-jev.sh:886- JEV_JQ_ABSORB_GATE scores every jev row in the window regardless of which backend produced it, even though absorption only ever acts on the local Rizzo answer. Shadow rows recordmodel("typesafe/jev-1.13" for OpenRouter, a source/weights/precision string for local). A home that ran OpenRouter shadow for weeks and then set config/jev-endpoint passes the gate on OpenRouter's accuracy, and the local classifier becomes active with no local evidence. Consider restricting the gate to rows whose model is the local backend's.bin/fm-watch.sh:1263- jev_signal_absorbed accepts a batch made only of<task>.turn-endedwith no new status write. absorb-try then judges it on the old last status line (e.g.working: ...). jev_mask turns the file path in the reason into<path>, so the classifier cannot tell a turn end from a status update. The watcher's own triage comment calls absorbing such a turn end "exactly the swallowed-finish this change guards against": for example, a crew that finished through an interactive menu without writing done:. The intent allowlists "a routine working/paused signal wake". Please confirm whether a bare turn-end with a stale working line is meant to be eligible, or whether only a status-file signal should be.bin/fm-jev.sh:262- The intent lists "calibrated" as a go-live criterion. The implementation only enforces a numeric floor (jev_absorb_threshold_valid, >= 0.9). Nothing checks that the configured threshold is supported by the shadow data at that confidence level; the docs only say it "must be calibrated". Please confirm the floor plus the 0.6-measured wrong count is the intended meaning of "calibrated".bin/fm-jev-lib.sh:135- fm_jev_absorb_digest_surface pipes raw lines intojq -rand then always advances the cursor to the pre-read size. One malformed or partial line (a truncated write, or a line read mid-append) makes jq stop there. Every later entry in that batch is then not printed, while the header count still includes it and the cursor moves past it, which weakens "never lost silently". Parsing per line (jq -R 'fromjson? | ...') and advancing only to the last complete newline would close this.docs/configuration.md:651- The docs say the gate needs "a minimum sample of 300 classified wakes", but the gate compares min_sample againstscored(classified rows with known ground truth), notclassified. That is stricter, which is fine, but the docs should say scored/measured wakes so operators readabsorb-gateoutput correctly.🔧 Fix: Guard dead-agent rechecks, harden digest parsing, fix gate docs
1 warning still open:
bin/fm-jev-lib.sh:126- This can lose a digest entry silently, against the intent's "surfaced with the next real wake or heartbeat, never lost silently". fm_jev_absorb_digest_surface moves its cursor forward on every fm-wake-drain.sh run, whoever runs it. But bin/fm-supervise-daemon.sh:1292 (handle_durable_wakes, the away-mode sub-supervisor) drains into a temp file, reads only the tab-separated queue rows, and deletes the rest. Failing sequence: in always-on mode Jev absorbs a routine working: signal and appends it to absorbed.jsonl. Before any real wake or heartbeat triggers a drain, the captain goes afk. The daemon's first drain prints the ABSORBED section into $out, where it is thrown away, and the cursor is saved past it. The captain never sees that entry: fm-afk-return.sh's catch-up drain (which does put drain output into its evidence) finds nothing pending. The line is still in absorbed.jsonl on disk, but it is never surfaced. Smallest fix: skip digest surfacing (and leave the cursor alone) while away mode owns triage, e.g. return early when $STATE/.afk exists. fm-afk-return.sh stops afk-launch before its own drain, so the pending entries would then show up in the return catch-up evidence.🔧 Fix: Hold the absorbed-wake digest while away mode owns drains
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-jev.test.sh(whole file, including the 13 new absorb-try / absorb-gate / digest tests)bash tests/fm-watch-triage.test.sh(whole file, because the sharedwatch_bghelper changed; includes the 5 new real-watcher Jev tests: signal absorbed, off still surfaces, declared-pause recheck absorbed, dead-agent recheck never absorbed, captain-held recheck never absorbed)Manual e2e against the REAL local Rizzo Flow server on 127.0.0.1:8017:e2e-absorb-demo.shcoversfm-jev.sh status,absorb-gateandabsorb-tryacross off / requested-without-gate / override / threshold 0.5 / done, needs-decision, blocked and failed verbs / OpenRouter backend / dead endpoint / hung endpointProbed the real Rizzo answers for routine working:/paused: lines through a logging curl wrapper. All came backfirstmateat 0.66–0.84, so absorb-try correctly fell throughManual positive-path e2e with a loopback stub speaking the Rizzo /v1/decisions shape (absorbable 0.95):e2e-absorb-positive.shcovers signal and stale absorption, the masked request and digest, the.afkdrain hold, surfacing on the nextfm-wake-drain.sh, no repeat, and a hung-server fall-through timed at 2.33s against a 2sconfig/jev-timeout✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.