Skip to content

Engine: when the node budget cuts, keep what the window shows (visible-first walk) - #306

Merged
SSFSKIM merged 15 commits into
mainfrom
feat/301-visible-first
Nov 6, 2026
Merged

SSFSKIM merged 15 commits into
mainfrom
feat/301-visible-first

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

When a window's accessibility tree is larger than cua's 4,000-node budget, the engine now spends that budget on what the window shows, not on the top of the document. Before this, on long pages scrolled a quarter or more down:

The printed tree stays in document order. When the budget cuts, the tree says so and says which way the omitted elements lie. The budget is cua's own; the vendor has none, so this moves cua closer to the vendor's full tree. An observation the budget doesn't cut reads, prints and numbers exactly what main does.

Closes #301

The rule

The design session's rulings are aed3f041 and 66f90453, and the spec's #301 Decision Log entries hold the full text.

  • The walk (Walk.swift) runs in two passes.
    • Selection reads depth-first. A node's children are taken up at once when its frame shows by more than a 1-pt strip in what its clipping ancestors leave of the window, or when it has no frame. Anything else is read and set aside, then taken up in document order with what the budget has left.
    • Emission numbers what was read in preorder. The tree, the allocation of new tokens, the revision's sibling lists and the guard's record therefore stay in document order.
  • Tokens. Every unread child is carried over with its subtree, in its place. A node present in consecutive observations keeps its token, and the re-fetch walk uses the same order and clipping.
  • The marker reads [truncated: at least N elements omitted, above|below|above and below the visible area]. The count is a lower bound. A part placed neither way counts in the total without a direction. The first-call docs and their mirrors (docs-oracle, core-documentation, the surface inventory) carry the wording.
  • The width rule's omitted branch (over 499 children, no visible subset) is handled in the guard's record only. The record keeps the children whose frames meet the window, found by bisection and bounded by 1,000 reads and the deadline. The printed tree keeps the vendor's rule.
  • The guard, under collapsed containers. A thin (≤ 1 pt) node whose children were cut counts for a hit only when the hit's live parent chain passes through it, and only inside the chosen node's recorded subtree. Main falsely refuses such a click as interactiveHit; this branch reads it container-only.
  • Plugin 0.27.0. The first-call document states the new marker and the limits.
  • Hit-test seeding was built, measured and removed (ruling 66f90453). It promoted nothing in 56 of 56 rows, at a p95 of 250 ms.

Limits

  • A visible control under a container that reports a collapsed (1-pt) frame can still be cut, and the guard then checks only its container. A wide shown list can also spend the budget on its rows' frames before later visible siblings: Chrome's toolbar on a 3,000-row table stays container-only, at 92–94% checked. Both are Spike: visible controls under collapsed-frame containers on cut pages (revisit seeding) #304.
  • Chromium re-creates its synthesized AXColumn and table-header AXGroup elements, so under the vendor's CFEqual identity rule they take new tokens at every observation. Main does the same (run 42243553112); visible-first only reaches them on long tables. This is Engine: re-created Chromium synthesized nodes (AXColumn, table header) keep their token #303.
  • Near the 6 MiB byte budget, an uncut walk can show a later-in-preorder action description, when same-named actions in one process answer differently per element. It is in tech-debt-tracker.md.
  • Scrolling a cut page changes which elements the tree carries. An element that leaves the kept set and comes back gets a new model index; the engine token survives.

Live proof (GitHub-hosted macOS runners, 2 reps, no clicks posted)

Evidence is in docs/evidence/2026-11-06-visible-first/.

The guard's share of clickable points checked, main against the branch without seeding (https://github.com/SSFSKIM/cua/actions/runs/42246731024):

Page top 25% 50% 90%
Chrome, Wikipedia article 96.9 → 100 18.3 → 100 30 → 100 14.6 → 100
Chrome, Wikipedia population table 94.1 → 100 89.7 → 100 23.5 → 100 15.4 → 100
Chrome, HN thread 90.4 → 100 39.2 → 100 52.2 → 100 40.4 → 100
Chrome, local 3,000-row table 92.1 → 92.1 34.3 → 93.6 31.6 → 94.1 31.4 → 94.1

Tests and review

Follow-up: #305 (P1) checks live whether #296's guard refuses ordinary clicks on still pages on main. The #301 A/Bs emulated that on GitHub's code view, Safari's toolbar and Finder's title bar.

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

…he window shows, printed in document order (refs #301)

Decision Log entries for ruling aed3f041: the two-pass walk (visible-first selection, document-order emission, the re-fetch in the same order), when to seed and its price, id stability across a scattered cut, the truncation marker and Chromium's strips, the 500 ms cap and the timings, and the width rule's omitted branch in the guard's record only; the Observation paragraph, the Indexes paragraph and the Skyshot interface amended.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ws, seeded by hit-tests on Chromium, and says what it left above and below (refs #301)

The walk reads visible-first (frames order it; on Chromium, once the read elements and the children they name exceed the budget, hit-test chains on an 80-pt grid seed it, capped at 500 ms inside the deadline) and emits in document order, so an uncut walk is the plain preorder, tokens included. Every unread child of a read element is carried over in its place, so tokens survive a cut that moves with the scroll. truncated gains above and below, rendered as '[truncated: at least N elements omitted: A above the visible area, B below it, C elsewhere]', and the first-call document's macOS paragraphs gain a fourth saying so. The width rule's omitted branch keeps its shown rows and their subtrees in the guard's record only. The re-fetch walks in the same order. Timings: seedMs and its counts, recordOnlyNodes.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…wice (refs #301)

Sminos-Session: cursor235#b93055dd (cua on macbook)
… the deadline, and the re-fetch clips as the walk does (refs #301)

From the review of 1abb734: the omitted branch's frame search is bounded by the deadline and by the children it reads; the search and the record-only reads run once the tree's selection is done, so a screenshot never changes the printed tree; the re-fetch walk carries its ancestors' clip, so it does not spend its budget on what a scroll area hides. Tests for each; the spec's #301 entries amended.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ancestors leave showing (refs #301)

From the re-review of e474396: a list in a scroll area scrolled off, whose rows' own frames overlap the window, no longer spends the record's budget before a shown list's. Test and spec entry amended.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…he seeding's trigger counts distinct elements (refs #301)

From the review of c4057c3..effffce: the per-walk description cache keeps the answer asked for the earliest element in the preorder, resolved at emission, so reading a visible sibling first no longer changes any node; the trigger counts distinct handles, so children shared by several parents (a table's cells under rows and columns) no longer seed a walk under the budget. The uncut test compares whole payloads; tests for both; the spec's #301 entries amended.

Sminos-Session: cursor235#b93055dd (cua on macbook)
… budget for every node it changes, and refused past it (refs #301)

From the re-review of effffce..ab0e019: an earlier element's longer answer, swapped in at emission for nodes already selected, could take the tree past the 6 MiB budget and the 8 MiB frame. The selection now charges the difference per node using the name and refuses a replacement that would not fit; an uncut walk never refuses one, so it stays the preorder's. Test and spec entry amended.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…iptions near the byte budget (refs #301)

From the re-review of ab0e019..9bbbacc, ruled doc-only: when the same action names in one process answer differently per element and one name's growth must wait for another's shrink near the byte budget, the growth is refused and the later-in-preorder answer shows. The spec's claim that an uncut walk never refuses one is corrected, Walk.swift's comment with it, and the fix is logged under Open in tech-debt-tracker.md.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…nd check a collapsed container's cut children container-only (refs #301)

Ruling 66f90453 on the hosted A/B (run 42231389508): the guard checked 100% of points on every cut page in Chrome and Safari, and seedPromoted was 0 in 56 of 56 rows at a p95 of 250 ms. Removed: the trigger and its distinct-element count, the hit-test grid and cap, the source's hit-test and parent seams, the seed timings and the seeding's tests. The stated limit replaces the grid's: a visible control under a container reporting a collapsed (1-pt) frame can still be cut (#304); its test found the guard's record treating a strip-framed container as framed, so a hit under it refused as interactiveHit, and screenshotNodes now counts such a node as frameless, checking the point container-only. The spec's #301 entries revised: the when-to-seed and cap entries superseded, a new entry for 66f90453 with the A/B's numbers, and the limits of #303's re-created Chromium columns and header groups and the read failures they cause.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…d which way the omitted lie, and the macOS paragraph states the new limits (refs #301)

Ruling 66f90453: '[truncated: at least N elements omitted, above the visible area]', 'below the visible area' or 'above and below the visible area', a part placed neither way counting in the total with no direction. The fourth paragraph of docs/cua-api/agent-cursor.md drops the 80-pt grid and states the collapsed-container limit (#304) and Chromium's re-created table columns and headers (#303); docs-oracle, the core-documentation test and the surface inventory follow.

Sminos-Session: cursor235#b93055dd (cua on macbook)
… to its parent in the guard's record (refs #301)

From the re-review of 4e73574..b268504: a 1-pt scroll area or page-scrolling group clips its children to itself, so its missing children are its own; counting them against the parent had passed a new button elsewhere in the window as unrecordedDescendant. screenshotNodes now uses clipsDescendants, the predicate the walk cuts by, to tell a collapsed container from a clipping strip. A test for the clipping strip (interactiveHit); the collapsed-container test stays unrecordedDescendant; each fails with its half removed. Spec sentence amended.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…s parents pass through it (refs #301)

From the re-review of b268504..c36c3c8 and the coordinator's ruling: the role cannot tell a collapsed container from a clipping strip (Chromium clips by overflow, so a 1-pt AXList can clip), so the guard stops inferring clipping. screenshotNodes keeps main's completeness rule and marks strips whose children the record lacks (thinGap); a verdict that would refuse an interactive hit, or an element route's target, reads that element's parents and passes it as unrecordedDescendant only when they run through such a strip. The clipsDescendants use added in StalePoint is gone. Tests: the hit under the collapsed container passes; an AXScrollArea strip and an AXList strip each with a new button elsewhere refuse (interactiveHit, pressedOther); each fails with its part of the rule removed. Spec sentence amended, with the climb's cost.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ed subtree (refs #301)

From the re-review of c36c3c8..9f5a045: every incomplete strip in the record counted, so a new button under a collapsed group, covering a fully recorded button there, passed as unrecordedDescendant on the coordinate path and the element route. screenshotNodes now gives each node the thin gaps of its recorded subtree (gapsBelow), and both verdicts consult only the chosen node's. The reviewer's case refuses on both paths and fails without the scoping; the collapsed-container test still passes. Spec sentence amended.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…without seeding, re-created Chromium columns) (refs #301)

Sminos-Session: cursor235#b93055dd (cua on macbook)
@SSFSKIM
SSFSKIM marked this pull request as ready for review November 6, 2026 16:43
@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T16:46:28.756434Z 5954c41 Draft marked ready
ℹ️ 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.

…uncation marker's wording (refs #301)

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5954c4115d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +490 to +493
private func childClip(_ item: Selected) -> CGRect? {
guard let clip = item.clip else { return nil }
guard clipsDescendants(role: item.read.data.role, actions: item.read.actions), let frame = item.read.data.frame else { return clip }
return clip.intersection(frame)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset inherited clipping at popover and menu boundaries

When an AXPopover or AXMenu is nested under a scroll area but extends outside that area's frame, this intersection incorrectly carries the scroll area's clipping into the popup. screenshotNodes explicitly resets clipping at clipBoundaryRoles, and StalePointTests.testTheRecordCutsFramesByClippingAncestorsAndTakesTheDeepestNode already establishes that popup contents outside the enclosing scroll area remain visible. The new selection instead defers those visible contents, so another large subtree can exhaust the budget before they are read, dropping popup controls that the previous preorder reached. Reset clipping at these boundaries in both selection and the corresponding re-fetch traversal, and ensure the boundary itself is not deferred solely because it lies outside its ancestor's clip.

Useful? React with 👍 / 👎.

@SSFSKIM
SSFSKIM merged commit 4525925 into main Nov 6, 2026
6 checks passed
SSFSKIM added a commit that referenced this pull request Nov 6, 2026
…every spot, so each refusal is seen on both heads; the report script

Sminos-Session: cursor235#b93055dd (cua on macbook)
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: when the node budget cuts, keep what the screenshot shows (visible-first walk)

1 participant