Skip to content

feat(bin): add opt-in Jev shadow classifier for supervision wakes - #40

Merged
alandomio merged 8 commits into
mainfrom
fm/jev-triage-ombra
Sep 26, 2026
Merged

alandomio merged 8 commits into
mainfrom
fm/jev-triage-ombra

Conversation

@alandomio

@alandomio alandomio commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Intent

Add Jev (TypeSafe's decision model on OpenRouter, model id typesafe/jev-1.13) to firstmate as an ADVISORY, SHADOW-ONLY classifier of supervision wakes. This is the first of several planned uses; this PR delivers shadow mode only (switch, log, measurement). Activation (letting Jev absorb wakes) is a later, separate PR and is out of scope. This is firstmate's own shared tracked material: follow firstmate-coding-guidelines (one-owner rule, one sentence per line in Markdown, shellcheck-clean bin scripts, colocated behavior tests, no agent co-author).

Captain's binding design decisions (data/jev-integrazione/decisioni.md):

  • Off by default. Enabled only when the private, gitignored .env of the firstmate home carries OPENROUTER_API_KEY (exact variable name), mirroring how Relay is presence-gated by FMX_PAIRING_TOKEN in .env. Never print, log, echo or commit the key; never read other .env values. Deliberate choice: an OPENROUTER_API_KEY in the ambient environment does NOT enable it (only the home .env does), and it only runs when STATE is the key home's own state dir, so tests or tools pointing STATE elsewhere can never spend the key. The key is handed to curl on stdin (-K -), never argv.
  • Per wake, ask one three-way question: needs firstmate / absorbable / urgent for the captain (Jev "choice" primitive with options firstmate, absorbable, captain).
  • Send ONLY the wake reason line and the worker's last status line, with paths and URLs masked (and capped at 500 chars). Nothing else leaves the machine.
  • Hard limits: 2 s timeout; a daily spend cap (default USD 1, configurable via config/jev-daily-cap); on timeout, API error or cap breach the wake surfaces exactly as today and Jev disables itself until the next local day. Interpretation decision: per the captain's decision 8 only limit breaches (timeout, API/transport error, missing usage.cost which makes the cap unenforceable, cap) pause Jev for the day; a low-confidence or out-of-set answer counts as "doubt" (which surfaces) at report time via --min-confidence (default 0.6) but does not pause Jev.
  • Shadow: classify and log next to firstmate's actual handling; act on NOTHING. It must never delay, drop, reorder, absorb or alter a wake, and never influence merges, destructive/security actions or captain decisions. A Jev failure must never break or slow the watcher/wake path, so the drain hands rows to a detached process (FM_JEV_FOREGROUND=1 is a test-only synchronous knob). Every hook is best-effort, silent, and returns 0.
  • Ground truth, automatic: a wake "needed firstmate" if its handling turn produced a captain message, a steer or a decision; "absorbable" if it ended with a plain acknowledgement. Recorded via hooks: fm-send.sh (steer, or decision with --resolve-key), fm-control.sh (steer), fm-captain-hold.sh hold/answer (decision), fm-wake-drain.sh --ack-through (ack), and fm-turnend-guard.sh (turn end outcome ack/message/unknown derived from the harness payload's last_assistant_message; only the outcome is stored, never the text; "Captain, shipshape." or empty = ack). The turn-end hook is optional and guarded so a missing helper can never change the guard's verdict. Attribution (captain decision, Option A): a steer/decision naming a task is credited only to that task's wakes still awaiting their turn end, from any drain; an unnamed one, or one naming a task with no open wake, is credited to every open wake and flagged shared so it lands in the doubtful list; a captain message is credited to every wake whose handling turn it ends, flagged shared when that is more than one wake. Automated sends (pending-reply resends, bootstrap and config-reread nudges, remote relays) are not recorded as steers. Harnesses without last_assistant_message (verified present in Claude Code 2.1.283 and Codex 0.152.1) leave that part unknown.
  • Measurement: bin/fm-jev.sh report reports over the shadow window agreement %, the count of wakes Jev would have absorbed that actually needed action (must be zero for go-live), a three-way breakdown, the go-live criteria, and a list of ~20 doubtful cases for the captain to review. Go-live criteria are for later: zero wrongly-absorbable wakes and at least 90% agreement over one week.

API facts (from OpenRouter docs and one allowed real smoke call): Jev is not a chat model; it is called at POST https://openrouter.ai/api/alpha/decisions with {model, state, questions}, and returns answers..choice/confidence/probabilities plus usage.cost in USD. The smoke call cost USD 0.0000196 and took 1.05 s.

Acceptance: switch off by default and verified off without the key; with the key, shadow classifications are logged privately under state/jev/ (gitignored) without changing any wake behaviour; limits enforced and tested (timeout, cap, API error) with the network mocked in tests (fake curl on PATH) - tests must never call OpenRouter; masking tested; measurement command works on a fixture log; docs updated where configuration and .env keys are documented (docs/configuration.md, AGENTS.md layout, docs/scripts.md). Known pre-existing issue out of scope: bin/fm-test-run.sh --check-coverage fails on unmodified main under a non-C locale (comm without LC_ALL=C) and passes with LC_ALL=C.

What Changed

  • Added bin/fm-jev.sh and bin/fm-jev-lib.sh, an advisory, shadow-only classifier. It runs only when the home's gitignored .env sets OPENROUTER_API_KEY (an OPENROUTER_API_KEY in the ambient environment does not count) and STATE is that home's own state dir.
    • For each wake it asks OpenRouter's Jev decisions endpoint (typesafe/jev-1.13) one three-way question: firstmate, absorbable, or captain.
    • It sends only the wake reason line and the worker's last status line, with paths and URLs masked and each capped at 500 chars.
    • The key reaches curl on stdin, never argv.
    • Each request has a 2 s timeout, and the daily spend cap defaults to USD 1 (override in config/jev-daily-cap).
    • A timeout, API error, response with no cost, or cap breach pauses Jev until the next local day.
    • Answers are logged privately under state/jev/.
    • status, mask, and report subcommands are included. report shows agreement %, wrongly absorbable wakes, a three-way breakdown, the go-live criteria, and up to ~20 doubtful cases.
  • Added best-effort, silent hooks that always return 0 and never change how a wake is handled. Rows go to a detached process, and they record ground truth:
    • fm-wake-drain.sh: classifies the drained batch and records --ack-through acks.
    • fm-send.sh and fm-control.sh: record steers; fm-send.sh --resolve-key records decisions.
    • fm-captain-hold.sh: records hold and answer decisions.
    • fm-turnend-guard.sh: records the turn-end outcome (ack, message, or unknown) from last_assistant_message, never the text.
    • Automated sends are marked with FM_JEV_OBSERVE=0 so they never count as a firstmate steer. This covers bootstrap nudges, config push/inherit, remote secondmate control, and pending-reply resends.
  • Added tests/fm-jev.test.sh, which uses a fake curl on PATH, and extended tests/fm-turnend-guard.test.sh. Documented the switch, limits, state/jev/ and the new env knobs in docs/configuration.md, docs/scripts.md and AGENTS.md, and registered the new test in bin/fm-test-run.sh.

Risk Assessment

✅ Low: The latest fix round correctly adds FM_JEV_OBSERVE=0 to the remote cmd_key relay, and the new fixture steer (task y, recorded after its unacknowledged wake is presented) would make the test fail if the unbounded-end branch were reverted; the rest of the shadow-only feature is best-effort, opt-in and off the wake path.

Testing

I ran the new colocated tests/fm-jev.test.sh (13 cases). I also ran the existing tests for the files that got hooks: turn-end guard, wake drain, send --resolve-key, captain-hold and control. All passed. I then ran a manual end-to-end demo against temporary homes with a fake curl, so nothing reached the network. It shows: - Jev stays off when the key is only in the environment: no state/jev directory and no curl call. - The drain output is identical with Jev on and off, once the per-run recovery-generation nonce is normalized. - Only the masked wake reason and the worker's last status line are sent, with <url> and <path> substituted. - The key is passed to curl on stdin (-K -) and appears nowhere in argv or under state/. - The private shadow log is mode 0600 and records the presented, classified and ack events. - The report lists the wake as doubtful because no turn end was recorded. - A timeout records a skip and a pause until the next day, and the wake is still shown. There is no UI surface, so the evidence is CLI transcripts and test logs. The overall result is a pass, and the worktree is clean.

Evidence: End-to-end CLI transcript: switch off/on, identical drain output, masked request body, key not in argv, shadow log, report, timeout pause

Source: End-to-end CLI transcript: switch off/on, identical drain output, masked request body, key not in argv, shadow log, report, timeout pause

\### 1. status without key (ambient OPENROUTER_API_KEY set) vs with .env key
Jev shadow triage: off (no OPENROUTER_API_KEY in /tmp/tmp.oVAW8Ea1vk/off/.env)
spend today: USD 0.000000 of a USD 1 daily cap
shadow log: /tmp/tmp.oVAW8Ea1vk/off/state/jev/shadow.jsonl
Jev shadow triage: on (OPENROUTER_API_KEY present in /tmp/tmp.oVAW8Ea1vk/on/.env)
spend today: USD 0.000000 of a USD 1 daily cap
shadow log: /tmp/tmp.oVAW8Ea1vk/on/state/jev/shadow.jsonl

\### 2. drain output: Jev off vs Jev on (must be identical)
1790000000	1	signal	task2.status	signal: task2.status: done: PR https://github.com/o/r/pull/7 green
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 387406.1790420854.vDCsBe
wake annotation: latest wake-EVENT observed at drain, not current state: task2.status: done: PR https://github.com/o/r/pull/7 green, notes in ~/wt/report.md
=> IDENTICAL presentation (recovery-generation nonce normalized)
off home: state/jev exists? no; curl calls: 0

\### 3. request body sent to OpenRouter (masked) and curl argv (key absent?)
{
  "model": "typesafe/jev-1.13",
  "state": {
    "wake_reason": "signal: task2.status: done: PR <url> green",
    "worker_last_status": "done: PR <url> green, notes in <path>"
  },
  "questions": {
    "handling": {
      "type": "choice",
      "instructions": "A supervisor agent (firstmate) coordinates autonomous coding workers and reports to a human captain. This wake notification just arrived. How must it be handled?",
      "criteria": {
        "firstmate": "Firstmate must act: steer, answer, unblock or recover a worker, review or land its work, or otherwise do something beyond acknowledging.",
        "absorbable": "Routine, duplicate or informational progress with nothing to do: firstmate would only acknowledge it.",
        "captain": "The captain must hear about it now: a decision only the captain can make, work ready for review, a real failure, a needed credential or login, or anything destructive or security-sensitive."
      }
    }
  }
}
-sS -K - --max-time 2 --connect-timeout 2 -H Content-Type: application/json --data-binary @/tmp/tmp.oVAW8Ea1vk/on/state/jev/.body.xGTZJm -o /tmp/tmp.oVAW8Ea1vk/on/state/jev/.resp.E7IQEF -w %{http_code} https://openrouter.ai/api/alpha/decisions
=> key not in argv
=> key not in state/

\### 4. ack, then shadow log
total 4
-rw------- 1 alan alan 502 Sep 26 13:07 shadow.jsonl
{"ev":"presented","t":1790420855,"id":"1790000000:1","seq":1,"kind":"signal","task":"task2","batch":"guNYFt"}
{"ev":"jev","t":1790420855,"day":"2026-09-26","id":"1790000000:1","outcome":"classified","choice":"absorbable","confidence":0.83,"probabilities":{"firstmate":0.1,"absorbable":0.83,"captain":0.07},"cost":0.0000196,"ms":6,"model":"typesafe/jev-1.13","reason":"signal: task2.status: done: PR <url> green","status":"done: PR <url> green, notes in <path>"}
{"ev":"ack","t":1790420855,"through":1}

\### 5. report
Jev shadow report, 2026-09-19T11:07:35Z to 2026-09-26T11:07:35Z
wakes presented: 1; classified: 1; skipped: 0; not sent: 0; actual handling known: 0
agreement (absorb vs surface): n/a (0 of 0)
wrongly absorbable (Jev would absorb, firstmate had to act): 0
three-way agreement: n/a
breakdown, Jev answer -> actual handling (absorbable/firstmate/captain/unknown):
  absorbable: 0/0/0/1
go-live criteria: zero wrongly absorbable met; agreement at least 90% NOT met; one week of shadow data NOT met (0 days)
doubtful cases for the captain (1, most important first):
  1. 2026-09-26T11:07:35Z signal seq 1 task task2: Jev absorbable (0.83), actual unknown (no turn end recorded) | wake: signal: task2.status: done: PR <url> green | worker: done: PR <url> green, notes in <path>

\### 6. timeout pauses Jev for the day; wake still presented
1790000000	1	signal	t3.status	signal: t3.status: working
wake annotation: latest wake-EVENT observed at drain, not current state: t3.status: working
Jev shadow triage: on (OPENROUTER_API_KEY present in /tmp/tmp.oVAW8Ea1vk/to/.env)
spend today: USD 0.000000 of a USD 1 daily cap
paused until tomorrow: timeout
shadow log: /tmp/tmp.oVAW8Ea1vk/to/state/jev/shadow.jsonl
{"ev":"jev","t":1790420856,"day":"2026-09-26","id":"1790000000:1","outcome":"skipped","why":"timeout","detail":"no answer within 2s","reason":"signal: t3.status: working","status":"working"}
{"ev":"disabled","t":1790420856,"day":"2026-09-26","why":"timeout"}
Evidence: Script that produced the end-to-end transcript (fake curl, no network)

Source: Script that produced the end-to-end transcript (fake curl, no network)

#!/usr/bin/env bash
# Manual end-to-end demo of Jev shadow mode with a fake curl (no network).
set -u
R=$1 T=$2
KEY=sk-or-v1-demo0000000000
mk() { mkdir -p "$T/$1/state" "$T/$1/config" "$T/$1/bin" "$T/$1/curl"; cat > "$T/$1/bin/curl" <<'SH'
#!/usr/bin/env bash
printf '%s\n' "$*" >> "$FAKE_LOG/argv"; cat > "$FAKE_LOG/stdin.cfg"
out='' body=''; while [ $# -gt 0 ]; do case $1 in -o) out=$2; shift;; --data-binary) body=${2#@}; shift;; esac; shift; done
cp "$body" "$FAKE_LOG/body.json"
case "${MODE:-ok}" in timeout) exit 28;; esac
printf '{"model":"typesafe/jev-1.13","answers":{"handling":{"type":"choice","choice":"absorbable","confidence":0.83,"probabilities":{"firstmate":0.1,"absorbable":0.83,"captain":0.07}}},"usage":{"cost":0.0000196}}' > "$out"; printf 200
SH
chmod +x "$T/$1/bin/curl"; }
run() { h=$T/$1; shift; FM_HOME=$h FM_STATE_OVERRIDE=$h/state PATH=$h/bin:$PATH FAKE_LOG=$h/curl FM_JEV_FOREGROUND=1 "$@"; }
mk off; mk on
printf 'OPENROUTER_API_KEY=%s\n' "$KEY" > "$T/on/.env"
for h in off on; do
  printf 'done: PR https://github.com/o/r/pull/7 green, notes in ~/wt/report.md\n' > "$T/$h/state/task2.status"
  printf '1790000000\t1\tsignal\ttask2.status\tsignal: task2.status: done: PR https://github.com/o/r/pull/7 green\n' > "$T/$h/state/.wake-queue"
done
echo '### 1. status without key (ambient OPENROUTER_API_KEY set) vs with .env key'
run off env OPENROUTER_API_KEY=$KEY "$R/bin/fm-jev.sh" status; run on "$R/bin/fm-jev.sh" status
echo; echo '### 2. drain output: Jev off vs Jev on (must be identical)'
A=$(run off env OPENROUTER_API_KEY=$KEY "$R/bin/fm-wake-drain.sh" 2>&1); B=$(run on "$R/bin/fm-wake-drain.sh" 2>&1)
printf '%s\n' "$B"; norm() { sed -E "s/--recovery-generation [^ ]+/--recovery-generation <nonce>/"; }; [ "$(printf "%s" "$A" | norm)" = "$(printf "%s" "$B" | norm)" ] && echo "=> IDENTICAL presentation (recovery-generation nonce normalized)" || { echo "=> DIFFERENT"; printf "%s\n" "$A"; }
echo "off home: state/jev exists? $([ -e $T/off/state/jev ] && echo yes || echo no); curl calls: $(cat $T/off/curl/argv 2>/dev/null | wc -l)"
echo; echo '### 3. request body sent to OpenRouter (masked) and curl argv (key absent?)'
jq . "$T/on/curl/body.json"; cat "$T/on/curl/argv"; grep -q "$KEY" "$T/on/curl/argv" && echo 'KEY IN ARGV!' || echo '=> key not in argv'
grep -rq "$KEY" "$T/on/state" && echo 'KEY ON DISK in state!' || echo '=> key not in state/'
echo; echo '### 4. ack, then shadow log'
ack=$(printf '%s\n' "$B" | sed -n 's/^WAKE_ACK_REQUIRED: after handling completes run //p'); run on "$R/"$ack >/dev/null 2>&1
ls -l "$T/on/state/jev/"; cat "$T/on/state/jev/shadow.jsonl"
echo; echo '### 5. report'
run on "$R/bin/fm-jev.sh" report --days 7 || true
echo; echo '### 6. timeout pauses Jev for the day; wake still presented'
mk to; printf 'OPENROUTER_API_KEY=%s\n' "$KEY" > "$T/to/.env"; printf 'working\n' > $T/to/state/t3.status
printf '1790000000\t1\tsignal\tt3.status\tsignal: t3.status: working\n' > "$T/to/state/.wake-queue"
run to env MODE=timeout "$R/bin/fm-wake-drain.sh" 2>/dev/null | head -3
run to "$R/bin/fm-jev.sh" status; cat "$T/to/state/jev/shadow.jsonl" | grep -E 'skipped|disabled'
Evidence: fm-jev behavior test output

Source: fm-jev behavior test output

ok - off by default: an ambient OPENROUTER_API_KEY neither logs nor calls the network
ok - a STATE other than the key home's own state never enables Jev
ok - shadow mode logs presentation, answer and acknowledgement without changing the drain
ok - only the masked reason and last status line are sent; the key stays off argv and disk
ok - a timeout skips the wake and pauses Jev until the next day
ok - HTTP errors, transport errors and a missing cost pause Jev until the next day
ok - the daily spend cap stops requests and pauses Jev until the next day
ok - the drain returns immediately while a slow Jev request runs detached
ok - hooks record steers, decisions and how a turn ended, never its text
ok - only sends firstmate itself makes count as steers; FM_JEV_OBSERVE=0 senders record nothing
ok - the report credits named actions to their task's open wakes across drains and shares the rest
ok - unacknowledged and pre-window wakes stay open, so their steers never spill onto unrelated wakes
ok - the report computes agreement, wrongly absorbable wakes, go-live criteria and doubtful cases
bash tests/fm-jev.test.sh  3,10s user 3,33s system 71% cpu 9,055 total
Evidence: Drain output is identical with Jev off and on
=> IDENTICAL presentation (recovery-generation nonce normalized)
off home: state/jev exists? no; curl calls: 0
state sent: {"wake_reason": "signal: task2.status: done: PR <url> green", "worker_last_status": "done: PR <url> green, notes in <path>"}
=> key not in argv
=> key not in state/

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 4 issues found → auto-fixed (3) ✅
  • ⚠️ bin/fm-send.sh:625 - The Jev steer/decision hook fires on every fm-send.sh invocation, including automated sends that no firstmate handling turn made. One example is the watcher's pending-reply recovery (bin/fm-pending-reply-lib.sh:830 calls fm-send.sh with FM_PENDING_REPLY_EXISTING_CORR set). Another is bin/fm-bootstrap.sh's secondmate nudges. Failure path: a wake is presented, the watcher sends a recovery message to that task before the ack or turn end, and a 'steer' event lands inside the window. The report then labels the wake truth=firstmate (why=steer). If Jev said absorbable, the wake counts toward 'wrongly absorbable', the go-live blocker, even though firstmate only acknowledged. This violates the intent's ground-truth rule ('needed firstmate if its handling turn produced ... a steer'). Fix: record only sends that firstmate initiates, e.g. skip the observe when FM_PENDING_REPLY_EXISTING_CORR is set or when called from the watcher or bootstrap paths.
  • ⚠️ bin/fm-jev.sh:470 - Steer and decision attribution gathers every steer or decision between a wake's presentation and its turn end, whichever batch the steer belongs to. It then attributes any steer whose task has no wake in this batch to all wakes in this batch. Example: batch 1 holds a single wake A (task X, or no task). A second drain presents batch 2 with wake B for task Y. Firstmate steers Y and acks through both. For wake A, $mates=[A] has no task Y, so the steer goes to A with shared=false (the batch has one mate). A becomes truth=firstmate, unflagged, and counts as wrongly absorbable if Jev said absorbable. The same happens for a steer naming a task that had no wake at all. The intent says 'a steer/decision naming a task attributes to that task's wakes in the same drain batch, otherwise to all wakes in it'. Possible fix: when a steer names a task that has a wake in any overlapping batch, or a known task with no wake, do not attribute it to unrelated single-wake batches, or at least flag it as shared. This changes measurement semantics the captain defined, so confirm the intended rule.
  • ℹ️ bin/fm-turnend-guard.sh:667 - The turn-end outcome is recorded before the guard's verdict, so a Claude stop that the guard then blocks (exit 2, supervision off) still logs a turn_end even though the turn continues. The new test asserts this. The report takes the first turn_end after the ack, so a blocked stop can become that wake's 'handling turn end'. This is rare (only when supervision is broken) and it only affects measurement.
  • ℹ️ bin/fm-jev.sh:463 - The report's jq scans all of $all for each wake (ack, turn_end, acts), which is O(wakes × events). The per-row dedupe check in observe-drain (line 405) also rescans the whole shadow.jsonl, which is append-only and never rotated. This is fine for a one-week shadow window but grows without bound if shadow mode is left on.

🔧 Fix: Credit Jev ground truth to open wakes; skip automated sends
2 issues (1 warning, 1 info) still open:

  • ⚠️ bin/fm-config-push.sh:155 - The fix sets FM_JEV_OBSERVE=0 on the bootstrap remote config-reread nudge (bin/fm-bootstrap.sh:538) and on the local config-reread pointer (bin/fm-config-inherit-lib.sh:886). It misses the matching remote reread nudge in fm-config-push.sh, which sends the same $FM_REMOTE_SECOND_MATE_NUDGE_MESSAGE through fm-send.sh to fm-$id without the opt-out. Failure path: firstmate runs fm-config-push.sh while a wake for secondmate task fm-$id is open. A 'steer' naming that task is then recorded, and the wake becomes truth=firstmate (why=steer). It counts as wrongly absorbable if Jev said absorbable. That contradicts the fm-jev-lib.sh header, which says config-reread sends record nothing. Fix: add FM_JEV_OBSERVE=0 to that fm-send.sh invocation.
  • ℹ️ bin/fm-jev.sh:376 - $open only includes wakes with a computed end, meaning an acknowledgement exists. It also only includes wakes presented inside the report window ($since..$now). Consider a steer naming task X whose wake is still unacknowledged when the report runs (for example, a report run mid-turn, or an ack-through covering only an earlier drain's seq), or whose wake was presented before --days. That steer is treated as 'no open wake' and credited, shared=true, to every other open wake. An unrelated wake can therefore become truth=firstmate. It is flagged shared and lands in the doubtful list, so the impact is limited to measurement noise the captain will see.

🔧 Fix: Keep unacked and pre-window Jev wakes open; skip config-push sends
2 warnings still open:

  • ⚠️ bin/fm-remote-secondmate-control.sh:205 - This round added FM_JEV_OBSERVE=0 to the remote relay in cmd_send, because the parent home already records the steer (bin/fm-send.sh:512 runs before the remote dispatch, for text and --key sends alike). The sibling relay cmd_key was not updated. It calls fm-send.sh against TARGET_HOME/state with no opt-out. Failure path: the parent firstmate runs fm-send.sh &lt;remote-task&gt; --key Enter. The parent records a steer, and then the remote leg's fm-send.sh records a second steer in the secondmate home's shadow log whenever that home's .env has OPENROUTER_API_KEY. That steer is credited to the secondmate's own open wakes, and it is shared when unnamed. It can therefore mark a secondmate wake truth=firstmate and count it as wrongly absorbable, even though that secondmate took no action. The updated fm-jev-lib.sh header and the docs row now say the remote relay records nothing, so this contradicts them. Fix: add FM_JEV_OBSERVE=0 to the fm-send.sh invocation in cmd_key.
  • ⚠️ tests/fm-jev.test.sh:368 - The new fixture test says it covers unacknowledged wakes, but it only exercises the pre-window half of the r2-2 fix. The only unacknowledged wake (e:4, task y) is presented after both actions, and no steer or decision names task y. The test would therefore still pass if the .end == null branch in bin/fm-jev.sh:376 were reverted to the old .end != null and ... condition. The user asked for fixture coverage of both halves. Fix: add a steer naming the unacked wake's task after its presentation, with another Jev-absorbable wake still open. Then assert that the steer is not credited to that other wake (wrongly absorbable stays 0) and that the unacked wake stays unknown.

🔧 Fix: Skip Jev observe on remote key relay; cover unacked wakes
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-jev.test.sh: all 13 cases pass. They cover: off by default and a key in the environment does not turn it on; a different state dir never uses the key; the drain shows the same output with Jev on or off; masking, and the key stays out of argv and off disk; timeout, API error, transport error and missing cost each pause Jev for the day; the daily spend cap; the detached request never blocks the drain; the hooks record events without the turn text; FM_JEV_OBSERVE=0 senders are not recorded; how the report attributes wakes across drains, shared cases, and unacknowledged or pre-window wakes; the report output itself.
  • bash tests/fm-turnend-guard.test.sh
  • bash tests/fm-wake-drain-unread-status.test.sh
  • bash tests/fm-send-resolve-key.test.sh
  • bash tests/fm-captain-hold-lifecycle.test.sh
  • bash tests/fm-control.test.sh
  • Manual end-to-end check: bash e2e-demo.sh &lt;repo&gt; &lt;tmp&gt; in the evidence dir, using temporary homes and a fake curl on PATH, with no network. It runs fm-jev.sh status off and on, drains the same wake in the off and on homes and compares the output, captures the masked request body and curl argv, acks the wake and dumps the 0600 shadow.jsonl, runs fm-jev.sh report --days 7, and forces a timeout to show the pause for the day while the wake is still shown.
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix: Silence jq SC2016 and replace A && B || C test check
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

Alan Domio added 8 commits September 26, 2026 12:20
Firstmate can now ask Jev (TypeSafe's decision model on OpenRouter,
typesafe/jev-1.13) one three-way question per presented wake - needs
firstmate, absorbable, or urgent for the captain - and log the answer next
to what firstmate actually did. It acts on nothing: the drain hands rows to
a detached process, so wakes are never delayed, dropped, reordered, absorbed
or altered, and no merge, destructive action or captain call reads it.

- Off by default; enabled only by OPENROUTER_API_KEY in the home's private
  .env (the ambient environment never enables it), mirroring Relay's gate.
  The key reaches curl on stdin, never argv, logs or disk.
- Only the wake reason line and the worker's last status line leave the
  machine, with URLs and paths masked.
- 2 s timeout and a daily spend cap (USD 1, config/jev-daily-cap); a
  timeout, API error, missing cost or the cap pauses Jev until the next day.
- Ground truth is recorded automatically: steers (fm-send, fm-control),
  decisions (--resolve-key, fm-captain-hold), acknowledgements (wake drain)
  and how the primary turn ended (turn-end guard, outcome only, no text).
- bin/fm-jev.sh report measures agreement, wakes Jev would have wrongly
  absorbed, the go-live criteria, and up to 20 doubtful cases.
…ts/fm-on.test.sh. All of its assertions passed ("ALL TESTS PASSED"), but the script then exited 1 because its EXIT trap failed with `rm: cannot remove .../remote-jobs/worker.lock: Directory not empty`. This is a flaky cleanup race that already existed before this PR. The PR doesn't touch fm-on, the remote job worker or that test. The trap sent the detached remote job worker a signal and ran `rm -rf` on the fixture straight away, while the worker was still writing files into worker.lock as it shut down. The fix is a small `cleanup_fixture` function used by the trap: after sending the signal, it waits up to 5 s for the worker process to exit (polling with kill -0) and only then removes the fixture. That makes the cleanup deterministic. Checked locally: `shellcheck -x tests/fm-on.test.sh` is clean, and `bash tests/fm-on.test.sh` passed 3 runs out of 3 with exit 0. The failure itself doesn't reproduce reliably, since it only happens when the timing lines up
… It was already flaky before this PR and is what failed "Behavior portable serial 2". The failing assertion was "the worker kept serving after its state root was deleted". The PR doesn't touch that test, `bin/fm-remote-job-worker.sh` or `bin/fm-remote-job-lib.sh`. Its only remote-side change is adding `FM_JEV_OBSERVE=0` to two `fm-send.sh` calls in `fm-remote-secondmate-control.sh`, which never runs the job worker. Likely cause (not reproduced locally): the test ran `rm -rf` on the state root while the worker was still running. That worker writes a heartbeat every second (a temp file created and renamed inside the state root). If a write lands in the directory while `rm -rf` is emptying it, the rm fails with "Directory not empty" and the directory stays. Later heartbeat writes then succeed, so the worker never notices the deletion, and after about 10 s the test gave up and failed. The CI timestamps match: the failure came about 10.4 s after the previous test passed, which is the length of that wait. It's the same kind of race as the earlier fm-on cleanup flake. Fix: the test now uses `mv` to rename the state root to `$TMP_ROOT/tripwire-jobs.deleted` instead of deleting it in place. A rename removes the path in one step, so a heartbeat write can't bring it back. The worker's next heartbeat fails, and the test still checks that the path is absent. The renamed directory is removed with the rest of `$TMP_ROOT` by the existing EXIT trap. Nothing outside the test changed. Checked: `shellcheck -x tests/fm-remote-job.test.sh` is clean, and `bash tests/fm-remote-job.test.sh` passed 2 runs out of 2 ("ALL TESTS PASSED", exit 0)
@alandomio
alandomio merged commit b2696a7 into main Sep 26, 2026
15 checks passed
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