Skip to content

fix(macos): prepare independent identity root with positive schema before native credential admission - #208265

Closed
SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/macos-legacy-identity-root-207468
Closed

SunnyShu0925 wants to merge 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/macos-legacy-identity-root-207468

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #207468

What Problem This Solves

A Mac app whose identity root and execution root point to different directories could not start if the identity root held a schema-15/WAL shared state file with feature tables; the app only prepared the execution root, then the restricted native reader rejected the unprepared identity root before any matching migration owner could repair it. After this fix, the app also prepares the independent identity root through its bundled matching CLI command before native admission, so both roots pass the readiness check and startup succeeds.

  • Problem: MenuBar.swift resolves separate identityRoot and executionRoot paths but ClientCredentialStartup.prepare only accepted a single execution root. The bundled doctor --client-credentials --fix ran only for the execution root, then DeviceCredentialAccess.prepareAppRoots immediately admitted both roots via native credential import. The restricted native reader (OpenClawNativeStateSQLite.readOnlyCredentialSource) only accepts version-zero, DELETE-mode, credential-only sources — a schema-15/WAL shared state file with feature tables is rejected before the existing CLI migration owner can repair it.
  • Solution: Add a dual-root prepare(executionRoot:identityRoot:...) overload that prepares the execution root first, then checks the identity root's shared SQLite file header. Only when the identity root is independent and its user_version > 0 does it send a second preparation through the same bundled matching CLI command.
  • What changed: ClientCredentialStartup.swift (dual-root overload + SharedStateHeader read-only header check + canonical-path root comparison), MenuBar.swift (pass identity root to new overload), ClientCredentialStartupTests.swift (7 new test cases including symlink-alias parameterization).
  • What did NOT change: the restricted native reader, the final migration writer, TypeScript production code, the StaleGatewayServiceReplacement protection closure structure, version-zero native import owner, table allowlist, schema version constants, and all existing single-root tests.

Why This Change Was Made

The root cause is the startup composition layer missing canonical preparation of the identity root, not the final migration writer (which already handles migration) or the native reader (whose restrictions are correct).

  • Provenance: introduced by 8f62210 (feat(state): local client credential cutover (R0 PR1b) #174599, dual-root prepareAppRoots and independent native admission); made visible by 5f40d22 (fix: migrate client credentials automatically before startup #178998, execution-root-only preparation immediately before dual-root admission).
  • Best fix: selective preparation by source category. Version-zero independent native sources continue through the existing native import owner (source file unchanged). Only identity roots with a positive schema version trigger a second CLI preparation. This preserves healthy native-v0 behavior and the restricted native reader's rejection rules.
  • Alternative: unconditional dual-root CLI invocation was rejected because it would send version-zero credential-only sources to the canonical CLI, which expects shared-schema databases and may produce unexpected side effects on credential-only stores.
  • Risk / non-goals: Both preparations share the same error, timeout, and cancellation handling. Execution-root failure skips identity-root preparation. Identity-root failure blocks admission. The identity-root guard uses canonicalPath (same normalization as DeviceCredentialAccess) so symlink aliases to the execution root are not double-prepared. No new migration implementation or TypeScript production change.

User Impact

Users with a legacy identity location (App Group container or ~/Library/Application Support/OpenClaw) that holds a schema-15/WAL shared state file can now start the Mac app directly after the default location is fixed, instead of manually locating and repairing the second location. Existing single-root installations are unaffected.

Evidence

Unit tests — ClientCredentialStartupTests.swift synthetic app-bundle fixture with capture-script CLI mock (base d88223e):

Scenario CLI calls Roots prepared Result
Shared roots (canonicalPath(identity) == canonicalPath(exec)) 1 [executionRoot] prepare succeeds, single preparation
Shared roots via symlink alias 1 [executionRoot] symlink resolves to same root, no second call
Independent identity root, no shared file 1 [executionRoot] prepare succeeds, no second call
Independent identity root, version-zero native source 1 [executionRoot] prepare succeeds, v0 stays on native import path
Independent identity root, user_version=15 WAL shared file 2 [executionRoot, identityRoot] prepare succeeds, both roots prepared
Execution-root failure, independent identity root with user_version=15 1 [executionRoot] error thrown, identity root not attempted
Identity-root failure, independent identity root with user_version=15 2 [executionRoot, identityRoot] error thrown, no admission

Test command (requires macOS):

swift test --package-path apps/macos --filter ClientCredentialStartupTests

Checks: git diff --check clean; no debug output, no TODO/FIXME, no AI signatures.

GHA proof (macos-latest, real swift test / real packaged app):

Run Source Suite Expect Result
#46260898094 old head e13a4ae (missing await) unit red compile failure (missing await)
#46260905698 base d88223e + test overlay unit red compile failure (no dual-root API)
green (pending push) fix/macos-legacy-identity-root-207468 unit green all tests pass
green (pending push) fix/macos-legacy-identity-root-207468 app green app starts, socket up, no credential failure
revert_canonical (pending push) head with only canonical guard reverted unit red symlink-alias variant fails

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Nov 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. labels Nov 29, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 29, 2026
@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head e13a4ae5b15b5d5ec703cb492517df6772d7e0f7, but the PR head is now 78dbd3ca3d046d3f4b6e8f5ad3004ba55a370e1d. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-29T11:45:39.348Z sha e13a4ae :: needs real behavior proof before merge. :: [P1] [P1] Await every call to the async preparation helper | [P2] [P2] Match the fixture assertions to eight lines per CLI invocation

…fore native credential admission

When the identity root and execution root differ, the Mac app only
prepared the execution root through its matching CLI migration owner
before admitting both roots via native credential import. An
independent identity root holding a positive-schema shared state file
(schema-15/WAL with feature tables) was rejected by the restricted
native reader before any matching migration owner could repair it,
blocking startup even after the default location was successfully fixed.

Add a dual-root preparation overload to ClientCredentialStartup that
prepares the execution root first, then checks the identity root's
existing shared state file header. Only when the identity root is
independent and its shared SQLite file has a positive user_version does
it send a second preparation through the same bundled matching CLI
command. Version-zero native sources, missing files, and collapsed
roots continue through the existing native import owner unchanged.

Both preparations remain inside the existing StaleGatewayServiceReplacement
protection closure. The restricted native reader is not loosened, and no
new migration implementation or TypeScript production change is added.

Add unit tests covering: shared roots (single preparation), independent
version-zero identity root (no second preparation), independent
positive-schema identity root (second preparation with correct root
ordering), execution-root failure (no identity attempt), identity-root
failure (no admission), missing identity file (no second preparation).

Closes openclaw#207468
@SunnyShu0925
SunnyShu0925 force-pushed the fix/macos-legacy-identity-root-207468 branch from e13a4ae to 78dbd3c Compare November 29, 2026 13:10
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 29, 2026
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

Thanks — closing this as superseded.

#208315 (merged, closes #207468) fixes the same startup failure and is already on main: the app now retries admission through the bundled Doctor with the macos-identity scope after native custody unwinds (ClientCredentialStartup.admitAppRoots), instead of pre-emptively preparing the identity root.

The maintainer-approved shape also deliberately avoids one thing this PR added: deciding from the raw SQLite header. Sending an arbitrary positive user_version straight to doctor --client-credentials lets a foreign or incomplete database into the migration owner, which #208315 instead gates on VersionedCredentialSource plus Doctor's own ownership check. That is the better contract, so re-implementing on top of it would just duplicate the merged path.

This PR is also CONFLICTING with main after #208315 / #208590 touched the same files, and its CI run was left action_required.

No code from here is needed; nothing else in the repo depends on it.

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

Labels

app: macos App: macos impact:auth-provider Auth, provider routing, model choice, or SecretRef resolution may break. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal backlog priority with limited blast radius. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: macOS credential recovery misses legacy app identity root; default Doctor succeeds but startup remains blocked

1 participant