get_app_state/snapshot fail with 'Apple event error -10005: cgWindowNotFound' after logout+relogin (macOS 27 beta); fixed by reboot
Environment
- open-computer-use: 0.3.1 (latest)
- macOS: 27.0 (Build 26A5406e), Apple Silicon MacBook Pro
- Launched as MCP server by a host agent (also reproduced via direct CLI)
Symptom
doctor reports accessibility=granted, screenRecording=granted, list_apps works, but get_app_state / snapshot fail for every app (even frontmost Google Chrome) with:
Apple event error -10005: cgWindowNotFound
Repro
open-computer-use call get_app_state --args '{"app":"Google Chrome","text_limit":200}'
What we ruled out
- Permissions: re-granted in System Settings;
doctorconfirms granted both times. - Reinstall:
npm uninstall -g+npm install -g(same signed build, TeamIdentifier J9P29FA5BX); TCC re-granted after. No change. - System-level Screen Recording works:
screencapturefrom Terminal succeeds.
Key finding (root cause)
The system's own Accessibility window enumeration was also broken: osascript -e 'tell application "System Events" to tell process "Google Chrome" to get name of every window' returned empty, while process-level queries worked fine. This points to the WindowServer session state, not to this plugin.
Trigger: the problem appeared after a user-session logout + re-login (loginwindow restarted, new WindowServer instance).
Fix: a full reboot (fresh WindowServer) restored everything — get_app_state / snapshot / system AppleScript window enumeration all work again, with no plugin or permission changes.
Suggested improvement (optional)
When the macOS window enumeration returns no windows while permissions are granted, consider detecting this state and suggesting a reboot/logout in the error message instead of returning a bare cgWindowNotFound.
Thanks for the detailed report. I looked through the code to see whether OCU itself could be holding state from before the logout. Here's what I found and what would settle it.
Where the error comes from. Apple event error -10005: cgWindowNotFound is a fixed string. It matches the official Computer Use error shape, and a test pins it. The snapshot path throws it in two cases (AccessibilitySnapshot.swift, SnapshotBuilder.build):
- Accessibility returns no usable window for the app: no
AXFocusedWindow, and nothing inAXWindowswith roleAXWindow(after one activate/raise retry). - The window was found, but
CGWindowListCopyWindowInfohas no window with that ID for the app's pid.
query throws the same string when case 1 applies.
Your System Events result (every window is empty while process queries work) is exactly case 1. It comes from a separate process that doesn't use OCU, which points at the macOS session rather than at OCU.
What OCU keeps across calls. It doesn't cache window lists, AX elements, or SkyLight connection IDs between calls. SLSMainConnectionID() is read on every call. The one long-lived piece is the app agent. doctor, list_apps, call and mcp are all proxied into a background Open Computer Use.app process, started through LaunchServices with a socket in $TMPDIR. A new call reuses that agent if its bundle path and build identifier match, and if it started after the executable's modification time. npm keeps the packaged mtime (the build date), so reinstalling the same version doesn't normally restart a running agent.
A logout should end that agent along with every other app. If it somehow survived on this macOS 27 beta, it would explain everything that goes through OCU. It wouldn't explain System Events, unless System Events also survived.
Next time it happens (before rebooting), could you run these and paste the output?
# 1. When did the current login start, and do the OCU agent / System Events predate it?
who -m; last -1 "$USER"
ps -axo pid,lstart,command | grep -E "__open-computer-use-app-agent|System Events" | grep -v grep
# 2. Does a fresh System Events also see no windows?
killall "System Events" 2>/dev/null; sleep 1
osascript -e 'tell application "System Events" to get name of every window of process "Google Chrome"'
# 3. Does WindowServer still list Chrome's windows (separate from Accessibility)?
osascript -l JavaScript -e 'ObjC.import("CoreGraphics"); const l = ObjC.deepUnwrap(ObjC.castRefToObject($.CGWindowListCopyWindowInfo(1, 0))); JSON.stringify(l.filter(w => w.kCGWindowOwnerName === "Google Chrome").map(w => [w.kCGWindowNumber, w.kCGWindowLayer, w.kCGWindowName]))'
# 4. Does a fresh OCU agent recover?
pkill -f __open-computer-use-app-agent; sleep 1
open-computer-use call get_app_state --args '{"app":"Google Chrome","text_limit":200}'
How to read the results:
- If step 4 fixes it, the agent outlived the session. The fix would be to restart the agent when it belongs to a different login session.
- If step 2 is still empty and step 3 lists the windows, macOS Accessibility is broken in the relogged session. That's a beta bug to report through Feedback Assistant. On our side, the most we could do is add a hint to this error when
AXWindowsis empty but WindowServer lists on-screen windows for the app. - If step 3 is empty too, WindowServer itself lost track of the session's windows.
The macOS build, and whether Fast User Switching was involved, would help too.
I'm holding off on a code change until we know which of these it is.
Another data point on macOS 27, with a different error but what looks like the same stale-agent shape. Your step 4 fixed it.
Setup: Apple M1, macOS 27.0 (26A428), open-computer-use 1.1.2 (npm global). The machine had just been upgraded from 26.4.1. This was the first login after the upgrade.
Symptom: list_apps worked. Every get_app_state call, and open-computer-use snapshot <app>, failed for every app I tried (App Store, Finder, an Electron app) with:
Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"
Nothing showed up in the unified log for process OpenComputerUse when it failed. doctor --json reported {"accessibilityTrusted":true,"allGranted":true,"missingPermissions":[],"screenCaptureGranted":true}.
Timing: The app agent (__open-computer-use-app-agent) started at 10:43:51. That is the same second as the login, and 2 s before the open-computer-use mcp process that spawned it (an MCP client that starts at login).
Fix: pkill -f __open-computer-use-app-agent. The next open-computer-use call get_app_state --args '{"app":"Finder",...}' started a fresh agent and returned the tree and screenshot right away. Running open-computer-use mcp servers then reported "Connection closed" until their clients reconnected.
My guess is that an agent started in the first second of the first login after a major upgrade keeps a session state that never becomes usable. A health check in the agent would help, for example a probe of AXFocusedWindow or CGWindowListCopyWindowInfo on start or after the first failure, followed by a self-restart. I'll report whether it recurs on a normal reboot.
Thanks, that's useful: step 4 fixing it means the long-lived agent was holding the bad state, not the session as a whole.
The error text is a Swift POSIXError(.ENOENT) bridged to NSError. On the get_app_state / snapshot path, unlike list_apps, every read first runs requireUsableComputerUseSession(). When the session reports unlocked, that calls LockedUseActionScope.validate(). If /Library/Application Support/OpenComputerUse/LockedUse/run/observer.sock exists, validate() connects to it, and its socket code throws exactly this kind of POSIXError. A Unix-socket connect() returns ENOENT when the path is gone by the time it connects. At the first login after an upgrade, the Locked Use broker may still be recreating its sockets. So list_apps working and every read failing fits that check, more than screenshots or Accessibility. That's my best guess from the code, not confirmed.
If it happens again, could you run these before killing the agent?
ls -la "/Library/Application Support/OpenComputerUse/LockedUse/run/"
open-computer-use locked-use status --json
If Locked Use isn't installed (no run/ directory), this guess is wrong, and the next suspect is something the agent loaded at launch that the upgrade moved.
Either way, your health-check idea looks right as the general fix. When a reused agent fails with an error a fresh agent wouldn't produce, the proxy should restart it once and retry, instead of keeping a broken agent for the whole session.
Follow-up on the questions above:
- Locked Use is not installed on this machine:
/Library/Application Support/OpenComputerUse/does not exist. So the observer-socket explanation does not fit our ENOENT. By your note, that points to something the agent loaded at launch that the upgrade moved. - After the next OS update (macOS 27.0 → 27.2, 26B123;
open-computer-use1.1.4), the first session after the restart worked right away:get_app_statesucceeded, with no stale agent and nopkill. So the failure is not reproducible on every update. - +1 for restart-once-and-retry in the proxy.
There are two different failures in this thread:
- The original report: System Events also listed no windows for Chrome, and System Events doesn't use OCU. So the macOS 27 beta session itself was broken, and the reboot fixed it. If it happens again on a release build of macOS 27, Feedback Assistant is the place to report it.
- The ENOENT error: killing the app agent fixed it, so the long-lived agent was holding bad state. Locked Use wasn't installed on that machine, which rules out the socket check, and the failure didn't come back on the next update.
I don't want to add an automatic agent restart without knowing the cause. The agent is shared, and restarting it drops every other MCP client's connection. If either failure shows up again, pkill -f __open-computer-use-app-agent is the workaround, and the next call starts a fresh agent. Before killing it, please paste the output of ps -axo pid,lstart,command | grep __open-computer-use-app-agent and the exact error. That output tells us whether the agent predates the login.