Skip to content

fix(web-fetch): accept spaced anchors, indented links; cache tokenizing - #253

Merged
lanyue-llk merged 2 commits into
mainfrom
fix/scorer-spacing-and-tokenizer-cost
Nov 5, 2026
Merged

lanyue-llk merged 2 commits into
mainfrom
fix/scorer-spacing-and-tokenizer-cost

Conversation

@lanyue-llk

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

Copy link
Copy Markdown
Contributor

What, why and how of this PR

Question

Why do correct stored answers still fail after #250, and why can a full rescore not finish?

Causes and fixes

Nested links from Obscura. It keeps source-HTML nesting, so its links sit in Markdown indented code blocks and parse to 0 records. _without_nested_link_indentation removes that indentation only when an indented link line exists and the answer has 5 or more whitespace-only deep lines, the signature of this serializer defect. Ordinary code samples do not leave those lines, so they stay literal; a sample with 5 such lines would still be read as page text (synthetic only, no stored row seen). Declared Markdown is unaffected.

Letter-spaced CJK labels. 登录 against page text 登 录 failed. _LETTER_SPACED_CJK joins only runs of single CJK characters. It applies to anchors and facts at this call site. Words of two or more characters stay separate, so 首页 登录 does not match 首页登录. Single characters in separate paragraphs can still join: <p>北</p><p>京</p> matches 北京 (synthetic only). The existing Markdown fold is unchanged.

Repeated tokenizing. _markdown_html_tag_spans reparsed the whole document after every code span and for every fact. It now has an lru_cache(maxsize=256), and a code span with no <, > or quote skips the reparse. Known limit: masking can still move a boundary after a tag name (<script></script`x`>); this is accepted and stated in the code. Fuzzing found no difference on ordinary documents, and no stored row was seen to change.

Evidence

Read-only rescore on copies of stored rows, main against this head: 554 rows compared (including 99 random rows). Ten verdicts change, all fail to pass, and all ten match the stored verdict.

Task Provider Cause
dynamic-products-api, dynamic-074-melon-com-chart, challenge-02, challenge-05, dynamic-062-zh-sspai-home obscura nesting
china-homepage-065-lingxing-com chromium, kitesurf, lightpanda, moli-fixed, moli-pr919 登 录

An independent review rejected the first version of both rules, which gave unearned passes. Each case it found is now a paired control: a nested code cheatsheet, unrelated samples, a product sample and Python call syntax stay literal; a sample with an unbalanced fence, open comment or script tag keeps the page's links; 北京大学 across paragraphs, 不含税 split across lines, 1月, 100元, two separate links, 首页 登录 and 攀登 录像 do not match.

Diagnostic metrics move on rule-touched Obscura rows. Mean word_f1 rises 0.063 on 81 rows, and 65 move closer to the stored value, so a rebuilt report's Obscura diagnostics would change and must say so.

Targeted tests: tests/test_scoring_regressions.py, tests/benchmarks/test_current_scoring_controls.py and tests/test_golden_reports.py pass (31 tests, 3,996 subtests). make lint-check passes.

Not done

  • The whitespace signature is still a heuristic, though it matches the defect. It fires on Obscura rows; other providers have 0 or 1 such row of 430 and fail the link check.
  • Cost is not fully solved: dynamic-058-zh-stable-tdesign-table (lightpanda) and dynamic-025-025-tabulator-vertical-virtual-dom (obscura) still did not finish within the time limit, so they are not compared. live-029-fetch (moli-fixed) and dynamic-058-zh-stable-tdesign-table (obscura) finished only on this head, so 4 rows have no main comparison.
  • No full rescore was run on the final code. No evidence or published report changed, and no provider was called.
  • Left for a separate decision: exact image URL identity, forbidden terms found in a task's own reference, swagger links, escaped backticks, blockquoted facts.

An undeclared answer that keeps source-HTML nesting put its links at three
or more depths inside indented blocks. They were read as code, so records
parsed to zero. normalize_native_markdown_layout now removes that
indentation from those blocks; declared Markdown and shallower code examples
stay literal.

The fold for layout space around CJK characters ran only in Markdown
normalization, so anchors matched through the plain-text view failed on a
split label such as '登 录'. Anchor matching now applies the same fold. Latin
word boundaries stay significant.

Tag spans were reparsed after every closed code span and again for each fact
and anchor. Results are now cached, and a span without tag delimiters or
quotes no longer triggers a reparse.

Adds eleven paired controls and the matching code-migration 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.

⚠️ Review complete · 599f57e

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

Comment on lines +767 to +769
depths = {len(line) - len(line.lstrip(' '))
for left, right in spans for line in text[left:right].expandtabs(4).splitlines()
if '](' in line}

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 depth threshold is document-wide, and the subsequent loop unindents every code block. For example, three separate examples separated by unindented headings, each containing one link at respectively 4, 8 and 12 spaces, collectively trigger this rule even though each example has only one depth. Likewise, a qualifying serializer block exposes unrelated shallow code examples elsewhere. _extract_named_candidates normalizes before removing literals, so those example links can now count as records and produce false-positive verdicts. This exceeds the stated preservation of shallow examples. Compute qualification per indented block and strip only qualifying blocks; add controls for separate shallow examples and mixed serializer/literal content.

The depth count treated any "](" as a link, so code samples passed record
tasks, and removing all indentation exposed unbalanced syntax in link-free
samples. The rule now needs whitespace-only deep lines, the serializer's own
signature.

The CJK fold also reached required facts and joined separate words such as
'北京' and '大学'. It now joins only labels letter-spaced into single
characters, and the existing Markdown fold is unchanged.

The tokenizer shortcut's comment now states its known limit.

Adds controls for both directions 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 · 57d74b4

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 a5f8c67 into main Nov 5, 2026
7 checks passed
@lanyue-llk
lanyue-llk deleted the fix/scorer-spacing-and-tokenizer-cost branch November 5, 2026 10:08
lanyue-llk added a commit that referenced this pull request Nov 9, 2026
Port of #252 (16 commits, head cebd6aa) onto #224 rebased on current #131,
resolved once. Same behavior as cebd6aa except:

- Keep main's CJK rule (#253): plain text folds letter-spaced single
  characters only, so separate CJK words or paragraphs never join
  (cjk-separate-paragraphs-fact-rejected passes again). The
  plain-text-typography control no longer relies on joining 中文 文本.
- Catalog price-heading cards keep #252's broader condition, which covers
  main's #250 case.
