Judge every new agent model by the same fair contest #120

Merged
aluminum-ice merged 1 commit from feature/fair-promotion into main 2026-10-31 07:09:51 +00:00
Owner

What this PR does

Makes the comparison between on-device and remote training fair. Until now the two were rarely compared at all:

  • No test for local models: every on-device run replaced the active model unconditionally, and counted as a local "win".
  • Remote models had to clear gates local ones didn't: a pull-time watermark filter, a 10% margin, and scoring on rows the local model had trained on.
  • The launch trigger was measured against the device's own model, so on a device that trains its own model the host never trained that algorithm. On the test device the tally read local 34, remote 0 with no contest ever held.

Now every new model is a candidate that replaces the active model only by winning one contest:

  • Held-out rows no model trains on (metrics.py): a row is held out when its hour block hashes into one bucket of five (HOLDOUT_SCHEME = "block-hash-v1", about 20%). It's deterministic on the device and the host, and stable as files rotate. train_from_logs keeps those rows out of the reward model and the replay env, and stamps holdout into the sidecar.

  • One rule (metrics.contest_decision, no notion of source):

    • stale: a candidate whose data is more than 900 rows behind is rejected;
    • baseline: it must beat the scripted baseline;
    • bootstrap: with no active model, that alone is enough;
    • paired test: the per-row difference against the active model must be significant (promotion_min_z, default 1.0, a new code default);
    • margin: its lift over the baseline must be at least 10% above the active model's.

    promotion_decision and remote_model_wins are removed.

  • On-device runs are candidates (train.py, controller.py):

    • Warm start: a run starts from the active model's weights (weights only).
    • Candidate folder: it writes .candidates/local/<slug>/.
    • Contest: a contest follows each finished run.
    • Remote: a staged remote model gets the same contest.
  • The contest (controller._run_contest, train.evaluate):

    • What's scored: the candidates, the active model and the baseline, on the newest 2,000 held-out rows in time order, with recurrent state reset at each hour block, under one r̂ fitted on the other rows.
    • Older models: one trained before rows were held out is scored only on rows newer than its data; with too few, the contest defers and retries after 32 episodes.
    • Outcome: the winner moves into the active slot, stamped with its contest; the others are deleted, and judged remote models are recorded in evaluated.json.
    • Logging: each decision is logged.
  • remote-train:

    • Pulling: the sidecar is pulled first; an unchanged or already-judged model isn't re-staged, and there's no watermark pre-filter.
    • Launch trigger: counts rows since the host's last model (host-models.json).
    • Algorithm order: the algorithm the agent runs is always trained, and first.
    • Before each launch: the device package is re-synced to the host and imported first (PYTHONPATH=pkg), so the host always runs the device's trainer.
    • Run script: the failing cd is fixed, and launches are logged.
  • Tally and dashboard: promotion-tally.json counts contests ({"local": {"won", "lost"}, "remote": {...}}); old counts move to before_fair_promotion. The agent card shows Model contests and Last contest.

  • pull-agent-diagnostics.sh is replaced by the fuller report built while investigating this:

    • Output: one private text file; it reads both old and new devices.
    • What it reads: the settings, the sidecars, the contests and launches from the journal, and each model's real-world yield.
    • --score and --remote-dir: re-scoring on the device, the contest's own way included.
  • Docs: agent-interface.md ("Candidates and promotion"), remote-training.md ("One contest for every model"), agent-setup.md, config-reference.md (promotion_min_z), GUIDE_MD, CLAUDE.md, the scripts README, and three follow-ups in deferred.md:

    • a live A/B on real handshakes;
    • the learned policy collapsing to one action;
    • pinning the host's ML stack.

