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 Source # 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 assigns each component its own branch. The code is on those branches, and none of them has been merged. The table in the README 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 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` . - `apply_change` takes these steps in order: - It refuses a tweak whose new value is "delete". - It reads the old value. If the setting already has the wanted value, it returns `AlreadySet` and logs nothing. - It appends a `Pending` entry holding the old value and saves the log to disk. - It writes the new value and reads it back. - 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` 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 ). 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 ). ### 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 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 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` . ### 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 . ### Upstream components The tuner's direct dependencies, from 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 . ## 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`. ``` 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 . 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` A write whose read-back does not match is rolled back and not logged `bad_readback_rolls_back` Refusal: a setting the user changed afterwards is left alone unless `force` is set `undo_leaves_settings_changed_by_someone_else_unless_forced` A `Pending` entry left by a crash is still undone `pending_entry_from_a_crash_is_still_undone` Refusal: a tweak may not delete a setting `refuses_to_delete_as_a_tweak` ### 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: ``` 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. - 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` (commit `4cebe95`) and in run `39293286436` (commit `2a2cda0`). This is host CI on a runner with a virtual display. It is not target-hardware evidence. - 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.