Skip to content

gate: a memory stop ends a run before memory runs out (D3D12-GATE-MEMORY-STOP) - #2812

Open
TheGeogeo wants to merge 4 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-gate-memory-stop
Open

TheGeogeo wants to merge 4 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-gate-memory-stop

Conversation

@TheGeogeo

@TheGeogeo TheGeogeo commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-GATE-MEMORY-STOP (#2570 (comment))

What and why

A memory pile-up has taken a PC's whole Windows down twice, not only the device (bug check 0x10E on a 3090). Testers stop their runs at 80 GB of private bytes or 60 s of full video memory. A fixed 80 GB cap never triggers on a PC whose commit limit is 40 GB. The gate now stops a run before memory runs out, with limits taken from the machine:

  • The supervisor of scripts/game-gate.ps1 already asks tools/game_gate.py state every 5 s. state now also answers memory_stop, from the runtime's latest memory lines (gate: summary.json gets the run's memory peaks (D3D12-GATE-MEMORY-PEAKS) #2810), so it works on any card. It stops when any of these holds:

    • the game's private bytes pass -StopPrivateMB (default: the lower of 90 % of this PC's commit limit and 1.25 times its physical memory: with a large page file the commit limit is far above what a PC survives, and two Windows crashes (0x10E) came at about 100 GB private on a PC with 64 GB of memory and a 175 GB limit);
    • the PC has less than -StopCommitLeftMB left to commit for 20 s (default: the larger of 128 MB and 0.25 % of the limit). On a PC with no page file, a normal run here left 267 MB at its lowest, so the floor is low and must hold for 20 s;
    • video memory stays over the system's budget for -StopOverBudgetSeconds (60).

    0 or less turns a limit off (for the two memory limits, a negative value is how the script asks for the computed default).

  • The run then stops the same clean way as at the end of its time (title suspended, cache saved), with the reason memory.

  • The limits go into run.json (memory_stop) and the summary (memory.stop_limits), and the gate's whole sentence (which limit, its value and the measured one) into stop.memory_why. The verdict is FAIL memory_stop: the run was on its way to running out. world_time_short and world_not_reached are not added on top.

  • At each 5 s check the order is: relaunched, world time reached, memory, STOP file, time limit. A run that reaches its world time at the same check as a limit stops as target and counts as a measurement; its memory peaks are in the summary anyway.

  • start forwards the limits to the detached run.

  • docs/game_gate.md describes all of it.

Tested

On Windows 11 Pro 10.0, rebased on main 8422def:

  • tests/test_game_gate.py: 30 tests OK (PowerShell 7 present, so the script tests ran). The new ones fail on main:
    • each limit asks for a stop, and doesn't below its limit or before its time;
    • 0 or no limits never stops;
    • a run stopped for memory fails with that reason only, with a world and without;
    • the script check: the limits exist, start forwards them, and run.json gets them;
    • since the review: the commit floor at exactly 20 s, a row exactly at the private limit, negative limits off, and the stop order (Get-StopReason is taken out of the script and run under PowerShell 7 with made-up polls; putting memory before the target, or the time limit before memory, fails the test).
  • The docs tests, test_tool_stdout_encoding.py and scripts/check_no_game_data.py on the changed files are clean. The script parses in PowerShell 7.
  • In game: RTX 3080 10 GB, driver 32.0.16.2140, Series S profile, diagnostics build of main 8f41d7d code, the driver mod from mods: gate_driver takes a run from the menus into the world (D3D12-GATE-DRIVER-MOD) #2784, -StopPrivateMB 15000 (a normal run reaches about 24 GB here).
    • At 79.7 s the runtime's memory line said 18,766 MB private. The gate logged stop_requested with reason memory and why: private bytes 18766 MB, over 15000 MB, then sent the close.
    • The game ended by itself 3 s later with exit 0, the title suspended and the cache saved.
    • Summary: FAIL memory_stop, stop_limits {15000, 128, 60}. The 128 MB is the default floor here: this PC's limit is 39.7 GB.

GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140

AI-assisted: yes. Claude Code (Claude Fable 5.2 and Claude Opus 5.5); a separate Claude Opus 5.5 agent reviewed the diff before this push.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head 0cd683949, main b7a1be296. CPU only, no pwsh and no game here. This branch contains #2810's head f806537a8, so red is #2810 + this PR's tests rather than main.

MEASURED

