Skip to content

fix(swift-sdk): take migration copies out of WAL mode - #5070

Merged
llbartekll merged 2 commits into
v4.2-devfrom
fix/swift-sdk-legacy-bridge-wal-copy
Sep 28, 2026
Merged

llbartekll merged 2 commits into
v4.2-devfrom
fix/swift-sdk-legacy-bridge-wal-copy

Conversation

@romchornyi

@romchornyi romchornyi commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

After updating from App Store Dash Wallet 9.0.0 straight to 9.1.1, users see "Couldn't open your wallet data". Those stores are labelled 1.0.0 with a graph that does not match the frozen V1, so only DashLegacySchemaBridge (legacy-v1-bridge-to-v3) can open them, and on a device the bridge always fails with DashLegacyStoreSQLite.Failure.database("unable to open database file").

The cause is how the bridge copies the store. sqlite3_backup copies page 1 as it is, so a copy of a WAL store keeps the WAL header (bytes 18/19 = 2) but has no -wal/-shm beside it. integrityCheck(backup) then opens that copy with SQLITE_OPEN_READONLY. A read-only connection cannot create the -shm, so the first statement fails with SQLITE_CANTOPEN. Every app-written store is WAL. The committed fixtures are DELETE-mode, so the tests never exercised this.

What was done?

  • DashLegacyStoreSQLite.copy(from:to:): when the copy goes to a new scratch file (no lockedDestinationCheck), it now switches that copy to journal_mode=DELETE on the connection that wrote it, and fails if the mode does not change. This covers both original.store and candidate.store. Promotion into the live store is unchanged.

How Has This Been Tested?

  • DashLegacySchemaMigrationTests has two new tests:
    • testCopyOfWALStoreLeavesWALModeAndReadsReadOnly: a copy of a WAL store with uncheckpointed data has a DELETE header, can be read by a read-only connection, and keeps the WAL data.
    • testWALStoreSnapshotIsReadableBeforeMigration: at afterSnapshot the retained original.store is not in WAL mode and passes integrityCheck, and the migration completes.
    • Both tests assert the header bytes rather than a failed open, because on the macOS test host a read-only open of a WAL copy still succeeds. That is why the existing WAL tests stayed green.
  • swift test --filter DashLegacySchemaMigrationTests: the two new tests fail without the fix and pass with it; the suite is 37/37 with the fix. This ran on the v4.3-dev base, where the persistence sources and these tests are identical to v4.2-dev.
  • On a device, iPhone 13 Pro on iOS 18.7.8. I built dashwallet-ios at the App Store 9.1.1 (35) commit against SDK ecb9d20b80 plus this change, and installed it over App Store 9.1.1, which was failing on a real store written by App Store 9.0.0 (1013) (testnet, throwaway wallet). Before the change, the log showed integrityCheck(backup) → unable to open database file. After the change, the whole chain afterSnapshot → afterMigration → afterCommit → store_open_succeeded ran, validatePreservation passed, and the wallets open with their history.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 55f0587

  • Bots — coderabbitai skipped by romchornyi · thepastaclaw ✓
  • Self-review — posted; again after any push
  • Within your 5 open PRs
  • Build green
  • Approvals — you own every area touched; none needed

When every box is checked the PR Hygiene check passes and this can merge.

Summary by CodeRabbit

  • Bug Fixes
    • Database copies created without a locked destination now use DELETE journal mode, improving compatibility with read-only access.
    • Migration snapshots are validated for integrity, and committed updates remain available in the migrated store.
    • Copies and snapshots preserve committed data and remain readable after creation.

A SQLite backup copies page 1, so a copy of a WAL store keeps the WAL
header but has no -wal/-shm beside it. The legacy bridge then opens its
snapshot read-only for the integrity check; on iOS that connection cannot
create the -shm and fails with SQLITE_CANTOPEN ("unable to open database
file"). Every store written by App Store 9.0.0 is a WAL store that needs
the bridge, so updating straight to 9.1.1 showed "Couldn't open your
wallet data".

Switch each new copy to DELETE journal mode on the connection that wrote
it. Promotion into the live store is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 27, 2026
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 27, 2026
@coderabbitai

coderabbitai Bot commented Sep 27, 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: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8308439e-3b85-4ded-8cd1-b7687cb51dca

📥 Commits

Reviewing files that changed from the base of the PR and between eaa9d1e and ab2aaa4.

📒 Files selected for processing (2)
  • packages/swift-sdk/Sources/SwiftDashSDK/Persistence/DashLegacyStoreSQLite.swift
  • packages/swift-sdk/SwiftTests/SwiftDashSDKTests/DashLegacySchemaMigrationTests.swift

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


📝 Walkthrough

Walkthrough

SQLite copies without a locked destination check now switch to DELETE journal mode after backup. Tests verify the copied database’s journal format, integrity, and data, including migration snapshots.

Changes

SQLite copy journal mode

Layer / File(s) Summary
Copy journal mode and validation
packages/swift-sdk/Sources/SwiftDashSDK/Persistence/DashLegacyStoreSQLite.swift, packages/swift-sdk/SwiftTests/SwiftDashSDKTests/DashLegacySchemaMigrationTests.swift
Copies without a locked destination check switch to DELETE mode and throw if SQLite reports another mode. Tests verify journal-format bytes, integrity, read-only access, and preservation of WAL updates in migration snapshots.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: llbartekll

Merge Risk: ⚪ Minimal · up to ab2aa

The snapshot-format fix has no identified merge-blocking issue. Merge after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ab2aa

The change makes migration snapshots readable without WAL sidecar files while leaving live-store installation guarded. No new security exposure was identified in the traced migration path, but device-interruption behavior was not independently verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed write is confined to migration scratch copies of the configured store. The traced live-store installation does not take the new journal-conversion branch.

Trust Boundaries and Controls

  • observed — The configuration selects the source store, but migration requires a matching legacy identity and schema, validates scratch data, and rechecks the source digest while holding SQLite’s destination write lock before installation.

Resilience and Maintainability Implications

  • observed — A failed scratch conversion throws before the bridge validates or publishes that snapshot; the bridge’s unpublished-attempt cleanup and published-journal recovery remain separate paths.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: switching Swift SDK migration copies out of WAL mode.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

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

@thepastaclaw

thepastaclaw commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 55f0587) · triage: normal

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

