Skip to content

fix(web-fetch): match escaped punctuation in anchors - #255

Merged
lanyue-llk merged 4 commits into
mainfrom
fix/scorer-escaped-backtick-anchor
Nov 5, 2026
Merged

lanyue-llk merged 4 commits into
mainfrom
fix/scorer-escaped-backtick-anchor

Conversation

@lanyue-llk

@lanyue-llk lanyue-llk commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Question

On dynamic-027-ej2-syncfusion-com-react, why do answers with \`Edit\` fail an anchor containing `Edit`?

Cause

The two sides are rendered differently. The answer's escape renders to a literal backtick, but _stable_literal_match also renders the anchor as Markdown, so its backticks become a code span and disappear. The comparison is toolbar `edit` button against toolbar edit button. The same happens with escaped *, _ and [.

This path only runs for body_text and page_identity anchors. Other schemas fold both sides through Markdown normalization.

Fix

When an anchor misses, compare its literal text against the answer rendered with code spans and code blocks masked out. This only runs if the answer has a backslash escape outside code and contains no tag-like text (< followed by a letter, /, ! or ?), so attribute values, hidden elements and comments cannot supply an anchor. The mask is a caseless word letter, so it adds no word or case boundary. It adds no new modules.

Evidence

  • Controls: 34 paired controls added, 9 accept and 25 reject. Seven of the accept controls fail on main; all 34 pass on head. Rejects cover the wrong word, missing text, code spans, fences, indented code, comments, link destinations, declared plain text, words joined to code spans, case boundaries next to code spans, and mixed HTML (alt, title, aria-label, <meta content>, <span hidden>, <script>, <style>). The 8 original mixed-HTML controls fail if the HTML skip is removed.
  • Bindings: code-migration.json and tests/golden/web-fetch.json updated. The golden changes are hash-only.
  • Tests: tests/test_scoring_regressions.py, tests/benchmarks/test_current_scoring_controls.py, tests/test_golden_reports.py and make lint-check pass.
  • Rescore: the 6 providers on this task plus 100 random stored rows (seed 20261105), on copies, main versus head, with a 30 s per-row limit. Each run took about 145 s; 105 of 106 rows were compared.
Row Main Head Note
chromium fail pass anchor now matches
lightpanda fail pass anchor now matches
moli-fixed fail pass anchor now matches
moli-pr919 fail fail unchanged, the anchor miss and required_facts_missing both remain
obscura fail fail unchanged, required_facts_missing
kitesurf fail fail unchanged, empty answer

The table is from the 6-row rerun on the current head. The 100 random rows ran only on the first revision and were not rerun; later revisions only narrow the fallback. They produced no verdict or error changes, except that obscura__dynamic-058-zh-stable-tdesign-table__r001 timed out on both sides and was not compared. The first run produced no verdicts because of a bug in my throwaway script, so it was fixed and rerun.

In the 430-task dataset bound to this evidence, 6,223 anchor alternatives exist across all schemas, and 4,058 of them (in 276 tasks) are body_text and can reach the fallback. One renders differently from its literal text under the check I ran, the anchor on this task. That does not bound the fix: the fallback runs for any missed anchor on those paths, and other datasets were not counted.

Limits and what I did not do

  • The issue description expected 2 failing rows; 3 flip to pass.
  • An answer with any tag-like text, even inside code or escaped, skips the comparison and can still miss a literal anchor, which is why moli-pr919 keeps its anchor error. This can't create a false pass.
  • Character references share this surface. Once the answer has a backslash escape, &#96;Edit&#96; also matches a literal backtick anchor. This is the one way matching goes beyond backslash escapes; those characters still render identically.
  • Contracts with text exclusions skip the new comparison, so an escaped answer there can still miss. This can't create a false pass.
  • I did not check why moli-pr919 and obscura miss required facts, and did not check whether fact matching has a similar gap.
  • No full test suite or wide rescore was run, no stored evidence was changed, and no providers, Docker or VMs were used.

@lexmount-ocr lexmount-ocr 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.

⚠️ Review complete · a985c04

This review found 1 issue(s), including 1 blocking issue(s).

prose = content
for start, end in sorted(markdown_literal_spans(content) + markdown_comment_spans(content), reverse=True):
prose = prose[:start] + '\ufffc' + prose[end:]
return _visible(prose, schema) if escape.search(prose) else ''

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
P2: The fallback bypasses mixed-HTML visibility filtering and can accept hidden text. For example, with the body anchor toolbar Edit button, an answer consisting of Intro \!\n\n<script>toolbar \Edit` button</script>reaches this path: it does not start with a block HTML element, sonative_htmlis false. The normal path usesvisible_mixed_html_textviaanchor_textand excludes the script, but this helper masks only Markdown code/comments, and_visible` leaves this embedded script payload in the surface. The literal fallback therefore supplies the missing anchor from hidden script text. Apply the shared mixed-HTML visibility projection before rendering the masked prose (preserving escaped literals), and add a rejection control for hidden HTML following ordinary Markdown prose.

An answer's backslash escape renders to a literal character, while a body
anchor is rendered as Markdown and loses the same characters as delimiters.
An observed '`Edit`' therefore could not match '\`Edit\`'.

Anchors now also compare literally against the answer's escape-rendered
prose. Code and hidden comments never supply that surface, and declared
plain text keeps its backslashes.
The literal fallback read the raw answer, so with any backslash escape a
mixed-HTML answer could supply an anchor from alt, title, aria-label, meta
content, hidden spans, scripts or styles. The fallback now runs only when the
answer has no HTML prose projection.

Adds eight rejection controls and updates the scorer bindings.
@lanyue-llk
lanyue-llk force-pushed the fix/scorer-escaped-backtick-anchor branch from a985c04 to edc9620 Compare November 5, 2026 10:55

@lexmount-ocr lexmount-ocr 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.

⚠️ Review complete · edc9620

This review found 1 issue(s), including 1 blocking issue(s).

Comment thread src/lexbench_webfetch/stable_tasks.py Outdated
from .reference_quality import markdown_comment_spans, markdown_literal_spans
prose = content
for start, end in sorted(markdown_literal_spans(content) + markdown_comment_spans(content), reverse=True):
prose = prose[:start] + '\ufffc' + prose[end:]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
P2: Masking inline code with U+FFFC creates a word boundary that was not present in the rendered answer. For a body_text contract with the single anchor edit, the answer "Use preedit \!" renders as "Use preedit !" and correctly fails the existing atomic-label check. The new fallback instead compares "Use \ufffcedit !", so _stable_literal_match accepts edit as a complete word. This introduces a false pass even for anchors without escaped punctuation; the unrelated escape enables it. Preserve the original boundary constraints around masked regions (or reject matches that rely on a mask as their word boundary), and add an adjacent-code negative control alongside the existing control for joining phrase words.

The escaped anchor surface masked code with a non-word character, so an anchor
could match a word joined to a code span, such as `pre`edit. The mask is now a
word letter, and two rejection controls cover both sides.
lanyue-llk added a commit that referenced this pull request Nov 5, 2026

@lexmount-ocr lexmount-ocr 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.

⚠️ Re-review complete · 5a008cc

This review found 1 issue(s), including 1 blocking issue(s).

Comment thread src/lexbench_webfetch/stable_tasks.py Outdated
from .reference_quality import markdown_comment_spans, markdown_literal_spans
prose = content
for start, end in sorted(markdown_literal_spans(content) + markdown_comment_spans(content), reverse=True):
prose = prose[:start] + '\u01a3' + prose[end:]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
P2: The lowercase mask can manufacture a camel-case boundary and produce a false pass. For a body_text anchor EDIT, the answer "PEDIT \!" renders as PEDIT !, which the original matcher correctly rejects. This fallback instead produces ƣEDIT !; _stable_literal_match calls separate_case_labels, which splits the lowercase ƣ from uppercase EDIT, so the missing standalone anchor passes. The new joined-word controls only use lowercase edit and do not cover this case. Preserve boundary semantics across masked regions (including case splitting), and add an uppercase joined-word rejection control.

An answer with tag-like text could still supply an anchor from HTML payloads,
and the lowercase code mask added a case boundary. The fallback now skips any
answer with tag-like text, which replaces the projection guard and comment
masking, and the mask is a caseless word letter.

Adds two rejection controls and updates the scorer bindings.

@lexmount-ocr lexmount-ocr 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.

✅ Re-review complete · 7b1dd1f

No findings in this incremental review.

lanyue-llk added a commit that referenced this pull request Nov 5, 2026
@lanyue-llk
lanyue-llk merged commit 4adc02c into main Nov 5, 2026
7 checks passed
@lanyue-llk
lanyue-llk deleted the fix/scorer-escaped-backtick-anchor branch November 5, 2026 11:35
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