[pr-fix][startup][shaders] Save partial preload work when a thread fails to start #234

Open
andrewpozdnakov7-jpg wants to merge 3 commits from andrewpozdnakov7-jpg/Darner:port/4410-save-partial-warm-outputs into main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

The two preload library paths return a thread startup error before their final save. Save the work already completed by the joined workers first. In into_library, keep the startup error when both startup and the final save fail, and keep reporting a save-only failure.

Restores locally saved VIctory-NVIDIA work from December 1, 2026. Previous review: CodeFloe #388. Adapted by andrewpozdnakov7-jpg (GitHub profile).

For shared warm runs, append completion marks only after the library save succeeds. If a checkpoint fails, keep that batch queued for the next save. The last checkpoint reports a save failure and still gives a worker startup failure priority when both fail.

How it was tested

  • Tested revision: 6b843c0 on f3840d7.
  • Commands and results: A Rust fixture used the current scope finalization from both paths. With an injected startup failure, main skipped the save and the patch saved the completed entry in both paths. A save failure did not replace a startup error. cargo check --locked -p darner --bin darner, xtask policy, and git diff --check passed.
  • Changes a default: no.
  • Additional checks at 5f1db98: a Windows fixture injected a rejected library save and then allowed a retry. Main wrote both completion marks after the rejection. The updated path wrote zero, retained both entries, and wrote all three marks after retrying with one additional pipeline. The focused Cargo type check, asset policy, and whitespace check passed.
  • Review follow-up at 88f546b: the worker count balances on a rejected spawn and both preload paths report secondary save errors. A Windows fixture checked the dropped closure and the selected error. The focused Cargo type check covers the new error-precedence unit test. Asset policy passed. The independent Windows checks at 6b843c0 are in issuecomment-864560.
  • Independent Windows verification on 88f546b: both workspace Clippy gates and asset policy passed. Cargo reported 149 app tests passed and one ignored, plus the cache_paths, census and picked_folders integration cases. Review result
  • Gates run on that revision: none of the three workspace-wide gates.
  • Coverage gaps: The fixture injected the outcomes; it did not exhaust OS thread resources or run gameplay.

Checklist

  • I ran this change in the game.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #147 implements optional periodic saves. #165 and #215 also touch warm.rs but do not change cleanup after thread startup failure. #215 and this PR have an existing merge conflict in warm.rs. The updated branch merges cleanly with #165 and #266.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: <!-- optional --> ## What it changes The two preload library paths return a thread startup error before their final save. Save the work already completed by the joined workers first. In into_library, keep the startup error when both startup and the final save fail, and keep reporting a save-only failure. Restores locally saved VIctory-NVIDIA work from December 1, 2026. Previous review: [CodeFloe #388](https://codefloe.com/TrustNo1/Darner/pulls/388). Adapted by [andrewpozdnakov7-jpg](https://git.gtahub.st/andrewpozdnakov7-jpg) ([GitHub profile](https://github.com/andrewpozdnakov7-jpg)). For shared warm runs, append completion marks only after the library save succeeds. If a checkpoint fails, keep that batch queued for the next save. The last checkpoint reports a save failure and still gives a worker startup failure priority when both fail. ## How it was tested - Tested revision: 6b843c0 on f3840d7. - Commands and results: A Rust fixture used the current scope finalization from both paths. With an injected startup failure, main skipped the save and the patch saved the completed entry in both paths. A save failure did not replace a startup error. cargo check --locked -p darner --bin darner, xtask policy, and git diff --check passed. - Changes a default: no. - Additional checks at 5f1db98: a Windows fixture injected a rejected library save and then allowed a retry. Main wrote both completion marks after the rejection. The updated path wrote zero, retained both entries, and wrote all three marks after retrying with one additional pipeline. The focused Cargo type check, asset policy, and whitespace check passed. - Review follow-up at 88f546b: the worker count balances on a rejected spawn and both preload paths report secondary save errors. A Windows fixture checked the dropped closure and the selected error. The focused Cargo type check covers the new error-precedence unit test. Asset policy passed. The independent Windows checks at 6b843c0 are in issuecomment-864560. - Independent Windows verification on 88f546b: both workspace Clippy gates and asset policy passed. Cargo reported 149 app tests passed and one ignored, plus the cache_paths, census and picked_folders integration cases. [Review result](https://git.gtahub.st/TrustNo1/Darner/pulls/234#issuecomment-867578) - Gates run on that revision: none of the three workspace-wide gates. - Coverage gaps: The fixture injected the outcomes; it did not exhaust OS thread resources or run gameplay. ## Checklist - [ ] I ran this change in the game. - [x] This PR contains one change based on main. - [x] The diff follows docs/asset-policy.md. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #147 implements optional periodic saves. #165 and #215 also touch warm.rs but do not change cleanup after thread startup failure. #215 and this PR have an existing merge conflict in warm.rs. The updated branch merges cleanly with #165 and #266. - Replaces or overlaps: none found