READ IN CODE

  • memory_alarm() reads the limits from run.json (memory_stop), and 0 turns a limit off.
    • Private bytes are compared on the last memory line only.
    • The commit floor needs since_end(...) >= 20 s of consecutive low lines.
    • Over-budget VRAM needs consecutive video lines over budget for over_budget_s.
    • state() exposes the result as memory_stop, for the script to act on.
  • In summary(), a memory stop adds memory_stop to fails, and stops world_not_reached or world_time_short from piling on. The verdict therefore names the real reason.
  • All three criteria rely on the memory and video lines that only diagnostics builds write (gate: summary.json gets the run's memory peaks (D3D12-GATE-MEMORY-PEAKS) #2810). The gate runs d3d12\target\diag\leonida.exe, so that holds for gate runs. A non-diagnostics exe would never trigger the stop.
  • On defaults, a data point from enlighted's 3090 posted on the bridge: their two Windows crashes (0x10E) came at about 100 GB private with VRAM full, and device losses at about 145 GB. On that machine, 90 % of the commit limit is about 158 GB, so criterion 1 alone would fire too late, and criterion 3 (VRAM over budget for 60 s) is the one that would have stopped those runs. Worth keeping 3 on by default, as it is.

ASSUMED

  • The script side (-StopPrivateMB / -StopCommitLeftMB / -StopOverBudgetSeconds reaching run.json, the clean close) was not run here (no pwsh). Only the static test that checks the parameters ran. Your RTX 3080 run (stop at 79.7 s, 18,766 MB) is not reproduced.

AI-assisted: Claude Code

@TheGeogeo

Copy link
Copy Markdown
Contributor Author

Thanks, checked and agreed. With a large page file the commit limit is far above what a PC survives. Your two Windows crashes (0x10E) came at about 100 GB private, on 64 GB of memory with a 175 GB limit. 90 % of that limit is 158 GB, which is too late.

Fixed in 5323dfa: the default -StopPrivateMB is now the lower of 90 % of the commit limit and 1.25 times the physical memory. That is 80 GB on that PC, the same as your wrapper, and 36 GB here. The video memory stop (over the budget for 60 s) was already on by default and stays so. The script test now checks the physical-memory bound, and the docs say why. test_game_gate.py 26 OK.

@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Re-verified on the new head 5323dfa69 (my comment above was on 0cd683949). macOS 27.2.1, Apple M5, Python 3.12, main d920d850d. CPU only, no pwsh.

MEASURED

READ IN CODE (0cd683949..5323dfa69: game-gate.ps1, game_gate.md, the test)

  • The default for -StopPrivateMB is now [math]::Min($commitLimitMB * 0.9, $physicalMB * 1.25), with $physicalMB from Win32_ComputerSystem.TotalPhysicalMemory. On enlighted's PC (64 GB RAM, a 175 GB commit limit) that gives 80 GB instead of about 158 GB, so it stops runs before the ~100 GB where their two 0x10E crashes happened. The over-budget-VRAM criterion is unchanged and still on by default.
  • Not run under pwsh here, so the computed default isn't measured. Only the static test that checks the script text ran.

AI-assisted: Claude Code

@fiestorra

Copy link
Copy Markdown
Contributor

Verified on Windows with the control: the suite fails when tools/game_gate.py is put back to main.

Cherry-picked onto main d920d850d, Python 3.13.14, no GPU and no game data:

python -m pytest tests/test_game_gate.py -q with this pull request: 26 passed in 3.67 s with tools/game_gate.py from main: 4 failed, 22 passed

So the new cases are tied to the new code and not to fixtures the file already had. They add to the same suite that #2805, #2804 and #2810 touch, and all five together are consistent - I have now run every one of them.

#2813 applies on top of this one (its tip cherry-picks cleanly over it), so the merge order is #2812 then #2813.

What I could not test: the PowerShell side (scripts/game-gate.ps1, 28 lines changed here). That path drives a real run folder, and this machine has the game but not the gate harness the reports describe - the Python parser and its summary are what the tests cover, and they are green.

AI-assisted: yes - DeepSeek v4.1 (flash), applied and ran both arms on the machine above.

Written with an AI assistant.

@ecox982745

Copy link
Copy Markdown
Contributor

I ran the stock PowerShell supervisor with real game_gate.py and a synthetic launcher under Windows 11, PowerShell 7.6.9 and Python 3.13. Head 5323dfa69 merged cleanly with bf19719ab (tree 8b471096e). The stock Python suite passed all 26 tests, including the runtime log contract test.

The harness supplied synthetic CIM values and fed the launcher synthetic log rows. The following are the recorded limits in run.json and the supervisor's resulting decisions.

Case Recorded limit Stop decision
64 GiB physical, 175 GiB commit 81,920 MB private Stopped at 81,921 MB, confirming the physical bound won
64 GiB physical, 40,000 MB commit 36,000 MB private Stopped at 36,001 MB, confirming the commit bound won
Explicit commit floor 777 MB Stopped after 25 s of rows below the floor
Default video-budget duration 60 s Stopped after 60 s of rows over budget
All three limits set to zero 0, 0, 0 No memory stop with all three synthetic limits exceeded

Each positive case produced one stop_requested event with reason memory and the parser's explanation. summary.json preserved that explanation and flagged memory_stop. The fixture exercises configuration and stop-reason propagation. Closing a title window and stopping the real process are outside this check. No game or GPU work was started.

AI-assisted with OpenAI Codex (GPT-6.2 Sol).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Dec 1, 2026

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ran on today's main (7f8bb903): the conflict is only tests/test_game_gate.py — both the #2805 Script test and this PR insert at the same spot — and keeping both gives 27 passed, so this is a one-line rebase. The needs rebase label is still correct, and #2810 (which the branch is stacked on) is already in main, so there is no duplicate work.

The core path holds: limits are read from the machine and written to run.json (scripts/game-gate.ps1:127-132, :149), the alarm is computed in tools/game_gate.py:286-304 and exposed as state.memory_stop (:318), the supervisor stops with reason memory before target/timeout (:207) and closes cleanly (:214-222), and the verdict is FAIL memory_stop with world_not_reached/world_time_short suppressed (:431-433, :438, :440). Deleting and reason != "memory" makes test_a_run_stopped_for_memory_fails_with_its_reason fail, so that guard is covered.

Three things before merge:

  1. The description is stale after 5323dfa69: it still says the private cap defaults to "90 % of this PC's commit limit", but code and docs now use the lower of that and 1.25 × physical (scripts/game-gate.ps1:131, docs/game_gate.md:30). Update the body.
  2. A test gap on the commit floor: the 20 s boundary is only exercised at 25 s, so >= → > at tools/game_gate.py:298 survives the suite. A 20 s case would close it (the 60 s VRAM boundary is covered at exactly 60).
  3. docs/game_gate.md:69 calls memory_why "the limit passed", but the code stores the full explanation string — say so.

One question, not a blocker: memory is checked before target (scripts/game-gate.ps1:207-209), so a run that reaches its world time in the same 5 s poll as a limit is reported FAIL memory_stop rather than PASS. If that is intended, it deserves a sentence; if not, check the target first.

…ORY-STOP)

