Skip to content

feat(bin): add a local Rizzo Flow backend to the Jev shadow wake classifier - #45

Merged
alandomio merged 6 commits into
mainfrom
fm/jev-local-rizzo
Sep 26, 2026
Merged

alandomio merged 6 commits into
mainfrom
fm/jev-local-rizzo

Conversation

@alandomio

@alandomio alandomio commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Intent

The developer wanted bin/fm-jev.sh to classify supervision wakes through a local Rizzo Flow server, meaning a Jev-compatible /v1/systemone endpoint on 127.0.0.1. Each home should be able to choose it, and it must need no API key. Instead of a spend cap it should pause when the load average is too high, it should refuse non-loopback endpoints, and a missing usage cost should count as normal. The OpenRouter path had to stay unchanged for homes that use it. After relaunch, the concrete goal was to rebase the existing branch, PR #45, onto origin/main. That meant resolving conflicts with #44's configurable Jev request timeout (default 5 seconds), keeping that timeout, and making config/jev-timeout also apply to the local backend. The developer also required updated docs, the AGENTS.md config line and tests, including one proving the timeout applies to the local backend. The work had to be proven with a live run against the permanent local rizzo serve on 127.0.0.1:8017 and then re-validated through the no-mistakes gate toward a green PR on github.com/alandomio/firstmate.

