fix(menu): the menu's settings and mods.json are on the disk before they replace the old #3022

Closed
PedroRossi wants to merge 2 commits from PedroRossi/Longshot:fix/settings-through-atomic-write into main
Contributor

Summary

host/hos_atomic_file.h is the one helper every write of a setting is meant to go through: written beside, flushed to
the disk, moved over the old file, retried while another program holds it. The menu's save of settings.ini
(vk_menu.cpp save()) and the write of mods.json (game/mods.c write_file) had their own, which never flush:
after a power cut or a crash at the wrong moment the new file can be empty or torn with the old one already replaced,
and the settings or the mod order reset.

write_file is now hos_atomic_write. The menu's save flushes its file (fsync; _commit on Windows) before the
move, and moves it with the helper's hos_af_move (retried for a second while another program holds the file, the
folder flushed). Its in-place fallback when the move still fails is kept as it was.

Read first: save() in gpu/vk/vk_menu.cpp, write_file in game/mods.c.

Testing

Tested: in game, Debian 13, GeForce GTX 1660 SUPER, NVIDIA 550.163.01, headless: V-Sync changed over the control bridge; the menu's save wrote the profile's
settings.ini whole with the change, nothing left beside it, exit 0. mods.json is written only from the Mods tab, which
the bridge can't drive: tests/test_mods_list.py builds the real mods.c and calls hos_mod_edit, through write_file
and so hos_atomic_write: passes.

Checks: the new source checks in test_settings_atomic.py fail on main and pass here. The fixtures that compile these
files build with the helper and pass (test_menu_env_overrides.py, test_mods_size_table.py, test_mods_sizes.py). Four
that cut save() for other checks already fail on main, for names of their own (i18n,
pause_background_now, publish_fps_cap): they get a stand-in that moves as save() did, so they fail only as on
main; with their one missing name stubbed locally, test_menu_save_atomic.py's 10 cases (full disk, a linked file,
read-only folder and file, the file's mode...) pass here as on main. Again on main @ 1938a302, the game built through the
PC's job queue: V-Sync changed over the control bridge, the game quit and the same profile started again: V-Sync
kept (settings.ini held vsync=2, nothing beside it), exits 0. For Windows with llvm-mingw, the renderer alone
compiled and longshot_vk.dll linked, and the host's C compiled (0 failed); mise run test (--strict) on main @ 1938a302, and on main with this change merged (together with #3017, #3018, #3019, #3020, #3021, from the same audit): 775 passed, 145 failed, 10 skipped both ways, so none fails only with it. The 145 are named at the end.

