Pipeline book: keep a batch that failed to write; flush at the end and on a GPU failure (#41) #88

Closed
github-bot wants to merge 1 commit from gh-pr/88/head into gh-pr/88/base
Owner

@⁠sharan104 on GitHub · 2026-11-26 02:51 UTC · original
sharan104:fix/41-known-flush → main · +74 −13 · 3 files · 1 commits · closed without merging

Fixes #41.

known::flush() took the batch out of the book before writing and returned on the first error, so a failed write (a scanner or backup agent holding the file, a full disk) silently dropped pipelines the book already counted as known. Only the two-second timer flushed, so the last batch before the process ended was lost too.

What changes:

  • Write first, then clear. On a failure, what was not written goes back in front of what was noted since, and the next flush tries again. The shaders' file is written first, so a failure on the pipelines' file keeps only the pipelines. The ids stay in keys, which is right now: they are still on their way to the file.
  • No torn entry in the middle of a file. A write that fails part of the way is cut back to where the file ended (set_len), so a later append never follows a torn entry. (The file is opened write, not append, because on Windows an append-only handle cannot set_len.)
  • Flush on the way out. save_pipeline_cache() (the title's end, lifecycle::end) and host::fail() (before the report ends the process with TerminateProcess, which is how most runs in the tracker end) now flush the book too.
  • One flush at a time. A WRITING mutex keeps the timer and those two from adding to the same file at once.

Tests: cargo test -p victory-gpu --locked pipeline::known (3 passed, including the new what_is_not_written_is_kept: a failing pipelines file, the batch kept behind later notes, the next write appending both). cargo build --locked --profile diag -p victory --features diagnostics builds. Clippy has no new warnings in the touched files (the two drop(...insert(..)) warnings in known.rs were already there).

Not tested: a real run with the title. There are no game files on this machine, so the failure path is covered by the unit test only.

🤖 Generated with Claude Code

**@⁠sharan104** on GitHub · 2026-11-26 02:51 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/88) `sharan104:fix/41-known-flush` → `main` · +74 −13 · 3 files · 1 commits · closed without merging Fixes #41. `known::flush()` took the batch out of the book before writing and returned on the first error, so a failed write (a scanner or backup agent holding the file, a full disk) silently dropped pipelines the book already counted as known. Only the two-second timer flushed, so the last batch before the process ended was lost too. What changes: - **Write first, then clear.** On a failure, what was not written goes back in front of what was noted since, and the next flush tries again. The shaders' file is written first, so a failure on the pipelines' file keeps only the pipelines. The ids stay in `keys`, which is right now: they are still on their way to the file. - **No torn entry in the middle of a file.** A write that fails part of the way is cut back to where the file ended (`set_len`), so a later append never follows a torn entry. (The file is opened `write`, not `append`, because on Windows an append-only handle cannot `set_len`.) - **Flush on the way out.** `save_pipeline_cache()` (the title's end, `lifecycle::end`) and `host::fail()` (before the report ends the process with `TerminateProcess`, which is how most runs in the tracker end) now flush the book too. - **One flush at a time.** A `WRITING` mutex keeps the timer and those two from adding to the same file at once. Tests: `cargo test -p victory-gpu --locked pipeline::known` (3 passed, including the new `what_is_not_written_is_kept`: a failing pipelines file, the batch kept behind later notes, the next write appending both). `cargo build --locked --profile diag -p victory --features diagnostics` builds. Clippy has no new warnings in the touched files (the two `drop(...insert(..))` warnings in `known.rs` were already there). Not tested: a real run with the title. There are no game files on this machine, so the failure path is covered by the unit test only. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
flush() took the batch out of the book before writing it and returned on
the first error, so a write that failed (a scanner or backup agent holding
the file, a full disk) dropped pipelines the book already counted as known:
they were never noted again in that run and never reached the file. And
only the two-second timer flushed, so what was noted in the last two
seconds before the process ended was lost too.

- What is not written goes back in front of what was noted since, and is
  tried again at the next flush. The shaders' file is written first, so a
  failure on the pipelines' file keeps only the pipelines.
- A write that fails part of the way is cut back to where the file ended,
  so a later append never follows a torn entry (the reader stops at one).
- The book is flushed at the end of a run (save_pipeline_cache, from the
  title's end) and in host::fail before the report ends the process,
  which is how most runs end. One flush at a time, so the timer and these
  never add to a file at once.

Fixes #41

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:57 +00:00
github-bot closed this pull request 2026-11-26 03:31:57 +00:00
Author
Owner

@⁠sharan104 on GitHub · 2026-11-26 02:55 UTC · original

Closing as a duplicate of #63 by @⁠Yoshi-233, which fixes #41 the same way and was opened first. It also keeps partially written bytes and flushes when the title's main thread returns.

One idea from this PR that #63 says it leaves out: the "forced termination on device removal" case. Here, host::fail() called crate::pipeline::known::flush() after its tracing::error! and before ON_FAILURE's report ends the process with TerminateProcess. With #63's WRITER mutex this is safe to add (the book lock is never held while fail runs). Since device removal is how most runs in the tracker end, the last batch is usually the one lost. Feel free to take it into #63 if it's useful.

**@⁠sharan104** on GitHub · 2026-11-26 02:55 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/88#issuecomment-7181240521) Closing as a duplicate of #63 by @⁠Yoshi-233, which fixes #41 the same way and was opened first. It also keeps partially written bytes and flushes when the title's main thread returns. One idea from this PR that #63 says it leaves out: the "forced termination on device removal" case. Here, `host::fail()` called `crate::pipeline::known::flush()` after its `tracing::error!` and before `ON_FAILURE`'s report ends the process with `TerminateProcess`. With #63's `WRITER` mutex this is safe to add (the book lock is never held while `fail` runs). Since device removal is how most runs in the tracker end, the last batch is usually the one lost. Feel free to take it into #63 if it's useful.
Author
Owner

@⁠Yoshi-233 on GitHub · 2026-11-26 03:19 UTC · original

Thanks, @⁠sharan104, for pointing out the device-removal path. I picked up your suggestion in #63 at 33439c8. I put the request in the failure callback after the crash log is written and before TerminateProcess. The existing background writer gets up to 250 ms to finish, so a slow disk or a busy writer cannot hold up termination indefinitely.

On Linux, an independent reader recovered the final two synthetic pipelines and their shaders after immediate process exit in 20/20 runs. I also held the book lock on the failing thread and separately stalled an in-flight append. The new hook returned in about 250 ms in both cases. The Windows target compiles; actual device removal still needs a Windows run. I credited the suggestion in the PR.

**@⁠Yoshi-233** on GitHub · 2026-11-26 03:19 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/88#issuecomment-7181605761) Thanks, @⁠sharan104, for pointing out the device-removal path. I picked up your suggestion in #63 at `33439c8`. I put the request in the failure callback after the crash log is written and before `TerminateProcess`. The existing background writer gets up to 250 ms to finish, so a slow disk or a busy writer cannot hold up termination indefinitely. On Linux, an independent reader recovered the final two synthetic pipelines and their shaders after immediate process exit in 20/20 runs. I also held the book lock on the failing thread and separately stalled an in-flight append. The new hook returned in about 250 ms in both cases. The Windows target compiles; actual device removal still needs a Windows run. I credited the suggestion in the PR.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.