Preserve pending pipeline records on write failure #2249

Manually merged
github merged 2 commits from github-bot/gh-2249 into main 2026-11-30 14:16:33 +00:00 AGit
Owner

@⁠LucaruluDev on GitHub · 2026-11-29 11:02 UTC · original
LucaruluDev:fix/pipeline-book-flush-durability → main · +488 −55 · 1 files · 2 commits · merged 2026-11-30 14:12 UTC

What it changes

The pipeline book can lose pending records when
opening or writing its cache files fails.

This change:

  • Keeps unwritten records queued for retry.
  • Writes shader batches before their pipeline records.
  • Avoids duplicating successfully written shader data
    when a subsequent pipeline write fails.
  • Rolls back partial writes to the original file length.
  • Stops appending to a file if rollback fails.
  • Limits pending encoded payload to 64 MiB, including
    records currently being written.
  • Preserves batched I/O and releases completed buffers.

On Windows, an append-only file handle can fail
truncation with ERROR_ACCESS_DENIED (5).
The revised implementation opens the file with
write access and seeks to its end.

How it was tested

Hardware: Ryzen 7 9700X, RTX 5070 12 GB,
32 GiB DDR5, Windows 11.

  • 14 focused tests passed.
  • Pipeline suite: 79 passed, 2 ignored.
  • Real Windows temporary file rollback verified.
  • Synthetic partial-write and rollback-failure tests.
  • Concurrent pipeline recording during an active flush.
  • Pending byte-budget and deduplication tests.
  • Clippy completed with unrelated repository warnings.

Synthetic buffered file I/O benchmark,
median of seven runs per mode:

Records Upstream Patched
1,000 0.318 ms 0.741 ms
5,000 0.865 ms 1.540 ms

Batched writes are preserved, with a small additional
cost for recoverable write handling.

No shader changes.

Limitations

This change assumes a single pipeline book writer.

It handles reported I/O failures but does not
guarantee persistence across power loss or abrupt
process termination.

The 64 MiB limit applies to pending encoded payload,
not total process memory.

Gameplay performance has not been measured.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.

AI-assisted implementation and validation using
Claude Code and OpenAI Codex.

**@⁠LucaruluDev** on GitHub · 2026-11-29 11:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2249) `LucaruluDev:fix/pipeline-book-flush-durability` → `main` · +488 −55 · 1 files · 2 commits · merged 2026-11-30 14:12 UTC ## What it changes The pipeline book can lose pending records when opening or writing its cache files fails. This change: - Keeps unwritten records queued for retry. - Writes shader batches before their pipeline records. - Avoids duplicating successfully written shader data when a subsequent pipeline write fails. - Rolls back partial writes to the original file length. - Stops appending to a file if rollback fails. - Limits pending encoded payload to 64 MiB, including records currently being written. - Preserves batched I/O and releases completed buffers. On Windows, an append-only file handle can fail truncation with ERROR_ACCESS_DENIED (5). The revised implementation opens the file with write access and seeks to its end. ## How it was tested Hardware: Ryzen 7 9700X, RTX 5070 12 GB, 32 GiB DDR5, Windows 11. - 14 focused tests passed. - Pipeline suite: 79 passed, 2 ignored. - Real Windows temporary file rollback verified. - Synthetic partial-write and rollback-failure tests. - Concurrent pipeline recording during an active flush. - Pending byte-budget and deduplication tests. - Clippy completed with unrelated repository warnings. Synthetic buffered file I/O benchmark, median of seven runs per mode: | Records | Upstream | Patched | |---|---:|---:| | 1,000 | 0.318 ms | 0.741 ms | | 5,000 | 0.865 ms | 1.540 ms | Batched writes are preserved, with a small additional cost for recoverable write handling. No shader changes. ## Limitations This change assumes a single pipeline book writer. It handles reported I/O failures but does not guarantee persistence across power loss or abrupt process termination. The 64 MiB limit applies to pending encoded payload, not total process memory. Gameplay performance has not been measured. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. AI-assisted implementation and validation using Claude Code and OpenAI Codex.
Book::flush took its pending shader/pipeline bytes out of the book before
writing them, so any failure writing either known-shaders.bin or
known-pipelines.bin (a full disk, a permissions error, a crash mid-write)
discarded that batch for good: the title would silently forget pipelines
it had already paid to create. write_all can also leave a file partially
written before returning an error, which previously had no handling at
all.

Book now keeps each pipeline's shader bytes and pipeline entry together as
a Pending entry in a queue, oldest first, and only removes an entry once
both of its files are durably appended (append_durably rolls a partial
write back to its pre-call length, so a retry never duplicates a torn
record). A file that cannot even be rolled back is marked jammed and
skipped until the next run's startup scan truncates its torn tail. A
pending_bytes budget (MAX_PENDING_BYTES, 64 MiB) bounds memory under a
sustained failure without marking a dropped record as already seen, so it
gets a real retry once there is room.

Adapted on top of upstream's async book-loading rework (853af252,
aa4ab86d, 72658a44, a347c633): Book now also tracks loaded/waiting, and
flush is driven by the background thread's 2-second loop instead of being
called synchronously from note().

Does not add fsync/FlushFileBuffers: this is crash-safety for an in-process
write failure, not durability across a power loss, matching the file
format's existing torn-tail self-healing on the next startup.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Check each record's encoded size before adding its key or any new
shader hashes. Keep in-flight writes charged to the 64 MiB budget and
release shader buffers when their batch has been written.

Open each file for writing and seek to its end once per batch so
Windows can truncate a partial write. Buffer records with a fixed
64 KiB buffer and restore a failed batch ahead of newer entries.

Exercise rollback with a real temporary file and record a new
pipeline while a flush is between writes.

Co-authored-by: Claude Sonnet 5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 11:06:36 +00:00
github manually merged commit e02bdfa9c4 into main 2026-11-30 14:16:33 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/trustno1-coder--VIctory-NVIDIA!2249
No description provided.