Skip to content

fix(web-fetch): repair six scorer defects with paired controls - #239

Merged
lanyue-llk merged 2 commits into
mainfrom
fix/web-fetch-scorer-bundle
Nov 4, 2026
Merged

lanyue-llk merged 2 commits into
mainfrom
fix/web-fetch-scorer-bundle

Conversation

@lanyue-llk

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

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Issues

Closes #83
Closes #85
Closes #86
Closes #110
Closes #111
Closes #112

Summary

All six public-scorer reproductions failed on the unfixed scorer, so each one gets a code fix. No stored verdict, frozen profile or receipt changes, no provider ran, and there are no provider-specific branches.

Issue Shared cause Fix
#83 The fixed-membership branch dropped rejected records without recording them It now records each rejected record's fields and record_sha256. Observed, matched and mismatched counts are consistent, including for matching answers
#85 The HTML article fallback emitted DOM text unescaped, so literal Markdown became links and headings article_markdown escapes text-node syntax, including literal HTML tags, when the answer is declared html. Real anchors and headings still create structure
#86 Document structure never received the plain_text representation _text_events gets a literal mode: fences, indentation, hashes and link syntax stay literal, and declared titles still match
#110 Inline nodes were joined with a space or split into separate fields, breaking one price token Inline-preserving text is added after the existing candidates in the scoped, unscoped and in-anchor paths. The title anchor stays a boundary
#111 A bullet description ran until the next bullet or end of input A heading (ATX, empty ATX or setext) left of the item's content column, measured with tabs expanded, now ends it in two cases: nothing follows the heading before the next bullet (ATX only; see Known limits), or the bullet is the last one and the heading does not repeat its title. A heading indented into the item stays with it, and a # line inside fenced code never ends it
#112 The definition body used recursive dd text Nested API signatures, including line-wrapped ones, and their bodies are removed from the parent's text. Nested parameter lists stay

Behavior worth checking

Controls

There are 69 new controls in src/harness/benchmarks/scoring-regressions.json, covering both error directions where both are plausible. test_current_corrections_run_through_the_public_scorer_and_task_predicate runs them through score_attempt and task_passed.

Run against the 43b149a8 scorer, 37 of the 69 give a wrong result: 33 on the verdict and 4 on expected_metrics only. The other 32 are guards that already held, such as the same bytes declared as Markdown, neighboring-record prices and card titles after a bullet.

The task named evaluation/scoring-regressions.json. That file is the frozen registry resolved from the pinned dataset, so new current controls go in the in-repo file that load_scoring_regressions already appends to it.

Values that moved

Value Before After
SCORING_SOURCE_SHA256 (computed at import) 5c8bfec2… 6744c189… (6744c189b278462692aaa20f88353c4a32873d09e3b2335cd127a00314b19d41)
code-migration.json after_sha256 Updated for article_comments.py, article_posts.py, article_text.py, dynamic_lists.py, metrics.py and stable_tasks.py
code-migration.json changes document_structure.py added, because it now differs from the pinned source
code-migration.json corrections Six new entries binding root cause, modules and control IDs
tests/golden/web-fetch.json Six routes, explained below

No other file in the repository contains the old hash.

Golden routes. attempts/fixture__ok__r001.html, attempts/fixture__fail__r001.html, their two en/ versions, results.jsonl and report-manifest.json changed only because the scorer hash moved. With the hash set back to 5c8bfec2… in-process, the Web Fetch golden test on this code passes against the base snapshot.

Historical verdict classes that could change

This is derived from the code; nothing was rescored and no provider ran.

Issue Class that could change Direction
#83 None. Only the stable_source_* diagnostics change for fixed-membership tasks No verdict change
#85 Answers declared html, with no native record containers, using the post or comment fallback Pass to fail when literal link, heading, bold or HTML tag syntax supplied the records, including doubly encoded forms such as #. Fail to pass when literal brackets, a literal script or style tag, or similar in genuine text broke parsing
#86 Answers declared plain_text on tasks with document_structure Fail to pass for indented, fenced or #-prefixed literal text. Pass to fail when a heading matched only through literal [Title](url) syntax
#110 HTML linked_product answers whose price is split by inline elements Fail to pass only. Existing candidates keep priority, so an already-selected price does not change
#111 Markdown name_description records, including composite groups, where a heading outside the item follows the last bullet and does not repeat its title, including empty ATX and setext headings Pass to fail when the description came only from the later section. Other records keep their verdict but have a shorter stored description, which can change a record hash under fixed membership
#111 Markdown name_description bullets where a heading outside the item has nothing after it before the next bullet Pass to fail when that heading was the whole description
#111 Markdown name_description last bullets followed by a line that reads as a heading once markup is removed, such as \# Text, #\# Text, **# Text** or [# Text](/x) Pass to fail when that line was the only description. These forms were treated as literal in an earlier revision of this PR and no longer are; cards and pipe tables with these forms keep the verdict they have on 43b149a8
#111 Bullets with a tab after the marker, followed by a heading left of the expanded content column, such as -\tWidget\n ## Section\n Text Pass to fail when the description came only from that section
#112 HTML definition contracts where a parent term contains a nested signature Pass to fail when that text was the parent's only body. document_body_chars also falls, which can fail the body floor

Known limits, left on purpose