- Keep both stable-anchor fallbacks (escaped prose from #131, link labels
  and extracted fields from #252).
- Bind loop variables for B023 and recompute scorer source hashes; add
  #252's two correction records to the migration receipt.

Co-authored-by: Maisiqi <[email protected]>
lanyue-llk added a commit that referenced this pull request Nov 9, 2026
Port of #252 (16 commits, head cebd6aa) onto #224 rebased on current #131,
resolved once. Same behavior as cebd6aa except:

- Keep main's CJK rule (#253): plain text folds letter-spaced single
  characters only, so separate CJK words or paragraphs never join
  (cjk-separate-paragraphs-fact-rejected passes again). The
  plain-text-typography control no longer relies on joining 中文 文本.
- Catalog price-heading cards keep #252's broader condition, which covers
  main's #250 case.
- Keep both stable-anchor fallbacks (escaped prose from #131, link labels
  and extracted fields from #252).
- Bind loop variables for B023 and recompute scorer source hashes; add
  #252's two correction records to the migration receipt.

Co-authored-by: Maisiqi <[email protected]>
lanyue-llk added a commit that referenced this pull request Nov 9, 2026
Port of #252 (16 commits, head cebd6aa) onto #224 rebased on current #131,
resolved once. Same behavior as cebd6aa except:

- Keep main's CJK rule (#253): plain text folds letter-spaced single
  characters only, so separate CJK words or paragraphs never join
  (cjk-separate-paragraphs-fact-rejected passes again). The
  plain-text-typography control no longer relies on joining 中文 文本.
- Catalog price-heading cards keep #252's broader condition, which covers
  main's #250 case.
- Keep both stable-anchor fallbacks (escaped prose from #131, link labels
  and extracted fields from #252).
- Bind loop variables for B023 and recompute scorer source hashes; add
  #252's two correction records to the migration receipt.

Co-authored-by: Maisiqi <[email protected]>
lanyue-llk added a commit that referenced this pull request Nov 9, 2026
Port of #252 (16 commits, head cebd6aa) onto #224 rebased on current #131,
resolved once. Same behavior as cebd6aa except:

- Keep main's CJK rule (#253): plain text folds letter-spaced single
  characters only, so separate CJK words or paragraphs never join
  (cjk-separate-paragraphs-fact-rejected passes again). The
  plain-text-typography control no longer relies on joining 中文 文本.
- Catalog price-heading cards keep #252's broader condition, which covers
  main's #250 case.
- Keep both stable-anchor fallbacks (escaped prose from #131, link labels
  and extracted fields from #252).
- Bind loop variables for B023 and recompute scorer source hashes; add
  #252's two correction records to the migration receipt.

Co-authored-by: Maisiqi <[email protected]>
lanyue-llk added a commit that referenced this pull request Nov 10, 2026
* fix(webfetch): score returned structured page fields

Port of #252 (16 commits, head cebd6aa) onto #224 rebased on current #131,
resolved once. Same behavior as cebd6aa except:

- Keep main's CJK rule (#253): plain text folds letter-spaced single
  characters only, so separate CJK words or paragraphs never join
  (cjk-separate-paragraphs-fact-rejected passes again). The
  plain-text-typography control no longer relies on joining 中文 文本.
- Catalog price-heading cards keep #252's broader condition, which covers
  main's #250 case.
- Keep both stable-anchor fallbacks (escaped prose from #131, link labels
  and extracted fields from #252).
- Bind loop variables for B023 and recompute scorer source hashes; add
  #252's two correction records to the migration receipt.

Co-authored-by: Maisiqi <[email protected]>

* fix(webfetch): stop link labels and document titles from passing content checks

Independent review of #252 found two false passes in the shared scorer:

- Labels of returned links (Firecrawl, Exa and Lexmount return page-wide
  link lists) satisfied required body facts and stable anchors, so a
  truncated body plus a table-of-contents link passed. Link labels no
  longer feed facts or anchors, and tasks without an acceptance contract
  keep body-only facts.
- The Lexmount projection copied the document title (result.title) into
  page_information.title, letting it pass title contracts that reject
  document titles. It is already scored as the title field.

returned-link-label becomes a negative control; returned-link-fact-cross-page
is new. Both are bound in a new correction record.

* fix(webfetch): keep malformed Lexmount envelopes free of answer fields

After rebasing onto main (#224), a non-JSON body still merged projected
page fields into metadata without a declaration, so its evidence failed
verification. Merge answer fields only for a parsed envelope. Refresh the
route baseline for the projection source hash.

* fix(webfetch): keep returned-field scoring within declared scope

Returned headings no longer satisfy title checks that exclude page regions,
since a flat field cannot prove it came from outside them. Remove the
dev.to-specific comment-card parser and revert the unbound named-link,
catalog-boundary, Han-spacing and section-heading scoring changes to main;
they need their own bound corrections.

* fix(webfetch): keep returned duplicates and paragraph breaks visible to checks

Repeated returned records now reach the duplicate-record check, and plain-text
paragraphs ending in CJK punctuation no longer join. A trailing reply-form
heading no longer hides earlier comments. Report evidence shows only fields
the scorer accepts for an anchor, and the method-comparison caption is
localized. Bind two new controls.

* fix(webfetch): merge returned records only with valid, case-exact text rows

A complete returned record replaces the same fields parsed as invalid text, and
API paths that differ only in case stay separate records. Revert the comment
discussion-heading start rule to main: a populated reply-form heading could
hide earlier comments.

* fix(webfetch): let each text record absorb only one returned copy

Further identical returned rows reach the duplicate-record check even when the
body also contains the record. Bind a paired control.

* fix(webfetch): consume each text record once across quote and exact matches

A body quote could absorb one returned copy by exact fields and another by
equivalent tags. Track consumed text rows by index. Bind a quote control.

---------

Co-authored-by: lanyue-llk <[email protected]>
Co-authored-by: Maisiqi <[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.

1 participant