Skip to content

Persist the AutoSave preference across restarts (#1901) - #1995

Merged
aiongg merged 1 commit into
storytold:mainfrom
bfenty:fix/autosave-persist-1901
Oct 22, 2026
Merged

aiongg merged 1 commit into
storytold:mainfrom
bfenty:fix/autosave-persist-1901

Conversation

@bfenty

@bfenty bfenty commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

AutoSave (the title-bar switch / Options ▸ Save checkbox) lived on GridState, which is never serialized. The desktop app persists UiState to ui.json on exit, so AutoSave silently reset to off on every restart (#1901).

Fix

Moved the flag from GridState.autosave (transient) to UiState.autosave (persisted, serde(default)), with SheetApp::toggle_autosave() as the single flip point for both call sites (title-bar switch, Options ▸ Save). The 2-second throttle timestamp stays on GridState — it's per-session timing, not a preference.

Old ui.json files without the key load fine via serde(default) and read as off, matching previous behavior.

Tests

autosave_persist.rs:

  • toggle → serialize → restore round-trip keeps AutoSave on (fails on main: no persisted field exists)
  • toggling back persists off too
  • a legacy ui.json without the key still deserializes with the rest of the settings intact

Full gridcraft-ui-egui suite green; clippy and rustfmt clean.

Closes #1901

Co-Authored-By: Claude noreply@anthropic.com

Summary by CodeRabbit

  • Features
    • The AutoSave setting is now stored with your UI preferences and remains available in both the Options page and title bar.
    • AutoSave is off by default. When enabled, eligible .xlsx workbooks save automatically after two seconds without an active cell or text-box edit.
    • Existing preferences without an AutoSave setting continue to load with AutoSave off.

Closes storytold#1901

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 49f7a52a-6841-4187-8076-eb661542bdc4
📥 Commits

Reviewing files that changed from the base of the PR and between 49fe41a and e34b0aa.

📒 Files selected for processing: 5
  • crates/ui-egui/src/backstage.rs
  • crates/ui-egui/src/grid.rs
  • crates/ui-egui/src/lib.rs
  • crates/ui-egui/src/ribbon.rs
  • crates/ui-egui/tests/autosave_persist.rs
💤 Files with no reviewable changes: 1
  • crates/ui-egui/src/grid.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

AutoSave now uses a persisted UiState preference instead of state stored in GridState. The preference defaults to off. The app’s save check and AutoSave controls use this preference, and tests cover persistence and older UI JSON.

Changes: AutoSave Preference

Layer / File(s) Summary
Persist the AutoSave preference
crates/ui-egui/src/lib.rs, crates/ui-egui/src/grid.rs, crates/ui-egui/tests/autosave_persist.rs
UiState stores AutoSave, defaults it to off, and provides a toggle method. GridState no longer stores or toggles AutoSave. Tests cover serialization and loading older UI JSON without the preference.
Use the persisted preference
crates/ui-egui/src/lib.rs, crates/ui-egui/src/ribbon.rs, crates/ui-egui/src/backstage.rs
The save check and both AutoSave controls read the preference from app.ui.autosave. The controls toggle it through app.toggle_autosave().

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: echelon, vangel76

Merge Risk: ⚪ Minimal · up to e34b0

AutoSave should remain enabled after a normal close and restart when preferences are enabled. No actionable merge-blocking risk remains.

Security architecture risk: 🔵 Low · up to e34b0

The change preserves the existing save restrictions and defaults older settings to off. AutoSave can now remain active across launches, but restoring that choice depends on best-effort settings storage.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The preference is application-wide: once restored as enabled, it can trigger saves for successive active, dirty .xlsx documents across launches. The inspected path writes to each active document's existing destination using the desktop process's filesystem authority; the preference itself does not supply a destination or credential.

Trust Boundaries and Controls

  • observed — The inspected preference source is local ui.json, restored through UiState deserialization. Both controls and the automatic-save gate use the same boolean. The PR changes the lifetime of that control rather than removing the existing save preconditions or adding a new save destination.

Resilience and Maintainability Implications

  • inferred — AutoSave now inherits the existing preference store's best-effort durability. An interrupted or failed settings write can prevent restoration of the chosen value; the inspected writer provides no atomic replacement or local locking. Broader process coordination was not established, so concurrent-instance ownership remains uncertain rather than a verified PR-introduced vulnerability.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: persisting the AutoSave preference across application restarts.
Linked Issues check Passed Issue #1901 requires AutoSave to remain enabled after the application restarts. The PR adds UiState::autosave with #[serde(default)], initializes it to false, uses it in the save path, and route…
Out of Scope Changes check Passed The changes stay within issue #1901. They move the preference from transient GridState to persisted UiState, update the two AutoSave controls and save condition, retain the session-only throttle t…
Full details: Linked Issues check

Explanation

Issue #1901 requires AutoSave to remain enabled after the application restarts. The PR adds UiState::autosave with #[serde(default)], initializes it to false, uses it in the save path, and routes both UI controls through SheetApp::toggle_autosave(). autosave_persist.rs verifies enabled and disabled JSON round-trips and verifies legacy JSON without the key.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #1901. They move the preference from transient GridState to persisted UiState, update the two AutoSave controls and save condition, retain the session-only throttle timestamp, and add focused persistence tests. No unrelated behavior is demonstrated.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@Harrison-Booth

Copy link
Copy Markdown
Contributor

Heads up for review order: I just opened #2017, which changes how AutoSave runs (a worker thread) and adds an options.autoSave command. It edits ui-egui/src/lib.rs near this change but does not touch how the AutoSave setting is stored. If this lands first I'll rebase #2017 onto it.

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.

[Bug Report] [GridCraft] Autosave doesn’t persist

3 participants