Skip to content

fix(settings): default fresh installs to the native retention period - #2246

Merged
shm11C3 merged 2 commits into
developfrom
fix/fresh-install-retention-default
Sep 23, 2026
Merged

shm11C3 merged 2 commits into
developfrom
fix/fresh-install-retention-default

Conversation

@shm11C3

@shm11C3 shm11C3 commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Why: On a fresh install, the Hardware Archive Retention Period default ends up persisted as 30 days instead of 365, even though fresh installs create and select a native database directly (#2203). Confirmed during the 2026-09-24 release audit.

What:

  • src-tauri/src/lib.rs: replace the inline inspect_startup_authority peek with app::native_lifecycle::default_hardware_archive_retention_days, which treats an empty profile (no hv-database.db, no hv-database.duckdb, no hv-database.authority.json) as heading for native authority, since startup creates and selects a native database for it moments later. An existing SQLite source with no native artifacts yet still resolves to the SQLite-era default.
  • src-tauri/src/commands/settings.rs (AppState::new): switch the one-time identity-key bootstrap save from save_to_path (which persists the whole CoreSettings object, including a never-saved retention default, as if it had been explicitly chosen) to the new CoreSettings::save_identity_only_to_path, which touches only the storageHealthIdentity section it owns.
  • core/src/settings/mod.rs: add save_identity_only_to_path, refactoring the shared read/write-document logic out of save_to_path so both can use it.
  • src-tauri/src/app/native_lifecycle.rs: add is_fresh_profile and default_hardware_archive_retention_days.

Evidence:

  • New unit tests in core/src/settings/mod.rs::settings::tests prove a defaulted retention value is never written to disk by the identity-key bootstrap save, and that an already-saved value is untouched (DP-06).
  • New unit tests in src-tauri/src/app/native_lifecycle.rs::tests drive is_fresh_profile / default_hardware_archive_retention_days against temp directories for the three cases: empty profile → 365, directory with only hv-database.db → 30, selected native profile → 365.
  • cargo fmt --all -- --check: clean.
  • cargo clippy -p hardviz-core --all-targets -- -D warnings and with --no-default-features: clean.
  • cargo clippy -p hardware_visualizer --all-targets -- -D warnings and with --no-default-features: clean.
  • cargo test -p hardviz-core --lib settings: 48 passed.
  • cargo test -p hardware_visualizer --lib -- --test-threads=1: 383 passed, 0 failed.

Closes #2244

Type of Change

  • Bug fix (fix/ branch)

Test Plan

  • Unit tests

Checklist

  • Self-reviewed the code
  • Linting and formatting pass (cargo tauri-lint && cargo tauri-fmt)
  • Tests pass (cargo tauri-test)
  • No new warnings or errors

Summary by CodeRabbit

  • Bug Fixes
    • Storage-health identity initialization now preserves existing settings and avoids saving a backend-specific hardware-archive retention default as an explicit setting.
    • Hardware-archive retention defaults now account for whether a profile is fresh or uses native or SQLite storage.
    • Identity-only saves preserve other existing settings, while invalid settings files return an error instead of being overwritten.

…y-only save

Adds the pure helpers and tests the #2136 fix in the next commit relies on:

- `app::native_lifecycle::is_fresh_profile` and
  `default_hardware_archive_retention_days` decide the Hardware Archive
  Retention Period default from on-disk authority facts alone, treating an
  empty profile (no source database, no native database, no marker) as
  heading for native authority rather than trusting
  `inspect_startup_authority`'s SqliteAuthoritative peek at face value.
- `CoreSettings::save_identity_only_to_path` persists only the storage
  health identity section, so the one-time identity-key bootstrap in
  `AppState::new` (next commit) stops writing a never-saved retention
  default to disk as if it were explicitly chosen.
Fresh installs default the Hardware Archive Retention Period to 30 days
instead of 365, and persist it as if the user had chosen it.

`run()` picked the default with a read-only peek at on-disk authority
facts, taken before `resolve_native_authority` creates and selects the
native database for a fresh profile later in the same startup (#2203). On
an empty profile the peek reports SqliteAuthoritative - correct about the
instant it was read, but not about the backend startup ends up on - so the
30-day SQLite-era default was chosen. `AppState::new` then made it
durable: its one-time identity-key bootstrap saved the whole
`CoreSettings` object, writing the defaulted 30 to `settings.json` as if
explicitly saved, after which the "365 only for a never-saved value" rule
could never apply to that profile again.

Switch the default selection to
`native_lifecycle::default_hardware_archive_retention_days`, which treats
an empty profile as native (#2136), and switch the identity-key bootstrap
save to `save_identity_only_to_path`, which touches only the identity
section it owns.

Closes #2244
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T16:18:05.088223Z 7fc79c2 PR opened
🔒 Security Review ✅ Completed 2026-09-23T16:19:20.522843Z 7fc79c2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: shm11C3/HardwareVisualizer/.coderabbit.yml

Review profile: CHILL

Plan: Team

Run ID: 5fb5b0a6-00e1-433a-aa03-47630f534c26

📥 Commits

Reviewing files that changed from the base of the PR and between b8dab33 and 7fc79c2.

📒 Files selected for processing (4)
  • core/src/settings/mod.rs
  • src-tauri/src/app/native_lifecycle.rs
  • src-tauri/src/commands/settings.rs
  • src-tauri/src/lib.rs

Included review availability: 1 review is currently available. Your included PR review attempts over the past 7 days set your current allowance at 6 reviews per hour.


📝 Walkthrough

Walkthrough

Settings initialization now saves only the storage-health identity. Startup selects the hardware-archive retention default based on whether the profile is fresh and which authority it resolves to.

Changes

Fresh-profile retention defaults

Layer / File(s) Summary
Identity-only settings persistence
core/src/settings/mod.rs, src-tauri/src/commands/settings.rs
Shared helpers read and atomically write settings documents. Identity-only saves update the identity section without adding an unsaved retention value. AppState::new uses this save when it creates a storage-health identity key.
Profile-based retention defaults
src-tauri/src/app/native_lifecycle.rs, src-tauri/src/lib.rs
The default selector uses the native default for fresh profiles and profiles with native authority. Other inspected states use the SQLite default. Startup calls the selector when the duckdb-archive feature is enabled.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 7fc79

Fresh profiles receive the native retention default without saving it as a user choice. No merge-blocking issue was established.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the bug, implementation, related issue, change type, tests, and checklist status. It omits the dedicated Related Issues and Screenshots / Videos headings, but the related issu…
Title check ✅ Passed The title clearly identifies the primary fix: fresh installs now use the native retention period by default.
Linked Issues check ✅ Passed The PR meets the coding objectives in [#2244]. default_hardware_archive_retention_days returns the native default for an empty profile and for a profile that resolves to native authority. `AppState:…
Out of Scope Changes check ✅ Passed The changes stay within [#2244]. The shared settings read/write helpers support the identity-only save, and the added tests verify the two required fixes and preservation behavior. No unrelated functi…
Docstring Coverage ✅ Passed Docstring coverage is 84.21% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 4 files.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

@github-actions github-actions Bot added change:fix PR: bug-fix branch work area:core Area: Tauri-independent Core code area:tauri Area: Tauri app, commands, app wiring, or bundling labels Sep 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Rust Tauri Coverage Report

Coverage Details
Filename                                                 Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
_tests/commands/background_image_test.rs                      39                 0   100.00%           6                 0   100.00%          21                 0   100.00%           0                 0         -
_tests/commands/settings_test.rs                             265                 0   100.00%          21                 0   100.00%         208                 0   100.00%           0                 0         -
adapters/tray.rs                                             127               127     0.00%          14                14     0.00%          87                87     0.00%           0                 0         -
adapters/window.rs                                           601               114    81.03%          44                11    75.00%         515                79    84.66%           0                 0         -
app/database_availability.rs                                  43                18    58.14%           5                 2    60.00%          44                16    63.64%           0                 0         -
app/native_conversion.rs                                    1097               214    80.49%          75                11    85.33%         826               158    80.87%           0                 0         -
app/native_lifecycle.rs                                      273                11    95.97%          27                 1    96.30%         240                11    95.42%           0                 0         -
app/native_maintenance.rs                                    726                42    94.21%          44                 3    93.18%         425                35    91.76%           0                 0         -
app/startup.rs                                               281               144    48.75%          17                 6    64.71%         191               110    42.41%           0                 0         -
cli/mod.rs                                                   471                74    84.29%          51                 9    82.35%         335                50    85.07%           0                 0         -
commands/ambient_sensor.rs                                    63                 5    92.06%           8                 3    62.50%          57                 8    85.96%           0                 0         -
commands/background_image.rs                                  22                 7    68.18%          11                 5    54.55%          19                 7    63.16%           0                 0         -
commands/cooling_insight.rs                                   63                63     0.00%          19                19     0.00%          65                65     0.00%           0                 0         -
commands/database_conversion.rs                               80                80     0.00%          16                16     0.00%          67                67     0.00%           0                 0         -
commands/external_component_guidance.rs                       42                42     0.00%           9                 9     0.00%          45                45     0.00%           0                 0         -
commands/external_component_setup.rs                          41                41     0.00%          11                11     0.00%          35                35     0.00%           0                 0         -
commands/hardware.rs                                         400               339    15.25%          76                66    13.16%         328               288    12.20%           0                 0         -
commands/settings.rs                                        1003               973     2.99%         160               157     1.88%         845               820     2.96%           0                 0         -
commands/system.rs                                            62                48    22.58%          19                16    15.79%          53                40    24.53%           0                 0         -
commands/ui.rs                                                17                17     0.00%           2                 2     0.00%          13                13     0.00%           0                 0         -
commands/updater.rs                                          144                97    32.64%          18                15    16.67%          90                66    26.67%           0                 0         -
enums/error.rs                                                91                 0   100.00%           7                 0   100.00%          76                 0   100.00%           0                 0         -
enums/hardware.rs                                            184                 3    98.37%          15                 0   100.00%         111                 2    98.20%           0                 0         -
enums/settings.rs                                            423                17    95.98%          27                 2    92.59%         279                10    96.42%           0                 0         -
infrastructure/database/migration.rs                         860                 0   100.00%          57                 0   100.00%         698                 0   100.00%           0                 0         -
infrastructure/database/migration_definitions.rs              32                 0   100.00%           2                 0   100.00%         474                 0   100.00%           0                 0         -
infrastructure/database/native_paths.rs                       27                 0   100.00%           3                 0   100.00%          23                 0   100.00%           0                 0         -
infrastructure/database/native_schema.rs                      80                 0   100.00%           9                 0   100.00%          59                 0   100.00%           0                 0         -
infrastructure/database/native_schema_definitions.rs           3                 0   100.00%           1                 0   100.00%           9                 0   100.00%           0                 0         -
lib.rs                                                       556               498    10.43%          22                18    18.18%         413               365    11.62%           0                 0         -
lifecycle.rs                                                 307               258    15.96%          35                31    11.43%         219               196    10.50%           0                 0         -
main.rs                                                        8                 8     0.00%           1                 1     0.00%           6                 6     0.00%           0                 0         -
models/archive_history.rs                                    115                50    56.52%          10                 7    30.00%         116                58    50.00%           0                 0         -
models/cooling_insight.rs                                   1089                34    96.88%          73                 3    95.89%        1098                35    96.81%           0                 0         -
models/database_conversion.rs                                 57                14    75.44%           6                 0   100.00%          50                13    74.00%           0                 0         -
models/elevation.rs                                           15                 2    86.67%           2                 0   100.00%          12                 2    83.33%           0                 0         -
models/environmental_sensors.rs                               52                 0   100.00%           6                 0   100.00%          45                 0   100.00%           0                 0         -
models/external_component_guidance.rs                         60                 4    93.33%           6                 0   100.00%          52                 4    92.31%           0                 0         -
models/external_component_setup.rs                           187                23    87.70%          13                 1    92.31%         156                20    87.18%           0                 0         -
models/hardware.rs                                           481                 3    99.38%          24                 0   100.00%         343                 3    99.13%           0                 0         -
models/hardware_archive.rs                                     8                 0   100.00%           2                 0   100.00%          10                 0   100.00%           0                 0         -
models/settings.rs                                           381                 0   100.00%          21                 0   100.00%         353                 0   100.00%           0                 0         -
models/storage_health.rs                                       7                 0   100.00%           2                 0   100.00%           9                 0   100.00%           0                 0         -
services/archive_history_service.rs                           65                65     0.00%          21                21     0.00%         101               101     0.00%           0                 0         -
services/background_image_service.rs                         208               128    38.46%          21                10    52.38%         115                71    38.26%           0                 0         -
services/cooling_insight_service.rs                           40                40     0.00%          18                18     0.00%          46                46     0.00%           0                 0         -
services/external_component_guidance_service.rs              187                16    91.44%          18                 1    94.44%         120                11    90.83%           0                 0         -
services/external_component_setup_service.rs                 167                57    65.87%          17                 5    70.59%         106                32    69.81%           0                 0         -
services/gpu_service.rs                                       45                45     0.00%           7                 7     0.00%          33                33     0.00%           0                 0         -
services/hardware_service.rs                                 210               123    41.43%          28                12    57.14%         161                94    41.61%           0                 0         -
services/language_service.rs                                 149                 0   100.00%          24                 0   100.00%          87                 0   100.00%           0                 0         -
services/memory_service.rs                                     9                 9     0.00%           2                 2     0.00%           5                 5     0.00%           0                 0         -
services/motherboard_service.rs                                9                 9     0.00%           2                 2     0.00%           5                 5     0.00%           0                 0         -
services/network_service.rs                                   34                13    61.76%           4                 1    75.00%          23                 6    73.91%           0                 0         -
services/settings_service.rs                                 929               239    74.27%          99                30    69.70%         754               211    72.02%           0                 0         -
services/system_service.rs                                   168                82    51.19%          22                12    45.45%         131                59    54.96%           0                 0         -
services/ui_service.rs                                        45                45     0.00%           8                 8     0.00%          36                36     0.00%           0                 0         -
tray/surface/mod.rs                                            8                 8     0.00%           2                 2     0.00%           5                 5     0.00%           0                 0         -
tray/surface/tauri_surface.rs                                 80                80     0.00%           6                 6     0.00%          48                48     0.00%           0                 0         -
tray/widget.rs                                               610                 5    99.18%          51                 1    98.04%         542                 3    99.45%           0                 0         -
utils/color.rs                                                66                 1    98.48%           4                 0   100.00%          26                 0   100.00%           0                 0         -
utils/file.rs                                                224                 5    97.77%          14                 0   100.00%         144                 4    97.22%           0                 0         -
utils/formatter.rs                                            55                 0   100.00%           5                 0   100.00%          39                 0   100.00%           0                 0         -
utils/logger.rs                                               71                71     0.00%           1                 1     0.00%          38                38     0.00%           0                 0         -
utils/tauri.rs                                               311                22    92.93%          42                 1    97.62%         195                14    92.82%           0                 0         -
webview_memory.rs                                             20                20     0.00%           4                 4     0.00%          13                13     0.00%           0                 0         -
workers/mod.rs                                                70                23    67.14%           2                 0   100.00%          40                10    75.00%           0                 0         -
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                      14663              4476    69.47%        1419               583    58.91%       11933              3559    70.18%           0                 0         -

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

CI telemetry

Commit 7fc79c2 · updated 2026-09-23 16:28 UTC

Workflow Result Wall time Longest queue Jobs
CI ✅ success 14m 38s 11s 20
CodeQL Advanced ✅ success 9m 25s 2s 3
PR Branch Name ✅ success 8s 2s 1
CodeQL Advanced · 3 jobs
Job Result Queue Duration CPU avg / p95 Mem peak Disk peak Caches
Analyze (rust) ✅ 2s 9m 22s – – – –
Analyze (javascript-typescript) ✅ 2s 1m 03s – – – –
Analyze (actions) ✅ 2s 48s – – – –

Slowest steps

Step Duration
Analyze (rust) › Perform CodeQL Analysis 7m 25s
Analyze (rust) › Setup Rust 1m 26s
Analyze (javascript-typescript) › Perform CodeQL Analysis 38s
Analyze (actions) › Perform CodeQL Analysis 25s
Analyze (javascript-typescript) › Initialize CodeQL 18s
CI · 20 jobs · 10 skipped
Job Result Queue Duration CPU avg / p95 Mem peak Disk peak Caches
test-e2e-native ✅ 3s 13m 40s 80% / 100% · 3.2/4T
T 79 · 82 · 79 · 81
4.6 / 15.6 GiB 68 / 145 GiB target exact · npm exact
test-core (windows-latest) ✅ 4s 10m 15s 45% / 100% · 1.8/4T
T 43 · 42 · 50 · 44
8.0 / 16.0 GiB 24 / 150 GiB target exact · sccache Rust 0% (0/1) · C/C++ n/a
test-tauri (windows-latest) ✅ 5s 7m 22s 21% / 63% · 0.8/4T
T 21 · 19 · 25 · 20
8.7 / 16.0 GiB 14 / 220 GiB target exact · sccache Rust 0% (0/1) · C/C++ n/a
test-core (macos-latest) ✅ 7s 6m 42s 95% / 100% · 2.8/3T
T 95 · 94 · 94
4.3 / 7.0 GiB 239 / 320 GiB target exact · sccache Rust 0% (0/1) · C/C++ n/a
test-build (macos-latest) ✅ 8s 5m 47s 79% / 100% · 2.4/3T
T 82 · 78 · 76
4.6 / 7.0 GiB 232 / 320 GiB target exact · sccache Rust 100% (615/616) · C/C++ 99% (292/295)
test-core (ubuntu-22.04) ✅ 3s 5m 10s 41% / 98% · 1.6/4T
T 40 · 43 · 40 · 43
2.6 / 15.6 GiB 79 / 145 GiB target exact · sccache Rust 0% (0/1) · C/C++ n/a
test-tauri (macos-latest) ✅ 11s 4m 23s 79% / 100% · 2.4/3T
T 82 · 78 · 76
4.4 / 7.0 GiB 234 / 320 GiB target exact · sccache Rust 0% (0/1) · C/C++ n/a
lint-tauri (windows-latest) ✅ 3s 4m 14s 33% / 85% · 1.3/4T
T 32 · 26 · 45 · 27
5.9 / 16.0 GiB 17 / 150 GiB target exact · sccache Rust n/a · C/C++ n/a
test-build (ubuntu-22.04) ✅ 4s 4m 14s 45% / 87% · 1.8/4T
T 40 · 43 · 51 · 46
3.5 / 15.6 GiB 69 / 145 GiB target exact · sccache Rust 100% (679/680) · C/C++ 99% (294/297)
test-build (windows-latest) ✅ 4s 3m 24s 34% / 99% · 1.4/4T
T 33 · 32 · 43 · 28
6.7 / 16.0 GiB 13 / 150 GiB target exact · sccache Rust 93% (13/14) · C/C++ n/a
test-tauri (ubuntu-22.04) ✅ 3s 3m 18s 39% / 80% · 1.6/4T
T 40 · 42 · 38 · 36
3.0 / 15.6 GiB 73 / 145 GiB target exact · sccache Rust 0% (0/1) · C/C++ n/a
lint-core (windows-latest) ✅ 3s 3m 17s 20% / 54% · 0.8/4T
T 21 · 15 · 29 · 15
5.5 / 16.0 GiB 12 / 220 GiB target exact · sccache Rust n/a · C/C++ n/a
check-tauri-bindings ✅ 3s 2m 42s 26% / 47% · 1.0/4T
T 25 · 21 · 22 · 36
2.2 / 15.6 GiB 72 / 145 GiB target exact · sccache Rust 0% (0/1) · C/C++ n/a
lint-tauri (ubuntu-22.04) ✅ 2s 2m 08s 36% / 56% · 1.4/4T
T 37 · 42 · 33 · 32
2.1 / 15.6 GiB 76 / 145 GiB target exact · sccache Rust n/a · C/C++ n/a
lint-core (ubuntu-22.04) ✅ 3s 1m 38s 38% / 60% · 1.5/4T
T 43 · 40 · 29 · 42
1.7 / 15.6 GiB 72 / 145 GiB target exact · sccache Rust n/a · C/C++ n/a
lint-tauri (macos-latest) ✅ 6s 1m 32s 72% / 90% · 2.2/3T
T 76 · 72 · 68
4.2 / 7.0 GiB 235 / 320 GiB target exact · sccache Rust n/a · C/C++ n/a
lint-core (macos-latest) ✅ 10s 1m 26s 78% / 100% · 2.3/3T
T 80 · 77 · 76
4.1 / 7.0 GiB 234 / 320 GiB target exact · sccache Rust n/a · C/C++ n/a
change-detection ✅ 6s 20s – – – –
rust-format ✅ 2s 17s 32% / 32% · 1.3/4T
T 35 · 17 · 33 · 44
1.7 / 15.6 GiB 59 / 144 GiB –
Merge Gate ✅ 5s 17s – – – –

Slowest steps

Step Duration
test-e2e-native › Run native E2E smoke 12m 14s
test-core (windows-latest) › Run Core tests 7m 28s
test-core (macos-latest) › Run Core tests 5m 33s
test-tauri (windows-latest) › Run Tauri tests 4m 42s
test-build (macos-latest) › Build Tauri Rust crate (CI optimized for PR) 4m 42s

Generated by the CI telemetry workflow from the GitHub API and job log markers. Queue = time from job creation to start. N/MT = average busy threads of M logical CPUs; T = per-thread average %.

@shm11C3
shm11C3 enabled auto-merge (squash) September 23, 2026 16:27
@shm11C3
shm11C3 merged commit 8f9c321 into develop Sep 23, 2026
42 checks passed
@shm11C3
shm11C3 deleted the fix/fresh-install-retention-default branch September 23, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Area: Tauri-independent Core code area:tauri Area: Tauri app, commands, app wiring, or bundling change:fix PR: bug-fix branch work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(settings): fresh installs persist the 30-day retention default instead of the native 365

1 participant