Files
engine/scripts/router-retrain-all.sh
zeekayandHanzo Dev 4ffbc0b067 feat(router-retrain): spark-local nightly Enso router-heads retrain
New hanzo-router-retrain crate + pipeline that refits the Enso routing heads
from the ai routing ledger nightly, gates the candidate on an 80/20 holdout,
and publishes only a non-regressing head per scope.

- hanzo-router-retrain/: enso-fit binary on the `fit --events --out` contract
  (drop-in for enso's own fit via $FIT_BIN) + tested core: transform_reward
  (ai reward tuple -> enso EvalSample), fit_policy (proof.rs (x,p,quality)
  join -> fit_base), holdout_reward, decide_gate (fail-closed), save_w/load_w
  (enso-base safetensors: f64 tensor "w", [D*K]). 9 unit tests green.
- scripts/router-retrain.sh: one scope (global -> heads-base.safetensors owner
  "*"; org=<slug> -> heads-<slug>.safetensors owner "<slug>"); pull -> fit ->
  gate -> promote-or-hold -> log.jsonl -> POST /v1/router/publish-artifact-meta.
  router-retrain-all.sh sequences global + per-opted-in-org.
- deploy/router-retrain/: systemd user timer (04:20 America/Los_Angeles,
  Persistent) = the live spark scheduler; hanzoai/tasks cron ConfigMap as the
  in-cluster convergence reference; install.sh; LLM.md with the blocker list.

Gate is holdout (RouterBench absent in-repo). DO_RELOAD=0 by default: publish
writes the versioned artifact + current pointer but does not restart the engine
until it mounts heads (unwired). Rebased onto origin/main; the crate builds
against the committed enso primitives (fit_base/ingest/parse_jsonl) and writes
the load_learner-compatible safetensors itself.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-16 00:46:52 -07:00

23 lines
933 B
Bash

#!/usr/bin/env bash
# The nightly composition the scheduler fires: fit the shared base heads on opted-in
# rows, then per-org heads for each opted-in org (the gate holds any org under
# MIN_ROWS). One script, scope as a flag -- this only sequences scopes.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
export PATH="$HOME/.cargo/bin:$PATH"
# Build the native fit fresh so it tracks the enso crate (override FIT_BIN to use
# enso's own `fit` once the learning-loop agent lands it -- identical flags).
cargo build --release -p hanzo-router-retrain --manifest-path "$ROOT/Cargo.toml" >&2
"$SCRIPT_DIR/router-retrain.sh" --scope global
if [[ -n "${CONTRIB_ORGS:-}" ]]; then
IFS=',' read -r -a ORGS <<< "$CONTRIB_ORGS"
for o in "${ORGS[@]}"; do
o="$(echo "$o" | xargs)"; [[ -n "$o" ]] || continue
"$SCRIPT_DIR/router-retrain.sh" --scope "org=$o"
done
fi