What Changed

  • bin/fm-jev.sh and bin/fm-jev-lib.sh add a second, keyless Jev backend. A home selects it with a non-empty config/jev-endpoint, which wins over OPENROUTER_API_KEY when both are set. Requests go to <base>/v1/systemone (for example, Rizzo Flow's rizzo serve on 127.0.0.1:8017) through curl with the proxy bypassed. Only a bare loopback origin (127.0.0.1, localhost or [::1], no path) is accepted. Any other URL is never dialed: the row is logged as skipped with invalid-endpoint and classification pauses for the day. The OpenRouter path works as before.
  • There is no spend cap on the local backend, and a missing usage.cost is not an error there. Instead, each request first checks the 1-minute load average against config/jev-max-load (default 8). If the load is at or above that ceiling, the row is skipped with why=load and the next reading below it classifies again. config/jev-timeout (default 5s) now applies to both backends, and status reports the active backend along with either its spend/cap or its endpoint and load ceiling.
  • The docs cover the new config: AGENTS.md lists config/jev-endpoint and config/jev-max-load and updates the timeout and cap lines, and docs/configuration.md and docs/scripts.md describe both backends plus the test-only FM_JEV_LOAD_OVERRIDE. tests/fm-jev.test.sh gains tests for the local backend, and a new tests/fm-jev-local-rizzo-live.test.sh runs a live check against a local Rizzo server.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The latest fix round does exactly what was prescribed. A load reading at or above the ceiling now only logs that row as skipped (why=load), with no day-long pause, and the next reading below the ceiling classifies again. The backend gate checks the file with the builtin -s test before it runs grep, so a home without config/jev-endpoint starts no process. The OpenRouter path, the loopback check, the timeout handling and the report logic still behave as before, and the updated tests assert the right outcomes.

Testing

I ran the targeted Jev suite (all 22 cases pass) and the opt-in live test against the permanent rizzo serve on 127.0.0.1:8017 (classified in 296ms, cost=null). I also did a manual live drain: a load spike above the ceiling skipped only that wake with no day pause, and a later drain below the ceiling classified the next wake on the same day. A logging fake grep confirmed the backend gate starts no process for a home without config/jev-endpoint and still rejects a whitespace-only file. Everything passed, and the worktree was left clean. There is no UI surface; the evidence is CLI and log transcripts.

Evidence: Live load-spike skip, same-day resume, status, and gate process cost transcript

Source: Live load-spike skip, same-day resume, status, and gate process cost transcript

== drain 1: 1-minute load 9.5 >= ceiling 4 == {"id":"1790000000:1","outcome":"skipped","why":"load"} state/jev/disabled: absent (no day pause) == drain 2: load back to 0.5, same day == {"id":"1790000000:2","outcome":"classified","model":"rizzo-flow-1.7b-q8_0","choice":"firstmate","cost":null,"ms":270} state/jev/disabled: absent Jev shadow triage: on, local backend (config/jev-endpoint = http://127.0.0.1:8017)&#10;load ceiling: 4 (1-minute average) request timeout: 5s none endpoint file -> backend=disabled, grep execs=0 blank endpoint file -> backend=disabled, grep execs=1 local endpoint file -> backend=local, grep execs=1

== drain 1: 1-minute load 9.5 >= ceiling 4 ==
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 6585.1790460754.VvbXKv
{"id":"1790000000:1","outcome":"skipped","why":"load"}
state/jev/disabled: absent (no day pause)
== drain 2: load back to 0.5, same day ==
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 2 --recovery-generation 6585.1790460754.VvbXKv
{"id":"1790000000:1","outcome":"skipped","why":"load","model":null,"choice":null,"cost":null,"ms":null}
{"id":"1790000000:2","outcome":"classified","why":null,"model":"rizzo-flow-1.7b-q8_0","choice":"firstmate","cost":null,"ms":270}
state/jev/disabled: absent
== status ==
Jev shadow triage: on, local backend (config/jev-endpoint = http://127.0.0.1:8017)
load ceiling: 4 (1-minute average)
request timeout: 5s
shadow log: /var/folders/tc/hhm5872n2ql638k7y8nh5nd40000gn/T/tmp.eoMgVQTvfv/home/state/jev/shadow.jsonl
== backend gate process cost (fake grep on PATH logs every exec) ==
none endpoint file -> backend=disabled, grep execs=0
blank endpoint file -> backend=disabled, grep execs=1
local endpoint file -> backend=local, grep execs=1
Evidence: Script that produced the live transcript

Source: Script that produced the live transcript

#!/usr/bin/env bash
# Live demo: load-spike skip (no day pause) then same-day resume against rizzo serve on 127.0.0.1:8017,
# and proof the backend gate forks no process for a home without config/jev-endpoint.
set -u
ROOT=${ROOT:?}
T=$(mktemp -d); home=$T/home; mkdir -p $home/state $home/config
printf 'http://127.0.0.1:8017\n' > $home/config/jev-endpoint
printf '4\n' > $home/config/jev-max-load
run() { FM_HOME=$home FM_STATE_OVERRIDE=$home/state FM_JEV_FOREGROUND=1 "$@"; }
q() { printf '%s\t%s\tsignal\tlive1.status\tsignal: live1.status: working: step %s\n' 1790000000 "$1" "$1" >> $home/state/.wake-queue; }
printf 'working: implementing the fix\n' > $home/state/live1.status
echo "== drain 1: 1-minute load 9.5 >= ceiling 4 =="
q 1; run env FM_JEV_LOAD_OVERRIDE=9.5 "$ROOT/bin/fm-wake-drain.sh" >/dev/null
jq -c 'select(.ev=="jev") | {id,outcome,why}' $home/state/jev/shadow.jsonl
[ -e $home/state/jev/disabled ] && echo "state/jev/disabled: PRESENT ($(cat $home/state/jev/disabled))" || echo "state/jev/disabled: absent (no day pause)"
echo "== drain 2: load back to 0.5, same day =="
q 2; run env FM_JEV_LOAD_OVERRIDE=0.5 "$ROOT/bin/fm-wake-drain.sh" >/dev/null
jq -c 'select(.ev=="jev") | {id,outcome,why,model,choice,cost,ms}' $home/state/jev/shadow.jsonl
[ -e $home/state/jev/disabled ] && echo "state/jev/disabled: PRESENT" || echo "state/jev/disabled: absent"
echo "== status =="
run "$ROOT/bin/fm-jev.sh" status
echo "== backend gate process cost (fake grep on PATH logs every exec) =="
mkdir -p $T/bin; printf '#!/bin/sh\necho grep >> %s/grep.log\nexec /usr/bin/grep "$@"\n' $T > $T/bin/grep; chmod +x $T/bin/grep
for case in none blank local; do
  h=$T/g-$case; mkdir -p $h/state $h/config; : > $T/grep.log
  case $case in blank) printf '  \n' > $h/config/jev-endpoint;; local) printf 'http://127.0.0.1:8017\n' > $h/config/jev-endpoint;; esac
  r=$(PATH=$T/bin:$PATH bash -c ". $ROOT/bin/fm-jev-lib.sh; fm_jev_backend $h $h/state || echo disabled")
  echo "$case endpoint file -> backend=$r, grep execs=$(wc -l < $T/grep.log | tr -d ' ')"
done
rm -rf $T
Evidence: Opt-in live Rizzo test output

Source: Opt-in live Rizzo test output

ok - classified live against http://127.0.0.1:8017 in 296ms: model=rizzo-flow-1.7b-q8_0 choice=firstmate cost=null

ok - classified live against http://127.0.0.1:8017 in 296ms: model=rizzo-flow-1.7b-q8_0 choice=firstmate cost=null
Evidence: Targeted Jev suite output

Source: Targeted Jev suite 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 - config/jev-timeout overrides the 5 second default and invalid values keep it
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 - config/jev-endpoint selects the local backend over an OPENROUTER_API_KEY, needs no key, and records the answering model
ok - config/jev-timeout also overrides the local backend's request timeout
ok - the local endpoint and load ceiling are read from the home's own config/, the same place that selected the backend
ok - a whitespace-only config/jev-endpoint does not select the local backend
ok - a local response with no usage.cost classifies normally instead of erroring
ok - a non-loopback or path-carrying config/jev-endpoint is refused, never dialed, and pauses Jev
ok - a 1-minute load average at or above config/jev-max-load skips only that wake; a later reading below it classifies again
ok - status names the active backend, its endpoint or spend, and (for local) its load ceiling
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

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed ✅
  • ℹ️ bin/fm-jev-lib.sh:36 - fm_jev_backend now starts a grep process on every hook call once the -ef state check passes, even when config/jev-endpoint doesn't exist. This happens on every fm-send, fm-control, captain hold, drain, and turn end. Before this change, a home that hadn't opted in returned after a single [ -f &#34;$home/.env&#34; ] builtin test, with no process started. The lib header still says the function 'costs one file test when the home has not opted in', and docs/configuration.md says 'one cheap file check'. Every home using the OpenRouter backend, or no backend, now pays an extra fork+exec on those hot paths. Fix: guard the grep with a builtin test first, e.g. if [ -s &#34;$home/config/jev-endpoint&#34; ] &amp;&amp; grep -q &#39;[^[:space:]]&#39; &#34;$home/config/jev-endpoint&#34; 2&gt;/dev/null; then. That keeps the whitespace-only handling and the cost stays one stat when the file is absent.
  • ℹ️ bin/fm-jev.sh:438 - One reading of the 1-minute load average at or above the ceiling (default 8) writes state/jev/disabled for the whole local day, the same as the spend cap. A spend cap only goes up during a day. Load average is momentary: a single build or a burst of fleet agents on the same machine stops local shadow classification until midnight, even if load drops a minute later. This machine runs many agents, so the default could pause the local backend on most days and starve the one-week shadow measurement. The alternative is to skip only the affected rows while load is high (log them as skipped with why=load) and not write the day-long pause. This matches the stated intent ('pause when the load average is too high') and the docs, so whether a whole-day pause is the right granularity is the author's call.
  • ℹ️ bin/fm-jev.sh:159 - Round 2 moved config/jev-endpoint and config/jev-max-load to $FM_HOME/config, so the local backend's settings are read from the same place that selected it. config/jev-timeout, which this change now also applies to the local backend, is still read from $CONFIG, and that honours FM_CONFIG_OVERRIDE. Take a detached drain that inherits FM_CONFIG_OVERRIDE (exported by fm-remote-secondmate-control.sh or fm-stow-cascade.sh). It dials the home's local endpoint under the home's load ceiling, but uses the override directory's timeout, or the 5 s default, instead of the home's config/jev-timeout. This read predates the change (feat(bin): make the Jev request timeout configurable, default 5 seconds #44) and is shared with the OpenRouter backend. Moving it would change OpenRouter behaviour, which the intent says must stay unchanged, so this needs the author's decision.

🔧 Fix: Skip rows on Jev load spikes; cheap backend gate
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-jev.test.sh: full targeted Jev suite, 22 cases, all ok, including test_local_backend_load_ceiling_skips_without_a_day_pause, the timeout-applies-to-local case, loopback refusal, whitespace-only endpoint, and the FM_CONFIG_OVERRIDE home-config case
  • FM_JEV_RIZZO_LIVE=1 bash tests/fm-jev-local-rizzo-live.test.sh against the live rizzo serve on 127.0.0.1:8017
  • curl -sS http://127.0.0.1:8017/v1/models: confirmed the live server answers and has the jev-latest alias
  • Manual live drain transcript (live-load-skip-and-gate.sh): drain at load 9.5 with ceiling 4 gives skipped/why=load and no state/jev/disabled; a same-day drain at load 0.5 is classified by rizzo-flow-1.7b-q8_0 in 270ms with cost=null; fm-jev.sh status shows the local backend, load ceiling 4 and timeout 5s
  • Manual gate-cost check: put a logging fake grep first on PATH and called fm_jev_backend: no endpoint file gives 0 grep execs (disabled); a whitespace-only file gives 1 exec (still disabled); a real endpoint gives 1 exec (local)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Alan Domio added 5 commits September 26, 2026 23:57
…ifier

config/jev-endpoint selects a loopback Jev-compatible server (e.g. Rizzo
Flow's `rizzo serve`) over the existing OpenRouter path: no API key, no
spend cap, a 1-minute load-average ceiling pause instead
(config/jev-max-load), and non-loopback URLs refused outright. The
OpenRouter path stays byte-identical when config/jev-endpoint is absent.
Guards the rebase onto #44's configurable timeout: both backends now
share one JEV_TIMEOUT read once per drain, so the override must apply
identically whichever backend is selected.
@alandomio
alandomio merged commit 69d7a13 into main Sep 26, 2026
11 of 12 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