Explore other actions, train from scratch now and then, honour the action lists #175

Merged
aluminum-ice merged 2 commits from agent-exploration into main 2026-11-05 05:46:16 +00:00
Owner

What this PR does

A learned policy acts greedily, so it only ever runs the action it already prefers. The episode logs then hold no evidence about other actions, and a fine-tune warm-started from the active model keeps making the same choices, so contests end in an exact tie (not better than the active model (mean diff +0.0000)). This PR gives the agent a way out:

  • Exploration (agent/explore.py). While the learned policy drives, explore_rate (default 5%) of its windows run another allowed action, held for explore_windows (default 2) windows for a cleaner reading, favouring the least-tried (weight 1/sqrt(1+n)). Rows are marked explore / explore_p, train the reward model like any other, and count under their own exploring metrics block, never learned. Never under the baseline. Status gains an explore block; the card an Exploring row.
  • Runs from scratch. Every fresh_every-th (4) on-device run, or one after stuck_contests (3) local contests where the candidate chose what the active model chose on every row, trains with --no-warm-start --seed <random> and fresh_timesteps (default 3 × train_timesteps). Same contest. train.evaluate now returns each policy's actions; the contest records each candidate's agreement (log line, last_decision, card), and the tally counts fresh_won/fresh_lost. kestrel agent train-now --fresh (a train-request-fresh file via pi_touch) and agent train --fresh.
  • Cautious scoring. The mean and state-conditioned reward models score an action with fewer than 8 rows at the lowest mean among actions with 8 or more, instead of the global mean, in training and in the contest alike; the provenance records unsupported_actions. A model can't win by choosing actions nobody has tried.
  • The action lists are honoured. [agent.action] postures, dwell_buckets and transmit_modes now bound every action the agent runs (learned, baseline, exploring), mapped with explore.nearest_allowed; models keep the full Discrete(32), so SPEC_VERSION is unchanged.
  • Guide figure gated by release. The publisher gains since on a figure, so the new Exploring screenshot is left out when building a release before 1.0.14 and the 1.0.13 page can still be republished.

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, the Release workflow (.forgejo/workflows/main.yml), a shipped config default (config.toml / default.conf), or a brand-new lib script.

The new settings are code defaults (AGENT_DEFAULTS), not in the shipped config.toml; the rest is the agent package, the CLI (kestrel.sh), docs and desktop tools.

Notes for review

  • Settings live in config.toml only, like promotion_margin/promotion_min_z: not on the Advanced page and not in CONFIG_SETTABLE, so plugins-ctl is unchanged. Documented in config-reference.md, agent-setup.md and the guide.
  • No web button for a fresh run; the CLI covers it (kestrel agent train-now --fresh). The dashboard's Train now stays a warm fine-tune.
  • Exploration under policy = baseline is off by design: the baseline is the reference every model is scored against. A device on baseline gathers no exploring data until switched to learned.
  • Counters are in memory (fresh_every cadence, the tie streak), so an agent restart starts them over; the tally's fresh counts persist.
  • [agent.action] behaviour change: narrowing those lists now actually narrows what the agent runs (the defaults allow all 32 actions, so nothing changes for a default config).
  • Tested off-device: 1724 passed / 11 skipped locally; the agent tests also pass with the real ML stack (torch 2.10, SB3 2.9, gymnasium 1.4), and an end-to-end run with real DQN models trained from scratch with seeds, ran a contest, logged agreement and counted fresh_won. First on-device run will be the next beta.
  • Deferred (deferred.md): runs from scratch on the remote host, weighting exploring rows by explore_p, and pausing training after a tie; the "collapses to one action" entry is narrowed to what's left.
  • The guide figure is since = "1.0.14"; change it if the next stable release has another number.

🤖 Generated with Claude Code

