Skip to content

Native key events may reach the frontmost app instead of the bound app (Chrome window closed twice after helper typing runs) #162

Closed

Description

@SSFSKIM

Problem & intent

On the Mac mini, the owner's Chrome "Profile 1" window, the only window of the resident Chrome (pid 36513), closed on its own twice in two days. Each time it followed a run in which the native computer-use helper typed into TextEdit:

  • the window had closed by 06:30Z on 2026-10-18; the last run before that was the accept-native sitting at 03:15Z, which types into TextEdit;
  • it closed between 15:43Z and 15:48Z on 2026-10-18, during native-baseline's vendor computer task set, which sends super+n ×2, typeText ×10, super+w ×10 and super+q ×1 to a TextEdit document the run opened itself.

Nobody was at the mini either time. The HID idle time puts the last input at the run's own final super+q. The browser runs in the same window can't reach that Chrome. AX confirmed every expected TextEdit close, but it can't show where any other key went. So the leading hypothesis is that a modifier key event (super+w, possibly super+q) reached whichever app held key focus at that instant, rather than the app the session is bound to. If true, a cua computer session could close or quit another app's window during normal use, the owner's included. super+q landing in Chrome would quit it.

The evidence is correlation, not a proven mechanism. The intent: establish how the helper posts key events (to the bound app's pid, or globally to the focused app), and if they can land elsewhere, make cua never deliver a key to an app other than the one the call names.

What to do

  1. Investigate, without risking the owner's apps. Use a scratch macOS user or the CI hosted runner's GUI session where possible, or on the mini a sacrificial app in front instead of Chrome. Find out how the vendor helper (Codex Computer Use) delivers pressKey and typeText: whether it posts to a pid or globally, and what happens when the bound app loses key focus mid-sequence. Use the logs, an event tap that observes without modifying, and the frontmost-app timeline.
  2. If keys can land elsewhere, add a guard in cua's API layer: check the frontmost app or the key window's owner against the bound app immediately before each key event, and refuse the call (a classified error) rather than send it. Or route keys to the pid, if the helper offers that. This touches Independence 4: cua's own native accessibility engine (replace sky) measured against a native baseline #117's goals: the driven window must not jump forward, and driving must stay off other apps.
  3. Until that's resolved, harnesses that send super+w or super+q on the mini do so only with no owner app window open, or they check the frontmost app before each such key.

Success criteria

  • A written finding on how the helper routes keys, with the reproduction or its absence.
  • If keys can misroute: a cua call that would send a key while the bound app isn't frontmost refuses with a classified error, pinned by a test with a stub helper.

Constraints

Never quit or kill the owner's Chrome or other apps; never automate permission dialogs; synthetic secrets only.

Activity

  1. added
    bug
    status:ready-for-architect
    priority:P1
    on Oct 18, 2026
  2. added 2 commits that reference this issue on Oct 18, 2026
  3. added
    status:in-design
    and removed
    status:ready-for-architect
    on Oct 18, 2026
  4. SSFSKIM commented on Oct 18, 2026

    @SSFSKIM
    OwnerAuthor

    [board] in-design: Taken by the cua coordinator: a static investigation of the key-delivery path (cua API → vendor JS → native helper symbols) is running, with no GUI or input. Its findings decide whether a live experiment is needed.

  5. SSFSKIM commented on Oct 18, 2026

    @SSFSKIM
    OwnerAuthor

    Static finding (read-only; nothing executed, no GUI, no helper launched): the helper posts keys to the bound app's pid, not to whichever app has focus.

    Delivery path:

    • cua's API layer: pressKey/typeText call sky.press_key({app, key})/sky.type_text({app, text}) (src/cua-api/bind-mac-app.mjs:55, :76) and go through the trusted service unchanged (src/services/sky.mjs). Only the app string travels.
    • Vendor JS (@oai/sky 0.7.5): withComputerUsePolicy resolves the app to the approved app's path. client.pressKey sends a ComputerUseIPCAppPerformActionRequest {app:<path>, action:{pressKey|type}} over the helper's socket.
    • Native helper (SkyComputerUseService, not stripped):
      • The request resolves the path to a running app (NSWorkspace.resolveApplicationTarget(for:)). Then ComputerUseAppController.performKeyboardAction gets the target from ApplicationUIElement.targetForKeyboardEvent(), a KeyboardEventTarget{pid, element} holding the bound app's pid. The one exception is an out-of-process focused element, which is accepted only when its AX parent chain ties it to the bound app.
      • The keys go SynthesizedEvent.send(to: pid, delay:), which only ever calls CGEventAPI.postToPid, by cross-reference.
      • The global CGEventAPI.post(_:tap:) has two callers, both in SystemLockScreenController: ctrl+cmd+Q to lock the screen, and typing the lock-screen password.
      • activateWithOptions: is reached only from the click path (syntheticallyActivateIfNeededForSendingClick), never the keyboard path.

    The closures don't fit the key path:

    • AX showed 10/10 super+w closes landing in TextEdit in every vendor run.
    • Chrome's pid never changed, so no super+q reached it.
    • The mini already measured that keys sent to TextEdit don't reach its out-of-process Open panel, even while TextEdit is frontmost (scripts/native-baseline/cells.mjs:66). That is what pid delivery predicts.
    • The HID-idle clue has a benign cause: the helper calls IOPMAssertionDeclareUserActivity("Codex Computer Use interaction") for every request, which resets HID idle without any HID-level key.

    Static analysis can't settle:

    • which function the hashed postToPid resolves to (CGEventPostToPid or SkyLight's equivalent, by name and signature);
    • whether macOS 26 ever reroutes pid-posted key events;
    • what happens when focus moves mid-sequence.

    The Open-panel measurement is evidence against rerouting.

    Decision:

    • No guard in cua's API layer now. A frontmost-only rule would break background driving, which the helper is built for, and Independence 4: cua's own native accessibility engine (replace sky) measured against a native baseline #117's rule that the driven window must not jump forward.
    • If the misroute is ever reproduced, the guard goes in handleRpc in src/services/sky.mjs on execute for press_key/type_text/paste, with a frontmost read from the supervisor (the nodeRepl.launchServices precedent). It refuses with a classified error, pinned by a stub-helper test.
    • The harness key guard (scripts/accept/key-guard.mjs, 9d4e5bb, 9173dbf) stays as step 3.

    Next: find what did close the window. A read-only timeline of Profile 1's window and tab closes from Chrome's Sessions/ files (timestamps and command types only, no URLs or titles), lined up against cua's tab operations and every run on the mini at those times. A live decoy-app experiment runs only if a close lines up with a super+w to the second.

  6. SSFSKIM commented on Oct 18, 2026

    @SSFSKIM
    OwnerAuthor

    Both closures were close-button clicks that came in over Screen Sharing. cua and the helper's keys were not involved.

    Closure 1, 2026-10-18 03:14:43Z.

    • The mini's unified log shows Chrome's trackMouse send action on mouseUp at 03:14:43.572Z, then windowShouldClose at .578Z.
    • The WindowServer HID mouse-down came at .454Z and the mouse-up at .569Z, while a Screen Sharing viewer was attached.
    • The click was 35 s before accept-native started (03:15:18.764Z), while its gate was waiting on front=com.google.Chrome (m1 sitting-log lines 1444–1456).

    Closure 2, 2026-10-18 15:31:52.737Z (not 15:43–15:48Z as first recorded).

    • The Default profile's window closed first, with a click at 15:31:49.703Z (window 2b623). Then Profile 1's (window 29bbc) closed at 15:31:52.737Z.
    • Verified on the mini by the coordinator:
      2026-10-19 00:31:49.703 KST Google Chrome[36513] (AppKit) trackMouse send action on mouseUp
      2026-10-19 00:31:49.710 KST ... windowNumber=2b623 windowShouldClose
      2026-10-19 00:31:52.737 KST Google Chrome[36513] (AppKit) trackMouse send action on mouseUp
      2026-10-19 00:31:52.737 KST ... windowNumber=29bbc windowShouldClose
      
    • screensharingd (pid 51162) re-added its viewer at 15:31:41Z, and ScreensharingAgent processed pointer events from 15:31:45Z.
    • Profile 1's session files hold a "Window" close entry at 15:31:52.748Z. cua's host log has native port closed (end) at 15:31:52.806Z, which is the profile unloading. The host's last cua session had ended at 07:02:21Z.
    • Nothing closed between 15:43Z and 15:48Z: Chrome had no window then. Group B's first vendor run started at 15:43:18Z.
    • MAWS CI job e2e:dashboard (run 39140360292) was in a waitForTimeout loop and sent no OS input. No cua session or helper activity appears at either second.

    Side findings:

    • ci-kit's posture lines read remote=none at 15:28:41Z and 15:32:07Z (~/Library/Logs/ci-kit/mac-runner-hooks.log) while that viewer was attached. Passed to CI-opt.
    • The last-tab guard (src/chrome/host.mjs keepWindow) lets a close go ahead after its 2 s wait, or when tabs.create is refused. That is deliberate, as its comment says, and it was not involved here.

    To re-read while the log lasts (mini; zsh shadows log, times in KST):
    /usr/bin/log show --start "2026-10-18 12:00:00" --end "2026-10-19 02:40:00" --predicate 'process == "Google Chrome" AND (eventMessage CONTAINS "windowShouldClose" OR eventMessage CONTAINS "trackMouse send action")' --style compact

    Records corrected in #164.

  7. added a commit that references this issue on Oct 18, 2026
  8. removed
    status:in-design
    on Oct 18, 2026
  9. added a commit that references this issue on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority:P1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions