Repository navigation
fix(desktop): read Automation status when System Events is stopped - #12625
Merged
Git-on-my-level merged 5 commits intoSep 3, 2026
Merged
Conversation
There was a problem hiding this comment.
1 issue found across 5 files
Confidence score: 3/5
SBOnboardingPermissionRuntime.swiftsynchronously waits on LaunchServices when System Events is stopped, which can freeze the main actor for up to five seconds and make the onboarding/chat permission check visibly unresponsive — run the probe, including the launch wait, off the main actor.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="desktop/macos/Desktop/Sources/Onboarding/SecondBrain/SBOnboardingPermissionRuntime.swift">
<violation number="1" location="desktop/macos/Desktop/Sources/Onboarding/SecondBrain/SBOnboardingPermissionRuntime.swift:133">
P2: When System Events is stopped, the chat permission status check can freeze the main actor for up to five seconds because this synchronous probe now waits for LaunchServices. Run the probe, including the launch wait, off the main actor before updating the shared projection.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| let status = read(false) | ||
| guard status == -600 else { return status } | ||
| start() |
There was a problem hiding this comment.
P2: When System Events is stopped, the chat permission status check can freeze the main actor for up to five seconds because this synchronous probe now waits for LaunchServices. Run the probe, including the launch wait, off the main actor before updating the shared projection.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/Onboarding/SecondBrain/SBOnboardingPermissionRuntime.swift, line 133:
<comment>When System Events is stopped, the chat permission status check can freeze the main actor for up to five seconds because this synchronous probe now waits for LaunchServices. Run the probe, including the launch wait, off the main actor before updating the shared projection.</comment>
<file context>
@@ -101,6 +101,39 @@ enum SBAutomationConsent {
+
+ let status = read(false)
+ guard status == -600 else { return status }
+ start()
+ return read(false)
+ }
</file context>
The Permissions page reported Automation as "Not Granted" on a Mac where System Settings showed the System Events toggle on, and no amount of reopening the page or reactivating the app moved it. `AEDeterminePermissionToAutomateTarget` answers -600 (procNotFound) whenever its target is not running, and System Events is a background-only app that exits as soon as it goes idle — which is its normal state. The passive probe treated that as "no new information" and preserved whatever the app already believed, and from a cold launch that belief is the `false` default of `hasAutomationPermission`. So the row settled on Not Granted for the whole session and every refresh re-confirmed it. Verified on the reporting machine: with System Events stopped, the shipped probe returns -600 and the same probe with the launch step returns 0. The request path already knew this — `SBAutomationConsent` starts the target before asking. Give it a non-prompting status read that does the same and point the passive probe at it, so both paths share one mechanism. LaunchServices sends no Apple Event and `askUserIfNeeded: false` cannot raise a dialog, so the read stays silent. -600 preservation stays as the fallback for a target that will not start. Also stop the chat permission tool from re-deriving `status == noErr` itself: on -600 it wrote a held permission away as missing, and clobbered the flag the Permissions page was showing. It now takes the same projection, for the reason the accessibility branch beside it already documents. Co-Authored-By: Claude Opus 5 <[email protected]>
The passive automation probe learned to start System Events, which makes it blocking: LaunchServices can take up to ~5s on a cold target. Both remaining call sites in ChatToolExecutor (@mainactor) still invoked it synchronously — the check-status tool froze the chat window for the duration of that wait, and the request tool's completion handler ran it inside Task { @mainactor … }. Route the probe through Task.detached(priority: .userInitiated) at both sites, the same rule AppState.refreshAutomationPermission already follows, and add a source-contract regression test so the probe cannot silently move back onto the main actor. Verification: xcrun swift test --package-path desktop/macos/Desktop --filter AppStatePermissionProbeTests (14 passed, incl. new testChatPermissionStatusProbeNeverRunsOnTheMainActor) and --filter SBOnboardingPermissionFlowTests (17 passed). Failure-Class: none Co-Authored-By: Claude Opus 5 <[email protected]>
Git-on-my-level
force-pushed
the
fix/automation-permission-system-events-stopped
branch
from
September 3, 2026 00:59
18499f8 to
378a052
Compare
The new main-actor regression test's escape comment sat three lines above the `String(contentsOf:)` call it was meant to cover. check_desktop_test_quality.py only looks at the offending line and the one immediately before it, so the escape never registered and the ratchet counted the site as new debt (55/148 against a 54/147 baseline), failing CI on Hygiene and both Desktop Swift jobs. Failure-Class: none Co-Authored-By: Claude Sonnet 5 <[email protected]>
…wording HubEscalationTests.testPublicWebPromptIsSpeakableAndExcludesPrivateToolContext still asserted the pre-bce354d767 prefix. That commit (2026-09-02, "preserve realtime voice context boundaries") added "thoroughly" to RealtimeHubTools.publicWebSearchPrompt's opening sentence without updating this assertion. It went unnoticed because CI path-filters skip the Swift jobs unless desktop/macos changes, and this is the first PR to touch that path since the commit landed — it fails only on the PR's merge-ref combination (this branch's test + main's current prompt text), not on either tip alone. Verified locally against the actual refs/pull/12625/merge combination (6/6 HubEscalationTests pass) and via full pr-preflight (22/22). Failure-Class: none Co-Authored-By: Claude Sonnet 5 <[email protected]>
Git-on-my-level
deleted the
fix/automation-permission-system-events-stopped
branch
September 3, 2026 10:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Automation is granted to Omi Beta in System Settings — Omi Beta ▸ System Events, toggle on — and the in-app Permissions page reports Automation · Not Granted, with the three-step "go turn it on" instructions under it. Reopening the page and reactivating the app both refresh, and both re-confirm Not Granted.
Root cause
AEDeterminePermissionToAutomateTargetanswers-600(procNotFound) whenever its target is not running, and System Events is a background-only app that exits as soon as it goes idle. On any Mac that is not currently being scripted — the normal state — the passive probe never gets to see the grant.applyAutomationPermissionStatusdeliberately treats-600as "no new information" and preserves the previous value. That is right on its own terms: a stopped target is not evidence of a revocation. But it also cannot upgrade from a value that was never determined, andhasAutomationPermissionstarts every launch at itsfalsedefault. So the row settles on Not Granted for the whole session, and each refresh re-confirms it.Measured on the reporting machine, same TCC grant, one variable:
The fix
The request path already knew this:
SBAutomationConsent.requestSystemEventsConsentstarts the target with LaunchServices before it asks. Only the passive status read was missing that step.SBAutomationConsent— which the file already names as the single owner of this mechanism — gainscurrentSystemEventsPermission(): probe, and if the answer is-600, start System Events and probe once more.AppState.queryAutomationPermissionStatus()now delegates to it, so the read and the request cannot disagree. It stays silent: LaunchServices sends no Apple Event, andaskUserIfNeeded: falsecannot raise a dialog. It is still a status read, not a request.-600preservation stays, as the fallback for a target that genuinely will not start.Same-machine verification of the fixed logic, System Events stopped:
Also in this PR: the chat permission tool re-derived
status == noErritself, so on-600it wrote a permission the user holds away as missing and clobbered the flag the Permissions page was showing. It now takes the shared projection, for the reason the accessibility branch immediately above it already documents.Tests
SBOnboardingPermissionFlowTests, four new behavioral cases against the production API:0/-1743/-1744) starts nothing-600, so the caller can preserve what it knowshasAutomationPermissionfalse, first probe-600, second0→ the row resolves to grantedLocal:
swift build -c debugclean; the permission suites pass (75 tests, 0 failures); pinned swift-format and SwiftLint clean;check_desktop_test_quality.pyat baseline; line-count ratchet clean at the original base.Follow-up (review): the launch-capable probe was still called synchronously from two
@MainActorsites in the chat permission tool, freezing the chat window for the LaunchServices wait (up to ~5s on a cold target). Both now route throughTask.detached(priority: .userInitiated)— the ruleAppState.refreshAutomationPermissionalready follows — with a source-contract regression test (AppStatePermissionProbeTests.testChatPermissionStatusProbeNeverRunsOnTheMainActor, suite 14/14 green;SBOnboardingPermissionFlowTests17/17 green).Line-Count-Exception: desktop/macos/Desktop/Sources/Providers/ChatToolExecutor.swift | 3750 -> 3772 | Two @mainactor call sites each need a small Task.detached hop so the launch-capable probe cannot freeze the chat window; upstream main grew the file under this PR, so the pre-existing +6 plus the +16 isolation fix are declared together.
Product invariants affected
ChatToolExecutor.swiftis touched only to route one already-existing permission-flag write through the shared projection. No transcript, session, or continuity state is read, written, or stored.Failure-Class: none
🤖 Generated with Claude Code