## What this PR does A learned policy acts greedily, so it only ever runs the action it already prefers. The episode logs then hold no evidence about other actions, and a fine-tune warm-started from the active model keeps making the same choices, so contests end in an exact tie (`not better than the active model (mean diff +0.0000)`). This PR gives the agent a way out: - **Exploration** (`agent/explore.py`). While the learned policy drives, `explore_rate` (default 5%) of its windows run another allowed action, held for `explore_windows` (default 2) windows for a cleaner reading, favouring the least-tried (weight `1/sqrt(1+n)`). Rows are marked `explore` / `explore_p`, train the reward model like any other, and count under their own `exploring` metrics block, never `learned`. Never under the baseline. Status gains an `explore` block; the card an **Exploring** row. - **Runs from scratch.** Every `fresh_every`-th (4) on-device run, or one after `stuck_contests` (3) local contests where the candidate chose what the active model chose on every row, trains with `--no-warm-start --seed <random>` and `fresh_timesteps` (default 3 × `train_timesteps`). Same contest. `train.evaluate` now returns each policy's actions; the contest records each candidate's **agreement** (log line, `last_decision`, card), and the tally counts `fresh_won`/`fresh_lost`. `kestrel agent train-now --fresh` (a `train-request-fresh` file via `pi_touch`) and `agent train --fresh`. - **Cautious scoring.** The mean and state-conditioned reward models score an action with fewer than 8 rows at the lowest mean among actions with 8 or more, instead of the global mean, in training and in the contest alike; the provenance records `unsupported_actions`. A model can't win by choosing actions nobody has tried. - **The action lists are honoured.** `[agent.action]` `postures`, `dwell_buckets` and `transmit_modes` now bound every action the agent runs (learned, baseline, exploring), mapped with `explore.nearest_allowed`; models keep the full `Discrete(32)`, so `SPEC_VERSION` is unchanged. - **Guide figure gated by release.** The publisher gains `since` on a figure, so the new Exploring screenshot is left out when building a release before 1.0.14 and the 1.0.13 page can still be republished. ## 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`, the Release workflow (`.forgejo/workflows/main.yml`), a shipped config default (`config.toml` / `default.conf`), or a brand-new lib script. The new settings are code defaults (`AGENT_DEFAULTS`), not in the shipped `config.toml`; the rest is the agent package, the CLI (`kestrel.sh`), docs and desktop tools. ## Notes for review - **Settings live in `config.toml` only**, like `promotion_margin`/`promotion_min_z`: not on the Advanced page and not in `CONFIG_SETTABLE`, so `plugins-ctl` is unchanged. Documented in `config-reference.md`, `agent-setup.md` and the guide. - **No web button for a fresh run**; the CLI covers it (`kestrel agent train-now --fresh`). The dashboard's Train now stays a warm fine-tune. - **Exploration under `policy = baseline` is off by design**: the baseline is the reference every model is scored against. A device on baseline gathers no exploring data until switched to `learned`. - **Counters are in memory** (`fresh_every` cadence, the tie streak), so an agent restart starts them over; the tally's fresh counts persist. - **`[agent.action]` behaviour change:** narrowing those lists now actually narrows what the agent runs (the defaults allow all 32 actions, so nothing changes for a default config). - **Tested off-device:** 1724 passed / 11 skipped locally; the agent tests also pass with the real ML stack (torch 2.10, SB3 2.9, gymnasium 1.4), and an end-to-end run with real DQN models trained from scratch with seeds, ran a contest, logged agreement and counted `fresh_won`. First on-device run will be the next beta. - **Deferred** (`deferred.md`): runs from scratch on the remote host, weighting exploring rows by `explore_p`, and pausing training after a tie; the "collapses to one action" entry is narrowed to what's left. - The guide figure is `since = "1.0.14"`; change it if the next stable release has another number. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A learned policy acts greedily, so it only ever ran the action it already
preferred, and warm-started fine-tunes kept choosing the same thing: every
contest ended in an exact tie. Now:

- While the learned policy drives, explore_rate (5%) of its windows run
  another allowed action for explore_windows (2) windows, favouring the
  least-tried; the rows are marked explore and counted apart from the
  learned figures.
- Every fresh_every-th (4) on-device run, or one after stuck_contests (3)
  contests with no changed choice, trains from scratch with a new seed and
  fresh_timesteps (3x train_timesteps). The contest records each
  candidate's agreement with the active model; the tally counts fresh runs.
- The reward models score an action with fewer than 8 rows at the lowest
  supported mean instead of the global mean.
- [agent.action] postures, dwell_buckets and transmit_modes now bound every
  action the agent runs.
- kestrel agent train-now --fresh; guide, docs, and a guide figure gated to
  the release it ships in (since, in the publisher).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Show the card row above Exploring in its guide figure
All checks were successful
Lint / lint (pull_request) Successful in 34s
Test / test (pull_request) Successful in 1m4s
Lint / lint (push) Successful in 32s
Test / test (push) Successful in 57s
40cd8e6517
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aluminum-ice deleted branch agent-exploration 2026-11-05 05:46:16 +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!175
No description provided.