Skip to content

feat(database): route Storage Health through dispatch - #2157

Merged
shm11C3 merged 2 commits into
developfrom
feat/2134-route-storage-health
Sep 19, 2026
Merged

shm11C3 merged 2 commits into
developfrom
feat/2134-route-storage-health

Conversation

@shm11C3

@shm11C3 shm11C3 commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Stacked on #2156 (which is stacked on #2154). Extends the #2134 dispatch boundary to Storage Health, reusing the same dispatch::DispatchError/native_handle plumbing the earlier PRs in this stack proved. insert_daily_records, refresh_daily_records, delete_old_data and latest_records now go through dispatch::storage_health instead of calling infrastructure::database::storage_health directly, in both the persistence worker and the App service.

Why / What / How / Why Not

  • Why now: Storage Health is explicitly named in feat(database): route database consumers to the selected native backend #2134's consumer list, has its own finalized-native module already (native_database::storage_health), and its own differential test suite (duckdb_storage_health.rs) - the same shape of work the earlier PRs in this stack already did.
  • What: dispatch::storage_health::{insert_daily_records, refresh_daily_records, delete_old_data, latest_records}; the call sites in core/src/persistence/storage_health.rs and src-tauri/src/services/hardware_service.rs.
  • How: identical shape to the earlier PRs - a match native_handle().await { Some(db) => native call, None => existing SQLite call } per function.
  • Why not keep get_storage_health_latest_records's sqlx::Error return type: dispatch's SQLite branch still returns sqlx::Error under the hood, but the native branch returns a different type, so the function has to return something both can convert into. DispatchError is that type; its only caller (commands/hardware.rs) already formats the error as a string via {e}, so nothing downstream changes.

Consumers routed / not yet routed

  • Routed (this stack): Process Stats, DATA_ARCHIVE, GPU_DATA_ARCHIVE, Ambient, Fan, Storage Health.
  • Not yet routed: the six Cooling projections, both baselines and the cooling rollup persistence. These are markedly larger in scope - cooling_rollup.rs alone commits six projections in one SQLite transaction across five other modules, several with their own baseline-resolution and pinning logic - and are tracked as follow-up work rather than attempted here, per the issue's explicit allowance to say so rather than route silently to SQLite.

