diff --git a/README.md b/README.md index 13c6c18..b0d5800 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,57 @@ Local AI and a measured FPS tuner for RTX gaming PCs, starting with the RTX 5070 Status: pre-alpha, under active build. Not tested on an RTX 5070 yet. Every speed claim links to a receipt in evidence/. +## How it works / How we built it + +**Walkthrough with a runnable exercise: [docs/TEACHING.md](docs/TEACHING.md).** + +**Problem.** A gaming PC with one 12 GB RTX card should run a local assistant and get +faster in games, and every claim about speed should be checkable. "Faster" is only +claimed against llama.cpp on the same card, and every number links to a receipt +([AGENTS.md](AGENTS.md), [plan](docs/PLAN.md)). + +**Where the code is.** `main` holds the plan and one placeholder README per component. +Each component is built on its own branch ([plan](docs/PLAN.md)). None of those branches +has been merged into `main`, and none has run on an RTX 5070. + +| Component | Branch at the pinned commit | What is there | Evidence and its limit | +|---|---|---|---| +| tuner | [`tuner/v0` @ 2a2cda0](https://github.com/aien-dev/aien-rig/tree/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner) | Rust crate `rig-tune`: a pure core (stats, frame selection, undo log, tweaks, receipts) with 46 unit tests, plus a Windows layer (ETW, registry, power, display, NVML) | Windows CI [run 39293286436](https://github.com/aien-dev/aien-rig/actions/runs/39293286436) passed on a GitHub runner with no NVIDIA card | +| creator | [`creator/v0` @ 87f98af](https://github.com/aien-dev/aien-rig/tree/87f98af04e15fffea4009ed34dca4d6892e6bd3e/creator) | Rust crate `rig-create`: caption parsers, chunked model pipeline, chapter and Shorts checks | [end-to-end runs](https://github.com/aien-dev/aien-rig/tree/87f98af04e15fffea4009ed34dca4d6892e6bd3e/evidence/creator) against a local model server on the DGX Spark | +| speech | [`speech/v0` @ af71f46](https://github.com/aien-dev/aien-rig/tree/af71f46fde79e566b2a1151bef3794b8f4636ee8/speech) | Rust Whisper-family runtime, CPU path plus an Omega GPU path for GB10 (sm_121) | [GB10 receipts](https://github.com/aien-dev/aien-rig/tree/af71f46fde79e566b2a1151bef3794b8f4636ee8/evidence/speech/2026-10-19-gb10); the RTX 5070 GPU path is not built | +| engine | [`engine/core` @ 19b0032](https://github.com/aien-dev/aien-rig/tree/19b0032ab3714ae3dc9d8311d7a7577dd0e63d05/engine) | README, 5070 ceiling math ([CEILING.md](https://github.com/aien-dev/aien-rig/blob/19b0032ab3714ae3dc9d8311d7a7577dd0e63d05/engine/CEILING.md)) and calc receipts; the serving code is in the `rig/engine-12gb` branch of aien-sovereign-core | GB10 under a 12 GiB budget only. That is not an RTX 5070 result. | +| app | [`app/v0` @ ea43b11](https://github.com/aien-dev/aien-rig/tree/ea43b1198f6598fd7cfc676bf8eb50047a03736f/app) | Windows `aien-rig.exe` local page (Play, Create, Chat), release workflow | none on the target PC | + +**One mechanism, end to end (tuner undo log).** Every change the tuner makes goes through +[`apply_change`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L175). +It reads the old value, writes a `pending` log entry to disk *before* it changes anything, +then makes the change and reads it back. If the read-back does not match, it puts the old +value back and drops the entry. +[`undo`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L258) +restores entries newest first. It refuses to overwrite a setting that someone else changed +after the tuner did, unless the user passes `--force`. + +**Why it is built this way** (from the module comments at that commit): +- Everything that decides something is pure Rust and is tested on every OS. Windows calls + sit behind a thin `win` layer and a `Store` trait, so the tests use an in-memory store + ([lib.rs](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/lib.rs)). +- The log is written before the change, so the old value can still be restored after a + power cut in the middle of a change + ([undo.rs](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L1-L14)). + +**A failed approach, kept on purpose.** The first creator end-to-end run (commit 8c2c463) +got HTTP 503 "GPU busy" from the shared model server on every try for 899 s and exited 1. +Commit 7aef4de added `--busy-wait`, and the next run passed +([creator evidence README](https://github.com/aien-dev/aien-rig/blob/87f98af04e15fffea4009ed34dca4d6892e6bd3e/evidence/creator/README.md)). + +**Limit.** The tuner has not run on the RTX 5070 PC. Its NVML reads (Resizable BAR, PCIe +link) and a real monitor refresh-rate change have only been compile-checked, because CI +has no NVIDIA card. No game FPS gain is claimed. + +**Run it yourself without a GPU.** The exercise in [docs/TEACHING.md](docs/TEACHING.md) +checks out `tuner/v0` at 2a2cda0 and runs its 46 unit tests on Linux or macOS. Then it +breaks the refusal check on purpose to show that a test catches it. + ## Human-Directed Agentic Engineering Development follows Human-Directed Agentic Engineering (HDAE): humans define goals, diff --git a/docs/TEACHING.md b/docs/TEACHING.md new file mode 100644 index 0000000..3ada93c --- /dev/null +++ b/docs/TEACHING.md @@ -0,0 +1,194 @@ +# Teaching AIEN Rig: the tuner's undo log, and a first local exercise + +This walkthrough explains one mechanism that has been implemented, and shows you how to run +its tests yourself. It uses only source, tests, commits and evidence that are already in this +repository. The repository has no ADRs yet, so the design reasons below are quoted from the +module comments and commit messages at the pinned commit. + +## 1. What is on `main`, and what is on the branches + +On `main`, `engine/`, `speech/`, `creator/`, `tuner/` and `app/` each hold a single +placeholder README. [PLAN.md](PLAN.md) assigns each component its own branch. The code is +on those branches, and none of them has been merged. The table in the +[README](../README.md#how-it-works--how-we-built-it) lists each branch at a pinned commit, +along with what it contains and the evidence behind it. Three different kinds of status +appear in this document, and they must be kept apart: + +- **Planned.** Described in `README.md` and `docs/PLAN.md` on `main`. Nothing runs. +- **Implemented and exercised on a host.** The branch has source and tests, and the tests + ran on CI or on a developer host. The tuner is in this category. +- **Qualified on the target.** Measured on an RTX 5070 PC, with a receipt. Nothing is in this + category yet. A DGX Spark (GB10) result under a 12 GiB budget is a Spark result. It is not + an RTX 5070 result. + +## 2. The problem the tuner solves + +The tuner changes Windows settings on the user's own PC. [AGENTS.md](../AGENTS.md) sets the +rule: *apply only safe changes, record a receipt for each, and be able to undo every change. +Do not add a change the tuner cannot revert.* The undo log is the mechanism that enforces +this rule. + +## 3. The mechanism + +All links below point to `tuner/v0` at commit +[`2a2cda0`](https://github.com/aien-dev/aien-rig/tree/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner). + +- [`apply_change`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L175) + takes these steps in order: + 1. It refuses a tweak whose new value is "delete". + 2. It reads the old value. If the setting already has the wanted value, it returns + `AlreadySet` and logs nothing. + 3. It appends a `Pending` entry holding the old value and saves the log to disk. + 4. It writes the new value and reads it back. + 5. If the read-back matches, it marks the entry `Applied`. If not, it writes the old value + back, drops the entry and returns an error. +- [`undo`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L258) + walks the entries newest first. The tuner treats a setting as still its own when the + current value equals the value it wrote or the old value, or when the entry is still + `Pending` ([line 292](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L292)). + If the setting is no longer its own, `undo` reports `ChangedSince` and leaves the value + alone, unless `--force` is given. +- The log is saved as JSON by writing a temp file and renaming it over the old one + (`save_log` in the same file). On Windows it lives at + `%LOCALAPPDATA%\AIEN-Rig\undo-log.json`. Set `AIEN_RIG_HOME` to put it somewhere else + ([paths.rs](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/paths.rs)). + +### Why it was built this way + +The reasons below are taken from source comments and commits. They are not a reconstructed +personal account. + +- **Logic that can be tested without Windows.** The comment in + [lib.rs](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/lib.rs) + says that everything which decides something is pure Rust and is unit tested on every OS, + and that `win` is a thin Windows layer. The commit history shows the same split: commit + `5a9ef1d` added the pure core with 45 unit tests, and commit `3ec1a34` added the Windows + layer and the CI. +- **Safe across a power cut.** The module comment in + [undo.rs](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L1-L14) + says that even if the PC loses power mid-change, the log already knows the old value. +- **The user's own changes win.** The same comment says that `undo` refuses to overwrite a + setting that someone changed after the tuner, unless the user passes `--force`. +- **Only offer what the PC has.** Commit `2a2cda0` (*only switch to power plans the PC + offers*) added the 46th test, + [`power_plan_respects_what_the_pc_offers`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/tweaks.rs#L189). + +### A failed approach elsewhere in the project + +Creator's first end-to-end run, at commit `8c2c463`, received HTTP 503 "GPU lock held by +other jobs" on every attempt for 899 s and then exited with status 1. The run was kept as +evidence. Commit `7aef4de` added `--busy-wait`, and the next run passed. Both runs are +recorded in the +[creator evidence README](https://github.com/aien-dev/aien-rig/blob/87f98af04e15fffea4009ed34dca4d6892e6bd3e/evidence/creator/README.md). + +### Upstream components + +The tuner's direct dependencies, from +[Cargo.toml](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/Cargo.toml), +are `anyhow`, `clap`, `serde` and `serde_json` on every OS. On Windows it also uses +Microsoft's `windows` and `windows-registry` crates. Exact versions are pinned in +`tuner/Cargo.lock`. The development method (HDAE) is attributed in the +[README](../README.md#human-directed-agentic-engineering). + +## 4. Exercise: run the pure core and its refusal case (offline after fetch, no GPU, no Windows) + +**Pins.** Repository `https://github.com/aien-dev/aien-rig.git`, commit +`2a2cda0e2e4684119d28859261dbe123b4ded009` (the head of branch `tuner/v0`, 2026-10-19). + +**Requirements.** Git and a stable Rust toolchain with `cargo`. The recipe was replayed with +rustc and cargo 1.98.1 on Ubuntu 24.04 aarch64. It needs no GPU, no model download, no +Windows and no administrator rights. The only network step is `cargo fetch`, which +downloads the crates pinned in `Cargo.lock` from crates.io. Every step after it can run with +`--offline`. + +**Inputs.** The tests build their own inputs. `MemStore` is an in-memory settings store, +and the test functions `hags()` and `dvr()` stand for the Windows registry values +`HwSchMode` and `HistoricalCaptureEnabled`. + +```sh +git clone https://github.com/aien-dev/aien-rig.git rig-exercise +cd rig-exercise +git checkout 2a2cda0e2e4684119d28859261dbe123b4ded009 +cd tuner +cargo fetch --locked # network: crates.io only +cargo test --offline --locked # step A: all pure-core tests +cargo test --offline --locked undo:: # step B: the undo-log tests +AIEN_RIG_HOME="$(mktemp -d)" cargo run --offline --locked -q -- undo --list # step C +cargo run --offline --locked -q -- scan # step D: expected refusal off Windows +``` + +**Expected output and exit status.** + +- **Step A** exits 0. The library test binary prints `running 46 tests` and + `test result: ok. 46 passed; 0 failed`. Three more sections each print + `running 0 tests`: the `rig_tune` binary, which has no tests; the `windows_os` integration + tests, which are Windows-only; and the doc-tests. +- **Step B** exits 0 with `10 passed; ... 36 filtered out`. +- **Step C** exits 0 and prints `Nothing has been changed by rig-tune on this PC.` +- **Step D** exits 1 and prints + `rig-tune: this command runs on Windows only (compare, receipts and undo --list work everywhere)`. + This is the platform boundary at + [main.rs#L242](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/main.rs#L242). + It is not a failure of the exercise. + +**What each test establishes.** + +| Claim | Test (in `tuner/src/undo.rs`) | +|---|---| +| The old value reaches disk before the change, and undo restores it exactly, including deleting a value that did not exist before | [`apply_then_undo_restores_exactly_including_missing`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L368) | +| A write whose read-back does not match is rolled back and not logged | [`bad_readback_rolls_back`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L416) | +| **Refusal:** a setting the user changed afterwards is left alone unless `force` is set | [`undo_leaves_settings_changed_by_someone_else_unless_forced`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L426) | +| A `Pending` entry left by a crash is still undone | [`pending_entry_from_a_crash_is_still_undone`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L469) | +| **Refusal:** a tweak may not delete a setting | [`refuses_to_delete_as_a_tweak`](https://github.com/aien-dev/aien-rig/blob/2a2cda0e2e4684119d28859261dbe123b4ded009/tuner/src/undo.rs#L508) | + +### Negative control: show that the refusal test can fail + +A test is only evidence if it fails when the behaviour it checks is removed. Disable the +`ChangedSince` guard in a throwaway checkout, run the test, then restore the file: + +```sh +sed -i.bak 's/if !ours && !force {/if false {/' src/undo.rs && rm src/undo.rs.bak +cargo test --offline --locked -q undo::tests::undo_leaves # expected: exit 101, test FAILED +git checkout -- src/undo.rs +cargo test --offline --locked -q undo::tests::undo_leaves # expected: exit 0, 1 passed +``` + +With the guard disabled, the test fails with +`assertion failed: matches!(out[0], UndoOutcome::ChangedSince { .. })` at `src/undo.rs:433`, +and cargo exits with status 101. Restore the file with `git checkout`, not by moving a +backup copy back into place. `mv` keeps the backup's older modification time, so cargo +treats the build as up to date and the test keeps failing. That happened in the first +replay of this recipe. + +### What this exercise does not show + +The exercise runs the pure core against an in-memory store. It does not touch the Windows +registry, ETW, NVML or a display. It produces no FPS number, and it is not a 5070 result. + +## 5. Optional: Windows and RTX 5070 qualification (separate, not done yet) + +These steps come from the tuner README and its CI at the same commit. They are listed here so +that a reader can tell what remains. + +1. **Windows host, no NVIDIA card needed.** `.github/workflows/tuner.yml` builds + `rig-tune.exe`, runs the unit tests and the Windows OS tests, runs clippy with + `-D warnings`, and runs `tuner/ci/windows-e2e.ps1`. That script checks `scan`, compares + the ETW frame count with a WARP Direct3D 11 probe presenting at 120 fps, runs + `apply --yes` followed by an exact `undo`, and checks game mode. This passed on + `windows-latest` in + [run 39292662908](https://github.com/aien-dev/aien-rig/actions/runs/39292662908) + (commit `4cebe95`) and in + [run 39293286436](https://github.com/aien-dev/aien-rig/actions/runs/39293286436) + (commit `2a2cda0`). This is host CI on a runner with a virtual display. It is not + target-hardware evidence. +2. **RTX 5070 PC (not done).** Run `rig-tune scan` as administrator. Check that the NVML + readings for Resizable BAR and PCIe link width are correct. Check a real monitor + refresh-rate change and its 15 s revert. Record `measure` before and after + `apply` for one game at the same spot, with `--label before` and `--label after`, then + run `compare` and `undo`. Keep the receipts in `evidence/` and name the card, driver and + game. Until these receipts exist, the tuner README's "Not yet verified" list still + applies, and no FPS gain is claimed. + +The engine and speech GPU paths have only been measured on a DGX Spark (GB10). See their +branch READMEs. Repeating those numbers on an RTX 5070 is a separate qualification, and none +has been done.