Adapt the locally saved VIctory-NVIDIA follow-up from December 1, 2026 (c0205161). Wait for already started workers and try the final save before returning the worker or saver startup error.

https://git.gtahub.st/andrewpozdnakov7-jpg
https://github.com/andrewpozdnakov7-jpg
First-time contributor

Independent Windows build, gate, and code-read review of 6b843c021 (based on main f3840d73d). Not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS
  • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS
  • cargo xtask policy: PASS (asset policy: 555 files ok)
  • cargo test --locked -p darner: PASS (148 passed; 0 failed; 1 ignored unit tests; 2 + 2 + 8 integration tests all passed).

Code-read audit

  • Confirmed the bug on main (apps/darner/src/warm.rs:444-470 and :574-600): std::thread::scope(...)?; joins already-spawned workers before returning a later spawn error, and ? exited without running flush() / known::keep_preloaded_library(), losing completed pipelines. Running them after the scope joins (safe even when 0 pipelines were added: library.rs:1512 returns Ok(0)) solves the root cause cleanly.
  • Two minor notes:
    1. Pre-existing alive leak on worker spawn failure (warm.rs:578-580): alive.fetch_add(1, Ordering::AcqRel) runs before spawn_library_worker, while WorkerGone(alive) is created inside the closure. It does not hang darner-pipelines-save today only because the saver is spawned after the worker loop (so ? skips spawning it), but constructing let gone = WorkerGone(alive); before spawn_library_worker and moving gone into the closure avoids leaking alive if the spawn order ever changes.
    2. Dropped save error when both fail (warm.rs:601): workers.and(saved)? keeps the startup error as intended, but if keep_preloaded_library() also fails (for example check_preload_save at crates/darner-gpu/src/pipeline/library.rs:1332-1340, which returns Err without logging), that save failure is silently dropped. Logging e_save when workers.is_err() would preserve visibility.
    3. No in-tree unit test was added to apps/darner/src/warm.rs for either partial-save path.

Verdict: PASS (with minor notes above).

AI-assisted: yes (Gemini 4 Neon).