Test Plan

  • core/tests/duckdb_dispatch_storage_health.rs (new) - one sequential test proving Storage Health answers from SQLite before selection, answers identically from native after reobserve_authority, that a post-selection refresh_daily_records write lands in the native file (SQLite's own row count stays put), and that delete_old_data through the boundary reaches the native database. Uses storage_device_id-shaped identities, per duckdb_storage_health.rs's own module doc on why an invented id shape would hide a broken join.
  • cargo fmt --all -- --check
  • cargo clippy -p hardviz-core --features duckdb-archive --all-targets -- -D warnings
  • cargo clippy -p hardviz-core --all-targets -- -D warnings
  • cargo clippy -p hardware_visualizer --features duckdb-archive --all-targets -- -D warnings
  • cargo nextest run -p hardviz-core --features duckdb-archive - 1428 passed
  • cargo test -p hardviz-core (feature off) - all passed
  • cargo test -p hardware_visualizer --lib - the Storage Health / hardware_service tests pass; 9 unrelated _tests::commands::settings_test failures are pre-existing in this sandbox (confirmed identical with this PR's diff stashed out - a file-write environment issue, not a regression from this change).

Related Issues

Part of #2134. Stacked on #2156.

Type of Change

  • New feature (feat/ branch)

Checklist

  • Self-reviewed the code
  • Linting and formatting pass
  • Tests pass
  • No new warnings or errors

Summary by CodeRabbit

  • Bug Fixes
    • Improved storage health data handling across database backend transitions.
    • Existing storage health records are preserved when the active database changes.
    • New and refreshed records are consistently written to the selected backend.
    • Latest storage health results remain available after backend selection.
    • Retention cleanup correctly removes outdated records from the active storage backend.
    • Storage health updates now provide consistent results across database configurations.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

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: 421a11ff-cc11-4b38-8a31-a4a6d1c851ba

📥 Commits

Reviewing files that changed from the base of the PR and between f07e660 and bd40abf.

📒 Files selected for processing (1)
  • core/src/infrastructure/database/dispatch.rs

Limit details: You’ve used all 4 included reviews currently available. Your 61 included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.


📝 Walkthrough

Walkthrough

Storage-health database operations now use the dispatch boundary. The boundary routes calls to SQLite or the selected native backend. Persistence and hardware-service reads use this boundary. A DuckDB-gated test verifies routing, reads, writes, and retention deletion.

Changes

Storage Health Dispatch

Layer / File(s) Summary
Storage-health dispatch operations
core/src/infrastructure/database/dispatch.rs
Adds insert, refresh, retention, and latest-record operations. Calls route to SQLite when native storage is unavailable or unselected, and to the native backend when selected.
Persistence and service integration
core/src/persistence/storage_health.rs, src-tauri/src/services/hardware_service.rs
Storage-health writes, retention deletion, and latest-record reads use the dispatch namespace. Latest-record retrieval now returns DispatchError.
Backend routing validation
core/tests/duckdb_dispatch_storage_health.rs
Adds an end-to-end test for SQLite seeding, native selection, native writes and reads, SQLite row isolation, and native retention deletion.

Priority: ⬇️ Low

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant StorageHealthPersistence
  participant HardwareService
  participant StorageHealthDispatch
  participant SQLite
  participant NativeBackend
  StorageHealthPersistence->>StorageHealthDispatch: Insert or refresh records
  StorageHealthDispatch->>SQLite: Route before native selection
  StorageHealthDispatch->>NativeBackend: Route after native selection
  HardwareService->>StorageHealthDispatch: Read latest records
  StorageHealthDispatch-->>HardwareService: Return records or DispatchError
  StorageHealthPersistence->>StorageHealthDispatch: Delete old records
  StorageHealthDispatch->>NativeBackend: Delete from selected native storage
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely states the main change: routing Storage Health through the database dispatch layer.
Description check ✅ Passed The description covers the change, motivation, implementation, scope boundaries, related issues, test plan, change type, and checklist. The optional Screenshots / Videos section is omitted, but the de…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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:feature PR: feature branch work area:core Area: Tauri-independent Core code area:tauri Area: Tauri app, commands, app wiring, or bundling labels Sep 16, 2026
@shm11C3
shm11C3 marked this pull request as ready for review September 16, 2026 17:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 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-16T17:52:55.456106Z c6c42bd Draft marked ready
🔒 Security Review ✅ Completed 2026-09-16T17:53:39.518165Z c6c42bd Draft marked ready
ℹ️ 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.

@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%         207                 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/startup.rs                                          188                87    53.72%          10                 3    70.00%         114                58    49.12%           0                 0         -
cli/mod.rs                                              155                18    88.39%          18                 0   100.00%         109                 9    91.74%           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                              43                43     0.00%          17                17     0.00%          45                45     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                                    371               310    16.44%          74                64    13.51%         309               269    12.94%           0                 0         -
commands/settings.rs                                    982               952     3.05%         157               154     1.91%         827               802     3.02%           0                 0         -
commands/system.rs                                       58                44    24.14%          18                15    16.67%          50                37    26.00%           0                 0         -
commands/ui.rs                                           17                17     0.00%           2                 2     0.00%          13                13     0.00%           0                 0         -
commands/updater.rs                                      97                97     0.00%          15                15     0.00%          66                66     0.00%           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                    892                 0   100.00%          59                 0   100.00%        1172                 0   100.00%           0                 0         -
lib.rs                                                  384               384     0.00%          17                17     0.00%         258               258     0.00%           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/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%         351                 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                            861               231    73.17%          92                28    69.57%         699               205    70.67%           0                 0         -
services/system_service.rs                               57                57     0.00%           7                 7     0.00%          40                40     0.00%           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                                           56                56     0.00%           2                 2     0.00%          32                32     0.00%           0                 0         -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                 11367              3794    66.62%        1153               524    54.55%        9479              2994    68.41%           0                 0         -

shm11C3 added a commit that referenced this pull request Sep 16, 2026
Reconciles this branch's own standalone SQLite-refusal fix (bff007e,
applied before this merge) with the same fix as it landed on the rest of
the stack (#2154 -> #2156 -> #2157). Conflicts were both "this branch
already has equivalent content the incoming side doesn't carry yet" -
Cooling's own submodules (already on resolve_backend()/Backend here) and
one restored doc comment - resolved by keeping this branch's content.

No functional change: `cargo check`/`clippy`/`nextest` all green before
and after, confirming the merge is a no-op over what PR #2161 already
shipped.
@shm11C3
shm11C3 added this pull request to stack #2165 September 19, 2026 07:42
@shm11C3
shm11C3 removed this pull request from stack #2165 September 19, 2026 07:46
@shm11C3
shm11C3 added this pull request to stack #2167 September 19, 2026 07:46
@shm11C3
shm11C3 removed this pull request from stack #2167 September 19, 2026 07:47
@shm11C3
shm11C3 added this pull request to stack #2168 September 19, 2026 07:47
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 19, 2026
Base automatically changed from feat/2134-route-raw-archive-families to develop September 19, 2026 08:04
Extends the #2134 dispatch boundary to Storage Health, reusing the same
boundary/DispatchError plumbing PR #2154 proved with Process Stats and
PR #2156 extended to the raw archive families. `insert_daily_records`,
`refresh_daily_records`, `delete_old_data` and `latest_records` now go
through `dispatch::storage_health` instead of calling
`infrastructure::database::storage_health` directly, in both the
persistence worker (`core/src/persistence/storage_health.rs`) and the App
service (`src-tauri/src/services/hardware_service.rs`).

`hardware_service::get_storage_health_latest_records`'s error type moves
from `sqlx::Error` to `dispatch::DispatchError`; its only caller already
formats the error as a string, so no other signature changes.

Cooling's six projections, both baselines and the cooling rollup
persistence remain unrouted - tracked separately, per the issue's explicit
allowance to say so rather than route silently to SQLite.
Follow-up to the merge of #2154's fix: Storage Health's four dispatch
functions now go through resolve_backend()/Backend like every other
routed family, so DispatchError::NativeUnavailable covers this branch's
consumer too instead of only the ones merged in from upstream.
@shm11C3
shm11C3 merged commit b0cda32 into develop Sep 19, 2026
79 checks passed
@shm11C3
shm11C3 deleted the feat/2134-route-storage-health branch September 19, 2026 08:27
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:feature PR: feature branch work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant