Skip to content

fix: migrate legacy backups missing wallet id on restore#619

Open
coreyphillips wants to merge 1 commit into
chore/bump-bitkit-core-0.3.9from
fix/backup-wallet-id-migration
Open

fix: migrate legacy backups missing wallet id on restore#619
coreyphillips wants to merge 1 commit into
chore/bump-bitkit-core-0.3.9from
fix/backup-wallet-id-migration

Conversation

@coreyphillips

Copy link
Copy Markdown
Contributor

Summary

Stacked on #617. Legacy backups that predate wallet-scoped activity data fail to decode on restore because their activity, tag and pre-activity-metadata records have no wallet id, and with bitkit-core 0.4.0 those records require one. The decode throws before the records reach Core.

Approach

Before decoding a restored envelope, each Core-owned array (activities, activityTags, tagMetadata) is handed to the matching bitkit-core migration helper as raw JSON:

  • migrateBackupActivitiesJson
  • migrateBackupActivityTagsJson
  • migrateBackupPreActivityMetadataJson

Core fills in the default wallet id for records that lack one (or have it empty) and preserves any existing non-default id such as trezor:{hash}. The app only extracts and reinserts the sub-arrays via JSONSerialization, so it never edits Core model JSON itself. The helpers are idempotent, so current backups that already carry a wallet id are unaffected.

This is the iOS half of synonymdev/bitkit-core#113; the migration APIs it calls shipped in bitkit-core 0.4.0.

Changes

  • BackupService.swift: add migrateCoreOwnedBackupFields and apply it at the .activity and .metadata restore sites.
  • Bump bitkit-core to 0.4.0 (pbxproj + Package.resolved).

Notes

Backups written before activity data became wallet-scoped have no wallet id on
their activity, tag and pre-activity-metadata records. With bitkit-core 0.4.0
those records require a wallet id, so decoding such a backup throws before the
records reach Core.

Before decoding a restored envelope, hand each Core-owned array to the matching
bitkit-core migration helper (migrateBackupActivitiesJson,
migrateBackupActivityTagsJson, migrateBackupPreActivityMetadataJson), which
fills in the default wallet id for records that lack one and preserves any
existing id. The app never edits Core model JSON itself, and current backups
that already carry a wallet id are unaffected.

Bumps bitkit-core to 0.4.0.
@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a restore-time migration for legacy Core backup data. The main changes are:

  • Bumps bitkit-core from 0.3.9 to 0.4.0.
  • Migrates activities and activityTags before activity backup decoding.
  • Migrates tagMetadata before metadata backup decoding.
  • Adds a helper to extract, migrate, and reinsert Core-owned JSON arrays.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The restore changes are scoped to the Core-owned backup arrays before the existing decode and upsert flow.

Important Files Changed

Filename Overview
Bitkit/Services/BackupService.swift Adds restore-time migration for Core-owned activity and metadata backup arrays before decoding.
Bitkit.xcodeproj/project.pbxproj Updates the bitkit-core package requirement to 0.4.0.
Bitkit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved Updates the resolved bitkit-core revision and version.

Reviews (1): Last reviewed commit: "fix: migrate legacy backups missing wall..." | Re-trigger Greptile

@coreyphillips coreyphillips requested a review from jvsena42 July 8, 2026 14:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8cd698d5c0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +214 to +217
let migrated = try self.migrateCoreOwnedBackupFields(dataBytes, fieldMigrations: [
"activities": migrateBackupActivitiesJson,
"activityTags": migrateBackupActivityTagsJson,
])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add the required changelog fragment

This commit is a user-facing fix: because it restores legacy backups that otherwise fail to decode, but it does not add a fragment under changelog.d/next/; root AGENTS.md says “ALWAYS add exactly ONE changelog fragment for user-facing feat: and fix: PRs”. Without the fragment, release automation will omit this restore fix from the release notes.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants