Skip to content

studiobench: compare a code fence one arm scrolled past on its text - #11741

Merged
danielhanchen merged 5 commits into
mainfrom
fix/parity-thread-content-noise
Sep 23, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
fix/parity-thread-content-noise

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Parity verdict, scored against the null failed on backend-only pull requests today, including #11687, #11724 and #11727. The flagged differences were assistant message sizes on the r100K film, such as msg15(assistant):1847269->2150610c, on model_change, reasoning_toggle, select_all_copy, settings and image_upload.

The product is fine; the harness compares scroll history.

code-fence-defer.tsx (#9462, the default since #9567) renders a code fence as a plain shell until it first comes within a viewport of the reader. After that it highlights the fence for the life of the mount. After reasoning_toggle, the r100K viewport lands either near the tail (scrollTop about 50,740) or about 20,000px higher, at random per cell on one build: 78 of 172 cells across 43 recorded CI payloads landed high. The high landing latches the fences in msg11, msg13 and msg15 until thread_reopen remounts the thread, and the census highlight_spans jumps from 6988 to 20K-26K in exactly those cells.

The null only excuses what it happens to observe, and at 2 repetitions per side it often observes nothing:

#11704 (run 35889028400) is a genuine positive and stays one: +55 chars on msg1, 3, 5 and 7 in every action and repetition, from a change to reasoning.tsx.

Both landing modes appear in every recorded payload since 2026-09-22 23:55, and the first failure of this shape is run 35838016289. #11522, which virtualized the reasoning transcript and lets it write scroll position, is the likely trigger. Older artifacts have expired, so that is not confirmed.

Change

  • scene/parity.js: in the same walk that produces the unchanged per-message digest, each message records per fence its latch state, a full digest and a text digest, plus a digest of the message with every fence replaced by a marker.

  • analysis/parity.py: new fence_latch_residue(). A differing message is excused only if all of these hold:

    • same role and same number of fences;
    • everything outside the fences is identical;
    • fences latched on both arms, or on neither, are identical in full;
    • fences latched on one arm only are identical in text, and there is at least one such fence.

    Nothing is excused when one arm latched no fence anywhere, which is what a build whose fences never upgrade looks like. An excused pair is a MATCH, so it does not lower the --min-compared coverage count.

  • sweep/ui_parity.py: the report prints how many matches were latch-only.

  • Payloads recorded before this carry no fence fields and score exactly as before.

What this gives up: the token markup of a fence that only one arm had latched is not compared, since it has no counterpart. The same fence latched on both arms in another cell still carries that comparison.

Testing

  • New sweep/selftest/test_studiobench_fence_latch_parity.py, 24 tests. It replays both failing runs from trimmed recorded CI payloads (160KB in testdata/):
    • As recorded, they fail with exit 1, exactly as CI did. With fence readings added they pass with exit 0, and the null-audit step still passes.
    • Injected genuine differences all still fail: a change to a message with no fences, a change outside a latched message's fences, a highlighting change on a fence both arms latched, and a build whose fences never upgrade.
  • With main's harness files swapped back in, 14 of the 24 fail, including both false-alarm replays.
  • tests/studio/studiobench selftests: 618 passed.
  • Live base-vs-base null on current main with the CI flags: the one cell that landed high produced 66 differing message pairs, and all of them fit the rule. Main's classifier failed 5 stable actions on that payload and the fixed one fails none.

The fence readings added to the recorded payloads are modelled from the mechanism, not captured; the live null run is what supports that model.

The UI parity gate failed on backend-only pull requests (#11724, #11727,
and others on 2026-09-23) with differences like
msg15(assistant):1847269->2150610c on model_change, reasoning_toggle,
select_all_copy, settings and image_upload at r100K.

Those are not rendering differences. code-fence-defer.tsx (#9462, the
default since #9567) renders a fence as a plain shell until it first comes
within a viewport of the reader, then highlights it for the rest of the
mount. After reasoning_toggle the r100K film leaves the viewport either
near the tail (scrollTop ~50,740) or about 20,000px higher, at random per
cell on one build (78 of 172 cells across 43 recorded payloads), and the higher landing
latches the fences of msg11/13/15 until thread_reopen remounts them. A null
control whose cells all landed low measured those actions stable, so the
result's latch noise was scored as a regression. The same noise also made
a null that did see it excuse settings and model_change outright, which
hid real changes there.

scene/parity.js now reads, in the same walk that produces the unchanged
per-message digest, each fence's latch state, full digest and text digest
(whitespace dropped, since streamdown emits one span per line and the
shell one text node), plus the message with every fence replaced by a
marker. analysis/parity.fence_latch_residue treats a message as differing
only by latch when everything outside its fences matches, every fence
latched on both arms or neither matches in full, and every fence latched
on one arm only matches on its text. Nothing is excused when one arm
latched no fence anywhere, which is what a build whose fences never
upgrade looks like. A latch-only pair is a MATCH, counted and printed, so
it costs no coverage; payloads recorded before this carry no fence fields
and score exactly as before.

The selftest replays both failing runs from their recorded CI payloads,
shows they fail as recorded and pass once the latch is recorded, and
injects genuine differences (a message with no fences, a change outside a
latched message's fences, a highlighting change on a fence both arms
latched, fences that never upgrade) that must still fail.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 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-09-23T22:51:52.066366Z f3d7b4d Manual request
🔒 Security Review ⚠️ Failed 2026-09-23T22:09:52.099875Z 6f9ace2 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.

@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: 6f9ace2f7d

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

const FENCE_DEFERRED_ATTR = "data-unsloth-fence-deferred";
const FENCE_MARKER = "<!fence>";

const fenceText = (raw) => normText(raw).replace(/\s+/g, "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve significant whitespace in fence comparisons

When a fence is latched on only one arm and both captures contain at least one latched fence, this removes every whitespace character before hashing, so visibly or semantically different code such as x = 1 versus x=1, Python indentation changes, or spaces inside string literals receives the same text digest. fence_latch_residue() can consequently classify the message as latch-only and return MATCH, hiding a real code-content regression; normalize only the line-boundary discrepancy between shell and highlighted DOM while retaining meaningful whitespace.

Useful? React with 👍 / 👎.

@danielhanchen danielhanchen Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, dropping every whitespace character was wider than the shell and highlighted forms differ by. Fixed in b484431: the fence text now drops line breaks only (streamdown's per-line spans carry none, the shell's text node does) and keeps every other character, running only the timestamp and id substitutions, not the whitespace collapse. The node-evaluated capture test now checks that x + 1 to x+1, a 4 to 2 space indent and f(2) to f( 2) each give a different text digest from the highlighted original; with the old stripping that test fails.

start: fence.start,
end: parts.length,
latched: fence.latched,
text: fenceText(fence.body === null ? fence.all : fence.body),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Compare fence language before normalizing a latch mismatch

For a fence latched on only one arm, the comparison retains only this body-text hash while digest_unfenced replaces the entire fence with a marker. Therefore a real change from, for example, a Python fence to a JavaScript fence with identical body text changes the language label, attributes, and highlighting but is still classified as latch-only and can make the pair MATCH. Capture and compare stable fence metadata such as the language separately from latch-dependent markup.

Useful? React with 👍 / 👎.

@danielhanchen danielhanchen Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed. Fixed in b484431: each fence now records its data-language, which is on the fence root in both the shell and the highlighted form, and fence_latch_residue refuses any pair whose languages differ. A one-sided fence that changed language with the same body is now a new row in test_anything_but_the_latch_still_differs, which fails without the check, and the capture test confirms the language is read from both forms.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

The one-sided fence comparison dropped every whitespace character, so
`x = 1` and `x=1`, an indentation change or a space inside a string
read as the same fence, and it never looked at the language, so a fence
that changed language but kept its body read as latch-only too. Drop line
breaks only, the one thing that differs between the shell and the
highlighted form, keep the rest of the text as it is, and record and
compare each fence's data-language.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: b484431eb2

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

const FENCE_DEFERRED_ATTR = "data-unsloth-fence-deferred";
const FENCE_MARKER = "<!fence>";

const fenceText = (raw) => normSubs((raw || "").replace(/\r?\n/g, ""));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve code-fence line boundaries

The revised fenceText now strips every newline, so when the thread has another latched fence and this fence is latched on only one arm, distinct sources such as a\nbc and ab\nc both hash as abc. With matching language and unfenced digest, fence_latch_residue() then treats the message as latch-only and can return MATCH despite a semantic code change. Preserve line boundaries by canonicalizing the shell's newlines and the highlighted form's per-line spans to the same separator instead of concatenating all lines.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, dropping every newline collapsed a\nbc and ab\nc. Fixed in 6ea2cef: the fence text is now read as lines in both forms. The shell's single text node is split on newlines, and in the highlighted fence each element directly inside the body's <code> starts a line (a blank line's lone \n is dropped, so it counts once, as in the shell). Lines are joined by one newline and trailing blank lines are dropped, since the shell trims them. New node-evaluated test: a\nbc against ab\nc and against abc both differ, while trailing newlines and blank lines read the same in both forms. It fails with the newline-dropping reading. Selftests: 621 passed.

Dropping every newline made a line break moved within the code, `a\nbc`
against `ab\nc`, read as the same fence. Read both forms as lines: the
shell's text split on newlines, and the highlighted fence one line per
element directly inside its <code>, a blank line's lone newline dropped.
Join them with one newline and drop trailing blank lines, which the shell
trims.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 6ea2cef786

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

.filter((line, k) => k > 0 || line !== "")
.map((line) => line.replace(/\r?\n/g, ""))
: s.split(/\r?\n/);
return normSubs(lines.join("\n").replace(/\n+$/, ""));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve volatile-looking code literals

When both captures contain some latched fence and this fence is latched on only one arm, applying normSubs to its source can hide genuine code edits: for example, timeout = "295ms" versus timeout = "310ms", different timestamp literals, or different UUID constants all produce the same text digest. Because digest_unfenced excludes the fence, fence_latch_residue() can then classify the message as latch-only and return MATCH; volatility substitutions intended for UI prose should not be applied to the source used for this one-sided fence comparison.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, the time and id placeholders are for UI prose and have no business in a fence's source. Fixed in f3d7b4d: the fence text is now the lines as written, with no normalisation beyond the line reading. New node-evaluated test: timeout = "295ms" against "310ms", and "10:30" against "11:45", each give a different text digest; it fails with the placeholders applied. Selftests: 622 passed.

…lders

The time and id placeholders are there for UI prose. Applied to a one-sided
fence's source they made `"295ms"` against `"310ms"`, or two different
timestamp or id literals, read as the same code.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: f3d7b4d50b

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

@danielhanchen
danielhanchen merged commit 45f8fa6 into main Sep 23, 2026
33 checks passed
@danielhanchen
danielhanchen deleted the fix/parity-thread-content-noise branch September 23, 2026 23:35
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nslothai#11741)

* studiobench: compare a code fence one arm scrolled past on its text

The UI parity gate failed on backend-only pull requests (unslothai#11724, unslothai#11727,
and others on 2026-09-23) with differences like
msg15(assistant):1847269->2150610c on model_change, reasoning_toggle,
select_all_copy, settings and image_upload at r100K.

Those are not rendering differences. code-fence-defer.tsx (unslothai#9462, the
default since unslothai#9567) renders a fence as a plain shell until it first comes
within a viewport of the reader, then highlights it for the rest of the
mount. After reasoning_toggle the r100K film leaves the viewport either
near the tail (scrollTop ~50,740) or about 20,000px higher, at random per
cell on one build (78 of 172 cells across 43 recorded payloads), and the higher landing
latches the fences of msg11/13/15 until thread_reopen remounts them. A null
control whose cells all landed low measured those actions stable, so the
result's latch noise was scored as a regression. The same noise also made
a null that did see it excuse settings and model_change outright, which
hid real changes there.

scene/parity.js now reads, in the same walk that produces the unchanged
per-message digest, each fence's latch state, full digest and text digest
(whitespace dropped, since streamdown emits one span per line and the
shell one text node), plus the message with every fence replaced by a
marker. analysis/parity.fence_latch_residue treats a message as differing
only by latch when everything outside its fences matches, every fence
latched on both arms or neither matches in full, and every fence latched
on one arm only matches on its text. Nothing is excused when one arm
latched no fence anywhere, which is what a build whose fences never
upgrade looks like. A latch-only pair is a MATCH, counted and printed, so
it costs no coverage; payloads recorded before this carry no fence fields
and score exactly as before.

The selftest replays both failing runs from their recorded CI payloads,
shows they fail as recorded and pass once the latch is recorded, and
injects genuine differences (a message with no fences, a change outside a
latched message's fences, a highlighting change on a fence both arms
latched, fences that never upgrade) that must still fail.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* studiobench: keep a fence's spacing and language in the latch comparison

The one-sided fence comparison dropped every whitespace character, so
`x = 1` and `x=1`, an indentation change or a space inside a string
read as the same fence, and it never looked at the language, so a fence
that changed language but kept its body read as latch-only too. Drop line
breaks only, the one thing that differs between the shell and the
highlighted form, keep the rest of the text as it is, and record and
compare each fence's data-language.

* studiobench: read a fence's text as lines, not a run of characters

Dropping every newline made a line break moved within the code, `a\nbc`
against `ab\nc`, read as the same fence. Read both forms as lines: the
shell's text split on newlines, and the highlighted fence one line per
element directly inside its <code>, a blank line's lone newline dropped.
Join them with one newline and drop trailing blank lines, which the shell
trims.

* studiobench: compare a fence's text as written, without prose placeholders

The time and id placeholders are there for UI prose. Applied to a one-sided
fence's source they made `"295ms"` against `"310ms"`, or two different
timestamp or id literals, read as the same code.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

1 participant