Repository navigation
feat(bin): record shadow advisory facts and add the candidate gates scorer - #34
Merged
Merged
Conversation
The Jev shadow trial could only score what the mod recorded: the answer bytes, with no deterministic snapshot of the state each answer judged. Every full-variant shadow record now carries a facts object - the wake key, new status bytes per task, pane identity and stale series, pane observation, authoritative PR presence and identity, severity criteria labels, and that record's own candidate Nouls - assembled from state the mod already read, so the request body is unchanged. The pane helper reports the window identity and the watcher's stale-series markers when it can read them, and the mod folds those into facts only. bin/fm-branch-shadow-gates.sh scores six candidate absorb, suppress, and escalate gates over those records against durable ground truth: outcome rows joined by wake key, the wake-drain backstop's surfacing, and derivable main actions such as a worker restart after a stale wake or a recorded PR behind a ready phase. Per wake it reports eligible, unscorable, fired, correct, and wrong split into delay- versus loss-class, sweeps floors 0.70-0.99 for the lowest clean floor, and reports unmatched records separately, so the trial can say what each gate would have done before anyone acts on one.
…ility, backstop span
This was referenced Sep 28, 2026
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
Add deterministic facts to the supervision-branch mod's Jev shadow advisory records - the wake key, new status bytes per task, pane identity and stale series, pane observation, authoritative PR presence and identity, severity criteria labels, and each record's own candidate Nouls - assembled from state the mod already reads so the request body to the TypeSafe endpoint is unchanged, and add bin/fm-branch-shadow-gates.sh, a sibling scorer that scores six candidate absorb, suppress, and escalate gates over those records against durable ground truth (outcome rows joined by wake key, the wake-drain backstop's surfacing, and derivable main actions), reporting per-wake eligible, unscorable, fired, correct, and wrong split into delay- versus loss-class plus missed, sweeping floors 0.70-0.99 for the lowest floor with zero loss-class wrong fires and the fire rate there, listing disagreements by wake key under -v, and treating records without facts as unscorable for a gate rather than guessed.
What Changed
branch.tsnow records afactsobject with every shadow advisory record instate/branch-mod-shadow.jsonl(wake key, new status bytes per task, pane identity and stale series, pane observation, authoritative PR presence andowner/repo#Nidentity, severity class labels, and the record's own candidate Nouls), assembled from state the hook already reads; the request body sent to the endpoint is unchanged.bin/fm-branch-shadow-pane.shadditionally prints the task'swindowand the watcher'sstale.series_index/stale.wedge_escalationsmarkers, read read-only fromstate/.count-<key>andstate/.wedge-escalations-<key>, and no longer treats missing tail and observation as empty when stale evidence exists.bin/fm-branch-shadow-gates.sh [-v] [<shadow-log>] [<outcomes-file>]scores six candidate gates (absorb-no-new-outcome,absorb-routine-working,stale-active-suppress,pr-ready-arm,severity-alert,candidate-order) over full-variant records against outcome rows joined by wake key, the wake-drain backstop's surfacing, and derivable main actions; reports per-wake eligible/unscorable/fired/correct/wrong (delay- vs loss-class)/missed, sweeps floors 0.70-0.99 for the lowest floor with zero loss-class wrong fires, lists disagreements under-v, and treats records without facts as unscorable. Tests added inbranch.test.tsandtests/fm-branch-mod-bin.test.sh; docs updated inAGENTS.md,docs/claude-supervision-branch.md,docs/configuration.md, anddocs/scripts.md.Risk Assessment
✅ Low: The final fix round is a bounded scorer change: the byte sum now emits "-" unless every wake task has a numeric entry, and the stale gate is unscorable unless facts.pane equals the window the wake text names; I traced every fixture record through the current gate_apply/gate_fire/loss logic and the updated table, sweep, and -v expectations all follow from the code, the pane and watcher window strings share the same meta-derived source, and no required intent behaviour is removed.
Testing
Ran the targeted bin test (11 checks, incl. the new 21-record gates fixture and pane helper window/stale cases) and the mod's own plugin suite under the installed Claude Code (36 pass, 0 fail, incl. the three new facts tests); then live-drove bin/fm-branch-shadow-gates.sh over a hand-built state directory with real fm-branch-outcome.sh rows and adversarial records (partial bytes object, empty bytes, torn JSON line, non-full/repeat-2 records, stale wake with another task's pane fact), verified --help, and live-drove bin/fm-branch-shadow-pane.sh against a real isolated tmux server with watcher marker files. All live-driven scenarios passed. The mod's facts-recording scenarios ran only under the stubbed plugin-test world and are reported untested. Only finding is stderr noise from the pane helper when markers are absent.
bash tests/fm-branch-mod-bin.test.shclaude plugin test, where the Jev endpoint and the evidence/pane subprocesses are stubbed by the plugin test world (36 pass, 0 fail in plugin-test.log). A live…claude plugin testworld (plugin-test.log). A live result needs a real supervision home with classifier-shadow=jev and a FM Jev API key, where…Evidence: Gates scorer fixture report rows (bin test)
Source: Gates scorer fixture report rows (bin test)
Evidence: Gates scorer adversarial live drive (-v)
Source: Gates scorer adversarial live drive (-v)
Evidence: Pane helper live drive on real tmux
Source: Pane helper live drive on real tmux
Evidence: Gates scorer --help tail
Source: Gates scorer --help tail
Evidence: bin test log
Source: bin test log
Evidence: claude plugin test log
Source: claude plugin test log
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 6 issues found → auto-fixed (5) ✅
bin/fm-branch-shadow-gates.sh:276- task_restarted_after never detects a restart in production. bin/fm-busy-event.sh arm mints gen asg<epoch>.<pid>.<random>(line 159), but the scorer rejects any gen matching*[!0-9]*, so every real busy-state record returns 1. wake_stale_repair then only sees teardown, and stale-active-suppress fires over a relaunched worker are countedcorrectinstead ofdelay, and stale wakes whose repair was a relaunch are neveractionablefor the absorb gates (loss fires counted as correct). The bin test fixture (tests/fm-branch-mod-bin.test.sh:80) writes a bare-number gen that the real appender never produces, which is why it passes. Fix: extract the epoch withsed -n 's/^g\{0,1\}\([0-9]\{1,\}\)\(\..*\)\{0,1\}$/\1/p'(or awk on^g?([0-9]+)) and write the fixture in the realg<epoch>.<pid>.<rand>form.bin/fm-branch-shadow-gates.sh:383- severity-alert eligibility requires R_SEVHIT == hit, i.e. the score already fell in a security/privacy/data-loss/credential/publication class. Every full record carries a severity answer, so all records scored 0-2 are countedunscorable("missing inputs for the gate") rather than eligible-and-silent: the fire rate in the sweep becomes fired/fired,missedcan never include a low-scored actionable wake, and the table misreports the gate as having almost no eligible wakes. Eligibility should beR_SEVCLS != "-"(score in range),R_SEVCONF != "-", andR_SEVANY = any;hitbelongs only in gate_fire.bin/fm-branch-shadow-gates.sh:205- LAST_EP[$task] is only advanced for rows that carry a wakeKey, because thecontinueon a-wake key (line 201) runs first. Unkeyed rows exist mid-trial (branch.ts:1186 appends a direct pass-to-main captain row with no --wake-key; pre-trial and Pi-branch rows are also unkeyed). Sequence: t1 row A (no key, captain, endpoint 100, span holdsneeds-decision: x), then row B (key W, routine, endpoint 200). Scorer scans (0,200] for B, finds the already-presented decision line, sets WK_BACKSTOP[W], and every absorb fire on W is scored a loss-class wrong fire. Moveprev_ep=${LAST_EP[$task]:-0}; LAST_EP[$task]=$endpointabove the wake-key guard so every row of the task advances the span start.bin/fm-branch-shadow-gates.sh:124- The record's stale flag uses jqtest("^stale:"), where^anchors to start of string, but branch.ts:905 uses/^stale:/mand the wake reason isreasonLines(...).join('\n')in queue order (branch.ts:1168). A compound wakesignal: ...\nstale: fm-t2gets a stale_state question and answer in the record but is classedplainhere: stale-active-suppress returns not-applicable for it, WK_ISSTALE stays unset so wake_stale_repair is never consulted, and stale_window_loss never sees it as a later stale wake of the pane. Usetest("(^|\n)stale:").bin/fm-branch-shadow-gates.sh:377- stale-active-suppress needs two facts the gate_apply check ignores: pane_observation.progressing (gate_fire line 340 requirestrue) and pane identity (stale_window_loss keys on it). A stale record with facts but no pane observation is counted eligible and, when absorbable,missed, although the gate could never have judged it; and pane_of (line 295) falls back to the first task id when the pane fact is absent, which both guesses an identity and cannot match records of the same pane that do carryfm-<task>. The header (lines 17-19) says a record without the inputs one gate needs is unscorable, never guessed. RequireR_PROG != "-"andR_PANE != "-"in gate_apply for this gate and drop the task0 fallback in pane_of..claude/mods/fm-branch-mod/hooks/branch.ts:725-paneExtras?.window ?? (st.pane ? String((st.pane as any).task ?? '') : '')- the fallback is unreachable: st.pane and paneExtras are set from the same helper line, so whenever st.pane exists paneExtras exists and window is either present or the fallback yields the task id, not a pane identity.facts.pane = paneExtras?.windowalone is equivalent and truthful.🔧 Fix applied.
3 issues (2 warnings, 1 info) still open:
bin/fm-branch-shadow-gates.sh:289- wake_stale_repair treats "task meta and status both gone" as a derivable stale repair, but bin/fm-teardown.sh:936 removes <task>.meta on every ordinary teardown, so at scoring time every stale wake of any task that has since finished normally becomesactionable. Concrete: stale wake W on t7, worker was fine (routine row, no restart, no backstop), t7 completes days later and is torn down; the scorer run afterwards scores an absorb-no-new-outcome fire on W as a loss-class wrong fire, a stale-active-suppress fire on W asdelay, any earlier same-pane stale fire within 1800s asloss, and W is nevermissed. The sweep's "lowest clean floor" therefore drifts upward the longer the scorer runs after the trial, which is the opposite of durable ground truth. The header (line 33) documents this clause, so it is a deliberate heuristic: decide whether teardown should count at all, or only when the busy-state gen shows a relaunch; the smallest remedy is dropping the teardown clause from wake_stale_repair.bin/fm-branch-shadow-gates.sh:201- For the first outcome row of a task prev_ep is 0, so backstop_span_has_surface scans (0, endpoint] over the whole status log. The real backstop it claims to mirror bounds the span by the wake's receipt offset as well as the previous row's endpoint (bin/fm-classify-lib.sh:1223[ "$prev" -le "$from" ] || from=$prev, with from = the classifier receipt), so lines the old classifier or Pi path presented before the mod's first row are never re-surfaced there. Concrete: a home enables the branch mod on a live task whose status already holdsdone: PR ... checks green(presented pre-mod, no outcome row); the first keyed routine row on that task scans from byte 0, finds the line, sets WK_BACKSTOP for that wake, and every absorb fire on it is a loss-class wrong fire that main's backstop would never have surfaced. No durable receipt exists for historical wakes, so the honest choice is either to treat the backstop as unscorable when the task has no earlier row (skip the scan when prev_ep is 0) or to accept the bias; that is a ground-truth policy decision, not a mechanical fix.bin/fm-branch-shadow-gates.sh:33- The header says stale repair is derived from "a later outcome row for the same task or the task's records gone", but wake_stale_repair derives it from a newer busy-state gen (relaunch) or teardown; no later-outcome-row check exists. Align the header with the code (or vice versa, per the teardown finding) so -v adjudication reads the right rule.🔧 Fix applied.
6 issues (4 warnings, 2 infos) still open:
.claude/mods/fm-branch-mod/hooks/branch.ts:724-new_status_bytes[task] = Math.max(0, b.to - b.from)records 0 when the evidence gatherer failed: gatherEvidence (branch.ts:585, 588) returns from=-1,to=-1 on a non-zero exit, a 25s timeout, or an unparseable range, and -1 - -1 = 0. The scorer then treats the wake as having zero new status bytes, so absorb-no-new-outcome is eligible and fires whenever the Noul clears the floor, and the fact header's promise ("never an invented value") is broken for exactly the wakes whose evidence is unknown. Concrete: fm-wake-evidence.sh t1 times out; record facts.new_status_bytes.t1 = 0; a routine wake with noul 0.9 counts as a correct absorb. Fix: skip the entry whenb.from < 0 || b.to < 0so the scorer sees-and counts the record unscorable for that gate.bin/fm-branch-shadow-gates.sh:363- gate_apply checksunavailableandnofacts(lines 363-364) before the per-gate applicability guards that return 2, so a plain wake at stale-active-suppress and a single-task wake at candidate-order are countedunscorablealthough the gate does not apply to them; stale-ness comes from the record's wake text and the task count fromtasks, neither needs facts. In production every unavailable or pre-facts record inflates the stale and ordering gates' unscorable columns by one each. The bin test enshrines it:stale-active-suppress | 5 | 2andcandidate-order | 2 | 1count the plain single-task nofacts record 1700:13, and the -v assertion at tests/fm-branch-mod-bin.test.sh:172 requires 1700:13 to be listed under stale-active-suppress. Fix: move theR_STALE = stale || return 2andR_NTASKS -ge 2 || return 2guards above the avail/facts checks and update those three assertions (stale unscorable 1, candidate-order unscorable 0, drop the 1700:13 stale line).bin/fm-branch-shadow-gates.sh:373- The stale gate's pane facts belong to tasks[0], not to the window the stale line names: branch.ts:842 calls fm-branch-shadow-pane.sh fora.tasks[0]only, and eligible tasks follow queue-row order, so a compound wakesignal: t1.status\nstale: fm-t2 (...)records pane=fm-t1 and fm-t1's progressing flag. gate_fire then fires stale-active-suppress on the wrong pane's progress, and stale_window_loss looks for later stale wakes of fm-t1 instead of fm-t2, so a captain stale on fm-t2 inside the window is never a loss. The watcher's reason isstale: <window> (...)(bin/fm-watch.sh:1143), so the honest guard is mechanical: capture the window afterstale:in the REC_ROWS jq and require it to equal R_PANE in gate_apply for stale-active-suppress, else return 1 (unscorable, never guessed).bin/fm-branch-shadow-gates.sh:273- The two derivable main actions are read from files teardown deletes, so ground truth still drifts with scoring time, now in the opposite direction from the round-2 teardown finding. task_restarted_after reads state/<task>.busy-state, which fm-busy-event.sh retire removes (bin/fm-busy-event.sh:211) during fm-teardown.sh (line 1258); task_poll_armed reads <task>.pr-poll and pr= in <task>.meta, both removed by teardown (lines 936, 1302). Concrete: stale wake W on t5, worker relaunched (gen newer), scorer before teardown scores a stale-active-suppress fire on W asdelayand an absorb fire asloss; after t5 is torn down the same records scorecorrect, and W becomesmissedfor the absorb gates; a pr-ready-arm fire whose only PR truth was the armed poll flips fromcorrecttodelay. The sweep's lowest clean floor therefore falls the longer after the trial the scorer runs. No durable launch or poll log exists in the state inventory, so this is a ground-truth policy decision rather than a mechanical fix: either document that the gates scorer is only valid while the trial's tasks are live (and print a note when a wake's task records are gone), or derive these actions from a durable store the intent authorises.bin/fm-branch-shadow-gates.sh:96---helpprints header lines 2-80, but the header now runs to line 82, so the last two lines of the Usage note ("Exit 0 always; ... only the empty tables.") are cut off. Use2,82por stop at the first non-comment line (sed -n '2,/^set -eu/{/^set -eu/!p}')..claude/mods/fm-branch-mod/hooks/branch.ts:725- Simplification: the fallback(st.pane ? String((st.pane as any).task ?? '') : '')is a second definition of pane identity the intent does not need. fm-branch-shadow-pane.sh always printswindowon any non-unavailable line (line 122), so paneExtras.window is present whenever st.pane is; if the fallback were ever reached it would record the task id asfacts.pane, which the scorer would then compare against realfm-<task>window names and never match. Remove it:const paneId = paneExtras?.window ?? ''.🔧 Fix applied.
1 warning still open:
bin/fm-branch-shadow-gates.sh:335- The round-4 fix keys the stale gate's identity and loss window on the window named in the wake text (R_STALE), but the fire condition at line 335 still reads R_PROG, which is facts.pane_observation.progressing for tasks[0]'s pane (branch.ts:842 runs fm-branch-shadow-pane.sh for a.tasks[0] only; eligibleTasks follow queue-row order). For a compound wakesignal: t1.status\nstale: fm-t2the record carries fm-t1's progressing flag, so the gate fires (or stays silent) on the wrong pane's evidence and the scorer counts a fire the real gate would never have had grounds for; the fixture record 1700:19 enshrines exactly this (facts.pane fm-t1 + progressing true, stale fm-t2) and the assertion at tests/fm-branch-mod-bin.test.sh:184 requires it to fire. This follows the round-3 user instruction that such a wake "must fire, delay, and take loss on fm-t2's identity", so it is a deliberate-intent question rather than a mechanical fix: the honest guard is to keep the facts.pane column and, in gate_apply for stale-active-suppress, return 1 (unscorable) unless facts.pane equals the named stale window, then change 1700:19's expectation to unscorable (stale row 6 | 2, no loss on 1700:19, 1700:20 stays delay). Please confirm which reading the trial wants.🔧 Fix applied.
1 warning still open:
bin/fm-branch-shadow-gates.sh:148- The round-3 fix omits a failed-gather task from facts.new_status_bytes (branch.ts:724), but the scorer sums whatever entries remain:[($f.new_status_bytes // {})[] | numbers] | add // 0turns an empty object into "0" ([] | addis null,// 0makes it 0), so the fake zero the fix was meant to remove reappears at scoring time. Concrete: fm-wake-evidence.sh t1 times out, the record carriesnew_status_bytes: {}(exactly what the branch.test.ts case asserts), REC_ROWS bytes = 0, gate_apply for absorb-no-new-outcome passes (R_BYTES != "-"), and a noul 0.9 record fires and is scored correct/loss on evidence that was never read. The same happens for a compound wake where t1 gathered 0 bytes and t2's gather failed ({"t1":0}sums to 0 while t2's bytes are unknown). This contradicts the intent's "treating records without facts as unscorable for a gate rather than guessed". Fix in the jq: emit "-" unless every task in$r.taskshas a numeric entry, e.g.(if ($f.new_status_bytes | type) == "object" and (($r.tasks // []) | length) > 0 and (($r.tasks // []) | all(. as $t | ($f.new_status_bytes[$t] | type) == "number")) then ([($r.tasks // [])[] as $t | $f.new_status_bytes[$t]] | add | tostring) else "-" end); no existing bin-test expectation changes (no fixture has a partial bytes object), and the branch.test.ts{}assertion stays valid.🔧 Fix applied.
✅ Re-checked - no issues remain.
bin/fm-branch-shadow-pane.sh:83- When a watcher marker is absent (the common case for a non-stale task), the shell reportsbin/fm-branch-shadow-pane.sh: line 83: .../.count-<key>: No such file or directory(and line 84 for the wedge marker) on stderr, because2>/dev/nullbinds to tr while the failing input redirect is evaluated by the shell first. Stdout JSON is unaffected and the mod reads stdout only, so behaviour is correct, but the header promises the helper 'prints nothing' for an absent marker and a human running it by hand sees two spurious errors per call. Fix: guard with[ -f "$STATE/.count-$key" ] && series=$(tr ... <"$STATE/.count-$key")or wrap as{ tr -d '[:space:]' <"$f"; } 2>/dev/null.bash tests/fm-branch-mod-bin.test.shclaude plugin test, where the Jev endpoint and the evidence/pane subprocesses are stubbed by the plugin test world (36 pass, 0 fail in plugin-test.log). A live…claude plugin testworld (plugin-test.log). A live result needs a real supervision home with classifier-shadow=jev and a FM Jev API key, where…bash tests/fm-branch-mod-bin.test.sh(test_gates_scorer_joins_full_records_to_outcomes_facts_and_derivable_actions, test_shadow_pane_helper_reports_only_what_it_can_read and siblings)CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude plugin test .claude/mods/fm-branch-mod(36 pass, 0 fail; facts ride every record / facts stay honest / facts omit failed-gather bytes / compound candidates) — stubbed world, not liveLive:FM_STATE_OVERRIDE=<tmp> bin/fm-branch-shadow-gates.sh -vover realfm-branch-outcome.sh append --wake-keyrows with partial bytes, empty bytes, torn line, non-full variant, repeat-2, and foreign-pane stale recordsLive:bin/fm-branch-shadow-gates.sh --helpline count equals header comment line count (85)Live:FM_STATE_OVERRIDE=<tmp> bin/fm-branch-shadow-pane.sh t9against an isolated tmux server (TMUX_TMPDIR) with .count-/.wedge-escalations- markers present, absent, garbage, and with the server killed✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.