Skip to content

fix(macos): keep Gateway profile Keychain reads noninteractive - #128820

Closed
hannesrudolph wants to merge 2 commits into
openclaw:mainfrom
hannesrudolph:fix/macos-keychain-noninteractive
Closed

hannesrudolph wants to merge 2 commits into
openclaw:mainfrom
hannesrudolph:fix/macos-keychain-noninteractive

Conversation

@hannesrudolph

@hannesrudolph hannesrudolph commented Aug 24, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Automatic macOS Gateway-profile reads and legacy migration can open login-Keychain authentication UI when a development signature does not own the saved item. Treating an unavailable Keychain like an empty registry can also make a later explicit mutation overwrite hidden profiles or discard a pending legacy-profile migration and its credentials.

Why This Change Was Made

Automatic reads and migration use a noninteractive LAContext and distinguish missing, temporarily unavailable, and failed Keychain states. A real legacy login-Keychain ACL proved that modern no-UI controls still summon SecurityAgent, so noninteractive reads and saves also use the legacy process interaction switch inside a serialized capture/disable/restore boundary. Explicit add/remove operations remain interaction-allowed, reload authoritative Keychain data, reapply the existing idempotent legacy migration, and commit the migration plus mutation in one registry save.

User Impact

Background refresh and local onboarding no longer trigger surprise Keychain dialogs or fail because the login Keychain is unavailable. Explicit profile changes may still request authorization, and they preserve hidden profiles, migrated credentials, and the migration receipt. There is no persisted schema change.

Evidence

  • Test-only baseline failed on current main because the noninteractive Keychain contract did not exist.
  • Follow-up migration tests failed before the mutation-loader repair with profileNotFound and lost credentials; after the repair all 17 MacGatewayProfilesTests pass.
  • Focused SwiftFormat and strict SwiftLint checks pass for both changed files; git diff --check passes.
  • Prior Base-VM acceptance with the same noninteractive Keychain boundary showed no Keychain dialog and completed onboarding.
  • Exact-head macOS proof found a real prompt at 5c39e305c257 with a legacy item restricted to /usr/bin/security, then verified 61dba15e6b82 launches without a prompt against the same item.
  • A GUI-run arm64 diagnostic proved kSecUseAuthenticationUIFail still prompts for the legacy item, while SecKeychainSetUserInteractionAllowed(false) returns without UI and restores the previous process state.
  • Production LOC: +165/-41; tests: +150. The production growth introduces an explicit unavailable/missing/failure state model, an injectable Keychain boundary, and the serialized legacy compatibility boundary; the canonical migration transform remains single-source and idempotent.

Proof gap: real legacy-ACL prompt suppression is exact-head tested; authorized mutation preservation is covered at the Keychain boundary with hidden-profile and migrated-credential regressions rather than UI automation.

@clawsweeper

clawsweeper Bot commented Aug 24, 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. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos size: M maintainer Maintainer-authored PR labels Aug 24, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 10:49 AM ET / 14:49 UTC (Revision 10).

ClawSweeper review

What this changes

The PR suppresses automatic macOS Gateway-profile Keychain dialogs and preserves hidden profiles and pending legacy credentials when an explicit edit later obtains access.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: the native proof supports the useful fix, but the previously reported process-wide Keychain coordination defect remains. Current main only partially addresses the problem, and the proposed replacement still acknowledges the same unfinished repair. Maintainer authorship and the protected label also prevent cleanup closure.

Priority: P2
Reviewed head: 61dba15e6b82ff1d711256cf059179c2a0a77b80

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong native evidence supports the useful behavior, but the known shared-state defect prevents merge readiness.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): The inspected signed-app before/after screenshots and diagnostic output exercise the changed profile Keychain boundary against the same restrictive legacy ACL and support exact-head prompt suppression. Mutation-preservation tests are supplemental; concurrent binding-key access remains an independent finding. The stored registry format is unchanged.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): The inspected signed-app before/after screenshots and diagnostic output exercise the changed profile Keychain boundary against the same restrictive legacy ACL and support exact-head prompt suppression. Mutation-preservation tests are supplemental; concurrent binding-key access remains an independent finding. The stored registry format is unchanged.
Evidence reviewed 9 items Pinned introduced change: Reviewed the merge-base-to-head delta, both changed files, and the profile store's surrounding migration, credential, and connection paths. The patch introduces a profile-local lock and temporarily disables process-wide Keychain interaction.
Uncoordinated sibling and observable consequence: The activation-binding store calls SecItemCopyMatching and SecItemAdd without the introduced lock. GatewayConnection obtains and retains that optional key during configuration; a failed overlapping lookup leaves the connection without an activation ownership fingerprint. Onboarding then cannot verify a previously bound setup receipt or uses an unbound attempt.
Apple dependency contract: The affirmative dependency signal is the introduced import of Security and direct SecKeychainSetUserInteractionAllowed call. Apple's implementation writes the shared Globals interaction flag; credential construction reads that flag. Inspected https://github.com/apple-oss-distributions/Security/blob/main/OSX/libsecurity_keychain/lib/SecKeychain.cpp, https://github.com/apple-oss-distributions/Security/blob/main/OSX/libsecurity_keychain/lib/Globals.h and https://github.com/apple-oss-distributions/Security/blob/main/OSX/libsecurity_keychain/lib/Globals.cpp. This establishes why a profile-only lock cannot protect unrelated Keychain operations.
Findings 1 actionable finding [P2] Coordinate every in-process Keychain operation
Security None None.

How this fits together

The macOS app stores saved Gateway endpoints and credentials in Keychain, then uses them to populate connection pickers and establish Gateway connections. Background reads and explicit profile edits share the process with other Keychain consumers.

flowchart TD
  A[Background profile refresh] --> C[Gateway profile store]
  B[Explicit profile edit] --> C
  C --> D[Keychain interaction policy]
  D --> E[macOS Keychain]
  F[Gateway binding key store] --> E
  E --> G[Saved profiles and connection credentials]
Loading

Before merge

  • Coordinate every in-process Keychain operation (P2) - The prior finding remains unfixed. SecKeychainSetUserInteractionAllowed(false) changes shared process state, but this lock only covers noninteractive profile operations; interactive operations bypass it, and GatewayActivationBindingKeyStore never acquires it. If that store reads an ACL-protected item while a profile read holds interaction disabled, its lookup can fail and return no binding key. GatewayConnection retains that missing key for the configured connection, preventing verification of bound setup receipts. Route the relevant Keychain consumers through one shared coordinator and add an overlap regression.
  • Resolve merge risk (P1) - Temporary process-wide interaction suppression can make a concurrent activation-binding or other Keychain operation fail; the current tests and native proof do not cover that overlap.
  • Resolve merge risk (P1) - The bug fix adds 124 net production lines around a profile-specific boundary; consolidate the duplicated Keychain coordination into the existing owner while retaining the necessary unavailable-state distinction.
  • Complete next step (P2) - Repair the shared Keychain coordinator, add overlap coverage, and reconcile the conflicting head with current main before merge.

Findings

  • [P2] Coordinate every in-process Keychain operation — apps/macos/Sources/OpenClaw/MacGatewayProfiles.swift:159-167
Agent review details

Security

None.

PR surface

Other +274. Total +274 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 315 41 +274
Total 2 315 41 +274

Review metrics

Metric Value Why it matters
Production versus test growth Production +165/-41, net +124; tests +150/-0 Typed unavailable-state handling has a concrete purpose, but the profile-local coordinator should be absorbed into the shared Keychain owner.

Merge-risk options

Maintainer options:

  1. Complete shared coordination (recommended)
    Coordinate interactive and noninteractive Keychain consumers through one owner and prove that overlapping binding-key acquisition succeeds after suppression is restored.

Technical review

Best possible solution:

Extend the existing Keychain owner with shared process-wide coordination, preserve denial/retry semantics and authoritative mutation recovery, and remove the profile-only coordination path.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes the introduced overlap: pause a profile operation after disabling process interaction, then request an ACL-protected activation-binding key from another actor. This review did not execute that scenario; the supplied native evidence separately demonstrates the original profile prompt.

Is this the best way to solve the issue?

No, the fix is too narrow at the process boundary. Query-only suppression was disproved by the native evidence, but a profile-only lock cannot safely own Apple's shared interaction state.

Full review comments:

  • [P2] Coordinate every in-process Keychain operation — apps/macos/Sources/OpenClaw/MacGatewayProfiles.swift:159-167
    The prior finding remains unfixed. SecKeychainSetUserInteractionAllowed(false) changes shared process state, but this lock only covers noninteractive profile operations; interactive operations bypass it, and GatewayActivationBindingKeyStore never acquires it. If that store reads an ACL-protected item while a profile read holds interaction disabled, its lookup can fail and return no binding key. GatewayConnection retains that missing key for the configured connection, preventing verification of bound setup receipts. Route the relevant Keychain consumers through one shared coordinator and add an overlap regression.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against db01f6d520b8.

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review merge-risk labels are merge-risk: 🚨 availability.

Label justifications:

  • P2: This is a bounded macOS profile reliability fix with an unresolved concurrency defect.
  • merge-risk: 🚨 availability: The introduced process-wide interaction toggle can disrupt concurrent Keychain access needed for Gateway setup verification.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (screenshot): The inspected signed-app before/after screenshots and diagnostic output exercise the changed profile Keychain boundary against the same restrictive legacy ACL and support exact-head prompt suppression. Mutation-preservation tests are supplemental; concurrent binding-key access remains an independent finding. The stored registry format is unchanged.
  • proof: sufficient: Contributor real behavior proof is sufficient. The inspected signed-app before/after screenshots and diagnostic output exercise the changed profile Keychain boundary against the same restrictive legacy ACL and support exact-head prompt suppression. Mutation-preservation tests are supplemental; concurrent binding-key access remains an independent finding. The stored registry format is unchanged.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The inspected signed-app before/after screenshots and diagnostic output exercise the changed profile Keychain boundary against the same restrictive legacy ACL and support exact-head prompt suppression. Mutation-preservation tests are supplemental; concurrent binding-key access remains an independent finding. The stored registry format is unchanged.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • stevenlee-oai: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Patrick-Erichsen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Route profile and activation-binding Keychain operations through one coordinator and add a deterministic overlap regression.
  • Repeat the restrictive-ACL native proof while a Gateway connection obtains its activation-binding key, after reconciling the branch with current main.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-24T18:51:56.254Z sha 61dba15 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-24T19:10:58.619Z sha 61dba15 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-24T19:53:25.255Z sha 61dba15 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T17:55:54.674Z sha 61dba15 :: found issues before merge. :: [P2] Coordinate every in-process Keychain operation
  • reviewed 2026-08-29T08:26:02.496Z sha 61dba15 :: needs changes before merge. :: [P2] Coordinate every in-process Keychain operation
  • reviewed 2026-09-02T14:30:48.568Z sha 61dba15 :: found issues before merge. :: [P2] Coordinate all in-process Keychain operations
  • reviewed 2026-09-02T14:56:42.353Z sha 61dba15 :: found issues before merge. :: [P2] Coordinate every in-process Keychain operation
  • reviewed 2026-09-04T14:36:01.798Z sha 61dba15 :: blocked before merge. :: [P2] Coordinate every in-process Keychain operation

@hannesrudolph

Copy link
Copy Markdown
Member Author

Exact-head macOS ACL proof completed on the live Base VM without restarting or logging out.

Setup: a valid ai.openclaw.gateway-profiles.debug registry containing a profile plus dummy token/password was created in the login Keychain with its ACL restricted to /usr/bin/security.

  1. Original head 5c39e305c257: failed. Launching the exact app produced a background OpenClaw Keychain password dialog despite LAContext.interactionNotAllowed.

Original head displays a background Keychain prompt

  1. SDK inspection and a GUI-run arm64 diagnostic confirmed the platform boundary: modern no-UI query controls do not suppress legacy login-Keychain ACL UI; serially disabling legacy process interaction returned -25293 without UI and restored the previous enabled state (PREVIOUS_STATUS=0, DISABLE_STATUS=0, RESTORE_STATUS=0).

Legacy interaction switch returns without UI and restores state

  1. Follow-up head 61dba15e6b82: passed. The rebuilt, signature-verified exact app launched against the same restricted item and remained on onboarding with no SecurityAgent prompt.

Follow-up exact head launches without a Keychain prompt

The follow-up wraps both noninteractive reads and the full update/add save transaction in a serialized capture/disable/restore boundary. Interactive mutations bypass it. The 17 focused tests remain green, including unavailable-read → authorized remove and blank same-route upsert cases that preserve hidden profiles, the migration receipt, and migrated credentials.

Remaining proof boundary: mutation preservation is exercised with injected Keychain operations rather than UI automation; the real legacy-ACL no-prompt contract is now proven on the exact PR head.

@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 24, 2026
@hannesrudolph

Copy link
Copy Markdown
Member Author

Final merge-ref native validation completed against GitHub synthetic merge commit da88aa8aa109d481d51e7db8eda2ecd56dd0b574 (parents f533cde95436 + PR head 61dba15e6b82):

  • swift test --package-path apps/macos --filter MacGatewayProfilesTests — 17/17 passed.
  • Pinned SwiftFormat lint on both changed files — clean.
  • Strict SwiftLint on both changed files — 0 violations.
  • git diff --check HEAD^1..HEAD — clean.

This supplements the exact-head restrictive-ACL signed-app proof already attached. No branch history rewrite was required.

@clawsweeper clawsweeper Bot removed the proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. label Aug 24, 2026
@hannesrudolph
hannesrudolph marked this pull request as ready for review August 25, 2026 17:50
@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@Patrick-Erichsen Patrick-Erichsen self-assigned this Aug 25, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Aug 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. and removed P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Aug 29, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants