Skip to content

Own engine brings the driven app to the front in MAWS sessions (MacBook opt-in build) #200

Closed

Description

@SSFSKIM

Observed

The owner reports, 2026-10-23: on the MacBook, MAWS development sessions that use cua's own engine keep bringing the app the agent is driving to the front, instead of working in the background.

Known

  • Activation is deliberate on some paths in the spec:
  • Which calls activate in these sessions is not yet known: which app, and whether it happens on getApp, getAXState, click, typeText or paste.

Next

Offline diagnosis first. Correlate the cua_repl calls in today's MAWS session transcripts with the engine's activation sites on d95261f. Then classify each site: by design (with its condition), or a defect. Then fix. A live confirmation follows on the MacBook only with the owner's go, since it is their working machine.

Relates to #117, #184, #188.

Activity

  1. added
    bug
    status:ready-for-implementer
    priority:P1
    on Oct 23, 2026
  2. SSFSKIM commented on Oct 23, 2026

    @SSFSKIM
    OwnerAuthor

    Offline diagnosis — the clearest cause is explicit Raise requests

    The UX-comparison agents explicitly asked cua to raise MAWS, Claude Desktop, and Codex/ChatGPT windows. Two such requests demonstrably completed without error; later attempts often swallowed errors. This is a much stronger explanation of windows jumping forward than an unconditional activation in getApp or getAXState, which I did not find.

    There is also a real coverage gap worth fixing: the route-3 non-interference guard finishes before the requested action is dispatched. It cannot detect a target becoming frontmost because of that action, or a delayed activation after preparation. This gap is established by code, but these transcripts do not establish that it caused this incident.

    No GUI was driven, no engine was launched or queried, and no repository was edited. The findings below contain only reduced API shapes, timestamps, and engine metadata—not transcript dumps, prompts, screenshots, or private app contents.

    1. Evidence and what it proves

    The useful evidence is in the architect session 37052769's subagent transcripts, not its top-level transcript. The initially named 593a1e3f transcript contains older October 19 cua calls and was last modified October 22 locally; it is not evidence of today's opt-in behavior. The coordinator's separate read-only verification was excluded.

    All timestamps below are 2026-10-23 UTC. The relevant results identify cua/nativeEngine.engine = cua, build 0c363f8f4512b24891ce22af50f6515f99af4b008bee09770245de03b8c7e80d, matching the reported opt-in build.

    Time / worker App and API Observed result / inference
    10:24:11.758 / a2afc7cb Claude Desktop: performSecondaryAction(0, 'Raise'), then screenshot No catch around Raise; the subsequent screenshot returned. The explicit AXRaise request succeeded.
    10:58:09.066 / ab82006e MAWS in Electron: state read, then performSecondaryAction(0, 'Raise') Successful result; metadata cua/inputRoute: 1. Explicit AXRaise, without route-3 preparation in this call.
    11:04:33.193 / ab82006e MAWS: performSecondaryAction(0, 'Raise').catch(...), then other input Raise was attempted, but its error was discarded; success cannot be established separately.
    18:26:14.023; 18:28:51.541 / ab82006e Claude Desktop: the same caught Raise, then click or Escape Both attempted; per-Raise success hidden. The latter cell returned userChanged on a subsequent action, not proof of activation.
    18:32:40.730 / ab82006e Codex/ChatGPT (com.openai.codex): caught Raise, then click/typeText Raise attempted; later field content changed. No separate Raise outcome.
    11:11:07.516 / a2afc7cb Claude: getApp(...) followed by Raise in the same cell Do not count this as a Raise: getApp failed with “No capturable window found: Claude”, before the Raise.
    10:10:56.793 / a2afc7cb MAWS: coordinate click Route 3; preparation guard 40.146 ms; activationClick: outsideFrame. Synthetic activation ran, but its extra activation-point click was skipped.
    10:53:21.968 / ab82006e MAWS: element click Route 3; guard 41.094 ms; activation-point click skipped (outsideFrame).
    10:28:42.727 / ac748858; 18:24:29.131 / aa50e56b MAWS open-panel Cancel button: element click Route 3; guards 43.359 / 48.711 ms; activationClick: noPoint. Again, no extra activation-point click. The panel can be served by a process other than Electron.
    18:13:06.090; 18:13:58.206 / aa50e56b Claude: setValue, then a later element click Surviving metadata reports route 3. A fresh activation is not proved merely by the route number: the held activation may be reused.
    10:19:00.592 / a2afc7cb; 10:55:39.694–10:56:39.736 / ab82006e; 11:11:36.320 / a2afc7cb; 18:12:52.598 / aa50e56b MAWS explicit paste/typeText; Claude typeText Metadata reports inputRoute: paste. Thus typeText is not necessarily a no-activation key-post path on this machine.

    The workers also issued many Command-key shortcuts to MAWS, Claude and Codex. Their source route condition is discussed below; most cells followed input with an observation, which overwrote the input metadata.

    Important evidence limit: no examined result records a before/after frontmost PID or top-window order, and none reports activationFailed or foregroundRestoreFailed. An AX tree header saying App: Electron/Claude/ChatGPT, a field's focused flag, or the advertised secondary action Raise does not say which application is globally frontmost. Successful AXRaise establishes that the app accepted a request to raise its window; it does not separately prove an NSWorkspace.frontmostApplication transition. We can identify concrete causes/candidates, not reconstruct every focus transition.

    2. Activation / raising inventory on d95261fb

    Links below are pinned to the inspected source. E/ in the table means native/engine/Sources/Engine/.

    Site Exact condition and effect
    E/SecondaryAction.swift:85–107, dispatch at :50–62 performSecondaryAction matches the supplied description against the target's offered actions. Raise maps to AXRaise and is performed on the target. There is no background-mode veto. Other explicitly requested AX actions, such as opening an item, can have app-defined window/activation side effects too.
    E/Activation.swift:201–274 Route 3: unless the target already has frontmost or key-focus PID, post AppKit application-activated subtype 1 to its PID, optionally click its AXActivationPoint, then guard. The extra click only occurs inside the window, outside the spared non-left-click target, and on inert hit-tested chrome (Routes.swift:241–267). No point, outside frame, control, or uncertain hit skips it. Subtype 2 releases the fake activation unless the target really became frontmost (:252–255).
    E/Activation.swift:82–93, 210–245 Real NSRunningApplication.activate(options: []) and AXRaise are injectable primitives. Route 3 uses them on the previous user app/window, not to intentionally foreground the target: raise the user's window if the target overtakes it; if target/bound-app becomes frontmost during preparation, reactivate the user app and throw activationFailed. A third app becoming frontmost is left alone. Menu mode restores by activation rather than AXRaise.
    E/Input.swift:270–318, E/ElementInput.swift:198–221 Element clicks use AXPick/AXPress for an eligible single left click; otherwise synthesized route 3 (coordinates always synthesize). Even the AX-action branch prepares through held route 3 if the target does not believe it has focus. The actual AX action/pointer events follow preparation.
    E/FocusHold.swift:105–138, Routes.swift:112–126 Held preparation for element clicks/actions/writes and Command-key equivalents when not believed-focused; recorded-menu actions already share a hold. Not Electron-only and not an “AXPress failed” fallback: this broader rule is explicitly approved by the design's October 22 amendment, design:1056. Holds are shared, refreshed after real activation/deactivation, and released on connection end, another-app request or 120 s idle. Do not mistake every route-3 result for a new activation.
    E/ValueSetting.swift:90–101, TextSelection.swift:154–169, ElementInput.swift:78–90, 228–237 setValue/selectText prepare the held activation, then for an unfocused, focus-settable text field/area/date-time area set AXFocused=true. If focus does not take, synthesize a click. Safari DOM fields go straight to the click. A minimized field skips the fallback click. This is a focus-changing path, not an AXFrontmost/AXMain setter. #188 describes unresolved field-preparation failures, not permission to visibly foreground Electron.
    E/Input.swift:330–358, 399–438 pressKey with a Command chord takes held route 3 if not believed-focused; ordinary keys and reliable Latin typeText use plain PID posts. Non-Latin/unknown per-app input-source context sends typeText to paste. A test-only forced route can acquire route 3 for keys/text; product service gates this spike override.
    E/Paste.swift:249–280 Explicit paste and typeText's paste fallback acquire shared route-3 activation, post Command-V, wait for paste consumption/effect, restore clipboard and release their lease. Reuses an existing hold; does not directly call real target activation.
    E/Input.swift:273–277, SecondaryAction.swift:88–95, MenuSpan.swift:310–323 Plain single left click on AXMenuBarItem with a menu, or its AXPick secondary action: activate-and-record the menu under a held fake activation. Other menu-bar click forms are refused; AXCancel clears the record. An ordinary in-app popup button is not this menu-bar path.
    E/ScrollDrag.swift:145–163 Drag prepares route 3 before its down/moves/up, or route 4 under the app override. Scroll itself is plain PID-posted input, not an activation route.
    E/ForegroundAssist.swift:41–79, Routes.swift:59–66 Route 4 deliberately activates the target, dispatches pointer input, then reactivates the previous app and raises its window. Only an explicit per-app routes[bundleID] = 4 override selects it. No route-4 result found; the default ~/.config/cua/engine.json is absent at inspection time. This does not prove historic configuration, but gives no evidence for route 4 here.
    E/Skyshot.swift:58–79, 166–178, Apps.swift:233–241 getApp calls get_app_state; observations launch a non-running app, or reopen a running app whose primary window is absent. Failed AX reads retry rather than reopen; minimized windows are not reopened. NSWorkspace.OpenConfiguration.activates = false. A target may react to launch/reopen itself, but there is no unconditional foreground request here. Normal existing-window observations only read/enable AX; the enablement writes are AXManualAccessibility/AXEnhancedUserInterface, not focus/raise.
    src/repl-host/launch-services.mjs:100–110, src/services/engine/client.mjs:197, src/runtime/engine.mjs:382–384 Launching the engine bundle by path uses open -n -g -a: background. The generic privileged launch service's bundle-ID branch uses open -b ID, without -g, and therefore can foreground an app. That branch is not how native cua.getApp('bundle.id') works and was not found in these calls. It is a separate contract asymmetry, not the incident's established cause.

    No SetFrontProcess, AXFrontmost=true, AXMain=true, or target-window makeKeyAndOrderFront implementation was found in this engine/service source. The potentially raising APIs are the ones above, including app-defined behavior after AX actions and PID-posted events.

    3. Classification and recommended fixes

    (a) By design, correctly conditioned in the evidence

    • Explicit Raise: correctly dispatched because the caller asked for it. The defect is using it as routine preparation in a background-only workflow, not an implicit getApp activation. Immediate fix: remove the agents' Raise-as-preparation calls and stop swallowing their errors. Ask for foreground operation only when the task actually requires it. Do not remove the public action or make Raise a silent no-op. A regression workflow should bind and operate a background app while a sentinel app stays frontmost, without an explicit Raise, and separately test that an explicitly requested Raise still maps to AXRaise.
    • Route-3 click/action/field preparation and paste: actual guard/paste metadata matches the designed conditions. The two observed outsideFrame and two noPoint cases specifically show that the activation-point safety skip worked. No evidence establishes an over-eager extra activation click, a broken hold-refresh condition, or a route-4 fallback.
    • Command chords and field-focus fallback are reachable by the calls, but the transcripts do not preserve enough intermediate metadata to certify each conditional branch. Their code conditions match the amended design. Likewise, no distinct menu-bar activate-and-record occurrence was established; in-app popup interactions alone are not evidence of it.

    (b) By design but firing too broadly: none demonstrated. In particular, do not “fix” the broad held-focus rule merely because the original motivation mentions Electron: the approved amendment deliberately covers element actions and Command shortcuts generally. Removing it would regress known delivery cases.

    (c) Static non-interference coverage defect, causation not established: guard ends before delivery.

    FakeActivation.activate() releases the screen hold and ends its polling before returning (Activation.swift:218–246); deliverPointer then posts the real click/drag (Input.swift:168–185). AX actions and field writes likewise happen after preparation. Held activations can bypass a new guard entirely. A target that becomes frontmost during/after the requested action is not checked or restored by this path; deactivation explicitly skips a target that is now really frontmost.

    • Minimal repair direction: retain the original user-app/window baseline across background action delivery and a bounded post-delivery check; detect target-attributable foreground/order changes there too, including actions that reuse a held activation. Restore only an engine-attributable target steal, never overwrite a genuine user switch. Keep the existing 100 ms screen-update cap. Report a post-delivery interference outcome, not the existing activationFailed sentence claiming “nothing was clicked”. Explicit Raise/foreground-assist must remain intentional exceptions, not actions immediately undone by this guard.
    • Catching test: with injected activation/posting seams, let preparation pass all three stable samples, then make the requested dispatch change frontmost PID or window order. Require detection and bounded restoration; repeat while reusing a hold and with a delayed activation notification. A control case switching to a third app must not be restored over. Follow with a harness-owned Electron window behind a sentinel app and an activation watcher, including AXPress, coordinate click, field focus, Command chord and paste. That live confirmation was not run here and needs the owner's go.

    The generic open -b branch is a separate, unobserved foreground-capable path. If privileged bundle-ID launches are intended to obey the same background contract as path launches, the small fix is ['-g', '-b', bundle], with an injected-open argument test for both forms. It should not be presented as a fix for native getApp or as the cause of today's report.

    4. M4 comparison and confidence

    Compared explicitly with 5d8148fb, rather than the moving worktree HEAD: none of the activation, held-focus, route-selection, field-focus, paste, menu, secondary-action, target-launch or generic launch-service implementations above is repaired there. Input.swift's change preserves permission-error metadata; it does not change input routing. M4 adds an explicit foreground option for the owner-attended engine approval experiment in src/runtime/engine.mjs; ordinary engine/session launches still use -g. That option foregrounds the engine for onboarding, not driven apps during normal work.

    The M4 worktree had already advanced to 0351f19c when inspected; the requested comparison is pinned to 5d8148fb so concurrent work does not change this conclusion.

    Confidence: high that explicit Raise calls are the first behavior to remove from the background UX workflow; high on the code-path inventory and pre-delivery-only guard gap; moderate on how much each explains the owner's full observation, because global frontmost/window-order transitions were not recorded. The service resets per-call metadata (service.mjs:76–82), so action → observation batches commonly erase the action's route diagnostics. For the authorized live follow-up, record each action's metadata plus a value-free frontmost PID/top-window trace; do not infer global focus from an AX tree header.

    Sminos-Session: cua_repl#1ea561bc (MAWS on macbook)

  3. SSFSKIM commented on Oct 23, 2026

    @SSFSKIM
    OwnerAuthor

    Consolidated report evidence supporting the existing diagnosis: /Users/new/Developer/GitHub/MAWS/plugin/cua/dogfood-feedback/l3-input.md §§1–2,6; l6-artifacts.md §§1,7; l9-browser-delivery.md §§1,6 explicitly describe Raise plus external NSRunningApplication activation as workarounds for occlusion/input. They corroborate intentional foreground requests, not proof that every normal cua input steals focus. Preserve the existing route-3 post-dispatch guard investigation.

    Drop the requested automatic activate/bringToFront/uncover-and-restore workaround for this background workflow: it conflicts with #117/non-interference and cannot undo the user-visible interruption merely by restoring later. A frontmost-only key gate also conflicts with background driving (closed #162). Screenshot diagnostics and open-panel routing are being filed separately. ScreenCaptureKit is already used by d95261f, so “switch to ScreenCaptureKit” is not an unimplemented cure. A read-only frontmost/visibility diagnostic is compatible, but not permission to foreground apps. Recommended P1 unchanged; no GUI driven.

    Sminos-Session: cua_repl#1ea561bc (MAWS on macbook)

  4. SSFSKIM commented on Oct 23, 2026

    @SSFSKIM
    OwnerAuthor

    New non-interference evidence: /Users/new/Developer/GitHub/MAWS/plugin/cua/dogfood-feedback/l4-approvals.md §2 reports external NSRunningApplication activation while the owner was typing redirected the owner’s keystrokes into the driven app. No typed content is reproduced here. Plausible and consistent with explicit activation, not evidence that ordinary background getApp/AX actions caused the switch.

    The report’s proposed “always Raise; never activate” is not a safe resolution of #117: AXRaise can change visible window order even when global keyboard focus stays with another app. Do not recommend blanket Raise or hide/unhide to repair screenshots. L1 §8 and L2 §7 also blame -10016 on prior agent input, but own-engine events are filtered by source PID; external osascript/other automation is not proven filtered. #208 owns attribution diagnostics, not a blanket exemption for anything an agent calls. L4’s global HID idle inference does not establish human presence; user-attributed event provenance is needed.

    Sminos-Session: cua_repl#1ea561bc (MAWS on macbook)

  5. SSFSKIM commented on Oct 23, 2026

    @SSFSKIM
    OwnerAuthor

    Final-wave non-interference evidence: /Users/new/Developer/GitHub/MAWS/plugin/cua/dogfood-feedback/l7-shell.md §5 and l8-settings.md §4 show Raise does not guarantee frontmost keyboard activation or fresh pixels, and several assessors hid/activated another app to route around it. Those are explicit workflow interventions, not permission for cua to do them automatically. Keep Raise, activation, hidden state, keyboard focus and repaint freshness distinct; do not offer “activate then restore” as a transparent background action. L7’s development-bundle relaunch is a separate launch-context investigation, not proof an ordinary Raise method launches a dead process.

    Sminos-Session: cua_repl#1ea561bc (MAWS on macbook)

  6. SSFSKIM commented on Oct 31, 2026

    @SSFSKIM
    OwnerAuthor

    Live sighting, 2026-10-30, during #235's attended sitting on the MacBook. The engine was built from feat/235-macos-cursor on fc15e1b's line (build 2f9b3bf06ca4). A background coordinate click on TextEdit's text took route 3 and raised TextEdit's window above the Chrome for Testing window covering it, and the window stayed raised. Chrome for Testing was the frontmost app: the owner had clicked it last, and the harness activated nothing before the click. The sampled CGWindowList order flips at the first click. It reproduces with the agent cursor off (CUA_CURSOR=0), so it comes from the click route, not the cursor. This is the gap the offline diagnosis above names. Route 3's non-interference guard finishes before the action is dispatched, so it cannot see the action itself raise the target above the user's frontmost window. Here it broke route 3's own promise to keep the user's app frontmost and answer a window ordered above it. Evidence: docs/evidence/2026-10-30-macos-agent-cursor/item-4-cursor-off-order.txt on feat/235-macos-cursor (pushed with the sitting's records). A vendor A/B (CUA_NATIVE_ENGINE=vendor) on the same scene is pending and will be added here.

  7. SSFSKIM commented on Oct 31, 2026

    @SSFSKIM
    OwnerAuthor

    Another sighting from #235's attended sitting (2026-10-30, the MacBook, cua's own engine build 2f9b3bf06ca4, harness TextEdit cua-scene.rtf in the background, Terminal frontmost: the owner had clicked it just before):

    • Acceptance 10's first step: one click on TextEdit's format-bar alignment button (the kit's ALIGN_TOGGLE cell, an element click by index followed by an observation), with the cursor switched off by engine.json. The owner saw it bring TextEdit to the front. Record: docs/evidence/2026-10-30-macos-agent-cursor/sitting/item-10.jsonl, step 5 (at 1793419968624).
    • What I can't give: the click's cua/inputRoute and activationClick meta. The kit keeps the route of the cell's last call, which was the observation (route: null), and it doesn't keep activationClick. So this sighting doesn't say whether it was route 1's held preparation or a route-3 click. No stacking samples were taken for it.
    • The measured case is the earlier comment's: route-3 text clicks in item 4 with the cursor off (docs/evidence/2026-10-30-macos-agent-cursor/item-4-cursor-off-order.txt). The vendor A/B comes with item 11.

    Sminos-Session: cursor235#b93055dd (cua on macbook)

  8. SSFSKIM commented on Oct 31, 2026

    @SSFSKIM
    OwnerAuthor

    Vendor A/B for the route-3 sighting above (2026-10-30, the same MacBook, harness TextEdit and Chrome for Testing, Chrome frontmost over TextEdit's right half). The three background text clicks are the same cells, the only difference being CUA_NATIVE_ENGINE=vendor.

    • Vendor: no raise. Chrome for Testing stayed above TextEdit in all 50 half-second samples (docs/evidence/2026-10-30-macos-agent-cursor/ab200-vendor-order.txt; record sitting/item-ab200-vendor.jsonl). The owner confirmed Chrome stayed in front, and the vendor's cursor was hidden under it.
    • cua's own engine: TextEdit raised at the first click, with the cursor on (item-4d-order.txt) and off (item-4-cursor-off-order.txt). Those clicks were route 3.

    The vendor engine posts these clicks without changing the stacking, and cua's route 3 changes it.

    Sminos-Session: cursor235#b93055dd (cua on macbook)

  9. added 2 commits that reference this issue on Oct 31, 2026
  10. added
    status:in-progress
    and removed
    status:ready-for-implementer
    on Nov 1, 2026
  11. added a commit that references this issue on Nov 1, 2026
  12. 20 remaining items

  13. added a commit that references this issue on Nov 1, 2026
  14. added
    status:in-review
    and removed
    status:in-progress
    on Nov 1, 2026
  15. SSFSKIM commented on Nov 1, 2026

    @SSFSKIM
    OwnerAuthor

    [board] in-review: PR #243: delivery guard + after-action watch; final live check PASS on bf458b9 (a 40/40, f 20/20)

  16. added 2 commits that reference this issue on Nov 1, 2026
  17. removed
    status:in-review
    on Nov 1, 2026
  18. SSFSKIM commented on Nov 1, 2026

    @SSFSKIM
    OwnerAuthor

    [board] done: Merged in #243; main tree = the gated head tree; plugin 0.20.2; follow-ups #244, #245

  19. added 4 commits that reference this issue on Nov 1, 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