A memory pile-up has taken a PC's whole Windows down, not only the device, and a fixed 80 GB cap never
triggers on a PC with a 40 GB commit limit. The supervisor now asks `game_gate.py state` for a memory stop,
read from the runtime's latest memory lines: the game's private bytes past -StopPrivateMB (default 90 % of
this PC's commit limit), the PC under -StopCommitLeftMB left to commit for 20 s (default the larger of
128 MB and 0.25 % of the limit), or video memory over the system's budget for -StopOverBudgetSeconds (60).
0 turns one off. The run then stops the same clean way, with the reason `memory`; the limits go into
run.json and the summary, the limit passed into `stop.memory_why`, and the verdict is FAIL `memory_stop`.
`start` forwards the limits to the detached run.
With a large page file the commit limit is far above what a PC survives: two Windows crashes (0x10E)
came at about 100 GB private on a PC with 64 GB of memory and a 175 GB limit, where 90 % of the limit
is 158 GB. The default is now the lower of 90 % of the commit limit and 1.25 x the physical memory
(80 GB there, 36 GB here); the video memory stop stays on by default.
…ested at 20 s (review)

A run that reached -WorldSeconds at the same poll as a memory limit was reported FAIL `memory_stop`.
It is a measurement, and its memory peaks are in the summary all the same, so the supervisor now
checks the target first. The poll's order is one function, Get-StopReason, which the test takes out
of the script and puts to PowerShell 7 with synthetic polls. The commit floor's boundary is now
tested at exactly 20 s, and the docs say what `stop.memory_why` holds: the gate's whole sentence.
…full (review)

A negative -StopOverBudgetSeconds stopped every run at its first video memory line: 0 s over the budget
passed a negative limit. Every limit is now off at 0 or less, with a test for each, and a line at
exactly the private limit is tested not to stop. The poll test gets a memory limit at the time limit
(memory wins), and the script text test checks the target and time limits the loop passes and that the
memory stop's sentence reaches the stop event. The docs give the poll's whole order (a STOP file and the
world time at the same check give `target`), say that `world_time_short` and `world_not_reached` are
not added to `memory_stop`, and name `memory.stop_limits`.
@TheGeogeo
TheGeogeo force-pushed the d3d12-gate-memory-stop branch from 5323dfa to 01203fb Compare December 2, 2026 03:44
@TheGeogeo

Copy link
Copy Markdown
Contributor Author

Rebased on main 8422def (#2810 is in main now, so its commit dropped out) and changed after @KelboLive's review (head 01203fb):

  1. The description is current: the private cap defaults to the lower of 90 % of the commit limit and 1.25 x physical memory.
  2. The commit floor is tested at exactly 20 s: with >= changed to > the test fails.
  3. docs/game_gate.md says memory_why is the gate's whole sentence, with the limit and the measured value.
  4. On your question: the target now comes before the memory stop. A run that reached its world time at the same 5 s check as a limit is a measurement, and its memory peaks are in the summary anyway. The order (relaunched, target, memory, STOP file, time limit) is one function, Get-StopReason, which the test takes out of the script and runs under PowerShell 7 with made-up polls. Putting memory before the target, or the time limit before memory, fails it. The docs give the order.

Also from a second review: a negative -StopOverBudgetSeconds stopped the run at the first video line. Every limit is now off at 0 or less. For the two memory limits, -1 stays the script's way to ask for the computed default. There is also a row exactly at the private limit. tests/test_game_gate.py: 30 OK on Windows 11 with PowerShell 7.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5; a separate Claude Opus 5.5 agent reviewed the diff before this push).

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants