known.rs flush() takes the batch before writing and never restores it: one failed write permanently drops pipelines the book already counts as known #41

Closed
opened 2026-11-26 03:31:29 +00:00 by github-bot · 0 comments
Owner

@⁠itsonewi on GitHub · 2026-11-25 23:59 UTC · original

The pipeline book takes its batch out of memory before writing it and never puts it back, and nothing flushes it at exit — so a failed write, or a device loss, silently drops pipelines the book has already recorded as known.

Where

crates/victory-gpu/src/pipeline/known.rs:126-146:

fn flush() {
    let Some(Some(book)) = BOOK.get() else { return };
    let (dir, new, added) = {
        let mut book = book.lock().unwrap_or_else(|e| e.into_inner());
        if book.added == 0 { return; }
        (book.dir.clone(), std::mem::take(&mut book.new), std::mem::take(&mut book.added))
    };                                    // 133: gone from memory
    for (file, bytes) in [SHADERS, PIPELINES].iter().zip(&new) {
        let written = std::fs::OpenOptions::new().create(true).append(true)
            .open(dir.join(file)).and_then(|mut f| f.write_all(bytes));
        if let Err(e) = written {
            tracing::warn!(error = %e, file, "title pipelines not written down");
            return;                        // 143: the batch is lost
        }
    }

note() has already put those pipelines into the in-memory dedupe sets before the write is tried (:98: if shaders.is_empty() || !book.keys.insert(id) { return; }), so after a failure the same pipeline is never noted again in this run: the entry is not in the file and will never be offered to it.

Why it happens in practice

  • The file is in the cache folder under a real Windows profile: an antivirus scan, a OneDrive/Defender/backup agent, or a full disk returns ERROR_SHARING_VIOLATION (0x20) or ERROR_DISK_FULL from OpenOptions::open or write_all. The run continues; the log has one warn line among thousands.
  • flush() is only ever called by the two-second timer started in book() (:78-83). BOOK is a OnceLock<Option<Mutex<Book>>> and its contents are never dropped, so the last batch is written only if the process lives another two seconds — and d3d12x::host_gpu_failed ends the process with TerminateProcess, which runs no destructors and no atexit. Device removal is the ending most runs in this tracker report, and the busiest pipeline-creation window is right before it.

Either way the loss is silent and permanent: known-pipelines.bin is smaller than the run's actual work, so the next run starts fewer pipelines early (the module's own premise is "which ones is known from earlier runs") and victory warm --used, which lists the file's keys (known::keys, :292), offers fewer of them — which also looks like the "0 to make" symptom of #26 rather than like data loss.

Fix

Write first, then clear: on a write error, put new and added back (book.new[i].splice(0..0, …) per file / re-add the count) or keep a pending list that is only cleared after a successful write; and drop the ids from book.keys/book.shaders for the pipelines that were not written, so they are noted again on the next creation. Also flush once on the way out of a normal run (the timer is not an exit path), and accept that a TerminateProcess loss of the last batch is unavoidable — but then the ids must not be remembered, which is the same fix.

Not checked

Source reading at 0a43566. I did not reproduce a failed flush() (no build, no Windows run), so the sequence above is read from the code; the TerminateProcess claim comes from crates/victory-hle/src/modules/d3d12x.rs:104-115.

AI use

AI-assisted review (source reading). No build, no run, no game files.

**@⁠itsonewi** on GitHub · 2026-11-25 23:59 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/41) The pipeline book takes its batch out of memory before writing it and never puts it back, and nothing flushes it at exit — so a failed write, or a device loss, silently drops pipelines the book has already recorded as known. ## Where `crates/victory-gpu/src/pipeline/known.rs:126-146`: ```rust fn flush() { let Some(Some(book)) = BOOK.get() else { return }; let (dir, new, added) = { let mut book = book.lock().unwrap_or_else(|e| e.into_inner()); if book.added == 0 { return; } (book.dir.clone(), std::mem::take(&mut book.new), std::mem::take(&mut book.added)) }; // 133: gone from memory for (file, bytes) in [SHADERS, PIPELINES].iter().zip(&new) { let written = std::fs::OpenOptions::new().create(true).append(true) .open(dir.join(file)).and_then(|mut f| f.write_all(bytes)); if let Err(e) = written { tracing::warn!(error = %e, file, "title pipelines not written down"); return; // 143: the batch is lost } } ``` `note()` has already put those pipelines into the in-memory dedupe sets before the write is tried (`:98`: `if shaders.is_empty() || !book.keys.insert(id) { return; }`), so after a failure the same pipeline is never noted again in this run: the entry is not in the file and will never be offered to it. ## Why it happens in practice - The file is in the cache folder under a real Windows profile: an antivirus scan, a OneDrive/Defender/backup agent, or a full disk returns `ERROR_SHARING_VIOLATION` (`0x20`) or `ERROR_DISK_FULL` from `OpenOptions::open` or `write_all`. The run continues; the log has one `warn` line among thousands. - `flush()` is only ever called by the two-second timer started in `book()` (`:78-83`). `BOOK` is a `OnceLock<Option<Mutex<Book>>>` and its contents are never dropped, so the last batch is written only if the process lives another two seconds — and `d3d12x::host_gpu_failed` ends the process with `TerminateProcess`, which runs no destructors and no `atexit`. Device removal is the ending most runs in this tracker report, and the busiest pipeline-creation window is right before it. Either way the loss is silent and permanent: `known-pipelines.bin` is smaller than the run's actual work, so the next run starts fewer pipelines early (the module's own premise is "which ones is known from earlier runs") and `victory warm --used`, which lists the file's keys (`known::keys`, `:292`), offers fewer of them — which also looks like the "0 to make" symptom of #26 rather than like data loss. ## Fix Write first, then clear: on a write error, put `new` and `added` back (`book.new[i].splice(0..0, …)` per file / re-add the count) or keep a `pending` list that is only cleared after a successful write; and drop the ids from `book.keys`/`book.shaders` for the pipelines that were not written, so they are noted again on the next creation. Also flush once on the way out of a normal run (the timer is not an exit path), and accept that a `TerminateProcess` loss of the last batch is unavoidable — but then the ids must not be remembered, which is the same fix. ## Not checked Source reading at `0a43566`. I did not reproduce a failed `flush()` (no build, no Windows run), so the sequence above is read from the code; the `TerminateProcess` claim comes from `crates/victory-hle/src/modules/d3d12x.rs:104-115`. ## AI use AI-assisted review (source reading). No build, no run, no game files.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:30 +00:00
github-bot 2026-11-26 08:24:50 +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/avatarmanz--VIctory-7900XTX#41
No description provided.