Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): preserve saved environments across catalog recovery #8923

Closedglopyglerky(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/8923/headopened View on GitHub

Summary

  • mirror each successfully encoded mobile connection catalog to a backup SecureStore key before publishing the primary value
  • recover a missing or undecodable primary catalog from that backup and restore the primary key
  • fail closed without deleting the only saved catalog when no valid backup exists
  • preserve the existing legacy migration path while seeding both durable copies

Why

The mobile catalog currently keeps connection targets, profiles, and credentials in one SecureStore document. If that document cannot be decoded, startup deletes it and continues with an empty catalog. A transient or version-related decode failure can therefore make every saved environment disappear and force the user to pair again.

This change keeps a last-known-good copy and treats unrecoverable catalog damage as an explicit persistence error instead of destructive empty state.

Verification

  • vp fmt --check apps/mobile/src/connection/catalog-store.ts apps/mobile/src/connection/storage.test.ts
  • vp test run apps/mobile/src/connection/storage.test.ts (4 passed)
  • pnpm --filter @t3tools/mobile typecheck
  • vp lint apps/mobile/src/connection/catalog-store.ts apps/mobile/src/connection/storage.test.ts --report-unused-disable-directives
  • git diff --check

Note

Medium Risk Changes local persistence recovery semantics: corrupt catalogs without a backup now surface errors on read instead of silently resetting, so startup flows must tolerate that path.

Overview Fixes mobile saved environments disappearing when the primary SecureStore catalog fails to decode. The app now keeps a last-known-good backup (CONNECTION_CATALOG_BACKUP_KEY) and writes it on every successful encode (updates and legacy migration) before updating the primary key.

On load, a corrupt primary catalog is restored from backup instead of being deleted and replaced with an empty catalog or legacy migration. If the primary is missing, backup is tried before legacy data. When the primary is corrupt and no valid backup exists, load fails with an explicit error and leaves the corrupt blob in place rather than wiping user data.

Tests now assert backup recovery, fail-closed behavior without deletion, and backup precedence over legacy when the primary is absent.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ac3678f50e266d0329de53ecb20e1c2a64c72191. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add backup key to mobile connectionStorage for catalog recovery

  • Introduces CONNECTION_CATALOG_BACKUP_KEY and writes a backup copy alongside the primary key on every catalog update and during legacy migration
  • Adds restoreBackup effect; loadCatalog now restores from the backup when the primary is corrupt or missing instead of deleting the corrupt primary and falling back to legacy
  • Risk: loadCatalog now fails closed with ConnectionTransientError (reason remote-unavailable) when the primary is corrupt and no valid backup exists; legacy data is only consulted when the primary is missing and no backup is available
Macroscope summarized ac3678f.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: a81cae99-2e0c-4a8d-b24f-c7b19de0e22b

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Warning

      Your free Security trial is over. An organization admin can activate Security or dismiss this notice.


      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. @@ -96,5 +108,20 @@
      108+ Option.match({
      109+ onNone: () =>
      110+ Effect.fail(
      111+ catalogError("recover", "No valid connection catalog backup is available."),
      112+ ),
      113+ onSome: Effect.succeed,
      114+ }),
      115+ ),
      96116 ),
      97117 ),
      98118 );
      99119 } else {
      100- catalog = yield* loadLegacyCatalog();
      120+ catalog = yield* restoreBackup().pipe(
      121+ Effect.flatMap(
      122+ Option.match({
      123+ onNone: loadLegacyCatalog,
      124+ onSome: Effect.succeed,
      125+ }),
      126+ ),
      127+ );
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High connection/catalog-store.ts:120

      When CONNECTION_CATALOG_KEY is absent and CONNECTION_CATALOG_BACKUP_KEY contains malformed data, restoreBackup() fails during decodeCatalog, so loadLegacyCatalog is never called and valid LEGACY_CONNECTIONS_KEY data cannot be migrated. Treat an invalid backup as unavailable in this fallback path so legacy recovery can proceed.

      -      catalog = yield* restoreBackup().pipe(
      +      catalog = yield* restoreBackup().pipe(
      +        Effect.catch(() => Effect.succeed(Option.none<ConnectionCatalogDocumentType>())),
               Effect.flatMap(
                 Option.match({
                   onNone: loadLegacyCatalog,
                   onSome: Effect.succeed,
                 }),
               ),
             );
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/mobile/src/connection/catalog-store.ts around lines 120-127:
      
      When `CONNECTION_CATALOG_KEY` is absent and `CONNECTION_CATALOG_BACKUP_KEY` contains malformed data, `restoreBackup()` fails during `decodeCatalog`, so `loadLegacyCatalog` is never called and valid `LEGACY_CONNECTIONS_KEY` data cannot be migrated. Treat an invalid backup as unavailable in this fallback path so legacy recovery can proceed.
    4. Effect service conventions review of the mobile connection catalog store. One finding on the new recovery failure path; imports, make shape, and dependency acquisition via MobileSecureStorage.MobileSecureStorage otherwise follow the conventions.

      Posted via Macroscope — Effect Service Conventions
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bb970c97e6fd1ee790686d3b8fbaf254021de9b9. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -90,6 +102,14 @@
      90102 if (raw !== null && raw.trim() !== "") {
      91103 catalog = yield* decodeCatalog(raw).pipe(
      92104 Effect.catch((error) =>
      93- Effect.logWarning("Discarding corrupt mobile connection catalog", error).pipe(
      94- Effect.andThen(deleteItem(CONNECTION_CATALOG_KEY)),
      95- Effect.andThen(loadLegacyCatalog()),
      105+ Effect.logWarning("Recovering corrupt mobile connection catalog from backup", error).pipe(
      106+ Effect.andThen(restoreBackup()),
      107+ Effect.flatMap(
      108+ Option.match({
      109+ onNone: () =>
      110+ Effect.fail(
      111+ catalogError("recover", "No valid connection catalog backup is available."),
      112+ ),
      113+ onSome: Effect.succeed,
      114+ }),
      115+ ),

      Successful load skips backup seed

      Medium Severity

      A successful primary decode never writes CONNECTION_CATALOG_BACKUP_KEY. Upgraded installs therefore have no last-known-good copy until a later catalog mutation, so an early decode failure fails closed and leaves saved environments inaccessible.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bb970c97e6fd1ee790686d3b8fbaf254021de9b9. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The PR changes production SecureStore handling for connection credentials, tokens, and saved environments by adding backup writes and new recovery/failure semantics. Unresolved findings cover missing backup seeding and malformed-backup migration behavior, so the persistence change warrants human review.

      Not approved because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    7. juliusmarminge added labelsmacroscope-review

    8. Note

      Written by claude-opus-5-5 on behalf of Maria

      Hi! We are cleaning up open PRs, and this one does not say which model or harness was used to create it. If this change is really important, we recommend rebuilding the PR with a newer model and noting the model and harness in the PR description.

    9. maria-rcks closed this

Sign in to join this conversation.