Skip to content

fix: event-driven saveOnEmpty to prevent data loss on fast shutdown#89

Merged
fank merged 1 commit intomainfrom
fix/save-on-empty-event-driven
Mar 3, 2026
Merged

fix: event-driven saveOnEmpty to prevent data loss on fast shutdown#89
fank merged 1 commit intomainfrom
fix/save-on-empty-event-driven

Conversation

@fank
Copy link
Member

@fank fank commented Mar 3, 2026

Summary

  • Event-driven saveOnEmpty: Replace the 30-second polling PFH with an immediate check inside HandleDisconnect. When the last player disconnects, the save triggers instantly instead of waiting up to 30 seconds for the next poll — preventing data loss when persistent=0 causes the server to shut down before the PFH fires.
  • Remove dead args from :MISSION:SAVE:: The extension ignores all arguments passed in this command (worldName, missionName, author, captureDelay, endFrameNumber, saveTag) — it already has this data from :MISSION:START: at init time. Removes the stale reads to prevent future confusion.

Reported by Darkstar2135: with saveOnEmpty + persistent=0, the world/map name occasionally saved incorrectly (~15%) because worldName was read live at save time when the world could already be unloading.

Test plan

  • Verify saveOnEmpty triggers when last player disconnects (no 30s delay)
  • Verify recording still saves correctly with proper world name and mission metadata
  • Verify manual export via CBA event still works
  • Verify MPEnded auto-save still works independently

)

Replace the 30-second polling PFH with an immediate check inside the
HandleDisconnect event handler. With persistent=0, the server could
terminate before the PFH fires, losing the recording entirely.

Also remove dead arguments from :MISSION:SAVE: — the extension already
has all mission/world data from :MISSION:START: at init time and ignores
these args.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the recording system by addressing a critical data loss scenario during server shutdowns. It transitions the saveOnEmpty functionality to an immediate, event-driven trigger upon the last player's disconnection, ensuring that recordings are saved promptly. Additionally, it cleans up the :MISSION:SAVE: command by removing unnecessary arguments, streamlining the code and preventing future confusion.

Highlights

  • Event-driven saveOnEmpty: The saveOnEmpty feature has been refactored from a 30-second polling mechanism to an immediate, event-driven check. When the last player disconnects, the recording now saves instantly, preventing potential data loss during rapid server shutdowns, especially when persistent=0.
  • Removed redundant arguments: Stale and ignored arguments have been removed from the :MISSION:SAVE: extension command. The extension already possesses the necessary mission metadata from :MISSION:START:, making these arguments redundant and a source of potential confusion.
Changelog
  • addons/recorder/fnc_eh_disconnected.sqf
    • Added logic to immediately trigger data export when the last player disconnects, provided saveOnEmpty is enabled and other conditions are met.
  • addons/recorder/fnc_exportData.sqf
    • Modified the :MISSION:SAVE: extension command to no longer pass redundant arguments, as they are ignored by the extension.
  • addons/recorder/fnc_init.sqf
    • Removed the CBA_fnc_addPerFrameHandler that previously implemented the 30-second polling for the saveOnEmpty feature.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses a potential data loss issue with saveOnEmpty on fast-shutdown servers by replacing the 30-second polling mechanism with an event-driven check in the HandleDisconnect event handler. This ensures that a save is triggered immediately when the last player leaves. Additionally, the removal of unused and problematic arguments from the :MISSION:SAVE: extension call is a good cleanup that prevents confusion and fixes a bug related to reading worldName at an incorrect time. The changes are logical and well-implemented. I have one minor suggestion for a small performance and robustness improvement in the player count check.

@fank fank merged commit c41e07f into main Mar 3, 2026
1 check passed
@fank fank deleted the fix/save-on-empty-event-driven branch March 3, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant