Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds a reusable Accessibility trust-settling poller with outcome tracking and tests for success, timeout, and interval clamping. Runtime snapshot and CLI permission checks now use settled trust results. Focused-window lookup gains recovery and trust-settling retries, with distinct 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Gentle bump on this one — small change (+160/−24, 3 files, all under
Happy to split or rework it if the approach isn't the one you'd want. |
43ecfc4 to
de872a5
Compare
| if visibleWindowCount > 0 { | ||
| // Why: on a fresh helper process AX reads can be denied by tccd's | ||
| // uncached preflight answer for a moment even though trust is granted | ||
| // (#9458) — the "visible windows but no accessibility window" state. | ||
| // Give the AX session time to settle before declaring it broken. | ||
| var settledWindow: AXUIElement? | ||
| let outcome = AccessibilityTrustSettling.settle { | ||
| settledWindow = lookupUsableWindow(systemWide: systemWide, appElement: appElement, app: app) | ||
| return settledWindow != nil | ||
| } | ||
| if let window = settledWindow, outcome.settled { | ||
| return window | ||
| } | ||
| throw ProviderError.coded( | ||
| "permission_denied", | ||
| "app '\(app.name)' has visible windows but no accessibility window (AX reads stayed blocked for \(outcome.waitedMs)ms after retries). macOS Accessibility may need Orca Computer Use toggled off and on again in System Settings." | ||
| ) |
There was a problem hiding this comment.
Stacked settle timeouts can reach 3 s end-to-end
buildSnapshot first calls accessibilityTrustedSettled() (up to 1.5 s), and if that succeeds the focusedWindow settle loop can add another 1.5 s. Both phases run independently, so a request in the race window can block for up to 3 s total rather than the 1.5 s cap described in the PR.
In practice the two races are correlated — once tccd caches the trust answer for the pid, both AXIsProcessTrusted and the AX attribute reads should resolve together, so the second loop should rarely add significant time. But the theoretical ceiling is worth documenting in a comment alongside the defaultTimeoutMs constant or in focusedWindow, especially since the error message already surfaces outcome.waitedMs and users may be surprised by a longer-than-expected stall.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Documented on defaultTimeoutMs: a snapshot can run the two settle phases back-to-back, so the worst-case stall is 2x the cap; tccd's cached answer makes the second phase near-instant in practice.
| @Test("final interval is clamped so total wait never exceeds the timeout") | ||
| func clampsFinalInterval() { | ||
| var sleeps: [Int] = [] | ||
| let outcome = AccessibilityTrustSettling.settle( | ||
| timeoutMs: 250, | ||
| intervalMs: 100, | ||
| sleepMs: { sleeps.append($0) }, | ||
| probe: { false } | ||
| ) | ||
| #expect(sleeps == [100, 100, 50]) | ||
| #expect(outcome.waitedMs == 250) | ||
| } |
There was a problem hiding this comment.
clampsFinalInterval leaves outcome.attempts unverified
The test confirms sleep durations ([100, 100, 50]) and waitedMs but not attempts. Based on the loop logic the expected count is 4 (three sleeps + one final probe after the last sleep hits the timeout). Adding #expect(outcome.attempts == 4) would fully pin the boundary condition and make it as tight as the neverGranted test immediately above it.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Added #expect(outcome.attempts == 4) to clampsFinalInterval — all 4 suite tests pass.
Greptile SummaryThis PR fixes a
Confidence Score: 4/5Safe to merge — the settling loop is bounded, the happy path adds zero latency, and the unit tests are deterministic with injected sleep. The core settle implementation is correct: interval clamping, the timeout boundary, and the probe-first ordering are all verified by the unit tests and confirmed by manual trace. The refactored lookupUsableWindow is a clean deduplication. Two observations worth a follow-up: the trust-check settle and the AX-read settle in focusedWindow are independent and can stack, theoretically reaching 3 s in the worst case; and the clampsFinalInterval test omits an attempts assertion. Neither affects correctness today. Files Needing Attention: The stacked-timeout interaction in main.swift (lines 604 and 1070–1086) is the area most worth a second read before merging.
|
| Filename | Overview |
|---|---|
| native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/AccessibilityTrustSettling.swift | New settling primitive: probe-then-poll loop with correct boundary conditions, interval clamping, and precondition guard against zero/negative intervals. |
| native/computer-use-macos/Sources/OrcaComputerUseMacOS/main.swift | Wires settling into three trust-gate sites and refactors focusedWindow with a dedicated settle loop for the AX-reads race; worst-case latency can stack across both settle phases in a single invocation. |
| native/computer-use-macos/Tests/OrcaComputerUseMacOSTests/AccessibilityTrustSettlingTests.swift | Four deterministic unit tests cover all key settle-loop paths; clampsFinalInterval leaves outcome.attempts unchecked but the sleep-sequence and waitedMs assertions are sufficient coverage of the clamping logic. |
Sequence Diagram
sequenceDiagram
participant CLI as CLI Invocation
participant main as main.swift
participant settle as AccessibilityTrustSettling
participant tccd as tccd (macOS)
participant AX as AX APIs
CLI->>main: buildSnapshot / printPermissionStatus
main->>settle: settle(probe: AXIsProcessTrusted)
loop until trusted or 1500ms elapsed
settle->>tccd: AXIsProcessTrusted()
tccd-->>settle: preflight_unknown (denied) OR granted
alt granted
settle-->>main: Outcome(settled: true, waitedMs: N)
else still denied and timeout remaining
settle->>settle: sleep 100ms
end
end
settle-->>main: Outcome(settled: false) → throw permission_denied
main->>AX: focusedWindow → lookupUsableWindow (fast path)
AX-->>main: window OR nil
alt "no window found AND visibleWindowCount > 0"
main->>settle: settle(probe: lookupUsableWindow)
loop until window found or 1500ms elapsed
settle->>AX: lookupUsableWindow
AX-->>settle: window OR nil
alt window found
settle-->>main: Outcome(settled: true)
main-->>CLI: return window
else still nil and timeout remaining
settle->>settle: sleep 100ms
end
end
settle-->>main: Outcome(settled: false)
main-->>CLI: throw permission_denied with waitedMs
end
Reviews (1): Last reviewed commit: "fix(computer-use): settle Accessibility ..." | Re-trigger Greptile
de872a5 to
2ec9487
Compare
… helper processes tccd answers a freshly spawned helper with preflight_unknown/do_not_cache, so the first Accessibility answers a new process sees can read as denied while the grant is real, flipping to granted moments later in the same pid (stablyai#9458). Every CLI call spawns a fresh helper, so one-shot checks lose the race on every invocation: permissions reports granted while every get-app-state fails permission_denied (stablyai#9159). - add AccessibilityTrustSettling.settle: immediate probe, then bounded 100ms polls (1.5s cap); zero added latency when already trusted - buildSnapshot trust gate, both permission-status printers, and the 'visible windows but no accessibility window' path now settle before concluding denial; the latter retries the actual AX window lookup and reports how long reads stayed blocked - extract lookupUsableWindow to dedupe the pre/post-recovery lookups - deterministic unit tests for the settle policy (injected sleep)
Co-Authored-By: Claude Fable 5 <[email protected]>
2ec9487 to
89174b5
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Closing as superseded: #13025 (merged 2026-08-07) lands the same settle mechanism this PR proposed — the PermissionTrustSettling loop is line-for-line the AccessibilityTrustSettling core from here (same Outcome shape, defaults, and final-interval clamp) — generalized to screen-capture checks with broader tests, including coverage of the buildSnapshot double-settle path this PR's review discussed. Nothing in this branch remains that main doesn't now do better. Thanks to whoever carried it over the line. |
Problem
orca computer permissionsreportsaccessibility: grantedwhile every windowed action (get-app-state,click, …) failspermission_denied— the diagnostic says healthy while the tool is unusable. Filed as #9159, consolidated into #9458.Root cause (from the tccd IPC trace in #9458)
Every CLI invocation spawns a fresh, short-lived helper process.
tccdanswers a freshly spawned process withpreflight_unknown/do_not_cache(auth_reason=5), so the first Accessibility answers a new pid sees can be denied while the grant is real — the same pid flips to granted moments later in the trace. One-shot checks therefore lose the race on every invocation:AXIsProcessTrusted()one-shots gatebuildSnapshotand the permission-status printers.Fix
AccessibilityTrustSettling.settle: probe immediately, then poll on 100 ms boundaries, capped at 1.5 s. Already-trusted processes pass on the first probe — zero added latency on the happy path; the cap only spends time in the exact state that used to hard-fail.buildSnapshottrust gate, both permission-status printers, and the "visible windows but no accessibility window" path — which now retries the actual AX window lookup (not just the trust bit) and reports how long reads stayed blocked if it still fails.lookupUsableWindowto dedupe the identical pre-/post-recovery lookup blocks.Validation
swift buildclean; full suite passes (37 existing + 4 new).get-app-state→permission_deniedwithpermissions→ granted, matching orca computer: Accessibility permission_denied persists despite granted TCC access (preflight-unknown race on fresh helper process) #9458's trace signature). We could not E2E the patched binary against that machine's TCC state: a dev-built helper has a different code identity, so it gets a fresh TCC row rather than inheriting the raced one. Review therefore leans on the orca computer: Accessibility permission_denied persists despite granted TCC access (preflight-unknown race on fresh helper process) #9458 trace: answers change across probes within one pid, which is exactly what a bounded settle loop addresses. Happy to iterate if maintainers with a repro rig can run this against it.Fixes #9458 (and the already-consolidated #9159).
ELI5
macOS said Accessibility was allowed, but every computer-use click still failed right after a fresh helper start. The app now waits for that permission check to settle before giving up, so tools work once you have granted access.