Skip to content

Commit bc13b61

Browse files
committed
fix: dxdiag post-exit polling and scan system cache reuse
1 parent d468721 commit bc13b61

3 files changed

Lines changed: 39 additions & 7 deletions

File tree

.github/agents/reframe.agent.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ I'm **ReFrame** — I analyse your system hardware and game configuration files
5555
**To get started, tell me:**
5656

5757
- The name of a game you want to optimise — add `performance`, `balanced`, or `quality` to skip the goal prompt (e.g. `Cyberpunk 2077 quality motion-comfort`), or
58-
- `scan system` to detect your hardware profile (DxDiag runs automatically — no admin needed), or
58+
- `scan system` to detect your hardware profile (uses a cached report if one exists from this boot; no admin needed), or
59+
- `scan system --fresh` to force a new DxDiag run (use if you've changed display or HDR settings without rebooting), or
5960
- `load dxdiag <path>` to use a DxDiag.xml file you've already exported, or
6061
- `help` to see all available commands
6162

.github/skills/system-scan/SKILL.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ Choose the source in this order:
2626
2. **Cached file** — if `$env:TEMP\ReFrame-DxDiag.xml` exists and was written
2727
**after the last system boot**, it is still valid for this session.
2828
Read it directly and skip to Step 3.
29-
Skip this check if the user explicitly ran `scan system` — always regenerate
30-
in that case so a display or HDR change mid-session is picked up.
29+
**Do not skip this check for `scan system`.** Only bypass the cache if the
30+
user explicitly asks for a fresh scan with `scan system --fresh` or says
31+
something like "re-scan", "fresh scan", or "rescan".
32+
Rationale: hardware does not change mid-session without a reboot, and
33+
regenerating DxDiag on every `scan system` call adds 10–30 seconds of
34+
unnecessary latency. If the user suspects a display/HDR change without
35+
rebooting (rare), they can force a fresh scan explicitly.
3136

3237
```powershell
3338
$lastBoot = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
@@ -36,6 +41,9 @@ Choose the source in this order:
3641
((Get-Item $dxPath).LastWriteTime -gt $lastBoot)
3742
```
3843

44+
If the cache is valid, tell the user: *"Using cached hardware profile from
45+
this session. Run `scan system --fresh` to regenerate."*
46+
3947
3. **Generate on the fly** — run dxdiag now (Step 2).
4048

4149
---
@@ -50,7 +58,23 @@ Write-Host "Generating DxDiag report — this takes a few seconds..."
5058
$proc = Start-Process -FilePath "dxdiag.exe" `
5159
-ArgumentList "/whql:off", "/x", "`"$dxPath`"" `
5260
-PassThru -WindowStyle Hidden
53-
$proc.WaitForExit(30000) # 30-second timeout
61+
$proc.WaitForExit(30000) # wait for dxdiag.exe process to exit (up to 30 s)
62+
63+
# DxDiag writes the XML asynchronously after the process exits.
64+
# Poll until the file exists, is non-trivially sized (> 1 KB),
65+
# and its size has been stable for two consecutive checks.
66+
$maxWait = 15 # extra seconds to wait after process exit
67+
$waited = 0
68+
$prevSize = -1
69+
while ($waited -lt $maxWait) {
70+
Start-Sleep -Milliseconds 500
71+
$waited += 0.5
72+
if (Test-Path $dxPath) {
73+
$size = (Get-Item $dxPath).Length
74+
if ($size -gt 1024 -and $size -eq $prevSize) { break } # stable and non-trivial
75+
$prevSize = $size
76+
}
77+
}
5478
5579
if ((Test-Path $dxPath) -and ((Get-Item $dxPath).Length -gt 1024)) {
5680
Write-Host "DxDiag report written to: $dxPath"
@@ -60,7 +84,7 @@ if ((Test-Path $dxPath) -and ((Get-Item $dxPath).Length -gt 1024)) {
6084
```
6185

6286
If the file is present and non-trivially sized (> 1 KB), proceed to Step 3.
63-
If the file is absent or empty, skip to **Step 4 (PowerShell fallback)**.
87+
If the file is absent or empty after polling, skip to **Step 4 (PowerShell fallback)**.
6488

6589
---
6690

@@ -197,8 +221,9 @@ Every downstream recommendation must be appropriate for this tier.
197221
session cache. It is considered valid as long as its `LastWriteTime` is after
198222
the last system boot — driver updates, HAGS changes, and GPU changes all
199223
require a reboot, so a post-boot file is safe to reuse.
200-
The explicit `scan system` command always bypasses this cache to pick up
201-
display, HDR, or monitor changes that don’t require a reboot.
224+
Use the cache for both `scan system` and `optimise <game>` — only bypass it
225+
when the user explicitly requests a fresh scan (`scan system --fresh`,
226+
"re-scan", "rescan", or "fresh scan").
202227
Windows does not reliably clean TEMP automatically; the file will persist
203228
across sessions but will be ignored after a reboot because its write time
204229
will pre-date the new `LastBootUpTime`.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased]
1111

12+
### Fixed
13+
14+
- `system-scan` skill — DxDiag post-exit polling: added a stability loop after `WaitForExit` that waits until the XML file size is stable for two consecutive 500 ms checks before proceeding, preventing partial-read failures on slower systems
15+
- `system-scan` skill — cache policy: `scan system` now reuses a valid post-boot cache instead of always regenerating; use `scan system --fresh` (or say "rescan", "re-scan", "fresh scan") to force a new DxDiag run
16+
- `reframe.agent.md` — greeting updated to document `scan system --fresh`
17+
1218
### Added
1319

1420
- `knowledge/games/skyrim-special-edition.json` — Skyrim Special Edition profile: Steam, GOG, and Xbox Game Pass config paths; 11 INI keys across Display, Imagespace, and Grass sections; engine override note (in-game menu overwrites INI); manual-only settings (resolution, AA / Skyrim Upscaler); notes covering SKSE64, ENB, Community Shaders, BethINI, and Anniversary Edition

0 commit comments

Comments
 (0)