Verified the findings against exact head ab2aaa4 and traced the snapshot, candidate, and locked-promotion callers. The journal-mode change is correctly limited to unlocked copies; no correctness or layering defect was confirmed, and only an ambiguous new comment warrants a nitpick. Validation was source inspection; tests were not independently rerun.

💬 1 nitpick(s)

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: architecture-layering); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: low by gpt-6-astra (effort low) — The diff adds a small, guarded journal-mode conversion in DashLegacyStoreSQLite.copy for scratch copies with two focused regression tests, leaving live-store promotion unchanged and lacking the size or intricacy required for critical.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — architecture-layering (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 95% left, weekly 27% left; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort medium); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort medium); agent phase2-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 `packages/swift-sdk/Sources/SwiftDashSDK/Persistence/DashLegacyStoreSQLite.swift`:
- [NITPICK] packages/swift-sdk/Sources/SwiftDashSDK/Persistence/DashLegacyStoreSQLite.swift:117-119: Clarify that the new copy is switched out of WAL mode
  The phrase "leave WAL on the new copy" can read as preserving WAL mode, whereas the following statement explicitly selects DELETE mode. Write "switch the new copy out of WAL mode" to make the direction of this fix unambiguous.

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Sep 27, 2026
@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Sep 27, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

Verified the complete PR diff and migration callers at head 55f0587. Scratch copies switch to DELETE mode after backup completion and verify the result, while locked live-store promotion remains unchanged; no actionable in-scope defects were found, and the prior comment finding is fixed. The added regression tests cover WAL-copy readability and migration snapshot integrity; git diff --check passed, but runtime tests were not independently rerun during this verification.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: architecture-layering); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — The diff changes SQLite storage-migration behavior and adds targeted tests, making it a small, contained logic fix, but it is not one of the defined critical surfaces such as consensus, funds, cryptography, or key handling.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — architecture-layering (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Sep 28, 2026
@romchornyi

Copy link
Copy Markdown
Contributor Author

/self-reviewed

@github-actions github-actions Bot removed the waiting-self-review Waiting for the author to post /self-reviewed label Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai review

No review for 55f05879 yet, so PR Hygiene is asking once. If nothing arrives, the requirement is dropped for this commit and the pull request is labelled bot-review-skipped.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Sep 28, 2026

@llbartekll llbartekll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 55f0587. The journal-mode conversion is limited to scratch copies after backup completion and verifies the resulting mode; locked promotion into the live store is unchanged.

Additional device validation: a store originating from App Store 9.0.1 failed on 9.1.1 (35) in the legacy-v1 bridge before afterSnapshot. With 9.1.2 (7), built from this exact PR head, the exported iPhone logs show the same source model checksum progressing through afterSnapshot, afterMigration, beforeInstall and afterCommit to store_open_succeeded. Wallet restoration and subsequent persistence writes succeeded. A separate app restart opened the existing V3 store successfully without rerunning the bridge, and persistence writes continued.

The Swift SDK build/tests and frozen-schema checks are green. No blocking findings. This device validation covers the tested 9.0.1 store; it does not claim coverage of every historical store layout.

@romchornyi

Copy link
Copy Markdown
Contributor Author

/skip-bots

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Sep 28, 2026
@romchornyi

Copy link
Copy Markdown
Contributor Author

/self-reviewed

@github-actions

Copy link
Copy Markdown
Contributor

Policy satisfied — this can merge.
Full checklist in the description.

@github-actions github-actions Bot removed the waiting-self-review Waiting for the author to post /self-reviewed label Sep 28, 2026
@llbartekll
llbartekll merged commit e826b8f into v4.2-dev Sep 28, 2026
33 checks passed
@llbartekll
llbartekll deleted the fix/swift-sdk-legacy-bridge-wal-copy branch September 28, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants