Skip to content

iOS: Hermit's data and keys stay out of iCloud and computer backups - #136

Draft
dbejarano820 wants to merge 1 commit into
mainfrom
dbejarano820/126-ios-no-backup
Draft

dbejarano820 wants to merge 1 commit into
mainfrom
dbejarano820/126-ios-no-backup

Conversation

@dbejarano820

Copy link
Copy Markdown
Contributor

What and why

Closes #126

On iOS, Hermit's database, model and QVAC caches are now excluded from iCloud and computer backups, and every Keychain item is WhenUnlockedThisDeviceOnly. Items written before this change are moved over without losing any data. Android is unchanged (allowBackup is already false).

  • Files: HermitVault.excludeFromBackup (Swift) flags Documents (which holds models and .qvac, QVAC's HOME_DIR) plus both folders by name, and Library/hermit.db with its -wal/-shm/-journal siblings. Each flag is read back after it is set. It runs when the database opens (on first creation and at every launch), when the models folder is created, and after each model load (QVAC makes .qvac).
  • Keychain writes: keychain() in adapters/secure.ts adds WHEN_UNLOCKED_THIS_DEVICE_ONLY on iOS and returns Android's options untouched. Every SecureStore.setItemAsync goes through it, and a test scans the adapters to keep it that way.
  • Migrating plain items: before any secret is read at launch, HermitVault.keychainToThisDevice lists the items under app:no-auth and the legacy app service by attributes only. It changes just the class with SecItemUpdate, so the value is never read or rewritten natively and the update is atomic. It reads the class back, and JS then reads each moved value back through SecureStore. A silent LAContext means it never shows a prompt.
  • Migrating the gated approval key: this happens lazily, right after the user's own authenticated read in gatedSecret. Changing the item in place would ask for Face ID a second time, so the code deletes it and adds it again with the value it just read (an add shows no prompt), then reads the class back. If the add fails, the item is put back with its old class. Nothing prompts at launch. Provisioning on iOS deletes the old item first for the same reason.

Vision fit

Data stays on the phone: a backup no longer carries Hermit's memories, model, caches or keys to Apple's servers or a computer.

Non-negotiables

  • This keeps every non-negotiable in AGENTS.md as it is.
  • Or it changes one, and this is the accepted RFC: #

Checklist

  • It closes one issue, linked above, or it's a small fix (a typo, a broken link, a wrong comment). A feature has an accepted proposal.
  • I wrote the failing test first. It fails without this change and passes with it. (apps/mobile/src/backup-guard.test.ts: it first failed because the module was missing. With the pure module in place, the adapter scan failed on 9 unguarded writes in app-lock, credentials, secure, vault and wallet. After the change, all 9 tests pass.)
  • These pass: pnpm check:privacy, pnpm typecheck, pnpm lint, pnpm test and node scripts/guard/check.mjs --patterns scripts/guard/patterns.txt.
  • No new network call, telemetry, analytics, ads or crash reporting. (A new request in an app adapter is explained below, with its host, skill and risk.)
  • No new dependency, or the reason for each one is below.
  • Every UI string is in packages/copy, in es-419 and en, with matching keys and placeholders, and no em or en dashes. (No UI strings added.)
  • Tests, fixtures and screenshots use made-up data only.

Model path

  • This doesn't touch the model path: packages/model, agent, skills or eval, the prompt, the router, tool descriptions, normalizers, examples or the model file.
  • It does. The eval numbers from before and after are below, run as docs/evals.md says. No held-out case was tuned on.

Screenshots

  • No UI change.
  • UI change. Each changed screen is below, in both themes and both languages, with made-up data.

New dependencies and network calls

n/a

Verification

  • An iOS Release build for generic/platform=iOS with CODE_SIGNING_ALLOWED=NO succeeded, with no errors or warnings in HermitVaultModule.swift.
  • Not yet checked on an iPhone: whether a backup leaves these out, and the Keychain classes reported on the device.

AI agents

  • No AI agent wrote any part of this.
  • An AI agent helped. Which one, and what it did: Claude Code (Claude Opus 5.5) wrote the tests, the Swift and TypeScript changes and the docs line, ran the gates and compiled the iOS app.
  • I read and ran everything in this pull request, and I can explain it.

@juancguerrerodev

Copy link
Copy Markdown
Contributor

Holding this one until it's been checked on an iPhone, as the description says. Merge it yourself once it passes, or say so here and I'll merge it. 🦀

On iOS, the documents folder (the model in models, QVAC's caches in .qvac) and the
SQLCipher database with its journal siblings are flagged isExcludedFromBackup when
each is created and again at every launch (HermitVault.excludeFromBackup, which
reads the flag back).

Every SecureStore write goes through keychain(), which adds
WHEN_UNLOCKED_THIS_DEVICE_ONLY on iOS and leaves Android's options untouched; a
test scans the adapters so no write can skip it. At launch, the plain items
already written move to WhenUnlockedThisDeviceOnly in place
(HermitVault.keychainToThisDevice: SecItemUpdate of the class only, never the
value), then each class and value is read back. The biometric-gated approval key
moves only right after the user's own authenticated read: deleted and added
again with the value just read, so no extra Face ID prompt, and put back as it
was if the add fails.

docs/devices.md says a restore from backup starts Hermit empty and downloads
the model again. Android is unchanged.

Closes #126

Signed-off-by: Daniel Bejarano <dbejarano820@gmail.com>
@dbejarano820
dbejarano820 force-pushed the dbejarano820/126-ios-no-backup branch from 67e3e48 to 0c5c31f Compare November 30, 2026 22:40
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.

iOS: keep Hermit's data and keys out of iCloud and computer backups

2 participants