Retain the last frame CSV rows when exiting normally #553

Open
SmallDevBigNothing wants to merge 0 commits from SmallDevBigNothing/Darner:codex/retain-final-frame-csv into Main
Contributor

What it changes

The frame CSV writer buffers rows separately from the play log. The Windows title exit and F1 quit or restart can end the process before it writes the last row, which can hide the final hitch in a capture. Ask the writer to flush and wait up to 500 ms before these exits. A completed later flush also satisfies earlier callers.

How it was tested

  • Tested 96e7962 against c8258f9. Five fresh Windows processes per revision wrote the same final row with the real CSV writer and immediately called TerminateProcess. Main retained 0/5 rows. The patched path retained 5/5, including present 42 and its 175.000 ms time.
  • cargo test --locked -p darner-gpu --lib bench::tests:: passed 8 tests. cargo test --locked -p darner-hle --lib closes_asked_of_the_window_end_the_title passed. Asset policy and git diff --check passed.
  • Tested without game files. No gameplay or full workspace gates. The CSV remains opt-in.

Checklist

  • Tested the Windows shutdown writer in separate processes.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • Depends on: none.

Checked for overlap

  • Searched issues and pull requests for the symptom and the changed files.
  • Related: #28 flushes the play log, #491 changes timed exit, and #154 changes the menu UI.
## What it changes The frame CSV writer buffers rows separately from the play log. The Windows title exit and F1 quit or restart can end the process before it writes the last row, which can hide the final hitch in a capture. Ask the writer to flush and wait up to 500 ms before these exits. A completed later flush also satisfies earlier callers. ## How it was tested - Tested `96e7962` against `c8258f9`. Five fresh Windows processes per revision wrote the same final row with the real CSV writer and immediately called `TerminateProcess`. Main retained 0/5 rows. The patched path retained 5/5, including present 42 and its 175.000 ms time. - `cargo test --locked -p darner-gpu --lib bench::tests::` passed 8 tests. `cargo test --locked -p darner-hle --lib closes_asked_of_the_window_end_the_title` passed. Asset policy and `git diff --check` passed. - Tested without game files. No gameplay or full workspace gates. The CSV remains opt-in. ## Checklist - [x] Tested the Windows shutdown writer in separate processes. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] Depends on: none. ## Checked for overlap - [x] Searched issues and pull requests for the symptom and the changed files. - Related: #28 flushes the play log, #491 changes timed exit, and #154 changes the menu UI.
First-time contributor

Tested merged onto c8258f95 (release), head 3313399c. RTX 3090 24 GB, driver 621.24, i5-10600K, 32 GB, Windows 11.

One unattended run with DARNER_BENCH_CSV and DARNER_EXIT_AFTER_WORLD_S=60: code 0, the CSV has 3,076 rows and its last elapsed_ms is 166,633 (main: 3,530 rows, last 166,690), no did not finish flushing line.

One thing I noticed while reading the diff: the timed exit (DARNER_EXIT_AFTER_WORLD_S) ends in exit_after_world() in host.rs, which calls std::process::exit after a 400 ms sleep, so it does not go through the flush this PR adds. #491 changes that path (it calls the log flush and TerminateProcess there). If the CSV should also be flushed on the timed exit, it may need a call there too. In my run the CSV looked complete, but one run does not show whether the tail can be lost.

AI-assisted testing (Claude Code, Claude Opus 5.5); results and text reviewed by me.

Tested merged onto `c8258f95` (release), head `3313399c`. RTX 3090 24 GB, driver 621.24, i5-10600K, 32 GB, Windows 11. One unattended run with `DARNER_BENCH_CSV` and `DARNER_EXIT_AFTER_WORLD_S=60`: code 0, the CSV has 3,076 rows and its last `elapsed_ms` is 166,633 (main: 3,530 rows, last 166,690), no `did not finish flushing` line. One thing I noticed while reading the diff: the timed exit (`DARNER_EXIT_AFTER_WORLD_S`) ends in `exit_after_world()` in `host.rs`, which calls `std::process::exit` after a 400 ms sleep, so it does not go through the flush this PR adds. #491 changes that path (it calls the log flush and `TerminateProcess` there). If the CSV should also be flushed on the timed exit, it may need a call there too. In my run the CSV looked complete, but one run does not show whether the tail can be lost. _AI-assisted testing (Claude Code, Claude Opus 5.5); results and text reviewed by me._
Author
Contributor

Thanks for the RTX 3090 run. You traced the timed path correctly. Its 400 ms pause is on the present thread, while the separate CSV writer flushes every 250 ms.

I checked that path's timing with the real CSV writer from 3313399: I enqueued a known final row, waited 400 ms and called std::process::exit(0), with no explicit flush. Eight fresh processes all retained the final row (present=42, frame_ms=175.000), across four enqueue times relative to writer startup. This tests the delay under ordinary I/O. It doesn't establish a guarantee if the writer is stalled.

I'll keep this PR focused on the title and F1 exits, where there is no timed pause. #491 preserves the pause. The flush helper here is available if timed exit needs an explicit acknowledgement as well.

Thanks for the RTX 3090 run. You traced the timed path correctly. Its 400 ms pause is on the present thread, while the separate CSV writer flushes every 250 ms. I checked that path's timing with the real CSV writer from `3313399`: I enqueued a known final row, waited 400 ms and called `std::process::exit(0)`, with no explicit flush. Eight fresh processes all retained the final row (`present=42`, `frame_ms=175.000`), across four enqueue times relative to writer startup. This tests the delay under ordinary I/O. It doesn't establish a guarantee if the writer is stalled. I'll keep this PR focused on the title and F1 exits, where there is no timed pause. #491 preserves the pause. The flush helper here is available if timed exit needs an explicit acknowledgement as well.
TrustNo1 changed title from [pr-fix] Retain the last frame CSV rows when exiting normally to Retain the last frame CSV rows when exiting normally 2026-12-06 03:27:14 +00:00
Owner

Test needed — commit 3313399c; what to check: The frame CSV writer buffers rows separately from the play log. The Windows title exit and F1 quit or restart can end the process before it writes the last row, which can hide the final hitch in a capture. Ask the writer to flush and wait up to 500 ms before these exits. A completed later flush also satisfies earlier callers.

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `3313399c`; what to check: The frame CSV writer buffers rows separately from the play log. The Windows title exit and F1 quit or restart can end the process before it writes the last row, which can hide the final hitch in a capture. Ask the writer to flush and wait up to 500 ms before these exits. A completed later flush also satisfies earlier callers. Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This branch is already included in the target branch. There is nothing to merge.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'codex/retain-final-frame-csv:SmallDevBigNothing-codex/retain-final-frame-csv'
git switch 'SmallDevBigNothing-codex/retain-final-frame-csv'

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 'SmallDevBigNothing-codex/retain-final-frame-csv'
git switch 'SmallDevBigNothing-codex/retain-final-frame-csv'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'SmallDevBigNothing-codex/retain-final-frame-csv'
git switch 'SmallDevBigNothing-codex/retain-final-frame-csv'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'SmallDevBigNothing-codex/retain-final-frame-csv'
git switch 'Main'
git merge --squash 'SmallDevBigNothing-codex/retain-final-frame-csv'
git switch 'Main'
git merge --ff-only 'SmallDevBigNothing-codex/retain-final-frame-csv'
git switch 'Main'
git merge 'SmallDevBigNothing-codex/retain-final-frame-csv'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 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!553
No description provided.