feat(desktop): add optional periodic full-session snapshot - #9720
Open
P-dawn wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add an opt‑in periodic full‑session snapshot engine for the desktop app, as a safety net for the existing TurnDone‑only autosave.
Currently, sessions are persisted only when
event.TurnDonefires (tabEventSink.Emit→scheduleTabSnapshot→tabSnapshotLoop). A long in‑flight turn, a crash before TurnDone, or a version‑upgrade migration can therefore lose data that never reached disk. This PR adds a configurable ticker that calls the existingsnapshotAllTabs()on an interval, so a force‑kill loses at mostintervalseconds of work instead of an entire in‑flight turn.Default behaviour is unchanged: the engine is disabled unless
REASONIX_ENABLE_PERIODIC_SNAPSHOT=1is set. No config‑system, migration, or UI changes.Issues
Addresses the data‑loss class of issues where in‑flight turns are lost on crash or before the TurnDone event persists the session. This PR lays the groundwork for later pre‑update snapshots and JSON export (both out of scope here).
Verification
Run unit tests:
Enable the feature and observe periodic snapshots:
On Windows:
set REASONIX_ENABLE_PERIODIC_SNAPSHOT=1 && reasonix-desktop.exeVerify logs or disk writes occur at the configured interval (default 30s, clamped to 5s min).
Ensure existing tests pass unchanged when the env var is absent (no‑op behaviour).
Documentation impact
Documentation-impact: none - This feature is opt-in and disabled by default; it only adds two environment variables, so no configuration file schema, migration, or UI changes are required.
Cache impact
Cache-impact: none - This change does not touch system prompt construction, memory prefix, output styles, skill index, tool schemas, provider request serialization, compaction, or MCP/tool registration. It only schedules calls to the existing
snapshotAllTabs()path.Cache-guard: Existing autosave tests in
app_autosave_test.gocover the snapshot path; this PR addspersistence_enhancer_test.gowith test cases covering env‑var parsing, interval clamping, and lifecycle (Start/Stop idempotency, stop‑before‑start safety). The engine is disabled by default, so no existing cache‑sensitive test path is affected.System-prompt-review: N/A