Independent Windows build, gate, and code-read review of `6b843c021` (based on `main` `f3840d73d`). Not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS** - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS** - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`) - `cargo test --locked -p darner`: **PASS** (`148 passed; 0 failed; 1 ignored` unit tests; `2 + 2 + 8` integration tests all passed). ### Code-read audit - Confirmed the bug on `main` (`apps/darner/src/warm.rs:444-470` and `:574-600`): `std::thread::scope(...)?;` joins already-spawned workers before returning a later spawn error, and `?` exited without running `flush()` / `known::keep_preloaded_library()`, losing completed pipelines. Running them after the scope joins (safe even when 0 pipelines were added: `library.rs:1512` returns `Ok(0)`) solves the root cause cleanly. - Two minor notes: 1. **Pre-existing `alive` leak on worker spawn failure (`warm.rs:578-580`):** `alive.fetch_add(1, Ordering::AcqRel)` runs before `spawn_library_worker`, while `WorkerGone(alive)` is created inside the closure. It does not hang `darner-pipelines-save` today only because the saver is spawned *after* the worker loop (so `?` skips spawning it), but constructing `let gone = WorkerGone(alive);` before `spawn_library_worker` and moving `gone` into the closure avoids leaking `alive` if the spawn order ever changes. 2. **Dropped save error when both fail (`warm.rs:601`):** `workers.and(saved)?` keeps the startup error as intended, but if `keep_preloaded_library()` also fails (for example `check_preload_save` at `crates/darner-gpu/src/pipeline/library.rs:1332-1340`, which returns `Err` without logging), that save failure is silently dropped. Logging `e_save` when `workers.is_err()` would preserve visibility. 3. No in-tree unit test was added to `apps/darner/src/warm.rs` for either partial-save path. **Verdict:** PASS (with minor notes above). AI-assisted: yes (Gemini 4 Neon).
Keep the shared warm batch queued after a failed checkpoint and append done marks only after the save succeeds. Finalize the batch even if worker startup fails. Prefer the startup error if both operations fail.

https://git.gtahub.st/andrewpozdnakov7-jpg
https://github.com/andrewpozdnakov7-jpg
The worker completion guard now belongs to the spawn closure so a rejected spawn balances the count. Both preload paths print the save error when worker startup also failed, while returning the original startup error.

Review: #234 (comment)
https://git.gtahub.st/andrewpozdnakov7-jpg
https://github.com/andrewpozdnakov7-jpg
Author
First-time contributor

Thanks for the independent Windows checks on 6b843c0, @lewis499. The branch now also covers both notes in 88f546b. The worker guard is captured before the spawn so rejecting the closure decrements the count. If startup and save both fail, Darner reports the save error and still returns the original startup error.

I verified the rejected-closure and error-priority cases with a Windows fixture, added an in-tree error-precedence test, and ran the focused Cargo type check and asset policy on the updated code.

Thanks for the independent Windows checks on `6b843c0`, @lewis499. The branch now also covers both notes in `88f546b`. The worker guard is captured before the spawn so rejecting the closure decrements the count. If startup and save both fail, Darner reports the save error and still returns the original startup error. I verified the rejected-closure and error-priority cases with a Windows fixture, added an in-tree error-precedence test, and ran the focused Cargo type check and asset policy on the updated code.
First-time contributor

PASS

Follow-up verification of 88f546b8206f9dd2a3ad275801775ab47aca6aed (base f3840d73d3504c30218debfbc8795b9225447317).

Environment

Windows 11 Pro 26H2 build 26300.10075; Intel Core i9-14900K; NVIDIA RTX A2000 12 GB (driver 621.47); Rust 1.98.1 x86_64-pc-windows-msvc; MSVC 19.44.35230.

Measured results

  • cargo clippy --workspace --all-targets --locked -- -D warnings: PASS.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: PASS.
  • cargo xtask policy: PASS (555 files ok).
  • cargo test --locked -p darner: 149 passed, 0 failed, 1 ignored; integration suites passed 2 cache_paths, 2 census, and 8 picked_folders tests.

Code-read audit

  • fill_library joins scoped workers before the final flush; on flush failure it restores the taken marks to pending (apps/darner/src/warm.rs:434-447, 450-480).
  • WorkerGone is created before spawning and moved into the closure, so a rejected spawn drops the guard and balances alive; the saver waits on that count (:535-542, 590-617).
  • finish_library_workers reports a save failure when a worker error already exists, preserves the worker error as the returned error in that case, and propagates a save-only failure. The focused regression test covers both error combinations (:527-532, 905-911).

Not run in-game.

AI-assisted: yes (GitHub Copilot, Auto mode).

**PASS** Follow-up verification of `88f546b8206f9dd2a3ad275801775ab47aca6aed` (base `f3840d73d3504c30218debfbc8795b9225447317`). ### Environment Windows 11 Pro 26H2 build 26300.10075; Intel Core i9-14900K; NVIDIA RTX A2000 12 GB (driver 621.47); Rust 1.98.1 x86_64-pc-windows-msvc; MSVC 19.44.35230. ### Measured results - `cargo clippy --workspace --all-targets --locked -- -D warnings`: PASS. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: PASS. - `cargo xtask policy`: PASS (`555 files ok`). - `cargo test --locked -p darner`: 149 passed, 0 failed, 1 ignored; integration suites passed 2 `cache_paths`, 2 `census`, and 8 `picked_folders` tests. ### Code-read audit - `fill_library` joins scoped workers before the final `flush`; on flush failure it restores the taken marks to `pending` (`apps/darner/src/warm.rs:434-447`, `450-480`). - `WorkerGone` is created before spawning and moved into the closure, so a rejected spawn drops the guard and balances `alive`; the saver waits on that count (`:535-542`, `590-617`). - `finish_library_workers` reports a save failure when a worker error already exists, preserves the worker error as the returned error in that case, and propagates a save-only failure. The focused regression test covers both error combinations (`:527-532`, `905-911`). Not run in-game. AI-assisted: yes (GitHub Copilot, Auto mode).
This pull request has changes conflicting with the target branch.
  • apps/darner/src/warm.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'port/4410-save-partial-warm-outputs:andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git switch 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git switch 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git rebase 'main'
git switch 'main'
git merge --ff-only 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git switch 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git rebase 'main'
git switch 'main'
git merge --no-ff 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git switch 'main'
git merge --squash 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git switch 'main'
git merge --ff-only 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git switch 'main'
git merge 'andrewpozdnakov7-jpg-port/4410-save-partial-warm-outputs'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!234
No description provided.