Skip to content

fix(mac): prevent app auth from blocking node-host startup - #115533

Merged
steipete merged 7 commits into
mainfrom
fix/swift-device-auth-sqlite-store
Jul 29, 2026
Merged

steipete merged 7 commits into
mainfrom
fix/swift-device-auth-sqlite-store

Conversation

@steipete

@steipete steipete commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Apple apps could permanently block a macOS node host from restarting after device-auth tokens were migrated to SQLite on the Node side.

PR #112663 made Node refuse startup whenever identity/device-auth.json remained, but the shared Swift store still rewrote that retired file. In the live 2026-07-28 incident, Doctor imported and deleted the file, the app recreated it on launch, and the next node-host restart failed again. This loop was reproduced twice on real hardware (megaclaw and miniclaw).

Why This Change Was Made

The shared Swift DeviceAuthStore now uses the exact Node-owned device_auth_tokens table in state/openclaw.sqlite, preserving the existing opaque role-key encoding and public Swift API. Every operation opens the shared database, validates or bootstraps the canonical table, and performs its row mutation in an immediate transaction. Legacy profile files are read through a hard 4 MiB bound, imported with preserve-canonical semantics, retired before the requested operation can commit, and quarantined only after successfully read content proves invalid.

Cross-container identity relocation now imports destination legacy auth first and then source auth into SQLite, preserving canonical destination rows while never deleting or rewriting the source auth file. The old JSON writer, destination-file publisher, and renamex_np auth path are removed.

Compatibility

This is an additive canonical table and does not bump user_version. Version-zero native bootstrap databases create it lazily. Versioned Node-owned databases must already contain it and fail closed otherwise, requiring a newer CLI plus Doctor. An older native build may reject a version-zero database containing the new table; native downgrades are not a shipped compatibility contract.

Unlike the retired file store, the profile parameter no longer selects a separate token-file namespace. It selects device identity resolution only; token rows are shared in the canonical table and keyed by (device_id, role), so the same row is visible for a supplied device ID regardless of profile. Per-profile identities remain disjoint because they resolve to distinct device IDs, and Node reads the same table by the same key.

The production diff is +248 net lines. That growth is the explicit SQLite statement layer plus bounded/retry-safe legacy I/O and non-creating identity lookup; it replaces the steady-state JSON write path and cross-container file publication with one canonical storage path.

User Impact

Mac, iOS, watch, and share-extension callers keep the same DeviceAuthStore API, but no Apple client writes device-auth.json, node-device-auth.json, or share-device-auth.json anymore. Node hosts can restart without the app recreating the retired-file startup gate. Existing tokens migrate once, gateway-scoped metadata is reconstructed from the stored key, profile clears affect only the current profile identity, and temporary filesystem failures remain retryable instead of losing credentials.

Evidence

Focused Swift package proof:

$ swift test --filter DeviceAuthStoreTests 2>&1 | tail -20
Test "failed legacy removal cannot commit a clear" passed
Test "temporary legacy access failure remains retryable" passed
Test "failed invalid-file quarantine aborts the requested write" passed
Test "corrupt legacy file is quarantined and SQLite remains writable" passed
Test "clear all without an identity leaves legacy state untouched" passed
Test "version zero bootstrap creates the exact composite key table" passed
Test "versioned database never synthesizes a missing auth table" passed
Suite DeviceAuthStoreTests passed
Test run with 12 tests in 1 suite passed
$ swift test --filter DeviceIdentityStoreTests 2>&1 | tail -20
Test "migration imports auth rows without removing its source" passed
Test "migration preserves canonical destination auth rows" passed
Test "migration imports destination legacy auth before source auth" passed
Test "source auth access failure preserves the identity claim for retry" passed
Test "migration rejects conflicting source auth stores" passed
Test "migration normalizes imported auth scopes" passed
Suite DeviceIdentityStoreTests passed
Test run with 34 tests in 1 suite passed

Structured Codex autoreview on the final uncommitted bundle:

autoreview clean: no accepted/actionable findings reported
overall: patch is correct (0.92)

Live incident evidence: the retired file was observed being recreated after Doctor cleanup and the resulting node-host restart failure was reproduced twice on megaclaw and miniclaw on 2026-07-28.

@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Jul 29, 2026
Missing-file tolerance now applies only to the first observation; a disappearance after the auth file was observed fails the migration so the claimed identity survives for retry instead of committing without its credentials.
@steipete
steipete marked this pull request as ready for review July 29, 2026 04:02
@blacksmith-sh

This comment has been minimized.

@steipete steipete self-assigned this Jul 29, 2026
@steipete
steipete merged commit b2701ac into main Jul 29, 2026
56 checks passed
@steipete
steipete deleted the fix/swift-device-auth-sqlite-store branch July 29, 2026 06:33
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 29, 2026
…ifecycle-hooks

* origin/main:
  fix(mattermost): key private channels as group on outbound routing (#96645)
  fix(ci): grant Telegram QA runtime scratch access (#115659)
  fix(telegram): stop retrying blocked recipients (#115640)
  fix(tts): persist generated speech in media store (#115647)
  fix(gateway): preserve complete streamed chat completions (#115652)
  fix(mac): prevent app auth from blocking node-host startup (#115533)
  fix(heartbeat): keep message-tool final replies private (#115629)
  fix(gateway): drain root work continuations before direct-stop process exit (#105848)
  fix(ollama): keep active streams within their idle timeout (#115648)
  fix(delivery): keep session keys out of inferred message targets (#115657)
  fix(ci): type code mode matrix catch callback (#115674)
  refactor(agents): centralize bundled CLI backend auth policy (#115633)
  refactor: remove 3,527 lines of runtime and test duplication (#115626)
  [AI] fix(doctor): stop repeated bundledDiscovery migration noise on beta (#115208)

# Conflicts:
#	scripts/code-mode-model-matrix.ts
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
…115533)

* fix(mac): move device auth tokens to shared SQLite state

* fix(mac): fail identity migration when source auth vanishes mid-read

Missing-file tolerance now applies only to the first observation; a disappearance after the auth file was observed fails the migration so the claimed identity survives for retry instead of committing without its credentials.

* fix(ios): validate auth scope UTF-8 encoding

* fix(ios): isolate SQLite auth profiles

* chore(ios): refresh native source inventory

* fix(mac): keep device auth in the shared token table

* test(mac): pin shared-key token cache semantics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant