Skip to content

macOS engine: AX text actions wait for a foreground click to land, and type_text never confirms over a selection a late click undid (#359) - #402

Merged
SSFSKIM merged 7 commits into
mainfrom
fix/359-click-ordering
Nov 17, 2026

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 17, 2026

Copy link
Copy Markdown
Owner

What changes

On macOS, a click into a field of a foreground browser could set its caret after the agent's next action, so the agent's selection was undone and text went in the wrong place. In the worst case type_text still answered success: main's Safari click → set_value → type_text gave NEWNEW359359, confirmed.

Cause (measured, not #341):

  • A foreground coordinate click is a posted mouse event. It answers once posted, but the browser can dequeue it late: the revert came p50 14–19 ms after the click returned, and in the worst case 419 ms after.
  • An AX action on the same app bypasses that queue and can run first: select_text's range write, set_value's write, and type_text's baseline read.
  • Posted keys (Cmd+A, press_key) are queued behind the click and were never wrong.
  • Background clicks take Engine: a click in a scrolled Chromium textarea places the caret on the line as if the field were scrolled to the top (focus scrolls it first) #341's AX route and were never wrong (0/3,437).
  • type_text's false success came from its baseline: it read the field after the revert, so the read-back faithfully confirmed an insertion at the wrong point.

The fix (ruling 1ea561bc:785, native/engine/Sources/Engine/ClickOrdering.swift):

agent-cursor.md (and its two copies) says what the wait is, when type_text types nothing, and that a click can still land after the wait, in which case type_text answers unconfirmed rather than claiming the text.

Evidence

The tables are in docs/evidence/2026-11-17-click-ordering/README.md. Every cell is judged against the fixture page's own DOM value and caret, never against AX.

  • The spike (main 15acf09): the background corpus 44107967517, the pilot 44112583792 and the real-route follow-up 44126242634. They found the cause above. The foreground select_text → type route was wrong in CfT 1/20 and Safari 3/20, Cmd+A in 0/20, and the AX traces show the baseline read the reverted caret.
  • The qualification, 44169327522: fix f350ced against main 136183a, both unmodified, on the same browser per job. 1,320 attempted, 1,274 valid; the 46 exclusions are Firefox click refusals.
Foreground textarea, 20 each main wrong fix wrong
click → select_text → type_text Safari 4 0 in all browsers
click → set_value → type_text Safari 3 (2 confirmed as success) 0
click → Cmd+A → type_text 0 0

Limits

Verification

  • swift test (native/engine), on the merged head: 1,292 tests, 0 failures, 1 skipped (pre-existing).
  • Node: core-documentation, docs-oracle, docs-source-behavior, repl-parity inventory, package-contents and every services-engine-* test, 220 tests: 219 pass, 0 fail. The one skip is test/services-engine-real.test.mjs "the untrusted engine: …", which runs only on GitHub-hosted runners.
  • Mutation checks: 33/33 on the first build; 11/11 on the review fixes.
  • Review: doperpowers:reviewer-high on 136183a..ef998db came back incorrect with three findings: a selection check against an earlier read, possible truncation hiding value differences, and no secure re-check during the value watch. All were fixed at f350ced, and the re-review came back correct. Every kit change was reviewed by doperpowers:reviewer-medium before dispatch.
  • ci-gate on 7a0b61e, gates plugin, test and engine-swift: GREEN, https://github.com/SSFSKIM/cua/actions/runs/44182108120. The sandbox and browser-parity gates were not run: the change touches neither the sandbox nor the browser extension path.

Plugin 0.28.9.

Closes #359

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

…osted click to land, and type_text after select_text types only over its selection (refs #359)

Ruling 1ea561bc:785 on the #359 spike: in a foreground browser a coordinate
click answers once posted, but the browser can take it in up to ~0.4 s later,
after a select_text, set_value or type_text's starting point.

- A posted pointer press arms a per-process window (ClickOrdering.swift):
  within 1 s, select_text, set_value, a text field's action click, the
  background focus routes and type_text's snapshot first wait for a stable
  range (50 ms dwell, 10 ms samples, 300 ms cap). Posted keys never wait;
  #282/#341's accessibility route posts nothing and arms nothing.
- type_text within 1 s of select_text waits for the range select_text wrote;
  still another at the cap, nothing is typed and it answers typeUnconfirmed
  (selectionChanged).
- set_value inside the window watches the field after its write: another
  value, or a caret off its end, is valueUnconfirmed.
- agent-cursor.md and its copies, PROVENANCE, the surface inventory and the
  native engine spec's Decision Log say so.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…e change (refs #359)

Mutation checks found the constants' changes survived (the tests derive from
them) and a value check by length alone survived the changed-value test.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ing point, and set_value's watch takes only a cut prefix at the cap and stops at a field turned secure (refs #359)

The review of ef998db (reviewer-high), three findings:
- P1: the selection was checked on the wait's read, while the snapshot's own
  range read and #354's settle could adopt a click landing after it. The
  final starting point must now be select_text's range, else nothing is
  typed (selectionChanged).
- P2: a value at Chromium's cap counted as written whatever it held; now
  only a strict prefix of the written value does, else valueChanged.
- P2: the watch now re-classifies the field before every read and, once it
  turned secure or cannot be classified, reads nothing more and answers
  valueUnconfirmed (fieldClosed).

Sminos-Session: cursor235#b93055dd (cua on macbook)
Brings #367 (0.28.8). Conflicts: docs-oracle.mjs (main's #367 truncation
sentences and #359's two sentences both kept, byte-identical to
agent-cursor.md), PROVENANCE.md (both sides' sources listed), the native
engine spec's Decision Log (#367's ruling 782 entry first, then #359's two,
oldest-first).

Sminos-Session: cursor235#b93055dd (cua on macbook)
…posted click to land, and type_text after select_text types only over its selection (refs #359)

Sminos-Session: cursor235#b93055dd (cua on macbook)
… text perhaps in at its point (refs #359)

The design session's ruling 1ea561bc:788: one sentence after the typing
paragraph's #359 sentence in agent-cursor.md, its two copies byte for byte,
with PROVENANCE and the surface inventory's amendment.

Sminos-Session: cursor235#b93055dd (cua on macbook)
… 785, and its limits (refs #359)

Sminos-Session: cursor235#b93055dd (cua on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T21:53:16.759220Z 7a0b61e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SSFSKIM
SSFSKIM merged commit 290303c into main Nov 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Engine: a click's caret effect can land after the next action (click, then select, then type puts the text in the wrong place)

1 participant