Still to test:

  • @Beanstalk Windows and the Steam Deck: change a few settings in the Insert menu during play, expecting
    frame time around each change as on main (each settings save now flushes the file to the disk before it
    replaces the old one)
  • Windows, by hand: change a setting in the menu and start again, expecting it kept (two starts: not
    something the Test Farm plays)
  • In the game, by hand: switch a mod off in the Mods tab and start again, expecting mods.json to keep it
    (the Mods tab can't be driven over the control bridge)

Measurements

Nothing to measure in play: a settings save, made only when a setting changes, adds one fsync of the ~4 KB file, 1.25 ms on this PC's NVMe (the median of 40, the slowest 2.0 ms); the Test Farm run asked for in Still to test watches frame time around a change.

Risks

A settings save now waits for the disk: milliseconds on an SSD, more on an SD card. A revert undoes it.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
The 145 checks of mise run test that fail on main @ 1938a302 on this PC too, with or without this change

97 need a tool this PC doesn't have on PATH (--strict fails them):

  • clang (63): test_audio_output_devices.py, test_box_light_reuse.py, test_camera_centering.py, test_camera_speed.py, test_drive_target.py, test_dynres_sites.py, test_exclusive_marks.py, test_fixed_scale_sites.py, test_floor_carry_step.py, test_frame_rate_cap_step.py, test_frame_whole.py, test_free_view_anchor.py, test_fullscreen_monitor_platform.py, test_high_fps_fixes.py, test_horse_jump_step.py, test_hos_ab.py, test_hud_layout.py, test_jump_takeoff_step.py, test_linux_audio_output.py, test_loop_step.py, test_menu_hooks.py, test_microphone_test_gain.py, test_monitor_friendly_names.py, test_mouse_native.py, test_movement_speed.py, test_movie_frame_count.py, test_nvn_null_pool.py, test_nvn_tex_builder_guard.py, test_ocarina_wait.py, test_ocb_hold.py, test_oot_barrier.py, test_oot_camera_clearance.py, test_oot_cloth.py, test_oot_cloth_60.py, test_oot_cloth_time.py, test_oot_damage.py, test_oot_fov.py, test_oot_heap_retry.py, test_oot_jitter.py, test_oot_shadow.py, test_oot_shadow_fit.py, test_oot_transition_autosave.py, test_oot_voice_option.py, test_oot_wide_bubble.py, test_oot_wide_save_picture.py, test_player_update_sites.py, test_sampler_stack_walk.py, test_saved_turn_rate.py, test_scarecrow_timing.py, test_scene_format.py, test_sdl_monitor_names.py, test_shadow_slot.py, test_song_note_cue.py, test_sound_held_frames.py, test_sprint.py, test_svc_core_mask.py, test_tex_compact.py, test_text_speed.py, test_title_card_sites.py, test_water_substeps.py, test_web_floor_steps.py, test_wide_sites.py, test_wide_ui.py
  • spirv-val (20): f2i_immediate, global_load_16, native_suatom, test_coop_spirv.py, test_default_point_size.py, test_depth_sample_types.py, test_draw_parameters.py, test_fsr4_tune.py, test_guest_page_fast32.py, test_image_arrays.py, test_mesh_fallback_layout.py, test_mesh_unreachable_outputs.py, test_mma_software.py, test_native_float_atomic_add.py, test_nonuniform_image_arrays.py, test_spirv_struct_identity.py, test_texture_phi_dominance.py, test_unsigned_image_types.py, test_vendor_translation.py, test_wmma16_spirv_val.py
  • clang++ (7): test_dead_targets_sweep.py, test_lower_depbar.py, test_lower_lds_after_sts.py, test_lower_register_markers.py, test_native_suatom.py, test_program_answer_domains.py, test_target_pool_cap.py
  • glslang (5): test_framegen_hdr.py, test_fsr3fi_hud_layer.py, test_fsr3fi_hudless_colour.py, test_host_shaders.py, test_temporal_present_bandwidth.py
  • glslang, spirv-val (1): test_fsr3_shaders.py
  • llvm-mc (1): test_lifter.py

48 fail on main itself: test_blocks_at_start.py, test_bug_report.py, test_cloth_kernels.py, test_cloth_loops.py, test_cloth_sphere.py, test_cloth_step12.py, test_cloth_step8.py, test_cloth_step9.py, test_control_picture.py, test_crash_record.py, test_crt_options.py, test_dev_update.py, test_dlssg_pace.py, test_draw_stream_visibility.py, test_framegen_resources.py, test_fsr_uniform_ownership.py, test_game_boundary.py, test_guest_holes.py, test_image_reaper_threads.py, test_image_view_retry.py, test_input_background.py, test_keyboard_option.py, test_linux_pressure.py, test_loaded_modules_drop.py, test_log_levels.py, test_menu_keys.py, test_menu_save_atomic.py, test_mesh_first_types.py, test_oot_occ_raster.py, test_option_ids.py, test_perf_send.py, test_pipeline_tour.py, test_present_acquire_ahead.py, test_present_image_free.py, test_present_source_crop.py, test_program_cache_cleanup.py, test_program_cache_one_variant.py, test_readback_timeout_reuse.py, test_recording_admission.py, test_screensaver.py, test_switch_table.py, test_target_retention.py, test_tex_desc_memo.py, test_thinlto_tls.py, test_upscaler_round_trip.py, test_vram_compact.py, test_windows_display_startup.py, test_windows_on_linux.py


Found in an AI-assisted audit of the repository. The test, the fix, the runs and this description were made with Claude Code; I reviewed them.

Co-Authored-By: Claude Opus 5.5 [email protected]

🤖 Generated with Claude Code

## Summary `host/hos_atomic_file.h` is the one helper every write of a setting is meant to go through: written beside, flushed to the disk, moved over the old file, retried while another program holds it. The menu's save of `settings.ini` (`vk_menu.cpp` `save()`) and the write of `mods.json` (`game/mods.c` `write_file`) had their own, which never flush: after a power cut or a crash at the wrong moment the new file can be empty or torn with the old one already replaced, and the settings or the mod order reset. `write_file` is now `hos_atomic_write`. The menu's save flushes its file (`fsync`; `_commit` on Windows) before the move, and moves it with the helper's `hos_af_move` (retried for a second while another program holds the file, the folder flushed). Its in-place fallback when the move still fails is kept as it was. Read first: `save()` in `gpu/vk/vk_menu.cpp`, `write_file` in `game/mods.c`. ## Testing **Tested:** in game, Debian 13, GeForce GTX 1660 SUPER, NVIDIA 550.163.01, headless: V-Sync changed over the control bridge; the menu's save wrote the profile's settings.ini whole with the change, nothing left beside it, exit 0. mods.json is written only from the Mods tab, which the bridge can't drive: tests/test_mods_list.py builds the real mods.c and calls `hos_mod_edit`, through `write_file` and so `hos_atomic_write`: passes. Checks: the new source checks in test_settings_atomic.py fail on main and pass here. The fixtures that compile these files build with the helper and pass (test_menu_env_overrides.py, test_mods_size_table.py, test_mods_sizes.py). Four that cut `save()` for other checks already fail on main, for names of their own (`i18n`, `pause_background_now`, `publish_fps_cap`): they get a stand-in that moves as `save()` did, so they fail only as on main; with their one missing name stubbed locally, test_menu_save_atomic.py's 10 cases (full disk, a linked file, read-only folder and file, the file's mode...) pass here as on main. Again on main @ 1938a302, the game built through the PC's job queue: V-Sync changed over the control bridge, the game quit and the same profile started again: V-Sync kept (settings.ini held vsync=2, nothing beside it), exits 0. For Windows with llvm-mingw, the renderer alone compiled and longshot_vk.dll linked, and the host's C compiled (0 failed); `mise run test` (`--strict`) on main @ 1938a302, and on main with this change merged (together with #3017, #3018, #3019, #3020, #3021, from the same audit): 775 passed, 145 failed, 10 skipped both ways, so none fails only with it. The 145 are named at the end. **Still to test:** - @Beanstalk Windows and the Steam Deck: change a few settings in the Insert menu during play, expecting frame time around each change as on main (each settings save now flushes the file to the disk before it replaces the old one) - Windows, by hand: change a setting in the menu and start again, expecting it kept (two starts: not something the Test Farm plays) - In the game, by hand: switch a mod off in the Mods tab and start again, expecting mods.json to keep it (the Mods tab can't be driven over the control bridge) ## Measurements Nothing to measure in play: a settings save, made only when a setting changes, adds one fsync of the ~4 KB file, 1.25 ms on this PC's NVMe (the median of 40, the slowest 2.0 ms); the Test Farm run asked for in Still to test watches frame time around a change. ## Risks A settings save now waits for the disk: milliseconds on an SSD, more on an SD card. A revert undoes it. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. <details><summary>The 145 checks of <code>mise run test</code> that fail on main @ 1938a302 on this PC too, with or without this change</summary> 97 need a tool this PC doesn't have on PATH (`--strict` fails them): - clang (63): test_audio_output_devices.py, test_box_light_reuse.py, test_camera_centering.py, test_camera_speed.py, test_drive_target.py, test_dynres_sites.py, test_exclusive_marks.py, test_fixed_scale_sites.py, test_floor_carry_step.py, test_frame_rate_cap_step.py, test_frame_whole.py, test_free_view_anchor.py, test_fullscreen_monitor_platform.py, test_high_fps_fixes.py, test_horse_jump_step.py, test_hos_ab.py, test_hud_layout.py, test_jump_takeoff_step.py, test_linux_audio_output.py, test_loop_step.py, test_menu_hooks.py, test_microphone_test_gain.py, test_monitor_friendly_names.py, test_mouse_native.py, test_movement_speed.py, test_movie_frame_count.py, test_nvn_null_pool.py, test_nvn_tex_builder_guard.py, test_ocarina_wait.py, test_ocb_hold.py, test_oot_barrier.py, test_oot_camera_clearance.py, test_oot_cloth.py, test_oot_cloth_60.py, test_oot_cloth_time.py, test_oot_damage.py, test_oot_fov.py, test_oot_heap_retry.py, test_oot_jitter.py, test_oot_shadow.py, test_oot_shadow_fit.py, test_oot_transition_autosave.py, test_oot_voice_option.py, test_oot_wide_bubble.py, test_oot_wide_save_picture.py, test_player_update_sites.py, test_sampler_stack_walk.py, test_saved_turn_rate.py, test_scarecrow_timing.py, test_scene_format.py, test_sdl_monitor_names.py, test_shadow_slot.py, test_song_note_cue.py, test_sound_held_frames.py, test_sprint.py, test_svc_core_mask.py, test_tex_compact.py, test_text_speed.py, test_title_card_sites.py, test_water_substeps.py, test_web_floor_steps.py, test_wide_sites.py, test_wide_ui.py - spirv-val (20): f2i_immediate, global_load_16, native_suatom, test_coop_spirv.py, test_default_point_size.py, test_depth_sample_types.py, test_draw_parameters.py, test_fsr4_tune.py, test_guest_page_fast32.py, test_image_arrays.py, test_mesh_fallback_layout.py, test_mesh_unreachable_outputs.py, test_mma_software.py, test_native_float_atomic_add.py, test_nonuniform_image_arrays.py, test_spirv_struct_identity.py, test_texture_phi_dominance.py, test_unsigned_image_types.py, test_vendor_translation.py, test_wmma16_spirv_val.py - clang++ (7): test_dead_targets_sweep.py, test_lower_depbar.py, test_lower_lds_after_sts.py, test_lower_register_markers.py, test_native_suatom.py, test_program_answer_domains.py, test_target_pool_cap.py - glslang (5): test_framegen_hdr.py, test_fsr3fi_hud_layer.py, test_fsr3fi_hudless_colour.py, test_host_shaders.py, test_temporal_present_bandwidth.py - glslang, spirv-val (1): test_fsr3_shaders.py - llvm-mc (1): test_lifter.py 48 fail on main itself: test_blocks_at_start.py, test_bug_report.py, test_cloth_kernels.py, test_cloth_loops.py, test_cloth_sphere.py, test_cloth_step12.py, test_cloth_step8.py, test_cloth_step9.py, test_control_picture.py, test_crash_record.py, test_crt_options.py, test_dev_update.py, test_dlssg_pace.py, test_draw_stream_visibility.py, test_framegen_resources.py, test_fsr_uniform_ownership.py, test_game_boundary.py, test_guest_holes.py, test_image_reaper_threads.py, test_image_view_retry.py, test_input_background.py, test_keyboard_option.py, test_linux_pressure.py, test_loaded_modules_drop.py, test_log_levels.py, test_menu_keys.py, test_menu_save_atomic.py, test_mesh_first_types.py, test_oot_occ_raster.py, test_option_ids.py, test_perf_send.py, test_pipeline_tour.py, test_present_acquire_ahead.py, test_present_image_free.py, test_present_source_crop.py, test_program_cache_cleanup.py, test_program_cache_one_variant.py, test_readback_timeout_reuse.py, test_recording_admission.py, test_screensaver.py, test_switch_table.py, test_target_retention.py, test_tex_desc_memo.py, test_thinlto_tls.py, test_upscaler_round_trip.py, test_vram_compact.py, test_windows_display_startup.py, test_windows_on_linux.py </details> --- Found in an AI-assisted audit of the repository. The test, the fix, the runs and this description were made with Claude Code; I reviewed them. Co-Authored-By: Claude Opus 5.5 <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
host/hos_atomic_file.h is the one helper every write of a setting goes through (written beside, flushed to the disk,
moved over, waited for while another program holds the file), but the menu's save of settings.ini and game/mods.c's
write of mods.json have their own, which never flush: a power cut after the move can find the file empty or torn.
Source checks in tests/test_settings_atomic.py; they fail on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(menu): the menu's settings and mods.json are on the disk before they replace the old
Some checks failed
PR description / Title and description (pull_request_target) Successful in 7s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
beanstalk/approval not approved yet
353d9da174
The menu's save flushes the new settings file to the disk (fsync; _commit on Windows) before it replaces the old one,
and moves it with the helper's hos_af_move (tried again for a second while another program holds the file, the folder
flushed); mods.c's write_file is hos_atomic_write. The fixtures that compile these files build with the helper
(test_menu_env_overrides.py, test_mods_size_table.py, test_mods_sizes.py), or, where they cut save() for other checks
and already fail on main for other reasons (test_menu_save_atomic.py, test_menu_keys.py, test_crt_options.py,
test_upscaler_round_trip.py), with a stand-in that moves as save() did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Debian 13, GeForce GTX 1660 SUPER, NVIDIA 550.163.01, headless: V-Sync changed over the control bridge (the menu's save), the game quit and the same profile started again: V-Sync kept, settings.ini whole with nothing beside it; exits 0

Tested in game: Debian 13, GeForce GTX 1660 SUPER, NVIDIA 550.163.01, headless: V-Sync changed over the control bridge (the menu's save), the game quit and the same profile started again: V-Sync kept, settings.ini whole with nothing beside it; exits 0
PedroRossi changed title from WIP: fix(menu): the menu's settings and mods.json are on the disk before they replace the old to fix(menu): the menu's settings and mods.json are on the disk before they replace the old 2026-12-02 17:54:32 +00:00
Member

Possibly related, for context:

  • PR #2882 refactor(settings)!: settings flow one way: the game makes every rule, the renderer reads the snapshot and reports facts — Touches renderer settings flow and settings save behavior; closed/unmerged refactor
Possibly related, for context: - PR #2882 refactor(settings)!: settings flow one way: the game makes every rule, the renderer reads the snapshot and reports facts — Touches renderer settings flow and settings save behavior; closed/unmerged refactor
Author
Contributor

@Beanstalk Windows and the Steam Deck: change a few settings in the Insert menu during play (V-Sync, the frame rate cap), and compare frame time around each change with main. Each settings save now flushes the file to the disk before it replaces the old one.

@Beanstalk Windows and the Steam Deck: change a few settings in the Insert menu during play (V-Sync, the frame rate cap), and compare frame time around each change with main. Each settings save now flushes the file to the disk before it replaces the old one.
Member

@PedroRossi only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@PedroRossi only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Owner

Mod support has been completely rebuild, please see if this is still applicable to the mod-api branch and re-open!

Mod support has been completely rebuild, please see if this is still applicable to the `mod-api` branch and re-open!
HumanBean closed this pull request 2026-12-02 21:35:53 +00:00
Some checks failed
PR description / Title and description (pull_request_target) Successful in 7s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
beanstalk/approval not approved yet

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 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
MagicBeanDev/Longshot!3022
No description provided.