Skip to content

Engine: in background Safari, cmd+a then type_text can lose the first typed character, both calls answering success (the key equivalent's effect trails the next call) #354

Closed

Description

@SSFSKIM

Problem

In background Safari, keypress("cmd+a") followed at once by type_text can leave the field with the wrong text, and both calls answer success. The select-all's effect lands after the first typed character, so that character is inserted and then replaced.

Measured on main 3c66931, run https://github.com/SSFSKIM/cua/actions/runs/42747547376 (kit probe/330-measure c40a482, the case "Safari textarea, cmd+a then immediate type"; 1 sample):

  • Requested: New typed sentence goes here. type_text returned success with entered=29.

  • The field: ew typed sentence goes here., at +12, +265, +1014 and +3015 ms after the call returned. The field was focused in every sample.

  • The trace (ms, with their shared prefix dropped):

    • the click returns at 819, and focusin fires at 823;
    • the cmd+a RPC has returned by 834, when type_text starts;
    • the cmd+a keydown reaches the page at 842;
    • N is input at 844, and the field reads OldN draft sentence goes here., so select-all hasn't applied yet;
    • at 876, e replaces the whole field, because the select-all is now in effect;
    • the rest follows, giving ew typed sentence goes here..

    All 29 input events, the N's included, were observed. The key isn't dropped: the calls are delivered out of order, because the key equivalent's effect trails the next call's text input.

  • Same probe, other cases: 35 of 36 cases contained the full sentence by 3,000 ms. 13 were partial right after the call and complete by 250 ms, which is late delivery, not loss. Every no-cmd+a case, with or without a 500 ms pause, completed 9 of 9, as did the paced cases.

Evidence on the MacBook: ~/.local/share/probe-330/run-42747547376/typing-facts.json, typing-summary.txt and safari-textarea-order.json, the full event trace.

Why it matters

Select-all, then type, is how a model replaces a field's text. Here the result is silently wrong text (the first character lost), and both calls answer success.

Intent

A key call's effect is delivered, in order, before the next call to the same app proceeds. Measure first:

  • The rate: repeat the case at least 20 times in Safari, Chrome and Firefox, in textareas, inputs and contenteditables, with other key equivalents too (cmd+a, cmd+z, cmd+x).
  • Where the delay lives: WebKit handles a key equivalent through its UI process and the responder chain, while text input goes to the web content process. That's a guess to test.

Candidate directions:

  • After a modifier key equivalent, confirm its effect before answering, for example by reading AXSelectedTextRange after cmd+a.
  • An ordering barrier between calls to the same pid.
  • type_text waiting until the previous key call's events have been consumed.

Constraints

Success criteria

  • cmd+a then immediate type_text gives the requested text in at least 20 of 20 runs per browser and editor.
  • The other key equivalents, measured, behave the same.
  • No regression in typing time beyond what the barrier costs, which is stated.

Activity

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

    @SSFSKIM
    OwnerAuthor

    Ruling (design session 1ea561bc, 567)

    • Priority: P1, at the front of lane 1 after Engine: a control relabelled in place (same handle, Save to Delete) passes the stale-point guard #298. There is only one sample so far, but the trace gives the mechanism, and that ordering can't be safe by luck.
    • The measurement covers both halves:
      1. Lost text: how often the ordering race leaves wrong text (cmd+a, then type_text, and other key equivalents), across browsers and editors.
      2. Partial text observed: 13 of 36 cases were partial right after type_text returned. Measure whether an observation taken right then (getState, getScreenshot) shows the partial text, since that's how a model gets misled.
    • Then a proposal before any build, for example an input-delivery barrier before a key or type call returns.

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

  3. added 10 commits that reference this issue on Nov 10, 2026
  4. SSFSKIM commented on Nov 10, 2026

    @SSFSKIM
    OwnerAuthor

    #354 measured: no tested signal fences key delivery; an exact read-back of type_text is viable

    Measurement only. Nothing is built; the proposal goes to the design session first.

    The setup:

    • Kit probe/354-measure, head eb28ae3; the full follow-up ran 56baa17.
    • Every engine build pinned main 3c66931.
    • Safari 27.2, Chrome for Testing 156.0.8078.80, Firefox 159.0, on hosted image 20261102.0473.1.
    • The primary corpus: 14,070 attempts, 14,068 scorable, 20 valid trials per key, editor and browser.
    • The follow-up corpus (fences and exact read-back): 3,780 of 3,780 valid, with 0 privacy violations.
    • Firefox's old rows are excluded: the kit's command channel could reach a hidden browser realm. The rerun binds the visible document, with 0 mismatches over 10,516 samples.

    1. Wrong final text after a key then type_text (out of 20, the browser behind a cover)

    App/editor Cmd+A Cmd+Z Cmd+X Cmd+V Cmd+Left Opt+Left Cmd+Shift+Left Left
    Safari textarea 12 13 0 13 0 0 0 0
    Safari input 14 17 0 13 0 0 0 0
    Safari contenteditable 13 15 0 14 0 0 0 0
    Safari compose 14 12 0 11 0 0 0 0
    Chrome textarea 5 5 0 6 0 0 0 0
    Chrome input 10 12 0 7 0 0 0 0
    Chrome contenteditable 7 3 0 3 0 0 0 0
    Chrome compose 10 11 0 9 0 0 0 0
    Firefox textarea, input 0 0 0 0 0 0 0 0
    Firefox contenteditable, compose 0 0 0 0 0 20 0 20
    TextEdit 0 0 0 0 0 0 0 0
    • The ordering race (Safari 161/640, Chrome 88/640). The page receives the key's keydown before the typed text. But the edit's effect (select-all, undo, paste) lands after typed input has begun, and later input overwrites it.
      • It happens in the foreground too: two-call Cmd+A then type went wrong in Safari 39/80, Chrome 36/80, Firefox 0/80.
      • It happens inside one call too: Safari 60/80, Chrome 43/80, Firefox 0/80.
      • The engine answers once it has posted the events, not once the app has consumed them. entered counts the posted units.
    • Firefox: background Left and Option+Left have no effect, and answer success. In contenteditables and the compose box, 20 of 20 each. All 80 keypress calls answered error:null, and the caret stayed at [29,0]. A foreground reference moves it to [28,0] and [24,0]. A separate defect.
    • A click's caret effect lands late. Click, then select by script at once, then type: the placement went wrong in Safari 3/10, Chrome 9/10 and Firefox 2/9. In one Chrome trace, the click's caret reappeared at +237 ms, after the script's selection, and the first typed input came at +416 ms. A separate defect, in 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 family.

    2. Partial text seen by the model

    • Right after type_text returned, the DOM or AX was incomplete in 200/240 (Safari), 160/240 (Chrome) and 160/240 (Firefox) trials. It completed within p50 9–10 ms and p95 20–45 ms, max 167 ms.
    • Every model-style observation (getState, getScreenshot) in the dedicated lane showed the requested text. The one partial model observation in the corpus is Engine: getState right after an action can return a reused tree older than the page (a field half typed after type_text answered success) #357's: 1 of 20 in its cell, and 1 of 4,329 Chrome observations.
    • The OS rewrites text by itself: macOS's "Add period with double-space" (on by default on the runner) turned "word is" into "word. is" in 2 Chrome trials of 500 characters. Turning it off made both cells exact (run 42814306485; 2 replays, which support the cause but don't prove its rate). TextEdit expanded "delivere" to "delivered" in all 60 of its 500-character trials.

    3. Fence candidates, all falsified as a general fence

    • A synchronous AX read fences nothing: Safari 150/640, Chrome 81/640, Firefox 80/640 wrong.
    • An effect predicate (read the range after Cmd+A) cleared the normal cells. But Cmd+A with the text already selected went wrong 62/80 (Safari) and 25/80 (Chrome) while the predicate confirmed, since it was already true.
    • An F20 marker behind the key:
      • Posting it alone doesn't help: Chrome 76/160 wrong.
      • Waiting for the page to receive it doesn't either: in Chrome, the marker arrived before the select-all effect 69/80 times.
      • F20 isn't a no-op in Safari: all 320 trials inserted U+0010, and 64 kept it in the final value.
    • Waiting for the AX selected-text notification:
      • The positive cells had 0 wrong.
      • Safari's negative control (Cmd+F20) falsely acknowledged 151/160.
      • Chrome's Cmd+A on already-selected input gave no acknowledgement in 40/40 (it timed out after about 1 s).
      • So it's app-specific, not general.

    4. An exact read-back of type_text works

    How it works:

    • Snapshot the focused field's value and selected range before posting.
    • Compute the expected value: the selected range replaced with the typed text.
    • After posting, compare the same field's value with it by equality (not containment), polling for up to about 1 s.

    With the key settled independently: 720 trials, 719 confirmed, and 1 honest refusal on a Firefox role read. 0 wrong values were accepted.

    The cost of the snapshot and poll, p50/p95: Safari 26.0/57.2 ms, Chrome 28.4/47.8 ms, Firefox 33.4/53.4 ms. A mismatch costs about 1 s.

    Fields it can't read: 120 password or concealed trials and 60 canvas trials all answered unconfirmed, with 0 leaks. Secure values are never queried.

    What to change in production: Chrome's canvas exposes an empty AX value that isn't its text, so reject non-text roles rather than treating any string value as readable.

    5. #357

    Covered on its own ticket. The partial observation is proven, and stale-tree causality is provisional.

    Runs:

    The tables are in ~/.local/share/probe-354/ on the MacBook: primary-owned/rates.tsv, run-42815192390/tables.tsv and fence-summary.json.

  5. 49 remaining items

  6. SSFSKIM commented on Nov 17, 2026

    @SSFSKIM
    OwnerAuthor

    [board] in-review: PR #396 opened (7082165, ci-gate GREEN)

  7. removed
    status:in-review
    on Nov 17, 2026
  8. SSFSKIM commented on Nov 17, 2026

    @SSFSKIM
    OwnerAuthor

    [board] done: Landed via PR #396 (cua 0.28.4)

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