Repository navigation
fix(wallet): give access-denied migrations their own guidance - #1020
Conversation
- WalletDataIncompatible no longer tells users to remove local wallet data; it asks them to write down recovery phrases and imported keys, move only the .sqlite files aside and keep the secrets folder, whose imported and masternode keys no recovery phrase can restore. - The compatibility bridge backs up only after the staged copy validates, right before the rebuild, and keeps at most one backup per database. - Deterministic upgrade failures are terminal storage-open errors, so they surface instead of being silently retried; busy, disk-full and I/O failures stay retryable. - Removing a wallet or identity, or clearing a network's data, deletes the upgrade backups of det-app.sqlite and the network wallet database. - Upgrade and funding-persist errors name their actual cause (another instance, full disk, or neither) without disk-space or "account" jargon where it does not apply; the two identity-roster variants share one message. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Keep upstream migration snapshots bounded, validate backup candidates, and preserve pending identity cleanup until backup removal succeeds. Clarify private-key recovery and SQLite sidecar handling. Co-Authored-By: Codex <noreply@openai.com> <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Remove pending upgrade snapshots during retention and deletion without pruning an active backup or replacing a published recovery copy. Clean backups when removing a wallet even if its backend is unavailable. Preserve transient storage and memory failures while surfacing deterministic access errors. Co-Authored-By: Codex <noreply@openai.com> <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Serialize snapshot creation and cleanup across processes. Classify staged validation failures from their typed causes so temporary resource errors retain retry guidance while invalid data stays terminal. Co-Authored-By: Codex <noreply@openai.com> <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
…w-blocking-findings
A wallet-storage migration that fails on SQLite DiskFull, SystemIoFailure or OutOfMemory is recoverable by freeing the resource and retrying, but it was classified as terminal WalletDataIncompatible, showing move-the- databases-aside guidance and stopping the cold-boot retry bridge. Route those causes to the generic retryable WalletStorage variant; access failures (PermissionDenied, ReadOnly) keep their existing classification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
remove_backups aborted on the first backup candidate that failed validation (directory, symlink, hard link, live-database alias), leaving every valid snapshot of the removed wallet on disk. Deletion now scans tolerantly, removes all valid snapshots and then reports the first rejection. Retention and publication keep the strict fail-fast scan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A wallet-storage migration refused by file permissions or a read-only disk (SQLite PermissionDenied/ReadOnly, or io PermissionDenied/ ReadOnlyFilesystem in the cause chain) was reported as incompatible data, telling the user to set the databases aside. Surface it as a dedicated, terminal WalletStorageAccessDenied variant that asks the user to fix access to the data folder and restart, mirroring the staged upgrade's UpgradeError::AccessDenied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: dashpay/dash-evo-tool/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🕓 Queued for automated review — 11th in line, estimated start in ~8 h (commit 91426e4)
|
…w-blocking-findings # Conflicts: # src/backend_task/error.rs # src/backend_task/mod.rs # src/context/wallet_lifecycle/spv.rs
remove_backups returned Ok after plain unlinks, so identity cleanup could retire its retry manifest while a backup deletion was still volatile and could reappear after a power loss. Sync every directory a backup was removed from and fail the removal when a sync fails, keeping the manifest for the next retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ion fails Post-open backup retention is best-effort housekeeping. A failure there (stray entry, hard link, transient scan error) discarded an already-open persister, aborting app boot or deferring the wallet backend. Warn-log it instead; the pre-open retention check still runs strictly on the next open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rage-access-denied Resolve conflicts in the wallet-storage open classification: keep both WalletStorageAccessDenied (this branch) and WalletDataFolderInsecure (base) as terminal storage-open errors, list both in the from_wallet_storage_open_error docs, and assert both in terminal_storage_open_errors_are_classified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…de snapshot - A pre-open retention failure no longer blocks a database that needs no snapshot: a probe open with auto-backups disabled proves it is current (upstream refuses pending migrations before mutating), then it is reopened with the full config. Migrations and bridge upgrades still fail closed on the strict retention error. - Publish the replacement bridge snapshot (and sync its directory) before pruning superseded ones, so a failed publication keeps the previous recovery snapshot. The strict scan still runs before publication. - Backup removal syncs every existing backup directory on each call, so a retry settles an earlier failed directory sync before callers retire their cleanup manifest. - Identity removal wipes upgrade backups only for a listed identity or a resumed removal; an unknown id leaves unrelated snapshots alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Retention picked the survivor by mtime alone, so an empty or truncated file left by an interrupted copy under a final snapshot name could win and get an older complete snapshot deleted. Retention now keeps the newest snapshot that opens (immutable, read-only), passes PRAGMA quick_check and has a non-empty migration history; when none qualifies it deletes nothing. Clearing a network's data also records a legacy shielded-file removal failure instead of returning early, so upgrade backups are still removed and the clear is reported incomplete. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tries An unknown-id removal still leaves a vault-cleanup manifest behind, and a direct retry or the startup sweep treated that manifest as permission to delete every upgrade backup. Record the authorization in a dedicated Global marker, written only after the identity is confirmed listed and before it is delisted, and retire it as soon as the backups are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SQLITE_OPEN_NOFOLLOW rejects a symlink anywhere in the path, so snapshots under e.g. macOS /var/folders were never usable and retention kept every copy. Canonicalize the parent directory and keep the entry name, so a symlink at the snapshot itself is still refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…emoval The backup-removal marker was a bare flag, and a failed retirement was only logged: cleanup still reported complete, the manifest was retired, and a later removal of the already-absent identity read the orphaned marker and deleted every current upgrade snapshot, including ones taken after the identity was gone. The marker (key bumped to v2) now records the backup file names that exist while the identity is still listed, and cleanup deletes only those. A failed retirement leaves the removal incomplete, keeping the manifest so the startup sweep retries it; repeating the scoped deletion can no longer reach newer snapshots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…w-blocking-findings
…oval Identity removal no longer deletes storage-upgrade backups. The persisted per-identity cleanup marker, the captured backup scope, and the named-backup removal helpers are gone, along with their retry logic and tests. Removing an identity keeps the vault key manifest cleanup unchanged. Upgrade backups now expire after a configurable retention period, 90 days by default. Retention covers bridge snapshots, upstream pre-migration snapshots, and legacy data.db migration backups. A backup's age is taken from the later of its modification time and the timestamp in its name, so a reset or skewed signal can only delay deletion. Pruning runs once both databases have opened successfully, at startup and whenever the user changes the setting. An expired snapshot is removed only after the data it protects has opened successfully. The policy lives under its own app k/v key, det:upgrade_backup_retention:v1. It is not a field in the positional AppSettings blob, so older builds and existing installs still decode their settings. An unreadable policy deletes nothing. Settings gains an Upgrade Backups section where the user can change the period (1 to 3650 days) or keep backups forever. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Removing a wallet no longer deletes upgrade backups. Each backup copies a whole database, including the data of the other wallets, so deleting it with a single wallet destroys recovery snapshots the remaining wallets still depend on. Time-based retention decides when backups are removed. Clearing a network's data still deletes them. Replace the wallet-removal deletion tests with tests asserting the backups survive removal, with and without a wallet backend. Drop the test for the cleanup-failure warning, since removal no longer attempts that cleanup. Update the CHANGELOG, the upgrade notes, and user stories WAL-007/WAL-034. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Address QA findings on time-based upgrade-backup retention: - Settings asks for a danger-mode confirmation before saving a stricter policy (shorter period, or turning deletion on), because that deletes backups immediately. The saved result reports how many backups were deleted and shows it in a banner. - The form treats a policy as saved only once the backend confirms it. A failed save restores the previous inputs instead of showing a policy that was never persisted. An unreadable setting is shown as not loaded (nothing is deleted), and an explicit Save Setting button repairs it. - Legacy backup pruning refuses a symlinked or non-directory `backups` path, and counts a backup deleted concurrently by another prune as handled instead of failing. - Correct the user-story wording: a change applies right away only to shared and current-network backups. - Add tests for the ensure_wallet_backend prune wiring, for skipping the prune when the wallet open fails, for both branches of handle_update_backup_retention, and for rejecting malformed upstream timestamps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…usy frames Fix three issues found in QA of the retention settings form: - Results and errors of UpdateBackupRetention now go to the network chooser screen, as ClearNetworkDatabase results already do, rather than to whichever screen is visible. Navigating away while a save is in flight no longer leaves the form disabled or loses the result banner. - Ticking "Delete old upgrade backups automatically" no longer saves on its own. The user picks the period and then applies it with "Turn On Automatic Deletion". The confirmation shows the period the user chose instead of the 90-day default, so choosing 365 days never deletes backups that are 90 to 365 days old. - A save is queued and emitted only on a frame with no other screen action, and is marked in flight only once emitted. Another action on the same frame, such as the SDK reinit after DAPI discovery, can no longer overwrite the save and leave the form waiting forever. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All production file deletions now go through a new `utils::file_deletion::delete_file` (plus `delete_tree`, which unlinks each file through it). Before anything is unlinked, the chokepoint makes sure the target is a regular file. It then checks a hard deny-list by name: det-app.sqlite, data.db, every network's wallet and shielded DB, *.pwsvault, .env and *.premigration, each with its -wal/-shm/-journal sidecars. The same deny-list is checked again by canonical location and inode, which catches `..`, symlink, case and hard-link aliases. After that come a link-count check and the scope of the caller's `DeletionIntent`. - Backup: upgrade-engine and legacy data.db backup retention (legacy pruning now gets the live-DB and hard-link checks the engine already had) - NetworkClear: confined to spv/<network>/ and its lock, used by the SPV cache clear and the retired shielded-file cleanup - Log: rotated `<stem>.<ts>.log` files; works before AppContext exists The deliberate exceptions (tempfile self-cleanup, atomic renames) carry a comment at the call site. A sentinel test runs retention, wallet removal, identity removal, log rotation and a full testnet network clear against a data dir holding every network's databases, and asserts that every untargeted file is byte-identical afterwards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… chokepoint Published upgrade snapshots are now deleted only by the user's time-based retention: opening a database removes just crash-left `.pending` copies and byte-identical duplicates of a newer snapshot of the same migration (size check, then a streamed comparison), so "Keep forever" keeps every distinct snapshot while repeated failed upgrades no longer pile up copies. Retention is one global policy for every database in the data directory (app database and every network's wallet database, plus legacy data.db backups) and always keeps the newest backup of each database, whatever its age or the clock. A database whose lifecycle lock is held is skipped, and one without backups is not locked at all. A network clear removes only that network's wallet backups; det-app.sqlite backups stay under retention. Deletion chokepoint: Backup intents allow only the exact backup name grammar of their database; delete_tree scope-checks every directory and walks iteratively; a network clear unlinks symlinked SPV entries without following them; Windows refuses alias-prone names; clippy.toml disallows raw fs remove calls. One shared prune helper, one storage-failure classifier, shared file-name constants, a single rotated-log grammar. UI: out-of-range retention days stay visible with an error instead of being clamped and saved, singular confirmation copy, the form re-syncs on arrival so a lost result cannot wedge it, and cleanup failures carry details. Docs (CHANGELOG, WAL-034, upgrade notes, AGENTS.md) describe the new behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… holds `flock` belongs to the open file description, and a child forked by any thread of this process shares that description until it execs. A lifecycle lock that was just released could therefore still look held, so an open or backup failed with a retryable "storage unavailable" error whenever another thread spawned a process at that moment (seen as a CI flake in platform_compatibility_failed_publication_keeps_previous_snapshot). Contended locks are now retried for a 500 ms grace period before reporting WouldBlock. A regression test re-acquires the lock while processes spawn alongside; it fails without the grace period. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…open copies The retention floor could keep an empty or truncated newest file while deleting the only complete snapshot. The floor is now the newest backup that passes a cheap structural SQLite check (magic, page size, file size covering every page the header claims, no hot rollback journal), for bridge, upstream and legacy backups alike. If nothing passes, the newest file is still kept. The floor no longer trusts a skewable clock alone: backups dated more than a day in the future do not displace one dated in the past, and the upstream snapshot of the latest migration (a clock-independent order) is kept too. The failed-open bound test depended on the umask: with a group-writable temp dir upstream refused the open before snapshotting, so it passed locally but failed in CI, where upstream writes a real pre-migration copy per failed open. It now uses an owner-only data dir and asserts that the real copies collapse to one. Also: one SPV directory helper, typed scan-classification errors, a shared lifecycle-lock path helper, truthful and shared cleanup-retry wording, and stale comments fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The retention check treated an unreadable backup as unusable, so a read error on the newest snapshot handed the floor to an older copy and let the newest one expire. Usability is now three-way: usable, unusable, or undetermined. Undetermined covers a file that cannot be read (also reported, so the pass retries) and a complete-looking file with a non-empty rollback journal beside it. Undetermined backups are never deleted automatically and never displace the newest usable one. Legacy data.db backups are now written to a pending file, synced and renamed without overwriting, so a crash cannot leave a torn copy under a backup name. The clock-skew limit is documented and pinned by a test: a future-dated backup stops being de-preferred once real time reaches its date. WAL-034, the CHANGELOG and the upgrade notes now mention the no-usable-backup fallback. Also: misplaced doc comment and test in error.rs, and the SPV root directory now comes from one helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A legacy data.db backup interrupted before its rename left a `<backup name>.<random>.pending` file that nothing ever removed. Every retention pass now sweeps such copies, whatever the policy, once they are more than a day old (so a copy still being written is left alone). Only the exact temporary-name grammar qualifies, and the deletion chokepoint's legacy allow-list accepts that grammar and nothing looser. WAL-034 now states the accepted clock limit instead of promising the floor holds whatever the system clock does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Legacy backup names have one-second resolution, and the non-clobbering publish returned AlreadyExists when a backup of the same second existed, aborting startup through backup_db. The copy is now published under the next free second (up to 60 tries), which keeps the data_backup_<ts> grammar and the chokepoint allow-list, never overwrites an existing backup, and leaves no temporary copy behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rage-access-denied Resolve the storage-classification conflict onto the unified StorageFailure policy: access-denied migrations now map via StorageFailure::in_chain(..) == Some(AccessDenied), dropping the duplicate cause-chain helpers. Fold the access-denied CHANGELOG line into the relocated "Safer guidance" Fixed entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Verified the supplied findings against exact head bdfe963 and the stated PR base. The migration-only classification preserves typed sources, shares the existing storage-failure policy, and reaches both terminal-error consumers correctly; two documentation nitpicks remain, with no blocking issues or functional suggestions. This verification used source inspection; tests were not independently rerun.
💬 2 nitpick(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
💬 Nitpick: Update the dispatch comment to include access-denied storage failures
src/backend_task/mod.rs:1219-1224
The new WalletStorageAccessDenied variant is terminal through is_terminal_storage_open_error, but this callsite's comment still lists only newer/incompatible data and an insecure folder before describing every other initialization error as transient. The behavior is correct; update the comment so it does not imply that access-denied migrations are deferred and retried.
// Terminal storage-open failures include newer/incompatible data,
// access-denied or insecure data folders, and non-retryable
// compatibility upgrades. Surface their actionable messages instead
// of the misleading generic "deferred" banner. Every other init
// error is a transient deferral the cold-boot bridge retries.
source: glm-5.3-flash (phase1-reviewer: general, rust-quality)
Review provenance
Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.1-sol(effort low) — The diff is a small, contained change to typed migration-error classification and user guidance in src/backend_task/error.rs and terminal-error handling in src/backend_task/mod.rs, with focused tests and no changes to migration execution or stored data. - Phase 1 reviewers:
glm-5.3-flash— general (completed, effort high); agentphase1-reviewer,glm-5.3-flash— rust-quality (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 98% left, weekly 80% left; passed overgemini-3.8-flash-high(antigravity below 15% reserve: weekly 13% left, 5h 100% left) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort medium); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `src/backend_task/mod.rs`:
- [NITPICK] src/backend_task/mod.rs:1219-1224: Update the dispatch comment to include access-denied storage failures
The new WalletStorageAccessDenied variant is terminal through is_terminal_storage_open_error, but this callsite's comment still lists only newer/incompatible data and an insecure folder before describing every other initialization error as transient. The behavior is correct; update the comment so it does not imply that access-denied migrations are deferred and retried.
In `src/backend_task/error.rs`:
- [NITPICK] src/backend_task/error.rs:6186-6189: Generalize the renamed SQLite migration helper's documentation
The helper was renamed to sqlite_migration_error and now also constructs SQLITE_PERM and SQLITE_READONLY fixtures for the new access-denied test. Its documentation still says it represents a migration that ran out of a resource, which no longer describes all its uses. Describe the supplied SQLite failure code rather than resource exhaustion.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- Access-denied failures outside a pending migration still get the generic disk-space copy — Outside the explicitly stated migration-only scope. The generic fallback already exists on the PR base, and the existing io_storage_error_maps_to_wallet_storage test preserves plain Io(PermissionDenied) as retryable. Changing guidance for non-migration errors is an adjacent design improvement, not an exceptional follow-up required by this PR.
- Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.
Preserve the merged backup lifecycle and shared storage failure policy, retaining the access-denied variant and regression tests. Generalize the SQLite fixture documentation.
|
/skip-bots |
TL;DR: When the app can't write to its data folder, it now tells the user to check folder permissions instead of telling them their wallet data is incompatible.
User story
As an Everyday User, I want a clear, accurate message when the app can't open my wallet data because of folder permissions, to fix the real cause without taking unnecessary and scary recovery steps.
Scenario
Base flow
The user starts the app. The wallet data folder is on a read-only disk, or the user has no write permission to it, and the wallet database needs a schema upgrade on open.
Actual behavior
The app shows the "wallet data was saved by an app version that this version cannot open" guidance. It tells the user to open an older app version, write down every recovery phrase, and move the database files out of the data folder, even though nothing is wrong with the data.
Expected behavior
The app says it isn't allowed to change its data folder. It asks the user to make sure the folder isn't on a read-only disk and that they have permission to change it, then restart:
Detailed discussion
What was done
TaskError::WalletStorageAccessDenied { #[source] source: WalletStorageError }. It has noStringfields and is terminal (added tois_terminal_storage_open_error), mirroring the non-retryableUpgradeError::AccessDeniedinplatform_compatibility.from_wallet_storage_open_errorclassifiesWalletStorageError::Migrationin this order: in use (busy or locked), then resource exhausted (disk full, I/O, out of memory), then access denied, then incompatible. Access denied is detected from the typed cause chain: SQLitePermissionDenied/ReadOnly, orio::ErrorKind::PermissionDenied/ReadOnlyFilesystem. This is the same setplatform_compatibilityuses. No error strings are parsed.StorageFailure::in_chainclassifier from the wallet compatibility layer.WalletStorageError::Io(PermissionDenied)outside a migration stays the retryableWalletStorage(covered by the existing WB-001 test). A transient file-lock denial on Windows can show up asPermissionDenied, and making it terminal would stop retries.Targets
v1.0-devand uses the shared storage-failure policy introduced by #994.Testing
access_denied_storage_errors_map_to_wallet_storage_access_denied. It covers SQLitePERMandREADONLY, plus ioPermissionDeniedandReadOnlyFilesystem, wrapped the way refinery wraps them. It asserts the variant, that the error is terminal, the message wording, and that the source is kept.terminal_storage_open_errors_are_classifiedto cover the new variant.cargo test --all-features --lib -- migration_error storage terminal_storage_open, 69 passed.Breaking changes
None.
Checklist
cargo fmt --allcargo clippy --all-features --lib -- -D warningsPrior work
Attribution
🤖 Co-authored by Claudius the Magnificent AI Agent
🤖 Generated with Claude Code
PR Hygiene ·
91426e4/skip-botsproceeds without the ones not yet reportedCHANGELOG.md,src/backend_task/error.rs,src/backend_task/mod.rs) — lklimekWhen every box is checked the
PR Hygienecheck passes and this can merge.Summary by CodeRabbit