Checklist

  • Lint passes — make lint (ansible --syntax-check, yamllint, shellcheck --severity=error, and the real-data check). The Lint workflow runs this on the PR.
  • Tests pass — make test (the kestrel_pi pytest suite and the real-data check's tests). The Test workflow runs this on the PR.
  • Nothing real: no secrets, no personal information, no real data. This is a public repository. The diff contains no real account passwords or hashes, Wi-Fi passphrases, private keys, API tokens, .env files, real names, personal emails, device serials, and no real captured or device data: SSIDs, MAC addresses, GPS coordinates, capture files, diagnostics bundles, logs, or screenshots of a real device — placeholders only. The real-data check catches MACs, emails, keys and capture files; real SSIDs, coordinates and screenshots are on you.
  • Consent gates intact. Capture and network plugins still ship disabled, enabling them still takes the authorized-use acknowledgment (never pre-ticked or given by code), and the capture whitelist is still enforced.
  • Docs updated in the same PR, if this changes something an operator sees or configures: the README package table, the relevant page under docs/, and the on-device operator guide (GUIDE_MD in kestrel_pi/userguide.py) where it applies.
  • Commit messages are short and imperative.

Release impact

  • App-layer-safe — changes only files the in-place update engine carries: the kestrel_pi package, plugins/*.py, systemd units, the journald drop-in, a lib script already in the engine's LIB_SCRIPTS, or the CLI.
  • Reflash-class — touches a build input the engine does not carry onto a running device: apt or pip packages, boot options / config.txt / cmdline, kernel modules, the base image or partition size, builder/config.json, builder/config.yml, the Makefile, .forgejo/workflows/, a shipped config default (config.toml / default.conf), or a brand-new lib script.

Notes for review

  • For 1.0.11-beta.2, an app-layer update on top of beta.1. No build input changes, so the stable release's min_update_from floor stays at beta.1.
  • Behaviour change: an empty remote-train algorithms now trains the agent's own algorithm instead of nothing (turning the plugin off still stops remote training). The release notes should say so.
  • Existing devices: the active model predates held-out rows, so its first contest uses only held-out rows newer than its data, and defers until 64 exist (about a day of capture at ~380 rows/day).
  • Tested beyond the unit tests: an end-to-end run with the real ML stack (the training host's venv, on synthetic episodes in a scratch folder, nothing on the host's own agent folder):
    • Held out: 552 of 2,400 rows kept out of every run.
    • Warm start: the on-device-style run started from the active model.
    • Contest: a real contest scored a warm-started local candidate and a staged 8,192-step "remote" model in 1.6 s. The local one won (z 4.29); the remote one didn't beat the active model.
    • Records: the tally, last_decision and evaluated.json were written, and a re-staged identical model was skipped.
    • Diagnostics: the script's device part ran against that folder; its section E reproduces the contest's numbers exactly.
    • Why held-out rows matter: on ordinary random splits the "remote" model looked better (+0.50 vs +0.42 lift), but on held-out hours the active one was (+0.57 vs +0.50).
  • make lint is clean. 1456 package tests pass, plus the release-tooling, real-data and ghost-guide tests. test_gps_serial_reader_recovers_from_a_stalled_link fails only on my machine (on main too) and passes in CI.

🤖 Generated with Claude Code

## What this PR does Makes the comparison between on-device and remote training fair. Until now the two were rarely compared at all: - **No test for local models:** every on-device run replaced the active model unconditionally, and counted as a local "win". - **Remote models had to clear gates local ones didn't:** a pull-time watermark filter, a 10% margin, and scoring on rows the local model had trained on. - **The launch trigger** was measured against the device's own model, so on a device that trains its own model the host never trained that algorithm. On the test device the tally read `local 34, remote 0` with no contest ever held. Now every new model is a **candidate** that replaces the active model only by winning one **contest**: - **Held-out rows no model trains on** (`metrics.py`): a row is held out when its hour block hashes into one bucket of five (`HOLDOUT_SCHEME = "block-hash-v1"`, about 20%). It's deterministic on the device and the host, and stable as files rotate. `train_from_logs` keeps those rows out of the reward model and the replay env, and stamps `holdout` into the sidecar. - **One rule** (`metrics.contest_decision`, no notion of source): - **stale:** a candidate whose data is more than 900 rows behind is rejected; - **baseline:** it must beat the scripted baseline; - **bootstrap:** with no active model, that alone is enough; - **paired test:** the per-row difference against the active model must be significant (`promotion_min_z`, default 1.0, a new code default); - **margin:** its lift over the baseline must be at least 10% above the active model's. `promotion_decision` and `remote_model_wins` are removed. - **On-device runs are candidates** (`train.py`, `controller.py`): - **Warm start:** a run starts from the active model's weights (weights only). - **Candidate folder:** it writes `.candidates/local/<slug>/`. - **Contest:** a contest follows each finished run. - **Remote:** a staged remote model gets the same contest. - **The contest** (`controller._run_contest`, `train.evaluate`): - **What's scored:** the candidates, the active model and the baseline, on the newest 2,000 held-out rows in time order, with recurrent state reset at each hour block, under one r̂ fitted on the other rows. - **Older models:** one trained before rows were held out is scored only on rows newer than its data; with too few, the contest defers and retries after 32 episodes. - **Outcome:** the winner moves into the active slot, stamped with its contest; the others are deleted, and judged remote models are recorded in `evaluated.json`. - **Logging:** each decision is logged. - **`remote-train`:** - **Pulling:** the sidecar is pulled first; an unchanged or already-judged model isn't re-staged, and there's no watermark pre-filter. - **Launch trigger:** counts rows since the **host's** last model (`host-models.json`). - **Algorithm order:** the algorithm the agent runs is always trained, and first. - **Before each launch:** the device package is re-synced to the host and imported first (`PYTHONPATH=pkg`), so the host always runs the device's trainer. - **Run script:** the failing `cd` is fixed, and launches are logged. - **Tally and dashboard:** `promotion-tally.json` counts contests (`{"local": {"won", "lost"}, "remote": {...}}`); old counts move to `before_fair_promotion`. The agent card shows **Model contests** and **Last contest**. - **`pull-agent-diagnostics.sh`** is replaced by the fuller report built while investigating this: - **Output:** one private text file; it reads both old and new devices. - **What it reads:** the settings, the sidecars, the contests and launches from the journal, and each model's real-world yield. - **`--score` and `--remote-dir`:** re-scoring on the device, the contest's own way included. - **Docs:** `agent-interface.md` ("Candidates and promotion"), `remote-training.md` ("One contest for every model"), `agent-setup.md`, `config-reference.md` (`promotion_min_z`), `GUIDE_MD`, CLAUDE.md, the scripts README, and three follow-ups in `deferred.md`: - a live A/B on real handshakes; - the learned policy collapsing to one action; - pinning the host's ML stack. ## Checklist - [x] **Lint passes** — `make lint` (ansible `--syntax-check`, `yamllint`, `shellcheck --severity=error`, and the real-data check). The **Lint** workflow runs this on the PR. - [x] **Tests pass** — `make test` (the `kestrel_pi` pytest suite and the real-data check's tests). The **Test** workflow runs this on the PR. - [x] **Nothing real: no secrets, no personal information, no real data.** This is a public repository. The diff contains no real account passwords or hashes, Wi-Fi passphrases, private keys, API tokens, `.env` files, real names, personal emails, device serials, and no real captured or device data: SSIDs, MAC addresses, GPS coordinates, capture files, diagnostics bundles, logs, or screenshots of a real device — placeholders only. The real-data check catches MACs, emails, keys and capture files; real SSIDs, coordinates and screenshots are on you. - [x] **Consent gates intact.** Capture and network plugins still ship disabled, enabling them still takes the authorized-use acknowledgment (never pre-ticked or given by code), and the capture whitelist is still enforced. - [x] **Docs updated in the same PR**, if this changes something an operator sees or configures: the README package table, the relevant page under `docs/`, and the on-device operator guide (`GUIDE_MD` in `kestrel_pi/userguide.py`) where it applies. - [x] Commit messages are short and imperative. ## Release impact - [x] **App-layer-safe** — changes only files the in-place update engine carries: the `kestrel_pi` package, `plugins/*.py`, systemd units, the journald drop-in, a lib script already in the engine's `LIB_SCRIPTS`, or the CLI. - [ ] **Reflash-class** — touches a build input the engine does not carry onto a running device: apt or pip packages, boot options / `config.txt` / `cmdline`, kernel modules, the base image or partition size, `builder/config.json`, `builder/config.yml`, the `Makefile`, `.forgejo/workflows/`, a shipped config default (`config.toml` / `default.conf`), or a brand-new lib script. ## Notes for review - **For 1.0.11-beta.2**, an app-layer update on top of beta.1. No build input changes, so the stable release's `min_update_from` floor stays at beta.1. - **Behaviour change:** an empty `remote-train` `algorithms` now trains the agent's own algorithm instead of nothing (turning the plugin off still stops remote training). The release notes should say so. - **Existing devices:** the active model predates held-out rows, so its first contest uses only held-out rows newer than its data, and defers until 64 exist (about a day of capture at ~380 rows/day). - **Tested beyond the unit tests:** an end-to-end run with the real ML stack (the training host's venv, on synthetic episodes in a scratch folder, nothing on the host's own agent folder): - **Held out:** 552 of 2,400 rows kept out of every run. - **Warm start:** the on-device-style run started from the active model. - **Contest:** a real contest scored a warm-started local candidate and a staged 8,192-step "remote" model in 1.6 s. The local one won (z 4.29); the remote one didn't beat the active model. - **Records:** the tally, `last_decision` and `evaluated.json` were written, and a re-staged identical model was skipped. - **Diagnostics:** the script's device part ran against that folder; its section E reproduces the contest's numbers exactly. - **Why held-out rows matter:** on ordinary random splits the "remote" model looked better (+0.50 vs +0.42 lift), but on held-out hours the active one was (+0.57 vs +0.50). - `make lint` is clean. 1456 package tests pass, plus the release-tooling, real-data and ghost-guide tests. `test_gps_serial_reader_recovers_from_a_stalled_link` fails only on my machine (on `main` too) and passes in CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Judge every new agent model by the same fair contest
All checks were successful
Test / test (pull_request) Successful in 23s
Lint / lint (pull_request) Successful in 33s
Test / test (push) Successful in 21s
Lint / lint (push) Successful in 32s
ad104d09bd
On-device runs now warm-start from the active model and write a
candidate; local and remote candidates replace the active model only by
winning one contest, scored on held-out hour blocks that no training run
sees, under one rule for both. remote-train stages without a watermark
pre-filter, launches the agent's own algorithm first on data since the
host's last model, and syncs the device package before every run. The
tally counts contests, and the agent diagnostics script reports them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aluminum-ice deleted branch feature/fair-promotion 2026-10-31 07:09:52 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aluminum-ice/kestrel!120
No description provided.