Skip to content

Mark a rewritten section as one change - #4887

Merged
max-sixty merged 8 commits into
mainfrom
fewer-change-marks
Nov 2, 2026
Merged

max-sixty merged 8 commits into
mainfrom
fewer-change-marks

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Comparing a page with an earlier version after the agent rewrote one section put a ⇄ Change margin entry beside every heading, paragraph, table cell and option in it: 28 entries for one rewrite on the page that prompted this, stacked down the margin, and h stopped at each one. That page was marked on the user's return, which #4890 has since turned off; Compare in Versions marks the same way.

The version comparison now groups the blocks it marks into changes. A change is a run of changed blocks with no unchanged block between them in page order, as a diff's hunk is a run of changed lines, and it ends where a view does: a details, a declared view (x-views, such as a tab), or the content a disclosure control names in aria-controls, such as a settled options group's options behind its row. Each block keeps its bar (#4890's margin-bars.js now draws one per block of each change). comparisonChanges(owner) returns changes, each the array of its blocks, so a change gets one margin entry beside the block it starts with, one stop of h, and one in the Δ counts on tabs and settled choices. The notice a comparison gives says "2 changes since v9" where it said "28 changed passages since v9". A change's margin entry opens and closes all its blocks' inline comparisons together, and its Page Map row counts the parts a reader sees: "heading and 5 more changed since v9", with a table counting once.

To group well, the comparison now lines up the two versions' blocks in document order with jsdiff's diffArrays, which the runtime already bundles. It used to count a block unchanged wherever the base held its words, so a short cell such as "No" that another table also held stayed unmarked and split a rewrite, while the other table's cell was marked. A block inserted with words the diff removed elsewhere has only moved and stays unmarked, as before. Past 1,000 block edits the comparison falls back to the one-pass reading, which keeps a long page rewritten whole fast.

Known gaps: a rewrite that keeps one short block identical in the same place, such as a "No" cell in both the old and the new table, splits into two changes, and a rewritten section whose new blocks share no ids with the old one shows none of the old text when its entry is pressed.

Tests: the inline-diff test reads log-retention's rewritten paragraph and the new paragraph after it as one change that one press opens. The script-words test finds the closing paragraph's inline diff through the change its three reworded paragraphs make. New tests, driven through Compare in Versions, hold a rewritten section to one margin entry and one walk stop, with an untouched table that shares a word left unmarked, and keep a change in a closed details or a settled options group apart from the visible one after it.

This was written by Claude Code on behalf of max-sixty

Coming back to a page after the agent rewrote one section, the user met a Change
margin entry beside every heading, paragraph, table cell and option of that section:
28 entries for one rewrite on the page in the report, stacked down the margin, and
`h` stopped at each one.

The version comparison now groups the blocks it marks into changes. A change is a
run of marked blocks with no unchanged block between them in page order, as a diff's
hunk is a run of changed lines (`changeRuns` in version.js). Each block keeps its
tint. `comparisonChanges(owner)` returns changes, each the array of its blocks, so
one margin entry stands beside the block a change starts with, `h` stops once per
change, the notice counts changes ("2 changes since v9"), and the Δ counts on tabs
and settled options count changes. A change's margin entry opens and closes the
inline comparisons of all its blocks together, and its Page Map row says where it
starts and how many blocks follow ("heading and 26 more changed since v9").

Tests: the inline-diff test reads log-retention's rewritten paragraph and the new
paragraph after it as one change that one press opens; the script-words test finds
the closing paragraph's inline diff through the change its three reworded
paragraphs make; a new since-seen test holds a rewritten section to one margin entry
and one stop of the walk.
…ts view

Review of the first commit found two cases it still got wrong. The comparison
counted a block as unchanged wherever the base held its words, so in a rewritten
section a short cell such as "Leaf", which an untouched table further down also
held, stayed unmarked and split the section into several changes, and the untouched
table's cell was marked instead. And a change that began inside a closed `details`
and ran into the visible paragraph after it put its one margin entry on the hidden
block, leaving the visible one without any.

The comparison now diffs the two versions' blocks in document order with jsdiff's
`diffArrays`, which the runtime already bundles, so a block is unchanged only where
it lines up with the base. A block inserted with words the diff removed elsewhere
has only moved and stays unmarked, as before. A change ends where a view does: the
nearest `details` or member of a widget's declared views (`x-views`), such as a tab.
A change's Page Map row counts the parts a reader sees changed, so a rewritten table
counts once: "heading and 5 more" on the reported page, where it said 26.

Tests: the rewritten-section test adds an untouched table holding one of the new
table's words and asserts it stays unmarked; a new test holds a change hidden in a
closed disclosure apart from the visible one after it.
The ordered diff runs on the main thread and costs the page's length times the
edits it finds: review measured about 300 ms for a 2,000-block page rewritten whole
on a loaded host. Past 1,000 block edits the comparison falls back to the one-pass
reading, a block being unchanged wherever the base holds its words; the worst case
review measured with the cap, on a 6,700-block page, was about 55 ms.

`viewOf` says why a settled options group is not a view: it declares neither
`details` nor `x-views`, and reading its options' `hidden` would make a change's
extent depend on whether the group was open when the comparison ran.
# Conflicts:
#	browser/runtime/version.js
#	dist/kernel/kernel.json
#	dist/kernel/runtime/bundle-data.js

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Keep independently disclosed content in separate changes. In viewOf, a settled option and the visible paragraph after its group both return null, so changeRuns merges their edits. I reproduced this with two settled options, changing the last option and the paragraph immediately after the group: the paragraph is tinted, but the only Change marker is invisible on the collapsed option, and repeated h presses return to that option rather than visiting the paragraph. The paragraph also loses its direct pointer/touch route to its inline comparison.

This is the same visibility boundary the new details handling protects, and the known-gap note does not preserve the removed route. The grouping needs a shared disclosure boundary that includes independently hidden widget content, so a hidden option cannot own the comparison entry for visible content outside its group.

A settled options group hides its options behind its own row rather than a
`details` or a declared view, so a change that ran from its last option into the
paragraph after the group was one run: its only margin entry stood on the hidden
option, `h` returned there, and the visible paragraph had no entry of its own.

The view a block stands in now also covers what a disclosure control names: an
element with `aria-expanded` lists it in `aria-controls`, as the settled row does
for its options. Elements one control names share its view. ARIA's disclosure
pattern is already how a widget or a page says which content a control shows and
hides, so a page's own disclosure groups the same way without a registry entry.
The walk up from a block now starts at the block itself, so an option or a tab
that is itself a block counts as its own view.

The disclosure test now runs over a closed `details` and a settled options group.
leaf-agent
leaf-agent previously approved these changes Nov 1, 2026
# Conflicts:
#	browser/runtime/change-walk.js
#	browser/runtime/version.js
#	dist/kernel/kernel.json
#	dist/kernel/runtime/bundle-data.js
#	tests/browser/startup/test_since_seen.py
leaf-agent
leaf-agent previously approved these changes Nov 1, 2026
# Conflicts:
#	browser/runtime/version.js
#	dist/kernel/kernel.json
#	dist/kernel/runtime/bundle-data.js
leaf-agent
leaf-agent previously approved these changes Nov 2, 2026
# Conflicts:
#	browser/runtime/change-walk.js
#	dist/kernel/kernel.json
#	tests/browser/startup/test_since_seen.py
@max-sixty
max-sixty merged commit 2b6d9a2 into main Nov 2, 2026
4 checks passed
@max-sixty
max-sixty deleted the fewer-change-marks branch November 2, 2026 04:23
leaf-agent added a commit that referenced this pull request Nov 2, 2026
The Unicode inline-diff test still expected a separate change marker for
each adjacent paragraph. #4887 deliberately groups those paragraphs into
one change and opens their inline comparisons together, so the second
click waited for a marker that no longer exists.

Read the trailing deletion after the first click, preserving the
assertions for astral character offsets, inserted words and the deleted
trailing phrase. Production behavior is unchanged.

The focused test reproduced the 120-second missing-marker timeout on
main at `7075a022d`, then passed with this correction (7.01 seconds).
Its failure screenshot already shows both comparisons open. Ruff and
`git diff --check` pass.

Closes #5090 — automated triage

Co-authored-by: leaf-agent <[email protected]>
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.

2 participants