Repository navigation
feat(tauri): add the App-owned native database conversion driver - #2158
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: shm11C3/HardwareVisualizer/.coderabbit.yml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
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. 📝 WalkthroughWalkthroughThe PR adds an App-owned native database conversion flow with resumable files, cancellation, producer coordination, lifecycle recovery, SQLite write checks, and coordinated startup cleanup. Space planning now accounts for an existing finalized file. ChangesNative database conversion
Priority: ➖ Normal Estimated code review effort: 5 (Critical) | ~90 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant App
participant run_conversion
participant WorkersState
participant NativeDatabase
participant Lifecycle
App->>run_conversion: start conversion
run_conversion->>WorkersState: pause and drain producers
run_conversion->>NativeDatabase: build and select database
run_conversion->>Lifecycle: record authority or recovery state
run_conversion->>WorkersState: resume producers
run_conversion-->>App: return conversion outcome
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Update: #2134 has landed its dispatch boundary at `core/src/infrastructure/database/dispatch.rs` (PRs #2154, #2156, #2157), with `dispatch::init(paths, expected_schema_version) -> bool` at startup next to `db::init`, and `dispatch::reobserve_authority() -> Result<AuthorityState, NativeDatabaseError>` to call after every successful `select_native_database` — it closes any live owner and adopts one fresh `NativeDatabase` only when the state is `NativeSelected`. This PR does not depend on that branch and is unchanged. For future reference: this PR's `open_selected_database` (called right after `select_native_database` succeeds in `reconcile_and_select`, inside `src-tauri/src/app/native_conversion.rs`) is exactly the call site `dispatch::reobserve_authority()` should replace once both branches land — same trigger (a successful selection), same job (hand the freshly selected database to whatever holds it for consumers), different owner. The `// #2134 seam:` on `NativeLifecycleOwner` in #2155 is the other half of that reconciliation. Left as a follow-up integration rather than changed here, since this PR must not depend on an unlanded branch. |
Rust Tauri Coverage ReportCoverage Details |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4adefdc37f
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Fixes four review findings on #2158 (Codex). Verified each against the current code before acting; all four were real. 1. (P1) Quiesce the on-demand Storage Health writer. commands::hardware::refresh_storage_devices writes through refresh_storage_health_for_date directly, on the caller's own request, independently of StorageHealthController - so it was not covered by pause_and_drain_producers and could commit a row absent from the candidate reconciliation had already captured, silently losing it once the native database was selected. It is also unsafe once native authority is already selected, whether or not a conversion is running: the source may already be retired, and refresh_storage_health_for_date opens SQLite with create_if_missing. Added app::native_lifecycle::sqlite_source_is_authoritative (true only for SqliteAuthoritative/ConversionRecoverable) and app::database_availability::ensure_sqlite_writable built on it; the command now refuses with a typed error for the whole window SQLite is not the live source, not just while a conversion is actively reconciling. 2. (P2) Discard stale conversion work before restarting. A `resumable: false` restart left any `.hardwarevisualizer-duckdb-*` directory already in the workspace untouched, so debris from a crashed attempt could grow unbounded across repeated restarts and could make the next attempt's own preflight fail for lack of space. discard_stale_conversion_work removes recognized debris directories before preflight measures available space, on every entry (not just the non-resuming branch, since a resumable ConversionInProgress can also carry leftover reconcile/runtime debris from a later crash). 3. (P2) Budget only remaining work when resuming. A resumed conversion skips finalization, but preflight still required candidate+finalized+workspace bytes free - since the finalized file already exists and the available-space measurement already excludes it, this double-counted roughly a full source-sized artifact and could refuse a resume the original preflight had already guaranteed enough space for. Core's conversion_space_requirement/plan_conversion_space gain a finalized_already_exists parameter that zeroes the finalized term; the driver passes resume_from_reconciliation. 4. (P2) Record and retry a post-selection open failure. If opening the newly selected database failed right after selection committed, the driver logged the error but still returned Selected, leaving the owner claiming progress with no open database and no way to recover without a process restart - `NativeAuthoritative` at entry returned AlreadySelected unconditionally, never attempting to open. Added LifecycleIssue::NativeOpenFailed and fail_open (distinct from fail: the selection itself did not fail); the entry path for NativeAuthoritative now always attempts open_selected_database rather than assuming success, which also fixes a related case surfaced while testing this: a *fresh* NativeLifecycleOwner (a later call, or #2136 constructing a new one) hitting an already-selected database would previously report AlreadySelected without ever opening it, leaving its own seam permanently empty. New tests: discard_stale_conversion_work (removes only recognized debris, no-op on a clean workspace), a fresh owner correctly opens an already-selected database instead of assuming it is open, a concurrently held database is reported ActionRequired rather than silently skipped (also documents why inspect_startup_authority itself, not the NativeAuthoritative branch, is what refuses in that specific case - observe_authority cannot read metadata from a file another instance holds either), plus Core preflight tests for the finalized_already_exists parameter and sqlite_source_is_authoritative's decision table. Test commands: cargo fmt --all -- --check; cargo clippy -p hardviz-core --features duckdb-archive --all-targets -- -D warnings; cargo clippy -p hardware_visualizer --features duckdb-archive --all-targets -- -D warnings; cargo clippy -p hardware_visualizer --all-targets -- -D warnings (feature off); cargo test -p hardware_visualizer --features duckdb-archive --lib -- --test-threads=1 (344 passed); cargo run --bin export_bindings --features bindings-export (no bindings.ts diff).
3437114 to
29c2dca
Compare
29c2dca to
8654c6f
Compare
Fixes four review findings on #2158 (Codex). Verified each against the current code before acting; all four were real. 1. (P1) Quiesce the on-demand Storage Health writer. commands::hardware::refresh_storage_devices writes through refresh_storage_health_for_date directly, on the caller's own request, independently of StorageHealthController - so it was not covered by pause_and_drain_producers and could commit a row absent from the candidate reconciliation had already captured, silently losing it once the native database was selected. It is also unsafe once native authority is already selected, whether or not a conversion is running: the source may already be retired, and refresh_storage_health_for_date opens SQLite with create_if_missing. Added app::native_lifecycle::sqlite_source_is_authoritative (true only for SqliteAuthoritative/ConversionRecoverable) and app::database_availability::ensure_sqlite_writable built on it; the command now refuses with a typed error for the whole window SQLite is not the live source, not just while a conversion is actively reconciling. 2. (P2) Discard stale conversion work before restarting. A `resumable: false` restart left any `.hardwarevisualizer-duckdb-*` directory already in the workspace untouched, so debris from a crashed attempt could grow unbounded across repeated restarts and could make the next attempt's own preflight fail for lack of space. discard_stale_conversion_work removes recognized debris directories before preflight measures available space, on every entry (not just the non-resuming branch, since a resumable ConversionInProgress can also carry leftover reconcile/runtime debris from a later crash). 3. (P2) Budget only remaining work when resuming. A resumed conversion skips finalization, but preflight still required candidate+finalized+workspace bytes free - since the finalized file already exists and the available-space measurement already excludes it, this double-counted roughly a full source-sized artifact and could refuse a resume the original preflight had already guaranteed enough space for. Core's conversion_space_requirement/plan_conversion_space gain a finalized_already_exists parameter that zeroes the finalized term; the driver passes resume_from_reconciliation. 4. (P2) Record and retry a post-selection open failure. If opening the newly selected database failed right after selection committed, the driver logged the error but still returned Selected, leaving the owner claiming progress with no open database and no way to recover without a process restart - `NativeAuthoritative` at entry returned AlreadySelected unconditionally, never attempting to open. Added LifecycleIssue::NativeOpenFailed and fail_open (distinct from fail: the selection itself did not fail); the entry path for NativeAuthoritative now always attempts open_selected_database rather than assuming success, which also fixes a related case surfaced while testing this: a *fresh* NativeLifecycleOwner (a later call, or #2136 constructing a new one) hitting an already-selected database would previously report AlreadySelected without ever opening it, leaving its own seam permanently empty. New tests: discard_stale_conversion_work (removes only recognized debris, no-op on a clean workspace), a fresh owner correctly opens an already-selected database instead of assuming it is open, a concurrently held database is reported ActionRequired rather than silently skipped (also documents why inspect_startup_authority itself, not the NativeAuthoritative branch, is what refuses in that specific case - observe_authority cannot read metadata from a file another instance holds either), plus Core preflight tests for the finalized_already_exists parameter and sqlite_source_is_authoritative's decision table. Test commands: cargo fmt --all -- --check; cargo clippy -p hardviz-core --features duckdb-archive --all-targets -- -D warnings; cargo clippy -p hardware_visualizer --features duckdb-archive --all-targets -- -D warnings; cargo clippy -p hardware_visualizer --all-targets -- -D warnings (feature off); cargo test -p hardware_visualizer --features duckdb-archive --lib -- --test-threads=1 (344 passed); cargo run --bin export_bindings --features bindings-export (no bindings.ts diff).
8654c6f to
126e486
Compare
Second of three stacked changes for #2135. Adds the driver that runs the whole conversion in order (preflight, candidate, finalize, pause every database producer, reconcile, select, resume every producer), calling Core's operations on paths the caller resolves rather than a hardcoded location, so it is fully testable without touching the real app-data directory. - app::native_conversion::run_conversion is the entry point. Its own entry is always decided by re-inspecting on-disk authority (inspect_startup_authority), never by trusting a previous call's memory, so a restart after any interruption resumes or discards cleanly and a second call after a successful selection is a no-op (guarded before touching disk at all, since observe_authority cannot safely reopen a native file the #2134 seam already holds open - see the code comment for the exact hazard this avoids). - Cancellation (ConversionCancellation) is checked only between steps, never inside an awaited Core call: build_candidate_database, finalize_candidate_database and reconcile_native_database accept no token, and their own documentation warns that dropping the future does not stop the blocking write. Every step's own persisted artifact is already exactly what a restart resumes or discards from. - Producers (ArchiveController, CoolingRollupController, StorageHealthController, and now the previously fire-and-forget startup retention cleanup) are paused and drained immediately before reconciliation and always resumed afterward, success or failure - reconciliation captures a fresh candidate from the live source, and selecting one a writer changed after that capture would silently drop whatever was written in between. - workers::WorkersState gains a scheduled_cleanup handle so both terminate_all (final App shutdown) and this driver's pause/drain can wait for a still-running startup retention pass instead of racing it. Six integration tests build a real SQLite source through App's own migrations and exercise: a fresh conversion end to end; a real ArchiveController actually drained and a fresh one running afterward; resuming from a finalized-but-unselected file (skips candidate/finalize); cancellation before any copy, leaving SQLite authoritative with nothing written; a missing source database failing cleanly at preflight; and a second call after selection being a no-op. Core's own preflight tests already cover disk-exhaustion refusal with exact numbers; this driver's preflight failure path is exercised here through the missing-source case instead of duplicating that coverage. Not wired into lib.rs: #2136 adds the explicit user-triggered flow that calls run_conversion. Until then this has no effect on any running installation, matching the previous stacked change.
Fixes four review findings on #2158 (Codex). Verified each against the current code before acting; all four were real. 1. (P1) Quiesce the on-demand Storage Health writer. commands::hardware::refresh_storage_devices writes through refresh_storage_health_for_date directly, on the caller's own request, independently of StorageHealthController - so it was not covered by pause_and_drain_producers and could commit a row absent from the candidate reconciliation had already captured, silently losing it once the native database was selected. It is also unsafe once native authority is already selected, whether or not a conversion is running: the source may already be retired, and refresh_storage_health_for_date opens SQLite with create_if_missing. Added app::native_lifecycle::sqlite_source_is_authoritative (true only for SqliteAuthoritative/ConversionRecoverable) and app::database_availability::ensure_sqlite_writable built on it; the command now refuses with a typed error for the whole window SQLite is not the live source, not just while a conversion is actively reconciling. 2. (P2) Discard stale conversion work before restarting. A `resumable: false` restart left any `.hardwarevisualizer-duckdb-*` directory already in the workspace untouched, so debris from a crashed attempt could grow unbounded across repeated restarts and could make the next attempt's own preflight fail for lack of space. discard_stale_conversion_work removes recognized debris directories before preflight measures available space, on every entry (not just the non-resuming branch, since a resumable ConversionInProgress can also carry leftover reconcile/runtime debris from a later crash). 3. (P2) Budget only remaining work when resuming. A resumed conversion skips finalization, but preflight still required candidate+finalized+workspace bytes free - since the finalized file already exists and the available-space measurement already excludes it, this double-counted roughly a full source-sized artifact and could refuse a resume the original preflight had already guaranteed enough space for. Core's conversion_space_requirement/plan_conversion_space gain a finalized_already_exists parameter that zeroes the finalized term; the driver passes resume_from_reconciliation. 4. (P2) Record and retry a post-selection open failure. If opening the newly selected database failed right after selection committed, the driver logged the error but still returned Selected, leaving the owner claiming progress with no open database and no way to recover without a process restart - `NativeAuthoritative` at entry returned AlreadySelected unconditionally, never attempting to open. Added LifecycleIssue::NativeOpenFailed and fail_open (distinct from fail: the selection itself did not fail); the entry path for NativeAuthoritative now always attempts open_selected_database rather than assuming success, which also fixes a related case surfaced while testing this: a *fresh* NativeLifecycleOwner (a later call, or #2136 constructing a new one) hitting an already-selected database would previously report AlreadySelected without ever opening it, leaving its own seam permanently empty. New tests: discard_stale_conversion_work (removes only recognized debris, no-op on a clean workspace), a fresh owner correctly opens an already-selected database instead of assuming it is open, a concurrently held database is reported ActionRequired rather than silently skipped (also documents why inspect_startup_authority itself, not the NativeAuthoritative branch, is what refuses in that specific case - observe_authority cannot read metadata from a file another instance holds either), plus Core preflight tests for the finalized_already_exists parameter and sqlite_source_is_authoritative's decision table. Test commands: cargo fmt --all -- --check; cargo clippy -p hardviz-core --features duckdb-archive --all-targets -- -D warnings; cargo clippy -p hardware_visualizer --features duckdb-archive --all-targets -- -D warnings; cargo clippy -p hardware_visualizer --all-targets -- -D warnings (feature off); cargo test -p hardware_visualizer --features duckdb-archive --lib -- --test-threads=1 (344 passed); cargo run --bin export_bindings --features bindings-export (no bindings.ts diff).
126e486 to
dd831d7
Compare
|
@coderabbitai approve |
|
✅ Action performedComments resolved and changes approved. |
…2164) * feat(database): checkpoint after native expiry and retire the SQLite source Adds NativeDatabase::checkpoint (one write-lane CHECKPOINT, per the retention evidence), retires the SQLite source by renaming it in place on a later verified native startup, and records the App lifecycle state vocabulary in the Design Doc. Rebuilt on develop after #2155 and #2158 were squash-merged; the checkpoint tests moved to core/tests/duckdb/native.rs with #2171's test layout. * docs(design): describe the lifecycle vocabulary as a projection of AuthorityState Two Core states map onto ConversionRecoverable, and ActionRequired also carries NativeOpenFailed, so 'lossless translation' overstated it. * test(database): assert the row written before the checkpoint survives it The fixture already holds process rows, so a non-empty result proved nothing. Also narrow the Design Doc's single-source claim: inspect_startup_authority is the only reader of Core's authority inspection, while the conversion driver and the native open path also produce lifecycle states. * feat(database): run the application on the selected native backend Fold the #2135 lifecycle onto the #2134 dispatch boundary: one startup decision (resolve_native_authority) that dispatch only adopts, the conversion driver handing the selected database to dispatch inside the paused block, producers starting on a native-authoritative boot, the expiry pass ending with dispatch::checkpoint, and shutdown closing the boundary after the writers drain. Includes the review fixes for the hand-over (explicit SelectionHandoff, NativeSelected as the only success, short-circuit while dispatch owns the file). * fix(tauri): keep producers paused when the selected database is not served Address review on #2164. Inside the paused block ActionRequired means the selection is durable but opening the database or handing it to dispatch failed, so SQLite is stale and dispatch either still routes to it or refuses every consumer. Producers now stay stopped in that case, as they do after a startup that ends in ActionRequired, and the entry path that later completes the hand-over restarts them if none are running. The conversion integration test drains its workers through terminate_all instead of closing dispatch underneath them, and the schema definitions comment names the startup function that replaced initialize_native_database_dispatch.
Summary
Second of three stacked changes for #2135, based on #2155 (App path
resolution and startup authority inspection). Adds the driver that runs
the whole native database conversion in order: preflight, candidate
capture, finalization, pausing every database producer, reconciliation,
durable selection, then resuming every producer.
app::native_conversion::run_conversionis the entry point. Paths andthe workspace directory are caller-supplied parameters rather than
resolved internally, so the driver never depends on the real app-data
directory and every scenario below runs against a temporary one.
(
inspect_startup_authority, from feat(tauri): own native database path resolution and startup authority #2155), never by trusting what aprevious call thinks it left behind — a restart after any interruption
resumes at the right step or discards and restarts, and a second call
after a successful selection is a no-op. That last case needed a guard
before touching disk at all:
observe_authorityhas to open thenative file as a second DuckDB instance to read its metadata, and
DuckDB refuses a second instance on a file the
// #2134 seam:mayalready hold open from a prior call in the same process. Found by the
"call it twice" test below; see the code comment at the top of
run_conversion.ConversionCancellationis checked only between steps, never insidean awaited Core call:
build_candidate_database,finalize_candidate_databaseandreconcile_native_databaseaccept notoken, and their own documentation warns that dropping the future does
not stop the blocking write underneath it. Every step's own persisted
artifact is already exactly what a restart resumes or discards from, so
there is nothing extra to clean up at a cancellation boundary.
ArchiveController,CoolingRollupController,StorageHealthController, and now the startup retention cleanup, whichwas previously fire-and-forget) is paused and drained immediately before
reconciliation and always resumed afterward regardless of outcome —
reconciliation captures a fresh candidate from the live source, and
selecting one a writer changed after that capture would silently drop
whatever was written in between.
workers::WorkersStategains ascheduled_cleanuphandle so bothterminate_all(final App shutdown) and this driver's pause/drain canwait for a still-running startup retention pass instead of racing it —
a small pre-existing gap (the pass was previously unjoined even at
process shutdown) that this change's own "drain every producer"
requirement exposed.
Why / What / How / Why not
producers, handles cancellation and copy failure, and resumes cleanly
at every persistent boundary, stacked after path resolution.
above. Nothing else.
rather than remembered state (correctness after interruption).
calls: they do not accept a token, and the module doc explains why
checking only between steps is the correct boundary rather than a
workaround. Why not wire this into
lib.rs: nothing triggers aconversion yet — that explicit user flow is feat(database): surface the DuckDB conversion as an explicit user flow #2136's scope, so wiring it
here would be dead integration ahead of its caller.
Related Issues
Towards #2135. Stacked on #2155.
Type of Change
feat/branch)Test Plan
cargo test -p hardware_visualizer --features duckdb-archive --lib -- --test-threads=1— 334 passed (6 new: fresh conversion; a realArchiveControllerdrained and a fresh one running afterward; resuming from a finalized-but-unselected file; cancellation before any copy; a missing source database failing cleanly at preflight; a second call after selection being a no-op)preflight.rstests; this driver's preflight failure path is exercised here via the missing-source case rather than duplicatedChecklist
cargo fmt --all -- --check;cargo clippy -p hardviz-core --features duckdb-archive --all-targets -- -D warnings;cargo clippy -p hardware_visualizer --features duckdb-archive --all-targets -- -D warnings;cargo clippy -p hardware_visualizer --all-targets -- -D warnings(feature off) — all clean🤖 Generated with Claude Code
Summary by CodeRabbit