Repository navigation
#200: route-3 clicks keep the person's window order and front app (delivery guard + after-action watch) - #243
Merged
Merged
Conversation
A route-3 click raised the driven window above the user's frontmost one at its own mouse down, after the guard had ended. AppKit (macOS 26.6.2) answers subtype 1 by arming _mouseActivationInProgress for one mouse down. The activation click consumed it, so the action's single left mouse down without ⌘ alone reached a key window of an app that believes itself active. -[NSWindow _handleMouseDownEvent:isDelayedEvent:] answers that with _NSDoDeferredWindowOrdering, the window server's _safeFrontWithClick. Route 3 now posts the standing activation's subtype 1 again, for the click's window, immediately before each such mouse down (clicks, a double click's first press, a drag's down, a click inside a held or shared activation), so AppKit takes the mouse down as the activation's own: the window made key, the click delivered, no ordering request. Nothing changes where no fake activation stands, nor on routes 1, 2, 2' and 4. Sminos-Session: cursor235#b93055dd (cua on macbook)
The 10-23 raises were agents raising or activating apps to reach a covered window. The computer surfaces' host notes now say not to raise, activate, hide or unhide an app for that unless asked, and to say what is in the way instead. The first-call document is unchanged, keeping the facade's parity with the vendor's. Sminos-Session: cursor235#b93055dd (cua on macbook)
…ouse down" This reverts commit 3be67de.
…en hold A route-3 click's own mouse down raises the target's window above the user's frontmost one (AppKit's ordering click), after the activation's guard has ended. From outside the app nothing both delivers a click to a view that refuses the first mouse (TextEdit's text) and avoids that raise: the activation click exists to make the window key, a re-armed subtype 1 arms nothing in an app already active, and Accessibility can neither key the window without ordering it nor while the arm is set (#200's readings). So route 3's pointer actions now post their events through a delivery guard. It keeps the activation's screen-update hold open across the events (the activation's guard then settles on one sample), answers the target's window above the user's with the user's window raised back and the target's process in front with the user's app made frontmost again, and ends on three stable samples before the hold is released. A click inside a held or shared activation takes a hold of its own; never a second hold for one action. At the 100 ms cap the guard ends and leaves the order as it is, reported; a third app in front is left alone. The meta's `delivery` (cua/delivery) carries the restores, whether the frontmost app was restored, the first restore's latency, the guard's and the hold's times, the cap and any raise left. Sminos-Session: cursor235#b93055dd (cua on macbook)
…eading's corrections in F §17 The design's Decision Log records why route 3 restores rather than prevents the click's raise (AppKit's ordering click; the activation click as the vendor's sacrificial first mouse; the rejected alternatives), the guard's parameters and costs, and Interfaces gains the delivery meta. F §17 records the #200 reading of the vendor: an enforcer always exists on the IPC path, a failed enforcement is rethrown (not retried with ⌘), the enforcement guard ends before the click, a WindowOrderingObserver re-raises the user's window on every ordering event, and §5.6's tap masks were wrong. Sminos-Session: cursor235#b93055dd (cua on macbook)
`cursor-sitting.mjs raise drive --engine cua|vendor` places the harness windows itself (TextEdit at the left, Chrome for Testing over its right half, Finder's and the Electron fixture's where TextEdit's is; harness windows only, through Accessibility), activates Chrome, and runs six cases, each on its own session after checking the arrangement: route-3 clicks in TextEdit's text under Chrome and clear of it, an element click then a coordinate click inside the standing activation, a drag, a double click on a word, a plain click on a Finder row, and a coordinate click on the fixture's push button with its focus counters recorded. A watcher compiled into the harness cache samples the two windows' order every 5 ms (CGWindowListCreate under the time-constraint policy: the MacBook held 5 ms at a load average of 70). Each sample keeps its action's route, activation meta, cua/actionInterval and cua/delivery, its delivery read back at once (the selected range by the approved bundle's text-view probe; the alignment, Finder's selection and the fixture's count by observation), and what the watcher saw: post to raise, post to the hold's release, late raises. A scene that breaks stops the run. `raise judge` reports per case and engine; cua passes on every sample delivered with no late, unguarded or left raise. The vendor's rows are recorded only. The runbook gets the item with its timing. Sminos-Session: cursor235#b93055dd (cua on macbook)
…at the cap, and reports what it saw Three corrections to route 3's delivery guard (6e94492), from review: - The window checked is the action's. A held or shared activation keeps its first holder's window, so a later click or drag on another window of the same process (a dialog) raised that window while the guard sampled the first one and reported nothing. deliverPointer now passes the window its events name (fields 91/92, stampedWindow), falling back to the activation's when they name none. - Nothing is repaired once the cap has passed. The cap was read only before the sleep, so a sample could re-activate the user's app or raise its window after the cap's timer had released the display: a visible repair. The deadline is now read after the sleep, the reads and any restore before them; past it the guard ends with `capped`, on a sample that only reads (no sleep), so `raiseLeft` rests on the order after the last repair. - `frontmostRestored` and `raiseLeft` come from observation, not from the re-activation's return value. A restore counts only once a later sample sees the user's app frontmost again (kept if the target comes back after); a guard that ends with the target or the bound app in front, at the cap or after a refused re-activation, reports `raiseLeft`. An accepted but ineffective re-activation is no longer reported as a restore. A third app in front is still left alone (`otherAppFront`). Sminos-Session: cursor235#b93055dd (cua on macbook)
…st the cap, and checks the action's window Sminos-Session: cursor235#b93055dd (cua on macbook)
…kets, and a clean end Three findings of the review of 1108451: - A cell that observes and then acts keeps only the action's meta, so a raise before the screen hold began counted as guarded. The delivery guard now reports `holdStartedAt` (Unix ms: the activation's hold when the action ran it, else the guard's own), read as releasedAt less the hold's monotonic span; a raise before it is unguarded. - The outlived check carried the last order forward across watcher gaps. The watcher now writes each change with the read before it, and a raise is late or outlived only when a read past the release and its 10 ms grace shows it; a gap that leaves it unknown is undecided, which makes the case incomplete and is reported apart. - A case that stopped in its tail could still pass. A pass now needs the last raise check passed, the session closed, the watcher stopped by the kit, and its record reaching the close. Sminos-Session: cursor235#b93055dd (cua on macbook)
The no-restore branch took the end record's writing time as proof that the watcher read past the release's grace. It now reads the end record's lastRead: a raise last seen at 1085 with a release at 1080 and the end written at 1100 is undecided (incomplete), not outlived. Sminos-Session: cursor235#b93055dd (cua on macbook)
… s window, unless the person acted The first live sample: the app raised its window 38 ms after the click, 42 ms into the hold, and the guard's samples (about 20 ms apart under load) found it only past the 100 ms cap, where it repaired nothing and left the raise. The cap stays 100 ms; after the release the guard keeps repairing (the user's window raised back, the user's app made frontmost again) until 1 s after the events, only while the person has given no input since them (CGEventSource seconds since any HID input) and never over a third app's front. Such a repair is reported apart (repairedAfterRelease, its latency; personInput when the person's input stopped it). The poll inside the hold sleeps 2 ms. The kit's judge counts a raise the engine repaired after the release, undone inside the window, as a flash: counted and reported, not failed. Sminos-Session: cursor235#b93055dd (cua on macbook)
The rerun's first sample: the guard settled 14 ms after the click (three 2 ms samples) and released, and TextEdit raised at 21 ms, after it. The first live samples saw TextEdit raise 21 and 38 ms after the click, so the guard now watches at least 60 ms after the events, inside the hold when it lasts, else in the repair window after it. Sminos-Session: cursor235#b93055dd (cua on macbook)
…ss on 318e5aa67691, the vendor half recorded cua's engine at d18797a (build 318e5aa67691): cases a-e PASS, 140/140 delivered, every raise restored under the screen hold (0 late, 0 unguarded, 0 left); post->raise 6.7-43.6 ms, post->release 60-78 ms. f INCOMPLETE (the kit's frame reader found no button on the cua run). The vendor half: TextEdit raised nothing and mostly did not deliver (a 1/40, b 0/20, c 5/20, d 1/20); Finder and the Electron button delivered 20/20 each with 20 raises undone, without a hold, in 5-62 ms. The two earlier cua runs that stopped at a#0 (the cap, then the 14 ms settle) are in the same files, their attempts before the judged last. The quiet checks are the quiet-*.txt files. Sminos-Session: cursor235#b93055dd (cua on macbook)
…nter action
After each delivery guard returns, a watch samples every 10 ms on another thread until
1 s after the events, under the guard's rules (the user's window raised back, the user's
app made frontmost again over the target's or the bound app's, never over a third app,
nothing after the person's input). The action still answers at the release.
The watch ends when the connection's next execute begins (at its very start) and when
any pointer action begins; a sample runs under the watch's lock, which the cancel takes,
so no repair starts once the next request has begun. Its repairs are recorded on the
connection and carried as afterActionRepairs {repairs, actions: [{postedAt, repairs,
latencyMs}]} on every later input result and observation (cua/afterActionRepairs in the
service), keyed by the delivery's new postedAt, plus a route3.afterAction.repair signpost.
The spec's Interfaces line and the #200 Decision Log entry are amended.
Sminos-Session: cursor235#b93055dd (cua on macbook)
…nd matches AXValue too element-frame walks the windows again every 100 ms for up to 3 s after setting AXManualAccessibility (the first live check read 13 elements and no button right after), and matches the name on AXTitle, AXDescription or AXValue; its answer says how many walks. Sminos-Session: cursor235#b93055dd (cua on macbook)
…fixture, found by the engine first The kit keeps cua/afterActionRepairs from every reply, and the judge counts a late or outlived raise as a flash when a later reply reports the watch's repair of that action (keyed by its delivery's postedAt) and the watcher saw it undone inside 1 s of the post; never undone there, it stays a FAIL. The report adds the watch's repairs and post to its first repair. Each case ends its tail with one observation, so the last action's repairs are reported. Case f now starts on a fresh Electron fixture for each engine: the kit brings it down and up through the scenes CLI (its accessibility record must be off), places it, activates Chrome, then the engine under test must find the fixture's button by its index (a missing button stops the case) before the frame reader and the clicks. Sminos-Session: cursor235#b93055dd (cua on macbook)
Sminos-Session: cursor235#b93055dd (cua on macbook)
…used re-activation is no repair; the interval is the events' - A closed connection cancels its after-action watch (Engine.connectionClosed, from Server.unregister); a watch that ends on its own clears the connection's live watch, and holds the connection's record weakly, so nothing keeps either alive. - A re-activation the system refuses ends the watch without counting a repair. - deliverPointer stamps the action interval around the events' own posting inside the delivery guard, as InputMeta.posting's contract says: no longer from before the guard's setup to its end. The guard's time stays in delivery.guardMs. Sminos-Session: cursor235#b93055dd (cua on macbook)
…hile its watch may run; the judge runs from postedAt - raiseOwners judges a raise with the cell whose span holds it, unless that cell's own hold had not begun (or it has none) and an earlier guarded action's hold had, with the raise inside its repair window after its post: the engine's watch runs until the next request reaches it, which a host-side cell's start precedes, so a raise its watch repaired there is that action's flash, not an unguarded raise. - callWatch's post is the delivery's postedAt (else the interval's start), for the repair window and every post-relative time. Sminos-Session: cursor235#b93055dd (cua on macbook)
… cell of its session has completed; the engine's watch is cancelled by the next request Sminos-Session: cursor235#b93055dd (cua on macbook)
…07724139591e) f on cua PASS (20/20 delivered, every raise restored inside the hold, 0 flashes) and a on cua PASS (40/40, likewise); f on the vendor recorded (20/20 delivered, 20 raises on the display). The first cua observation of a freshly launched Electron fixture lacked the button (14 lines) and had it 2 s later (27 lines); the vendor's first had it. That diagnostic ran as a temporary kit change, reverted, its diff kept beside the records. Sminos-Session: cursor235#b93055dd (cua on macbook)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…elivery meta Sminos-Session: cursor235#b93055dd (cua on macbook)
SSFSKIM
added a commit
that referenced
this pull request
Nov 1, 2026
Brings main's #235 (cua's own macOS agent cursor, #240), #236's fix (#241), #200 (#243) and #244 (#247) under M3, so M3's gate judges the tree that ships. A merge, not a rebase: the spec and the evidence cite this branch's commit SHAs. The overlapping files and how each was resolved: - src/runtime/launch.mjs (conflict): both sides kept. M3's Linux branch (cua's own service: CUA_SKY_SERVICE, CUA_ENGINE_BIN and CUA_DESKTOP_MODE for the cua selection, the vendor service and helper otherwise) beside #240's macOS branch, which adds the agent cursor's environment (cursorEnv) to cua's engine. The env header comment merged cleanly with both sides' entries. - src/runtime/doctor-engine.mjs (auto-merged): #240's macOS row (the cursor switch in factsReport, cursorWords, settingsOf's cursor check) and M3's Linux row (service cua, capabilities, the IsEnabled row) touch separate functions; kept as merged. - src/cua-api/sky.mjs and test/cua-api/sky.test.mjs (auto-merged): #241's fix for #236 (setupError exported, then/toJSON/symbols read undefined after a failed setup, the declared vendor difference and its settle test) beside M3.2's truncated-field scenario. Compatible by design: cua's Linux service's setup always resolves with the 20 methods and keeps a failure for each method to refuse with, so the facade's setupError stays unset there; a setup that does throw now fails the bootstrap with its own error instead of hanging. - tech-debt-tracker.md (conflict): every row from both sides kept, main's five newer rows first (74 at the base, +2 M3, +6 main = 82). - .claude-plugin/plugin.json, marketplace.json (conflict): main's 0.20.3 here; M3's own bump follows in its own commit. Focused suites (services, facade, doctor, selection, harness, accept, cursor) on the merged tree: 1948 pass, 8 fail; the same 8 fail on both parents in this VM (umask 077 modes, macOS-only and env tests). Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
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.
Summary
cua's own macOS engine brought the driven app's window to the front on a background click (route 3). This PR keeps the window order and the frontmost app as the person left them, while the click still lands.
Cause. Route 3 posts an AppKit-defined event (subtype 1) that arms
_mouseActivationInProgress. The activation click consumes that arm, so the action's own left mouse-down, without ⌘-only flags, is an ordering click.-[NSWindow _handleMouseDownEvent:]then calls_NSDoDeferredWindowOrdering, which raises the window. An inactive app's window is never key, and NSTextView refuses the first mouse. So no posting variant both delivers and avoids the raise: re-arming, skipping the activation click, a 2→1 pair and AX keying were each ruled out by reading AppKit. The first, re-arming, was also built and reverted.Fix: an activation delivery guard (
FakeActivation.deliver,native/engine/Sources/Engine/Activation.swift).deliveryGuardMinimumMs), polling every 2 ms. It raises the person's window back and reactivates their app only when the target (or bound) app took the front. The hold is capped at 100 ms.otherAppFront), that is never undone.cua/delivery(restores, frontmostRestored, otherAppFront, restoreLatencyMs, guardMs, screenHoldMs, capped, raiseLeft, holdStartedAt, releasedAt, postedAt, repairedAfterRelease, …) andcua/afterActionRepairs, keyed bypostedAt. The engine service forwards both.actionIntervalagain brackets only the events' own posting, not the guard, so speed comparisons against earlier runs and against the vendor keep their meaning.Host note (macOS and Linux computer notes, not the first-call document, to keep facade parity): "- Leave the person's windows as they are: unless asked, don't raise, activate, hide or unhide an app to reach a covered or background window; say what is in the way instead." The 10-23 symptom was agents raising apps on purpose, which the engine fix doesn't touch.
Plugin 0.20.2 (own commit 39fb837,
plugin.jsonandmarketplace.json): plugin users get the new host note and the delivery meta.Ordering race
The engine posts the activation event and the mouse events from one thread, each through
CGEventPostToPid. That sends a one-waymach_msgto the window server's event port: one FIFO, the same path for type 13 and mouse events. HIToolbox pulls them in arrival order, so the app cannot see the mouse-down before the event that precedes it. Caveat: a third-party active event tap can delay or reorder events on their way through.Measured (live, MacBook, 2026-11-01;
docs/evidence/2026-10-30-macos-agent-cursor/item-200/item-200.md)Build 318e5aa67691 (d18797a), cases a–e: PASS. 140/140 delivered; every raise was restored inside the hold; 0 late, 0 unguarded, 0 left; 1 of 140 capped.
The shipping build bf458b9 (build 07724139591e), with the after-action watch (
item-200/final/):Both PASS. On f, the fixture's counters show what the page sees from route 3's activation: on cua, appDidBecomeActive and windowFocus once per click, plus appDidResignActive 5 and windowBlur 3 over the 20 clicks; on the vendor, 1 of each. Route 3 activates the app for the click by design (#188); this PR changes when that is visible, not that it happens.
Vendor, same cells. On TextEdit's text the vendor's "no raise" was no delivery: a 1/40, b 0/20, c 5/20, d 1/20. Its click there is a ⌘-click, which AppKit neither orders front nor treats as a plain click. Finder (e) and the Electron button (f) delivered 20/20, each with 20 raises undone by its window-ordering observer in 5–62 ms with no screen hold, so they were visible flashes. The correction is on #200.
Speed. The guard adds about 30 ms per route-3 click over the vendor's bare post (release at post + 60–78 ms). In-cell, cua measured 4–140 ms against the vendor's 229–1038 ms (M2b hold3), so cua stays well ahead.
Limits
A fresh Chromium or Electron app's first observation can miss its content on cua's engine: 14 lines without the button, then 27 lines with it 2 s later. The vendor's first read already has it. This came up in the final check and is outside Own engine brings the driven app to the front in MAWS sessions (MacBook opt-in build) #200: macOS engine: the first observation of a freshly enabled Chromium/Electron app returns an incomplete tree (vendor's is complete) #244 (numbers in
item-200/final/README.md).Route 3 fires a page focus event on every click on Electron: on cua, appDidBecomeActive and windowFocus once per click, with appDidResignActive 5 and windowBlur 3 over 20 clicks; on the vendor, once for the series. Route 3's per-action activation is by design (Repair Electron background field preparation for typeText, Tab and paste #188). Holding the activation across consecutive actions is measured in macOS engine: route 3's per-action activation fires a page focus event on every background click (vendor: once per session) #245.
A capped action can answer up to 1 s late. Past the 100 ms cap, repairs stay synchronous until post + 1 s (1 of 140 actions capped in the run). Tech-debt row: "A capped route-3 action can answer up to 1 s late".
A third app's front is never undone, by design: the person's own switch wins.
The stub tests check the sequence the engine posts and the guard's decisions, not what AppKit does with them. The re-arm attempt passed its stubs and failed in AppKit, so the live check is the gate.
Tests
ClickDeliveryTestsandFocusHoldTests(GuardSeam covering target above, mouse-down timing, windows above, person input, hold/release, repairs outside the hold, a third app's front, the watch's cancellation). Engine suite 640/640 at the last engine change (12ae081).cua/deliveryandcua/afterActionRepairsforwarding.scripts/cursor-sitting/raise.mjs(cases a–f, the 5 ms window-order watcher, the judge), with 190 tests intest/cursor-sitting/raise.test.mjsand the runbook section "Item 200".Docs
Native-engine design spec: the #200 Decision Log entry (amended for the watch), the Interfaces meta line and route 3's text. Research F §17, with inline corrections in §5.4/§5.6. Tech-debt row.
Shared files with #211 (stale draft, not rebased)
native/engine/Sources/Engine/Input.swiftanddocs/doperpowers/specs/2026-10-18-own-native-engine-design.md.Closes #200
Sminos-Session: cursor235#b93055dd (cua on macbook)