Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-rig/blob/main/docs/TEACHING.md # aien-rig AIEN Rig: local AI and frame-rate tuning for RTX gaming PCs. Pre-alpha; host fixtures and target-card qualification are separate. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-rig / docs / TEACHING.md` 194 lines ยท 12028 bytes Raw Blame History Rendered 1 # Teaching AIEN Rig: the tuner's undo log, and a first local exercise 2 3 This walkthrough explains one mechanism that has been implemented, and shows you how to run 4 its tests yourself. It uses only source, tests, commits and evidence that are already in this 5 repository. The repository has no ADRs yet, so the design reasons below are quoted from the 6 module comments and commit messages at the pinned commit. 7 8 ## 1. What is on `main`, and what is on the branches 9 10 On `main`, `engine/`, `speech/`, `creator/`, `tuner/` and `app/` each hold a single 11 placeholder README. [PLAN.md](PLAN.md) assigns each component its own branch. The code is 12 on those branches, and none of them has been merged. The table in the 13 [README](../README.md#how-it-works--how-we-built-it) lists each branch at a pinned commit, 14 along with what it contains and the evidence behind it. Three different kinds of status 15 appear in this document, and they must be kept apart: 16 17 - **Planned.** Described in `README.md` and `docs/PLAN.md` on `main`. Nothing runs. 18 - **Implemented and exercised on a host.** The branch has source and tests, and the tests 19 ran on CI or on a developer host. The tuner is in this category. 20 - **Qualified on the target.** Measured on an RTX 5070 PC, with a receipt. Nothing is in this 21 category yet. A DGX Spark (GB10) result under a 12 GiB budget is a Spark result. It is not 22 an RTX 5070 result. 23 24 ## 2. The problem the tuner solves 25 26 The tuner changes Windows settings on the user's own PC. [AGENTS.md](../AGENTS.md) sets the 27 rule: *apply only safe changes, record a receipt for each, and be able to undo every change. 28 Do not add a change the tuner cannot revert.* The undo log is the mechanism that enforces 29 this rule. 30 31 ## 3. The mechanism 32 33 All links below point to `tuner/v0` at commit 34 [``2a2cda0``](https://github.com/aien-dev/aien-rig/tree/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner). 35 36 - [`apply_change`](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/src/undo.rs#L175) 37 takes these steps in order: 38 1. It refuses a tweak whose new value is "delete". 39 2. It reads the old value. If the setting already has the wanted value, it returns 40 `AlreadySet` and logs nothing. 41 3. It appends a `Pending` entry holding the old value and saves the log to disk. 42 4. It writes the new value and reads it back. 43 5. If the read-back matches, it marks the entry `Applied`. If not, it writes the old value 44 back, drops the entry and returns an error. 45 - [`undo`](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/src/undo.rs#L258) 46 walks the entries newest first. The tuner treats a setting as still its own when the 47 current value equals the value it wrote or the old value, or when the entry is still 48 `Pending` ([line 292](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/src/undo.rs#L292)). 49 If the setting is no longer its own, `undo` reports `ChangedSince` and leaves the value 50 alone, unless `--force` is given. 51 - The log is saved as JSON by writing a temp file and renaming it over the old one 52 (`save_log` in the same file). On Windows it lives at 53 `%LOCALAPPDATA%\AIEN-Rig\undo-log.json`. Set `AIEN_RIG_HOME` to put it somewhere else 54 ([paths.rs](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/src/paths.rs)). 55 56 ### Why it was built this way 57 58 The reasons below are taken from source comments and commits. They are not a reconstructed 59 personal account. 60 61 - **Logic that can be tested without Windows.** The comment in 62 [lib.rs](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/src/lib.rs) 63 says that everything which decides something is pure Rust and is unit tested on every OS, 64 and that `win` is a thin Windows layer. The commit history shows the same split: commit 65 ``5a9ef1d`` added the pure core with 45 unit tests, and commit ``3ec1a34`` added the Windows 66 layer and the CI. 67 - **Safe across a power cut.** The module comment in 68 [undo.rs](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/src/undo.rs#L1-L14) 69 says that even if the PC loses power mid-change, the log already knows the old value. 70 - **The user's own changes win.** The same comment says that `undo` refuses to overwrite a 71 setting that someone changed after the tuner, unless the user passes `--force`. 72 - **Only offer what the PC has.** Commit ``2a2cda0`` (*only switch to power plans the PC 73 offers*) added the 46th test, 74 [`power_plan_respects_what_the_pc_offers`](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/src/tweaks.rs#L189). 75 76 ### A failed approach elsewhere in the project 77 78 Creator's first end-to-end run, at commit ``8c2c463``, received HTTP 503 "GPU lock held by 79 other jobs" on every attempt for 899 s and then exited with status 1. The run was kept as 80 evidence. Commit ``7aef4de`` added `--busy-wait`, and the next run passed. Both runs are 81 recorded in the 82 [creator evidence README](https://github.com/aien-dev/aien-rig/blob/`87f98af04e15fffea4009ed34dca4d6892e6bd3e`/evidence/creator/README.md). 83 84 ### Upstream components 85 86 The tuner's direct dependencies, from 87 [Cargo.toml](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/Cargo.toml), 88 are `anyhow`, `clap`, `serde` and `serde_json` on every OS. On Windows it also uses 89 Microsoft's `windows` and `windows-registry` crates. Exact versions are pinned in 90 `tuner/Cargo.lock`. The development method (HDAE) is attributed in the 91 [README](../README.md#human-directed-agentic-engineering). 92 93 ## 4. Exercise: run the pure core and its refusal case (offline after fetch, no GPU, no Windows) 94 95 **Pins.** Repository `https://github.com/aien-dev/aien-rig.git`, commit 96 ``2a2cda0e2e4684119d28859261dbe123b4ded009`` (the head of branch `tuner/v0`, 2026-10-19). 97 98 **Requirements.** Git and a stable Rust toolchain with `cargo`. The recipe was replayed with 99 rustc and cargo 1.98.1 on Ubuntu 24.04 aarch64. It needs no GPU, no model download, no 100 Windows and no administrator rights. The only network step is `cargo fetch`, which 101 downloads the crates pinned in `Cargo.lock` from crates.io. Every step after it can run with 102 `--offline`. 103 104 **Inputs.** The tests build their own inputs. `MemStore` is an in-memory settings store, 105 and the test functions `hags()` and `dvr()` stand for the Windows registry values 106 `HwSchMode` and `HistoricalCaptureEnabled`. 107 108 ```sh 109 git clone https://github.com/aien-dev/aien-rig.git rig-exercise 110 cd rig-exercise 111 git checkout `2a2cda0e2e4684119d28859261dbe123b4ded009` 112 cd tuner 113 cargo fetch --locked # network: crates.io only 114 cargo test --offline --locked # step A: all pure-core tests 115 cargo test --offline --locked undo:: # step B: the undo-log tests 116 AIEN_RIG_HOME="$(mktemp -d)" cargo run --offline --locked -q -- undo --list # step C 117 cargo run --offline --locked -q -- scan # step D: expected refusal off Windows 118 ``` 119 120 **Expected output and exit status.** 121 122 - **Step A** exits 0. The library test binary prints `running 46 tests` and 123 `test result: ok. 46 passed; 0 failed`. Three more sections each print 124 `running 0 tests`: the `rig_tune` binary, which has no tests; the `windows_os` integration 125 tests, which are Windows-only; and the doc-tests. 126 - **Step B** exits 0 with `10 passed; ... 36 filtered out`. 127 - **Step C** exits 0 and prints `Nothing has been changed by rig-tune on this PC.` 128 - **Step D** exits 1 and prints 129 `rig-tune: this command runs on Windows only (compare, receipts and undo --list work everywhere)`. 130 This is the platform boundary at 131 [main.rs#L242](https://github.com/aien-dev/aien-rig/blob/`2a2cda0e2e4684119d28859261dbe123b4ded009`/tuner/src/main.rs#L242). 132 It is not a failure of the exercise. 133 134 **What each test establishes.** 135 136 | Claim | Test (in `tuner/src/undo.rs`) | 137 |---|---| 138 | 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) | 139 | 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) | 140 | **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) | 141 | 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) | 142 | **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) | 143 144 ### Negative control: show that the refusal test can fail 145 146 A test is only evidence if it fails when the behaviour it checks is removed. Disable the 147 `ChangedSince` guard in a throwaway checkout, run the test, then restore the file: 148 149 ```sh 150 sed -i.bak 's/if !ours && !force {/if false {/' src/undo.rs && rm src/undo.rs.bak 151 cargo test --offline --locked -q undo::tests::undo_leaves # expected: exit 101, test FAILED 152 git checkout -- src/undo.rs 153 cargo test --offline --locked -q undo::tests::undo_leaves # expected: exit 0, 1 passed 154 ``` 155 156 With the guard disabled, the test fails with 157 `assertion failed: matches!(out[0], UndoOutcome::ChangedSince { .. })` at `src/undo.rs:433`, 158 and cargo exits with status 101. Restore the file with `git checkout`, not by moving a 159 backup copy back into place. `mv` keeps the backup's older modification time, so cargo 160 treats the build as up to date and the test keeps failing. That happened in the first 161 replay of this recipe. 162 163 ### What this exercise does not show 164 165 The exercise runs the pure core against an in-memory store. It does not touch the Windows 166 registry, ETW, NVML or a display. It produces no FPS number, and it is not a 5070 result. 167 168 ## 5. Optional: Windows and RTX 5070 qualification (separate, not done yet) 169 170 These steps come from the tuner README and its CI at the same commit. They are listed here so 171 that a reader can tell what remains. 172 173 1. **Windows host, no NVIDIA card needed.** `.github/workflows/tuner.yml` builds 174 `rig-tune.exe`, runs the unit tests and the Windows OS tests, runs clippy with 175 `-D warnings`, and runs `tuner/ci/windows-e2e.ps1`. That script checks `scan`, compares 176 the ETW frame count with a WARP Direct3D 11 probe presenting at 120 fps, runs 177 `apply --yes` followed by an exact `undo`, and checks game mode. This passed on 178 `windows-latest` in 179 [run `39292662908`](https://github.com/aien-dev/aien-rig/actions/runs/`39292662908`) 180 (commit ``4cebe95``) and in 181 [run `39293286436`](https://github.com/aien-dev/aien-rig/actions/runs/`39293286436`) 182 (commit ``2a2cda0``). This is host CI on a runner with a virtual display. It is not 183 target-hardware evidence. 184 2. **RTX 5070 PC (not done).** Run `rig-tune scan` as administrator. Check that the NVML 185 readings for Resizable BAR and PCIe link width are correct. Check a real monitor 186 refresh-rate change and its 15 s revert. Record `measure` before and after 187 `apply` for one game at the same spot, with `--label before` and `--label after`, then 188 run `compare` and `undo`. Keep the receipts in `evidence/` and name the card, driver and 189 game. Until these receipts exist, the tuner README's "Not yet verified" list still 190 applies, and no FPS gain is claimed. 191 192 The engine and speech GPU paths have only been measured on a DGX Spark (GB10). See their 193 branch READMEs. Repeating those numbers on an RTX 5070 is a separate qualification, and none 194 has been done.