RFC: Deterministic world-frame GameInput replay & gated autonomous benchmark loop over framelog #1303

Open
opened 2026-11-26 13:19:40 +00:00 by github-bot · 0 comments
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 13:18 UTC · original

Right now performance iteration here (including the daily AI-assisted workflow in #1272) has great per-stage timing via framelog.rs and visual captures via shot.rs / capture.rs, but live testing still relies on manual play or wall-clock VICTORY_KEYS=<seconds>:<key>, and multi-step A/B or autonomous agent loops lack built-in guards against regressions, subtle blackouts, or metric gaming.

We opened companion PR #1302 (https://github.com/fxceless/victory-fork/pull/1302) implementing a deterministic traversal benchmark and closed-loop optimization harness directly in victory-gpu, victory-hle, and xtask — with zero changes to Cargo.toml, Cargo.lock, or xtask/src/policy.rs (kept 100% compliant with docs/asset-policy.md, no external dependencies, works on both Windows and Linux/Wine).

Design highlights (PR #1302)

  1. Why world_frame-indexed GameInput replay + multi-save playlists beats title memory teleports:
    • Memory-hack teleports break across title builds and skip realistic streaming/remapping buildup. Instead, crates/victory-gpu/src/bench.rs tracks WORLD_FRAME from the first >= 500-draw presented frame (matching capture.rs / shot.rs), and crates/victory-hle/src/modules/gameinput_script.rs records/replays full PadState (analog sticks, triggers, buttons) + KeyState keyed by world_frame. Loading screens (world_frame == 0) are waited out automatically, and speedups never desync the route.
  2. Closed-loop signal straight from framelog.rs (bench.rs):
    • When VICTORY_BENCH_OUT=<abs.json> is set (ensure_outside_repo checked, atomic temp+rename write), bench.rs emits frame_ms (avg/median/p95/p99, 5%/1% low FPS), draws (min/avg/max), DXGI VRAM + Win32 PROCESS_MEMORY_COUNTERS_EX peaks, device_removed, zero_draw_world_frames, black_frames, and 12 per-frame framelog.rs stage averages (prepare_ms, card_wait_ms, card_idle_ms, copy_ms, copyback_ms, remap_ms, refresh_ms, pipeline_wait_ms, guard_faults, card_sync_ms, card_check_ms, card_lists_ms), then exits cleanly after VICTORY_BENCH_WARMUP + VICTORY_BENCH_EXIT_FRAMES.
  3. cargo xtask bench-loop (xtask/src/bench_loop.rs):
    • --mode ab runs interleaved baseline vs. candidate passes over a TOML playlist of saves/input scripts.
    • --mode loop plugs into any --agent-cmd (Claude Code, Codex, Gemini CLI, etc.), optionally pre-filters with --fast-cmd (micro-benchmarks / offline frame replay) before live launches, commits kept wins so later reverts never wipe earlier gains, rolls back failed trees cleanly, and writes experiments.jsonl (hypothesis, git SHA, diff stat, top framelog bottlenecks, gate verdicts) so agents do not repeat dead ends.
  4. Six anti-reward-hacking gates before any candidate is kept:
    1. Workspace --locked build + cargo xtask policy + --locked clippy + tests
    2. Exit code 0, watchdog timeout (taskkill /F /T tree cleanup on Windows), device_removed == false
    3. avg_draws within ±15% of baseline + input_script_sha256 match (blocks draw-skip cheats)
    4. zero_draw_world_frames == 0, black_frames == 0, plus pure-std PNG checkpoint luma/MAE parity against baseline captures
    5. Warmup exclusion + multi-run median / interleaved A/B
    6. Primary median frame_ms gain >= --min-gain-pct with non-regression guardrails on 1% low FPS, peak VRAM, and peak system RAM commit

Tested on both debug and diagnostics builds (cargo test --locked -p xtask 17/17 with mock loop & git-revert tests). Feedback on thresholds or additional framelog fields is very welcome on #1302.

**@⁠Vladimir-Human** on GitHub · 2026-11-26 13:18 UTC · [original](https://github.com/fxceless/victory-fork/issues/1303) Right now performance iteration here (including the daily AI-assisted workflow in #1272) has great per-stage timing via `framelog.rs` and visual captures via `shot.rs` / `capture.rs`, but live testing still relies on manual play or wall-clock `VICTORY_KEYS=<seconds>:<key>`, and multi-step A/B or autonomous agent loops lack built-in guards against regressions, subtle blackouts, or metric gaming. We opened companion PR **#1302** (`https://github.com/fxceless/victory-fork/pull/1302`) implementing a deterministic traversal benchmark and closed-loop optimization harness directly in `victory-gpu`, `victory-hle`, and `xtask` — with **zero** changes to `Cargo.toml`, `Cargo.lock`, or `xtask/src/policy.rs` (kept 100% compliant with `docs/asset-policy.md`, no external dependencies, works on both Windows and Linux/Wine). ### Design highlights (PR #1302) 1. **Why `world_frame`-indexed `GameInput` replay + multi-save playlists beats title memory teleports:** - Memory-hack teleports break across title builds and skip realistic streaming/remapping buildup. Instead, `crates/victory-gpu/src/bench.rs` tracks `WORLD_FRAME` from the first `>= 500`-draw presented frame (matching `capture.rs` / `shot.rs`), and `crates/victory-hle/src/modules/gameinput_script.rs` records/replays full `PadState` (analog sticks, triggers, buttons) + `KeyState` keyed by `world_frame`. Loading screens (`world_frame == 0`) are waited out automatically, and speedups never desync the route. 2. **Closed-loop signal straight from `framelog.rs` (`bench.rs`):** - When `VICTORY_BENCH_OUT=<abs.json>` is set (`ensure_outside_repo` checked, atomic temp+rename write), `bench.rs` emits `frame_ms` (avg/median/p95/p99, 5%/1% low FPS), `draws` (min/avg/max), DXGI VRAM + Win32 `PROCESS_MEMORY_COUNTERS_EX` peaks, `device_removed`, `zero_draw_world_frames`, `black_frames`, and 12 per-frame `framelog.rs` stage averages (`prepare_ms`, `card_wait_ms`, `card_idle_ms`, `copy_ms`, `copyback_ms`, `remap_ms`, `refresh_ms`, `pipeline_wait_ms`, `guard_faults`, `card_sync_ms`, `card_check_ms`, `card_lists_ms`), then exits cleanly after `VICTORY_BENCH_WARMUP + VICTORY_BENCH_EXIT_FRAMES`. 3. **`cargo xtask bench-loop` (`xtask/src/bench_loop.rs`):** - `--mode ab` runs interleaved baseline vs. candidate passes over a TOML playlist of saves/input scripts. - `--mode loop` plugs into any `--agent-cmd` (Claude Code, Codex, Gemini CLI, etc.), optionally pre-filters with `--fast-cmd` (micro-benchmarks / offline frame replay) before live launches, commits kept wins so later reverts never wipe earlier gains, rolls back failed trees cleanly, and writes `experiments.jsonl` (hypothesis, git SHA, diff stat, top `framelog` bottlenecks, gate verdicts) so agents do not repeat dead ends. 4. **Six anti-reward-hacking gates before any candidate is kept:** 1. Workspace `--locked` build + `cargo xtask policy` + `--locked` `clippy` + tests 2. Exit code `0`, watchdog timeout (`taskkill /F /T` tree cleanup on Windows), `device_removed == false` 3. `avg_draws` within ±15% of baseline + `input_script_sha256` match (blocks draw-skip cheats) 4. `zero_draw_world_frames == 0`, `black_frames == 0`, plus pure-std PNG checkpoint luma/MAE parity against baseline captures 5. Warmup exclusion + multi-run median / interleaved A/B 6. Primary `median frame_ms` gain `>= --min-gain-pct` with non-regression guardrails on 1% low FPS, peak VRAM, and peak system RAM commit Tested on both debug and `diagnostics` builds (`cargo test --locked -p xtask` 17/17 with mock loop & git-revert tests). Feedback on thresholds or additional `framelog` fields is very welcome on #1302.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:19:41 +00:00
This discussion has been locked. Commenting is limited to contributors.
No milestone
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
github/fxceless--victory-fork#1303
No description provided.