Each of these is left as it is on purpose, because the owner asked to focus on the main behavior and leave minor edge cases:

  • Mid-document borrow keeps its base verdict. - Widget\n\n## Related\nUnrelated section prose.\n\n- Gadget\n Gadget description text here. still passes, because a heading before another bullet cannot be told apart from a card title with text. This is the accepted cost of keeping card-title answers correct. The same applies after the last bullet when the section heading happens to repeat the bullet's title.
  • A horizontal rule under a description reads as a setext heading. - Widget\n\nGenuine description of widget.\n---\nFooter text. goes from pass to fail.
  • A line that starts with a hash once markup is removed reads as a heading. After the last bullet, - Widget\n\# Text, - Widget\n**# Text**, - Widget\n[# Text](/x), - Widget\n<br># Text and - Widget\n![](/x.png)# Text go from pass to fail. A scan of the 3,755 stored files under webfetch-430-refresh-20261014 found no &#35; or emphasis-wrapped form at a line start. Nearly all \# lines there are hashtags or numbers with no space after the hash, so they are not headings; five are a bare \#. The sampled [# lines are links wrapping real headings.
  • A setext heading with nothing after it does not end a description before the next bullet. - Widget\n\nRelated products\n-------\n\n- Gadget\n A genuine gadget description. still passes, while the ATX form fails. The review found this form in none of the 2,945 stored answers.
  • A title heading only counts when it repeats the bullet's text exactly. - [Alpha](/a)\n\n### Alpha ###\n\nAlpha is a great item., and a truncated title such as ### 1,000 Places to See ..., lose the last card's description. One stored answer, obscura/live-034-travel, loses one card this way.
  • A mixed fence closer ends the fence. In - Widget\n```\n```~~~\n# Text, the ```~~~ line closes the fence, so # Text is a heading and the verdict goes from pass to fail.

No dataset release is needed: tasks do not depend on the scorer, and #114 is closed with the reason.

Test plan

  • All six reproductions from the issues, before and after the fix. They all reproduced before, and each now gives the expected verdict
  • 69 new controls through the public scorer: all match expectations on this branch, 37 do not on 43b149a8
  • tests/test_golden_reports.py: goldens regenerated through UPDATE_GOLDEN=1, hash-only as described above
  • Ruff lint gate: both commands pass
  • tests/benchmarks, tests/test_scoring_regressions.py, tests/test_golden_reports.py locally: 11398 passed, 4317 subtests passed
  • Stored Obscura answers ecommerce-list/run-001.txt and live-038-mystery/run-001.txt with minimum_records 20: both pass, as on 43b149a8, with 21 and 22 complete records
  • Review findings fixed, each with new controls: line-wrapped nested signatures, escaped markup reparsed as a price, headings left of the item's content column, existing price candidates keeping priority across all selected nodes, fenced # lines, empty ATX and setext headings, literal HTML tags in text nodes, unique matched counts under fixed membership, literal tags surviving the fallback reparse, whitespace-only blank lines before a setext title, doubly encoded references in the fallback, a tab after the bullet marker, and card titles after a bullet

Base: the branch sits on 43b149a8.

CI on the first revision had one failure: tests/test_local_task_replacement.py::test_current_replacement_validates_live_qualification_without_before_matrices[call], DID NOT RAISE ValueError. The test sets a record's elapsed_ms to 1 and expects a mismatch, and this PR changes nothing it touches. It passed locally and on the next CI run, so it looks intermittent. My unconfirmed reading is that it flakes when the fixture call really took 1 ms.

@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 · 28a4421

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

# parameter definitions, remain part of the enclosing description.
local = copy(description)
for term in local.select('dt'):
if term.decomposed or not _api_signature(term.get_text()):

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 — Normalize HTML signature whitespace before testing for nested ownership. term.get_text() preserves source newlines, but _api_signature uses .* without DOTALL. Changing the existing definition-nested-signature-body-only control's child term to <dt>child(\n)</dt> therefore leaves the child and its description in the parent's copied dd. The parent still receives sufficient body text and passes despite having no description of its own, leaving #112 unfixed for line-wrapped HTML signatures. Collapse whitespace for this HTML signature check (without broadening recognition to non-signature parameter terms), and add this variant as a rejection control.

Comment thread src/lexbench_webfetch/dynamic_lists.py Outdated
Comment on lines +1460 to +1461
inline = visible_html_text(''.join('<br>' if id(child) in ancestry else str(child)
for child in children))

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 — Escape text nodes before reparsing this fragment. str(child) serializes a Tag safely, but returns decoded text for a NavigableString. With declared HTML <article><a href="/item/1">Widget</a>&lt;span&gt;$10.00&lt;/span&gt;</article> and price pattern \$\d+\.\d{2}, the existing field correctly fails to match the literal <span>$10.00</span>, whereas this new candidate reparses it as markup and accepts $10.00. This introduces a false-positive product record. Preserve DOM text as text (and exclude comments), either by escaping non-Tag children or by projecting the existing nodes without a serialize/reparse round trip. Add an escaped-markup negative control paired with genuine inline elements.

Comment thread src/lexbench_webfetch/stable_tasks.py Outdated
Comment on lines +734 to +735
end = next((section.start() for section in sections
if bullet.end() <= section.start() < end and len(section[1]) <= indent), 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 — Compare the heading indentation against the list item's content column, not the bullet marker's indentation. For - Widget\n\n ## Related\nUnrelated section prose., the one-space-indented heading is outside the item (whose content starts at column 2), but 1 <= 0 is false, so the unrelated section still supplies Widget's missing description. This leaves the ownership defect in #111 unresolved for valid indented headings. Derive the content column from the marker plus following whitespace and stop at headings below that column; add this case and an ordered-marker case alongside the existing in-item heading control.

@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 · ef4d8c6

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

⚠️ 1 warning(s) occurred during review.


⚠️ Warnings:

  • src/lexbench_webfetch/article_comments.py (token_budget_reached): skipped round 2 of group "src/lexbench_webfetch/article_comments.py,src/lexbench_webfetch/article_posts.py,src/lexbench_webfetch/article_text.py,src/lexbench_webfetch/document_structure.py,src/lexbench_webfetch/dynamic_lists.py,src/lexbench_webfetch/metrics.py,src/lexbench_webfetch/stable_tasks.py,tests/golden/web-fetch.json": used 504161 tokens exceeds budget 500000

Comment thread src/lexbench_webfetch/dynamic_lists.py Outdated
Comment on lines +1543 to +1545
prices = [_visible_product_field(value, representation)
for node in owner.select(scope['price_selector'])
for value in (node.get_text(' ', strip=True), visible_html_text(str(node)))]

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 — Preserve existing price-candidate priority across all selected nodes. This comprehension interleaves each new inline-preserving candidate with the old candidates, rather than appending them afterward. With two matching price elements, <span class="price">$<b>10</b>.00</span><span class="price">$20.00</span> and pattern \$\d+\.\d{2}, the old path selects $20.00, but this change selects $10.00 via prices[0]. This contradicts the stated compatibility guarantee that already-selected prices remain unchanged and can change fixed-membership outcomes when price participates in the record hash. Collect all original get_text candidates first, then append all inline-preserving candidates; add a two-price-element regression control.

@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 · 724cf90

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

⚠️ 1 warning(s) occurred during review.


⚠️ Warnings:

  • src/lexbench_webfetch/article_comments.py (token_budget_reached): skipped round 2 of group "src/lexbench_webfetch/article_comments.py,src/lexbench_webfetch/article_posts.py,src/lexbench_webfetch/article_text.py,src/lexbench_webfetch/document_structure.py,src/lexbench_webfetch/dynamic_lists.py,src/lexbench_webfetch/metrics.py,src/lexbench_webfetch/stable_tasks.py,tests/golden/web-fetch.json": used 512046 tokens exceeds budget 500000

Comment thread src/lexbench_webfetch/stable_tasks.py Outdated
return records
bullets = [] if literal else list(re.finditer(r"(?m)^\s*(?:[-*+]|\d+[.)])[ \t]+\S.*$", text))
if bullets:
sections = list(re.finditer(r'(?m)^( {0,3})#{1,6}[ \t]+\S', text))

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: This boundary scan also matches escaped literal hashes after _visible() has decoded Markdown escapes. For example, the Markdown answer - Widget\n\# This is the widget description. has a valid lazy paragraph continuation, not a section heading. _visible() restores \# to # before _descriptions() runs, so the new scan truncates the record before its only description and turns a previously complete record into a failure. Preserve whether the heading marker was escaped through boundary detection (or identify boundaries before escape restoration), and add a public-scorer control pairing an escaped hash continuation with a real outside heading.

@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 · 96ab646

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

Comment thread src/lexbench_webfetch/stable_tasks.py Outdated
Comment on lines +289 to +291
opaque = not body_view and value in {'`', '\\'} or (
schema == 'name_description' and value == '#'
and not text[text.rfind('\n', 0, match.start()) + 1:match.start()].strip())

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: Preserve escaped hashes within a leading hash run, not only at its first position. For example, - Widget\n#\# This is the widget description. is a bullet with a lazy paragraph continuation, not an ATX heading: the escaped second hash prevents the raw heading prefix from matching. Here the prefix before that escape is #, so _visible restores it as an unescaped ##; the new section scan then truncates the record and rejects its otherwise valid description. #&#35; ... has the same problem. Keep such decoded hashes opaque until scalar rendering and add a paired regression control so literal hash runs cannot become section boundaries.

Comment thread src/lexbench_webfetch/stable_tasks.py Outdated
return records
bullets = [] if literal else list(re.finditer(r"(?m)^\s*(?:[-*+]|\d+[.)])[ \t]+\S.*$", text))
if bullets:
sections = list(re.finditer(r'(?m)^( {0,3})#{1,6}[ \t]+\S', text))

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: Empty ATX headings still allow a bullet to borrow the following section's prose. For example, - Widget\n\n##\nUnrelated section prose. contains a valid Markdown heading outside the list, but this pattern requires whitespace and a non-whitespace title after the hashes, so it finds no boundary. _descriptions consequently assigns the unrelated prose to Widget and a name_description contract with minimum_records: 1 still passes. This leaves a boundary case of #111 unfixed. Recognize empty ATX headings as well (including optional trailing whitespace), preserving the indentation ownership check, and add a public-scorer regression for this case.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review, round 1

Head reviewed: 96ab646a. Each finding was reproduced through the public score_attempt and task_passed, on this head and on base 8f2232b7. All inputs are declared markdown unless stated.

Findings

P1. src/lexbench_webfetch/stable_tasks.py:289: an escaped hash inside a hash run still becomes a section boundary (regression)

The opaque rule only covers a hash with nothing before it on the line. In #\# and #&#35; the second hash decodes to ##, and the new scan at line 731 truncates the record.

Input Base Head Expected
- Widget\n#\# This is the widget description. pass fail pass
- Widget\n#&#35; This is the widget description. pass fail pass

This confirms the bot comment. Fix: drop the line-prefix test and keep every decoded hash opaque for this schema: opaque = not body_view and value in {'', '\'} or (schema == 'name_description' and value == '#')`. I applied this locally: both inputs pass, and all current and historical controls still pass. Add the pair as controls.

P1. src/lexbench_webfetch/stable_tasks.py:731: a # line inside a fenced code block ends the description (regression)

_visible restores code payloads before _descriptions runs, so the scan treats a code comment as a heading. The neighbouring document-structure code states the opposite rule: "Markdown code contributes body content, but cannot declare section titles".

Input Base Head
- Widget\n```\n# code comment text here\n``` pass fail
- Widget\n```\nprint(1) and more\n``` pass pass

The verdict now depends on whether the code has a # comment, which is not an ownership signal. Fix: consume fences in the same scan, so one regex rule decides boundaries, and keep only matches of the heading group:

sections = [match for match in re.finditer(
    r'(?ms)^ {0,3}(`{3,}|~{3,}).*?(?:^ {0,3}\1[ \t]*$|\Z)'
    r'|^( {0,3})(?:#{1,6}(?:[ \t]+\S|[ \t]*$)|[^\s\n][^\n]*\n {0,3}(?:=+|-+)[ \t]*$)', text)
    if match[2] is not None]

Then compare len(section[2]) < column. I applied this locally. It also fixes the next two findings, and the only test failure was the expected after_sha256 binding. Add the pair above as controls.

P2. src/lexbench_webfetch/stable_tasks.py:731: empty ATX headings do not end a bullet

- Widget\n\n##\nUnrelated section prose. and the same input with ## both pass on head. The pattern requires a title after the hashes. This confirms the bot comment, and #111 is not fully closed. The regex above fixes it. Add a control.

P2. src/lexbench_webfetch/stable_tasks.py:731: setext headings do not end a bullet

- Widget\n\nRelated\n-------\nUnrelated section prose. and the ======= form both pass on head. This is the defect #111 describes, with a heading syntax that _text_events already recognizes. The regex above fixes it. - Widget\n Real desc.\n---\n- Other\n Other desc. still passes with that change. Add a control.

P2. src/lexbench_webfetch/article_text.py:156: a literal HTML link in a text node still creates a permalink (#85)

With the #85 issue contract, declared html:

<h2>&lt;a href="/post/1"&gt;Alice&lt;/a&gt;</h2><p>First post.</p><h2>&lt;a href="/post/2"&gt;Bob&lt;/a&gt;</h2><p>Second post.</p>

This passes on base and on head, although the DOM contains no links. str(node) decodes the entities, _literal_markdown_text does not escape <, and the record parser then reads a real anchor. #85 says fallback must not credit structure that is absent from the DOM, so Closes #85 is not yet accurate. Fix: add < to the escaped set, r'([\\*[]<])'`. I applied this locally: the input fails, the genuine-anchor control still passes, and all controls pass. Add a rejection control.

P2. PR body: stale values and undisclosed verdict classes

  • Stale hash. SCORING_SOURCE_SHA256 at this head is 825e584b1d28…, but the body gives 11a32c43… in "Values that moved" and "What #114 needs". Update it after the fixes above move it again.
  • Stale counts. The file adds 44 controls, not 43. 18 of them fail on verdict alone against the base scorer. Recount the "21 of 43" figure at the final head, including expected_metrics.
  • Inaccurate #111 row. It says other records keep their verdict. These do not:
    • \# Widget\n\nDesc of widget here. goes from pass to fail, because the no-bullet heading branch no longer sees the now-opaque hash. Failing is defensible, since a literal hash is not a heading, but it is a verdict class that #114's change_note must disclose.
    • The fenced-code case above also moves, unless it is fixed first.

Add the first class to the table, and re-derive the table after the fixes.

P3. src/lexbench_webfetch/stable_tasks.py:2025: matched can exceed observed on duplicates

For #83's contract, an answer repeating one quote gives stable_source_observed_record_count: 2 and stable_source_matched_record_count: 3. The verdict correctly fails. #83 asks for consistent counts, so consider counting unique matched records.

Verified with no defect

  • #83: the swapped-author reproduction gives observed 2, matched 0, mismatched 2, and the rejected records carry their hashes. The matching answer gives 2, 2, 0 and passes.
  • #85: literal [Alice](/post/1) now fails and genuine anchors pass. Literal ## <a…> in a paragraph also fails.
  • #86: indented and fenced plain text pass, and the same bytes declared as Markdown still fail.
  • #110:
    • Inline prices pass in the unscoped, in-anchor and comment-split forms.
    • Escaped &lt;b&gt;$10.00&lt;/b&gt; fails, $<br>10.00 and block-split prices fail, and a neighbour's price does not fill a record.
    • The extra visible_html_text parsing added 0.3 to 0.5 s on 1,500 to 3,000 element pages, which is acceptable.
  • #112: the reproduction, the line-wrapped form and an empty child all fail, and the parameter-list control passes. [source], → and classmethod prefixed nested terms stay parent text, as the PR describes for non-name(...) terms. The four frozen definition contracts I found on disk contain only plain name(...) headings.
  • Hash \# in _render_inline_scalar: a fixed-membership hash for a name containing literal C\# still matches in HTML, plain text and Markdown (C\\\#).
  • Bindings: code-migration.json regression IDs match the 44 added controls exactly, and data-lock.json, frozen profiles and receipts are untouched.
  • Over-design: nothing to remove. _api_signature, _local_definition_text and the literal flag are proportional, and there is no new test machinery.
  • Local tests: tests/test_golden_reports.py, tests/benchmarks, tests/test_scoring_regressions.py and tests/test_scoring.py gave 11426 passed. The ruff gate passes.
  • Golden routes: the snapshots pass. I did not independently repeat the PR's check that the route changes come only from the scorer hash.

CI

"Tests and static checks", "Installation and packaging", "Rendered reference and report checks" and "Python 3.11" all pass on 96ab646a. ocr-review is red, and two of the findings above are its two blocking findings.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 1 is addressed on 0a048f9b.

Fixed

One change from the suggested regex

A setext title now needs an empty line before it. As suggested, - Widget\nGenuine lazy description.\n------- would change from pass to fail, although CommonMark reads that text as a lazy continuation and the underline as a thematic break. The control bullet-description-lazy-line-before-rule covers this.

The scan also accepts a longer closing fence and does not treat an inline ```x``` as an opening fence.

Disputed: nothing.

Not rebased: the branch stays on 8f2232b7. Main has moved to d905949c. A rebase applied cleanly locally, but the force push it needs was denied in this environment, so these commits were pushed as a fast-forward.

Known limits, both still open:

  • A multi-line setext title is not treated as a boundary.
  • An empty line containing only whitespace before a setext title is not treated as empty.

@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 · 0a048f9

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

Comment thread src/lexbench_webfetch/article_text.py Outdated
def article_markdown(content):
def _literal_markdown_text(text):
"""Escape Markdown syntax in a DOM text node; only elements create structure."""
text = re.sub(r'([\\`*\[\]<])', r'\\\1', text)

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: Backslash-escaping < does not preserve literal tags through the fallback's subsequent HTML parse. Both _coverage_text_records and _text_records pass this projection through article_html/_post_html again, and BeautifulSoup still recognizes \<script> as a script element. For example, a genuine fallback comment whose body is <p>&lt;script&gt;This is visible comment prose.&lt;/script&gt;</p> loses that prose during the second visibility pass, even though it is displayed text in the declared HTML. This leaves the literal-tag requirement of #85 incomplete and can reject valid records. Protect text-node tag syntax with opaque placeholders (restored only when reading owned fields), or otherwise prevent it from reaching another HTML parser as markup; add a positive literal-tag body control.

sections = [match for match in re.finditer(
r'(?ms)^ {0,3}(`{3,}(?=[^`\n]*$)|~{3,}).*?(?:^ {0,3}\1[`~]*[ \t]*$|\Z)'
r'|^(?:(?= {0,3}#{1,6}(?:[ \t]+\S|[ \t]*$))'
r'|(?<![^\n]\n)(?= {0,3}\S[^\n]*\n {0,3}(?:=+|-+)[ \t]*$))( {0,3})', text)

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 setext boundary requires a literally empty preceding line, rather than a Markdown blank line. (?<![^\n]\n) rejects a line containing spaces or tabs. For example, - Widget\n \nOther section\n-------------\nUnrelated prose still assigns the section title and prose to Widget, whereas the same input with an empty separator stops ownership. _visible preserves this whitespace, so this misses a valid heading boundary and can still accept a bullet with no description. Recognize whitespace-only blank lines too, and add a paired control with a space/tab-only separator.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

The two new lexmount-ocr comments on 0a048f9b are fixed on 7bcd5126. Each was reproduced first.

  • f21e01a2, literal tags: < in a declared-html text node is now encoded as &lt; instead of backslash-escaped, because the projection is parsed as HTML again.
    • A literal <script> or <style> body now keeps its visible prose, and the literal-anchor control still rejects.
    • The post body failed on both base and the previous head, so this was an existing false negative. The comment body failed only on base; it already passed on 0a048f9b. Both now have positive controls.
  • 7bcd5126, setext boundary: a whitespace-only line now counts as blank before a setext title. New controls cover the space and tab forms, and the lazy-continuation control still passes. This removes the second known limit from my previous comment.

The scorer hash is now 3547c1b4…, and there are 59 new controls in total. 32 of them are wrong on 8f2232b7: 27 by verdict and 5 by metrics only. The PR body is updated.

Still open: a multi-line setext title is not treated as a boundary. The branch is still based on 8f2232b7, not rebased.

@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 · 7bcd512

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

Comment thread src/lexbench_webfetch/article_text.py Outdated
def _literal_markdown_text(text):
"""Escape Markdown syntax in a DOM text node; only elements create structure."""
# The projection is reparsed as HTML, where a backslash would not protect a tag.
text = re.sub(r'([\\`*\[\]])', r'\\\1', text).replace('<', '&lt;')

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: Literal entity spellings still become Markdown structure during the fallback reparse. For example, declared HTML <p>&amp;#35; Comments</p><p>&amp;#35;&amp;#35; Alice</p><p>Actual body.</p> produces DOM text &#35; Comments / &#35;&#35; Alice. This helper leaves those ampersands untouched; _coverage_text_records then reparses the projection through article_html/visible_html_text, yielding real # Comments and ## Alice lines and accepting a heading-authored comment despite neither heading existing in the HTML. This leaves the #85 literal-text guarantee bypassable. Protect literal ampersands as well as < across the reparse (before inserting your own entities), and add a declared-HTML negative control with entity-spelled hashes, paired with genuine headings.

# Fences are consumed so their code lines cannot declare a section. A
# setext title needs a blank line before it; otherwise it is a lazy
# continuation of the item and the underline is not a heading.
sections = [match for match in re.finditer(

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: Detect headings before inline formatting is flattened. This new scan runs on _visible() output, which has already removed **/__. For example, Markdown - Widget\n**# Genuine description** contains a bold lazy continuation, not an ATX heading, but _visible() turns its second line into # Genuine description. The new boundary truncates the record to - Widget, changing a valid one-record answer into too_few_complete_records. Preserve source heading ownership through normalization (or protect hashes emitted by inline-format removal), and add a paired public-scorer control for this case alongside a genuine heading. This is a localized false-negative regression.

# setext title needs a blank line before it; otherwise it is a lazy
# continuation of the item and the underline is not a heading.
sections = [match for match in re.finditer(
r'(?ms)^ {0,3}(`{3,}(?=[^`\n]*$)|~{3,}).*?(?:^ {0,3}\1[`~]*[ \t]*$|\Z)'

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: Fence masking must respect the enclosing list boundary. For - Widget\n ```\n Genuine code description\n# Unrelated section\nUnrelated prose, the unclosed fenced block ends when its list container ends: the unindented # Unrelated section is a real heading outside the item. This regex instead consumes through \Z, hiding that heading from sections, so the new ownership check still appends the unrelated section to Widget's description (and can reject an otherwise matching fixed-membership record). Use container-aware fence ranges, as markdown_fenced_code_blocks already computes, rather than treating every fence as document-wide until a closing delimiter.

Comment thread src/lexbench_webfetch/stable_tasks.py Outdated
end = bullets[index + 1].start() if index + 1 < len(bullets) else len(text)
# A section heading left of the item's content column ends its
# ownership; a heading indented into the item remains a continuation.
column = re.match(r'\s*(?:[-*+]|\d+[.)])[ \t]+', bullet[0].rsplit('\n', 1)[-1]).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: Measure indentation in Markdown columns, not character offsets. For -\tWidget\n ## Unrelated section\n Unrelated descriptive text., the tab puts the item's content at column 4, so the two-space heading is outside the item and must end its ownership. Here column is 2 and len(section[2]) is also 2, so the new boundary check retains the unrelated section as Widget's description. This leaves the #111 false-pass case reachable for supported tab-separated bullets. Expand tabs to four-column stops when calculating the content column and add a paired tab-indentation control.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review, round 2

Head reviewed: 7bcd5126. Every verdict below comes from score_attempt and task_passed, run on this head and on base 8f2232b7.

Findings

P1, regression: src/lexbench_webfetch/stable_tasks.py:734 (a hash behind inline markup becomes a section boundary)

The boundary scan runs on _visible() output, where emphasis and link wrappers are already gone. A wrapped hash therefore looks like a real ATX heading. The lexmount-ocr comment on this line is correct.

Answer (name_description, declared Markdown) Base Head
- Widget\n**# Genuine description here** pass fail
- Widget\n__# Genuine description here__ pass fail
- Widget\n*# Genuine description here* pass fail
- Widget\n_# Genuine description here_ pass fail
- Widget\n[# Genuine description here](/x) pass fail

Suggested fix: apply the same opaque-hash rule to these lines. Add this immediately before the rendered_literal substitution in _visible:

if schema == 'name_description':
    # A hash behind inline markup is prose, never a heading.
    text = re.sub(r'(?m)^([ \t]*(?:[*_]+|\[)[ \t]*)#', r'\1\\#', text)

Applied locally, all five inputs pass, and a real ## section still ends the bullet. The stored description becomes # Genuine description here, whereas base stored it without the hash. Add paired controls, and add the description change to the historical verdict table.

P1, regression: src/lexbench_webfetch/stable_tasks.py:346 (the opaque hash leaks a backslash in pipe tables)

_visible now keeps \# opaque for name_description, but _render_inline_scalar(pipe_cell=True) only unescapes a backtick. For a cell written Issue \#12 desc here. or Issue &#35;12 desc here.:

  • Head stores Issue \#12 desc here.. Base stores Issue #12 desc here..
  • Under fixed membership on description and name, base passes. Head fails with stable_source_mismatched_record_count: 1.

Suggested fix: use r'\\([#])' if pipe_cell, and add a paired control. Applied locally, the record is Issue #12 desc here.` and the task passes.

P2, incomplete Closes #85: src/lexbench_webfetch/article_text.py:157 (entity spellings in a text node still create structure)

The projection is reparsed as HTML, so an & left unescaped decodes a second time. This declared-HTML answer has no DOM links, yet it passes on base and head because the text nodes become [Alice](/post/1):

<h2>&amp;#91;Alice&amp;#93;(/post/1)</h2><p>First post.</p><h2>&amp;#91;Bob&amp;#93;(/post/2)</h2><p>Second post.</p>

The comment form <p>&amp;#35;&amp;#35;&amp;#35; Alice</p><p>Body prose.</p> also passes on both. lexmount-ocr raised the same defect on this line.

Suggested fix: use .replace('&', '&amp;').replace('<', '&lt;'), and add paired controls. Applied locally, both inputs fail, and genuine anchors plus text such as AT&amp;T and &amp;amp; still pass.

P2, PR body: ## Historical verdict classes that could change omits a fail-to-pass class

The escaped-hash row lists only pass-to-fail. These answers go from fail on base to pass on head, and the #114 change_note needs to disclose them:

  • ## Widget\n\# Desc of widget here.
  • Widget\n\# Desc of widget here.
  • Widget\n&#35; Desc of widget here.

Suggested fix: add this class to the table, along with whatever the two P1 fixes change.

P3: src/lexbench_webfetch/stable_tasks.py:743 (a tab after the bullet marker gives the wrong content column)

-\tWidget\n ## Unrelated section\n Unrelated descriptive text. still passes, because column is measured as 2 instead of 4. The false pass is the #111 defect in a rare form; base also passes this input.

Suggested fix: match against bullet[0].rsplit('\n', 1)[-1].expandtabs(4), and add a rejection control. Applied locally, the input fails and -\tWidget\n ## In item\n Item text. still passes.

All the suggested code changes applied together: tests/benchmarks/test_current_scoring_controls.py, tests/test_scoring_regressions.py and tests/test_scoring.py had one failure, the expected after_sha256 binding. Those changes were not committed. New controls, migration hashes and goldens still need updating.

Considered and not raised

The lexmount-ocr comment at stable_tasks.py:735 is accurate: an unclosed fence inside an item hides a later unindented heading. It needs malformed Markdown, base behaves the same, and handling it would add container tracking to the scan, which is disproportionate. I would leave it and note it in the PR.

Verified

  • Round 1 fixes: escaped hashes in a run, fenced # lines, empty ATX, setext including whitespace-only separators, < in text nodes, literal script text and unique matched counts all behave as described.
  • Controls: all 59 new controls match on head. On base, 32 are wrong, 27 on verdict and 5 on metrics only, matching the PR body.
  • Scorer hash: head computes 3547c1b4c4be…. The old hash no longer appears in src, tests, evaluation or docs.
  • Goldens: with the base scorer hash patched in and the base web-fetch.json snapshot, the Web Fetch golden test passes on this head. The six golden route changes are hash-only, including after f21e01a2 and 7bcd5126.
  • #83, #86, #110, #112: probes of plain-text headings, nested and wrapped signatures, parameter lists, and inline, hidden, block-split and neighbor prices found no defect.
  • Over-design: I found no unnecessary abstraction or layer. The diff is proportional to six defects.
  • Local runs: the ruff gate passes. tests/test_golden_reports.py, tests/benchmarks/test_current_scoring_controls.py, tests/test_scoring_regressions.py, tests/test_scoring.py and tests/test_scoring_revision.py gave 104 passed.
  • CI on this head: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks" and "Python 3.11" all pass. ocr-review shows as failed; it has no duration and links back to this PR's review comments, so I read it as the review bot's status rather than a test failure and did not rerun it.

@lanyue-llk

Copy link
Copy Markdown
Contributor Author

Review round 2 fixes, on head 681a61ab. All five findings are fixed and none are disputed.

Finding Commit Result
P1: a wrapped hash such as **# Text** ended a bullet description 992e2277 All five wrapper forms pass again, and a genuine heading still ends the item. The stored description now keeps #, and a card such as **# Widget** followed by a separate paragraph goes from pass to fail. Both are disclosed in the PR body
P1: the opaque hash leaked a backslash in pipe tables c6d033de The record is Issue #12 desc here. again and the fixed-membership task passes
P2: doubly encoded text created structure in the fallback ec179cfa The encoded permalink, comment heading and comment section all fail. Genuine anchors and text such as AT&amp;T still pass
P2: the verdict table omitted a fail-to-pass class PR body Added, along with the classes these fixes change
P3: a tab after the bullet marker gave the wrong content column 681a61ab The input now fails, and a heading inside the item still passes

One change from the suggested fix: the pipe-table fix does not use r'\\([#])'in_render_inline_scalar. _pipe_cellscollapses\to` first, so that regex would turn a cell with \\# into # instead of \#, which is a new mismatch. The hash is rendered before the cell split instead, and pipe-description-escaped-backslash-keeps-backslash guards this.

Controls: 18 new paired controls, 12 of which give the wrong verdict on 7bcd5126.

Not changed:

  • The inline comment on stable_tasks.py:735 about an unclosed fence at the end of a list item was not in this round's findings. It gives the same result on 8f2232b7, so it is not a regression, and it is listed as a known limit in the PR body.
  • The branch is not rebased onto d905949c. Force-pushing was denied in this environment, so these commits are a fast-forward on 7bcd5126. main changes no scorer, binding or golden file, and the scoring tests also passed with these commits rebased onto it.

@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 · 681a61a

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

# setext title needs a blank line before it; otherwise it is a lazy
# continuation of the item and the underline is not a heading.
sections = [match for match in re.finditer(
r'(?ms)^ {0,3}(`{3,}(?=[^`\n]*$)|~{3,}).*?(?:^ {0,3}\1[`~]*[ \t]*$|\Z)'

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 fence terminator accepts mixed backticks and tildes because of [~]*. For example, in - Widget\n \n ~~~\n# Literal code heading\nThis is still code belonging to Widget.\n ````, the ```~~~ line does not close the Markdown backtick fence, but this regex closes it and treats the following `#` as an external section boundary. The new truncation therefore drops owned description text (and can invalidate an otherwise complete record). Require all closing-fence characters to match the opening fence character, and add a control with an invalid mixed-character closer followed by a hash line.

@lanyue-llk lanyue-llk left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review, round 3

Head reviewed: 681a61ab. Every verdict below comes from score_attempt and task_passed, run on this head and on base 8f2232b7, with a one-record name_description contract and a Markdown answer.

Findings

P2, regression: src/lexbench_webfetch/stable_tasks.py:741 (a mixed-character line closes a fence)

The closer pattern \1[~]*accepts tildes after a backtick fence, and backticks after a tilde fence. CommonMark does not treat such a line as a closer, so the next#line is still code. The scan reads it as a section boundary and cuts the description. The lexmount-ocr comment on this line is correct, and it is whyocr-review` is red.

Answer Base Head
- Widget\n ```\n ```~~~\n# Literal code heading\nThis is still code belonging to Widget.\n ``` pass fail
- Widget\n ~~~\n ~~~```\n# Literal code heading\nThis is still code belonging to Widget.\n ~~~ pass fail

Suggested fix: replace \1[~]* with ``\1(?:(?<=)*|(?<=~)~*)``, and add paired controls: a mixed closer followed by a #` line (pass), and a longer same-character closer followed by a real section (fail). Tried locally: both inputs pass, and - Widget\n ```\n ````\n# Real section\nprose still fails.

P2, regression: src/lexbench_webfetch/stable_tasks.py:274 (nested wrappers still turn a hash into a boundary)

The round 2 fix accepts one wrapper kind per line, either [*_]+ or [. A wrapped hash with both kinds, or with two separate runs, still reaches the boundary scan as a heading.

Answer Base Head
- Widget\n**[# Genuine description here](/x)** pass fail
- Widget\n[**# Genuine description here**](/x) pass fail
- Widget\n** **# Genuine description here pass fail

Suggested fix: one pattern for any mix of wrapper characters, ^([ \t]*(?:[*_\[][ \t]*)+)#, with paired controls. Tried locally: all three inputs pass.

With both trial changes applied, tests/benchmarks/test_current_scoring_controls.py, tests/test_scoring_regressions.py, tests/test_scoring.py and tests/benchmarks/webfetch/test_stable_tasks.py had one failure, the expected after_sha256 binding. The changes were not committed. New controls, the migration hashes, the goldens and the PR body's scorer hash and control counts still need updating.

P2, PR body: ## Behavior worth checking omits a remaining pass-to-fail class

A hash that follows an inline element removed during normalization still ends a description. The first three inputs below pass on base and fail on head, and the suggested fix does not change them. Each would need its own special case, which I do not think is justified for inputs this rare. The class should be disclosed instead, because the #114 change_note is built from this list.

  • - Widget\n<br># Genuine description here
  • - Widget\n![](/x.png)# Genuine description here
  • - Widget\n[](/x)# Genuine description here

Suggested fix: add this class to the historical verdict table.

Considered and not raised

  • Unclosed fence in an item: - Widget\n ```\n# Section\nprose keeps its base result, and the PR body discloses it. Handling it would add container tracking.
  • Thematic break read as a title: - Widget\n\n---\n---\nDesc after rule goes from pass to fail. I do not expect this form in real answers, and it does not justify another rule.
  • Blockquoted bullets: > - Widget\n> ## Related\n> Unrelated prose text. passes on base and head. It does not enter the bullet branch, and #111 does not cover it.
  • _table_records hash rendering for every schema: in Markdown, other schemas have already decoded \# by this point, so only literal \# in undeclared projected HTML could change. I did not find a verdict change.

Verified

  • #85: literal and encoded link, heading and bold forms fail under declared HTML. Genuine anchors, headings and bold authors pass, including text with &, <, >, brackets, asterisks and backslashes.
  • #111 paths: CRLF answers, declared plain_text and DOM-derived text behave as intended. A # line from HTML text does not end a description in the probes I ran, and declared plain_text keeps literal # lines.
  • #83: no code outside stable_tasks.py reads the changed stable_source_* diagnostics, so they cannot change a verdict.
  • Controls: all 77 new controls match on head. On base, 42 are wrong, 33 on verdict and 9 on metrics only, matching the PR body.
  • Scorer hash: head computes eb31cd27c2e9…, matching the PR body.
  • Migration bindings and bounds: the binding test passes. data-lock.json and .github/workflows/ are unchanged.
  • Goldens: with the base scorer hash patched in and the base web-fetch.json snapshot, the Web Fetch golden test passes on this head, so the six route changes are hash-only.
  • Over-design: I found no unnecessary abstraction or layer.
  • Local runs: the ruff gate passes. tests/test_golden_reports.py, tests/benchmarks/test_current_scoring_controls.py, tests/test_scoring_regressions.py, tests/test_scoring.py, tests/test_scoring_revision.py and tests/benchmarks/webfetch/test_stable_tasks.py gave 167 passed.
  • CI on this head: "Tests and static checks", "Installation and packaging", "Rendered reference and report checks" and "Python 3.11" all pass. ocr-review is red because of the fence finding above, so I did not rerun it.

@lanyue-llk
lanyue-llk force-pushed the fix/web-fetch-scorer-bundle branch from 681a61a to b875978 Compare November 4, 2026 13:54
lanyue-llk added a commit that referenced this pull request Nov 4, 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.

✅ Review complete · b875978

No findings in this review.

…ue hashes

A heading left of a bullet's content column ended the description even when it was the card's own title. It now ends the description only when nothing follows it before the next bullet, or after the last bullet unless it repeats the bullet's title.

Remove the opaque-hash handling and the rare-form controls that only guarded it, restoring base code in _visible, _render_inline_scalar and _table_records.

@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 · 4fb3e5c

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

section = next((section.start() for section in sections
if bullet.end() <= section.start() < end and len(section[2]) < column), None)
if section is not None:
heading, _, body = text[section:end].partition('\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.

bug · medium
P2: The new empty-body check counts a setext heading's underline as body text. For example, - Widget\n\nRelated products\n-------\n\n- Gadget\n A genuine gadget description. leaves body starting with -------, so the non-final Widget bullet keeps the unrelated heading as its description and becomes a valid record. This violates the stated boundary rule for a heading with nothing after it before the next bullet (and differs from the equivalent ATX heading). Consume the entire heading, including its setext underline, before checking whether any body remains, and add a public-scorer control with minimum_records: 2 for this case.

if bullet.end() <= section.start() < end and len(section[2]) < column), None)
if section is not None:
heading, _, body = text[section:end].partition('\n')
title = _line(heading)

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 card-title exception rejects valid ATX headings with closing hashes. For - [Alpha](/a)\n\n### Alpha ###\n\nAlpha is a great item., _line(heading) returns Alpha ###, which is not in the normalized bullet - Alpha. The last bullet therefore loses its entire genuine description and fails a one-record name_description contract, despite the requirement to preserve repeated card titles. Normalize optional ATX closing hashes before comparing the heading title, and add this variant to the card-title control.

lanyue-llk added a commit that referenced this pull request Nov 4, 2026
@lanyue-llk
lanyue-llk merged commit f28058e into main Nov 4, 2026
6 of 7 checks passed
@lanyue-llk
lanyue-llk deleted the fix/web-fetch-scorer-bundle branch November 4, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant