Repository navigation
fix(webfetch): score returned structured page fields - #252
Conversation
dd529e0 to
0054ad0
Compare
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]>
cebd6aa to
661138c
Compare
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]>
661138c to
bb73243
Compare
…ent 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.
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]>
b0b73a0 to
3f8cd71
Compare
…ent 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.
|
Status at A second independent review found three more blocking issues. Fixes keep surfacing new problems in the shared scorer, so I stopped patching here and am leaving them to you. Please address them or split them out: P1. Returned headings bypass reviewed title exclusions (false pass).
The head passes ( P1. A site-specific comment parser inside the shared scorer. P1. Verdict changes in
Main requires each scoring correction to bind its root cause and paired controls. A smaller PR per behavior would be much easier to verify. Also, the 390/530 and 113/530 results were measured at |
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]>
…ent 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.
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.
3f8cd71 to
8439d70
Compare
|
Rebased onto main after #224 merged ( |
There was a problem hiding this comment.
This review found 7 issue(s), including 7 blocking issue(s).
| str(passed), f'{passed/len(selected):.1%}')) | ||
| context = _table([('方法', 'Method'), ('保存结果', 'Saved results'), | ||
| ('通过', 'Passed'), ('通过率', 'Pass rate')], rows, | ||
| '本轮方法对比') |
There was a problem hiding this comment.
P2 — This caption is always Chinese, including on English report routes. _table escapes its caption directly into both <caption> and aria-label; it does not translate it. Thus every saved-matrix explainer rendered in English gains untranslated visible and accessibility text, contrary to the report-language contract. Pass a localized string (for example, bilingual_text('本轮方法对比', 'Method comparison')) and cover the English rendering.
| field_match=next(((field,text) for field,text in candidates if any( | ||
| _stable_literal_match(text,value,representation='plain_text') for value in item.get('matched',[]))),None) |
There was a problem hiding this comment.
P2 — The fallback can attribute a passing anchor to evidence that the scorer explicitly excludes. For example, with an unscoped body_text contract, empty body, page_information.published_at='October 2024', and a returned link labeled 'October 2024', the scorer passes on page_information, but this renderer selects the link first and displays links as the justification. The same fallback also accepts page fields for scoped anchors without checking their eligibility. Remove returned link labels from page-text evidence candidates and apply the scorer's unscoped_page_information(contract) and anchor scope/control guards before using page information. Add a report regression using real scored metrics so excluded fields cannot be presented as proof of a pass.
| return None | ||
| content, fences = mask_markdown_code(content, retain=True) | ||
| lines = content.splitlines() | ||
| start, _, _ = _coverage_text_start(lines, contract) |
There was a problem hiding this comment.
P2 — The new card parser discards the discussion heading level and stops only at named end markers. Unlike _coverage_text_records, it therefore continues through a same-level heading such as ## Related and counts matching cards in that unrelated section. For example, ## Comments with one valid card followed by ## Related with another valid card now satisfies a two-comment minimum; the existing section-boundary behavior requires only the first to count. Retain the returned section level and stop at the next peer/ancestor heading as well as reviewed end markers. Add a rendered-card counterpart to test_explicit_comment_heading_stops_at_same_level_even_without_known_footer.
| if matched is None: | ||
| matched = next((text for text in headings | ||
| if _title_key(text, representation='plain_text') in expected), None) |
There was a problem hiding this comment.
P2 — Returned headings bypass the title contract's exclusions. _title forwards both page_structure.headings and page_information.headings unchanged, so a matching heading from an excluded aside or screen-reader-only element makes this pass even when the HTML candidate was explicitly removed. The adjacent extracted-title fallback already rejects contracts with excluded_html_selectors, but this fallback does not. Apply the same exclusion guard to returned headings (or require evidence of eligible ownership), and add a negative control combining an excluded title with a matching returned heading. This is a blocking scoped-title false pass.
| events = _text_events(content, headings, key_function, literal=representation == 'plain_text') | ||
| declared = {key_function(h['text']): h for h in headings} | ||
| if not definitions and not html_document and not any(level is not None for _, level in events): | ||
| events = _declared_section_events(content, section_headings, declared) or events |
There was a problem hiding this comment.
P2 — The new fallback searches the raw Markdown after _text_events has deliberately excluded code from heading recognition. Consequently, a response containing only a fenced example with the declared section names and enough example text can pass document structure when section_headings repeats those names: the fallback promotes matches inside the fence to headings and counts the remaining code as their section bodies. Preserve heading eligibility when locating returned headings (in particular, exclude fenced and indented code for Markdown), and add a negative control for a code-only response with matching returned headings.
| heading_title = bool(re.fullmatch(r' {0,3}#{1,6}[ \t]+', content[line_start:link.start])) | ||
| items.append(LocatedItem(destination, title, link.start, owned_title=heading_title)) |
There was a problem hiding this comment.
P2 — A heading prefix does not establish that this link is the heading's title. For example, ## [18](/person/alice) [Alice](/person/alice) marks only 18 as owned_title; _is_named_label consequently admits the numeric badge, and the new deduplication rank prefers it over Alice even though Alice agrees with the destination slug. Previously the default name validator rejected the numeric label. This can now produce the wrong record title (or count a badge-only link as a named record). Require the link to own the complete heading title, or derive the title from the complete heading through the card parser, before granting ownership. Add paired controls for a genuine numeric heading title and a heading-leading numeric badge.
| value = normalize_native_markdown_layout(value) | ||
| # Preserve the punctuation itself while folding layout gaps after CJK | ||
| # punctuation, before NFKC turns some marks into ASCII punctuation. | ||
| value = re.sub(r'([,。!?、;:])\s+', r'\1', value) |
There was a problem hiding this comment.
P2: This substitution also removes paragraph breaks in declared plain text. For example, a required fact 编者按:日前,BBC发布消息。 now matches the artifact 编者按:\n\n日前,BBC发布消息。: both normalize to the same string, and _stable_literal_match has no remaining paragraph boundary to reject. This introduces a false pass contrary to the stated preservation of separate plain-text paragraphs. Restrict this layout folding to horizontal whitespace (or otherwise preserve paragraph boundaries), and add a negative control with a paragraph break immediately after CJK punctuation alongside the inline-spacing positive control.
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.
There was a problem hiding this comment.
This review found 5 issue(s), including 5 blocking issue(s).
| str(passed), f'{passed/len(selected):.1%}')) | ||
| context = _table([('方法', 'Method'), ('保存结果', 'Saved results'), | ||
| ('通过', 'Passed'), ('通过率', 'Pass rate')], rows, | ||
| '本轮方法对比') |
There was a problem hiding this comment.
P2: Localize the new table caption and accessible label. _table() inserts this argument verbatim into both <caption> and aria-label, and this string has no translation entry. Consequently, English saved-matrix reports retain a Chinese comparison heading and screen-reader label. This violates the English-route localization requirement in presentation-quality.md. Use an English-source t(...) entry with a Chinese catalog translation, and cover the caption and accessible label in an English rendering test.
| from lexbench_webfetch.stable_tasks import _stable_literal_match | ||
| fields=_returned_answer_fields(metadata or {}) | ||
| _,links,_,_=answer_input(b'',fields) | ||
| candidates=[('links',label) for _,label in safe_named_links(links,base_url)] |
There was a problem hiding this comment.
P2: The evidence fallback still considers returned link labels before eligible page-information fields, although the scorer now excludes those labels from page-text anchors. With body text lacking Help center, an unscoped body-text anchor can legitimately pass from page_information.headings=['Help center']; if the response also returns a link with that label, this renderer attributes the pass to links instead of the heading. Scope-restricted checks can likewise be attributed to ineligible fields because the field fallback has no eligibility guard. Build evidence candidates using the scorer's schema/scope rules (and only use returned links for checks that actually accept named-link records), so the report identifies evidence capable of supporting the saved verdict.
| if heading and label in markers: | ||
| return index + 1, len(heading[1]), True |
There was a problem hiding this comment.
P2: This also treats a trailing comment-form heading as the start of the discussion, discarding genuine comments before it. The supported contract in test_article_comment_boundaries.py includes both Comments and Post your reply as section markers. For The article ends right here.\n\n**Alice**\nFirst actual reply.\n\n**Bob**\nSecond actual reply.\n## Post your reply, the new scan returns the position after the final heading and counts zero comments; previously both records counted. Preserve the existing trailing-form behavior while excluding biographies before a discussion heading, and extend the existing trailing-form regression test to cover a Markdown heading.
| value = normalize_native_markdown_layout(value) | ||
| # Preserve the punctuation itself while folding layout gaps after CJK | ||
| # punctuation, before NFKC turns some marks into ASCII punctuation. | ||
| value = re.sub(r'([,。!?、;:])\s+', r'\1', value) |
There was a problem hiding this comment.
P2: This whitespace fold also removes paragraph boundaries in declared plain text. For example, 第一段。\n\n第二段 now normalizes to 第一段。第二段, so that contiguous required fact or stable anchor passes even though the response separates the paragraphs. The previous plain-text branch preserved a separating space. This contradicts the stated requirement that separate CJK paragraphs never join; preserve paragraph boundaries for plain text here and add a punctuation-ending negative control alongside the existing separate-paragraph control.
| records.append(record) | ||
| else: | ||
| records[equivalent] = record | ||
| known.add(identity) |
There was a problem hiding this comment.
P1: Updating known for every returned row silently removes duplicates within returned_records, bypassing the existing duplicate_records failure. For example, a review contract with minimum_records: 1 and two identical valid returned reviews passes, whereas the same repeated records parsed from text fail. The registered returned-records-duplicate control uses a minimum of 2, so it fails only on count and does not detect this bypass. Deduplicate overlap with text-derived records separately, while preserving repeated returned rows for the normal duplicate-policy checks; add a control where the unique count already meets the minimum.
…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.
There was a problem hiding this comment.
This review found 5 issue(s), including 5 blocking issue(s).
| field_detail=('<p class="source-note">' + t('whole_records_are_judged_by_field_text', 'Whole records are judged by field; text appearing does not mean list boundaries are intact.') + f"</p>{table([t('field', 'Field'), t('reference_answer', 'Reference answer'), t('actually_parsed', 'Actually parsed'), t('verdict', 'Verdict')], rows, metrics=[])}") | ||
| badge=t('invalid_field_boundaries', 'Invalid field boundaries') | ||
| actual=(f'<p translate="no">{esc(excerpt)}</p>' if excerpt else ('<p class="empty">' + t('no_continuous_source_excerpt_could_be_located', 'No continuous source excerpt could be located in the actual output.') + '</p>')) | ||
| actual=f'<p translate="no">{esc(excerpt)}</p>' if excerpt else '' |
There was a problem hiding this comment.
P2: Field-backed passes can be displayed as body-backed matches that the scorer explicitly rejects. For example, with answer_format='plain_text', output 中文 文本, an unscoped body-text contract anchoring 中文文本, and page_information.description='中文文本', the scorer passes only via the returned field (separate multi-character CJK words must not join). However, the initial _exact_evidence_lines search normalizes without the representation, joins those words, and populates actual, so the new field-evidence branch never runs. The report incorrectly presents the body as proof and omits the matching field reference. Select excerpts using the scorer's representation and scope restrictions before accepting them, or retain match-source provenance and render that source; add a regression for this field-only pass.
| if heading and label in markers and any(line.strip() for line in lines[index + 1:]): | ||
| return index + 1, len(heading[1]), True |
There was a problem hiding this comment.
P2: A populated trailing reply form still discards valid earlier comments. Using the existing boundary-test contract, append \n## Post your reply\nWrite a reply to the article ending plus the Alice/Bob comments. Because Post your reply is a section marker and now has nonblank text below it, this branch starts extraction after that heading and loses both comments (the previous loop retained them). The new trailing-form test only covers an empty form heading. Preserve earlier records when the later heading introduces a reply form, and add a control with form instructions or fields below the heading; nonempty trailing content does not establish that this is the discussion start.
| if not isinstance(returned_records, list): | ||
| raise ValueError('returned records must be a list') | ||
| names = SCHEMA_FIELDS[schema] | ||
| known = {source_record_hash(row['fields'], names, schema) for row in records} |
There was a problem hiding this comment.
P2: Only valid text-derived records should suppress a complete returned record. known currently includes invalid parse candidates. For example, a Markdown review table with headers date | text and a row 2026-11-01 | Great service | extra produces a record with the correct date/text but invalid_table_columns. A returned {date: '2026-11-01', text: 'Great service'} hashes identically and is skipped, so a minimum-one contract still fails even though the structured response supplies a complete valid record. Build the suppression set from valid records (or replace equivalent invalid candidates), and add a regression covering this mixed-evidence case.
| for fields in returned_records: | ||
| if not isinstance(fields, dict) or not all(isinstance(fields.get(key), str) for key in names): | ||
| continue | ||
| selected = {key: fields[key] for key in names} |
There was a problem hiding this comment.
P2: Preserve supported optional product fields when admitting returned records. product contracts allow field_minimum_records and fixed source_membership.fields to include financing and shipping, but this projection retains only name and price. A complete returned product with shipping: 'free shipping' therefore fails a shipping requirement (and a source hash bound to shipping) even though the response supplied it. Include the schema-supported optional fields in the admitted record and account for them when comparing it with text-derived records; add a structured-only product control with an optional-field requirement.
| identity = source_record_hash(selected, names, schema) | ||
| if identity not in known: |
There was a problem hiding this comment.
P2: Do not use the case-folded source hash alone to merge API-operation records. source_record_hash() case-folds the path, whereas the uniqueness check below deliberately preserves API path case. With a text-derived GET /Foo and a returned GET /foo having the same summary, this check silently drops the latter. A two-operation contract then falsely fails its minimum (or a maximum-one contract falsely passes). Use a merge key that preserves the schema's case-sensitive path identity, without changing frozen source-hash normalization, and cover this mixed text/structured case.
…t 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.
There was a problem hiding this comment.
This review found 2 issue(s), including 2 blocking issue(s).
| visible = _visible(output, metrics.get('stable_task_schema'), | ||
| representation=(metadata or {}).get('answer_format')) |
There was a problem hiding this comment.
P2 — Apply the scorer's scope/exclusions before locating fallback evidence. This new fallback calls _visible on the entire response, without the contract's text_exclusions or content_scope, and runs before the non_record_lines branch. For example, a body_text contract excluding .biography can pass on a multiline phrase in the accepted body, yet this fallback can select an earlier, inline-marked-up occurrence in .biography after rendering removes the tags. The scorer explicitly removes excluded selectors and text patterns before matching (stable_tasks.py:1836–1856), so the displayed excerpt is not evidence for the saved pass. The later passage fallback likewise starts from unfiltered output. Construct the accepted surface using the same scope/exclusion rules before either fallback, and add a regression with duplicate text in excluded and accepted regions. This is a localized report-correctness issue; it does not change the score.
| if not isinstance(fields, dict) or not all(isinstance(fields.get(key), str) for key in names): | ||
| continue | ||
| selected = {key: fields[key] for key in names} | ||
| if merge_key(selected) not in known: |
There was a problem hiding this comment.
P2: Repeated returned rows evade duplicate validation when the same row is also parsed from the body. known is a set of text-derived keys, so every occurrence of that returned row is skipped. For example, extend returned-records-duplicate-unique-count so the artifact contains one valid copy of its review: both returned copies disappear here and the one-record contract passes, although the same returned list correctly fails with artifact Reviews. Consume each text/returned overlap once (rather than skipping unlimited occurrences), retaining subsequent returned copies for the existing duplicate_records check. Add a paired regression with and without the body copy.
Further identical returned rows reach the duplicate-record check even when the body also contains the record. Bind a paired control.
There was a problem hiding this comment.
This review found 1 issue(s), including 1 blocking issue(s).
| if known[key]: | ||
| known[key] -= 1 |
There was a problem hiding this comment.
P2 — A quote body row can absorb two returned copies because known and text_quotes track the same row independently. For example, with schema quote, minimum_records=1, body “A complete quotation” by Alex Writer Tags: books reading, and two returned copies of {quote: 'A complete quotation', author: 'Alex Writer', tags: 'books reading'}, the first copy decrements known; the second pops the still-available text_quotes entry and replaces that same row. Only one record reaches the duplicate check, so the task incorrectly passes. Consume the text-row match in both indexes (including the reverse, equivalent-tags replacement path) so each body row absorbs at most one returned row. Add a quote-specific negative control; the current duplicate-with-body-copy control only exercises reviews.
…atches 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.
There was a problem hiding this comment.
✅ Re-review complete · 6b29ac0
No findings in this incremental review.
Structured extraction responses retained headings, review records, dates and other page information in raw evidence, but the scorer could receive only the main text and resource fields. Plain extracted code examples could also be mistaken for HTML. Preserve declared representations and hash-bound fields, then evaluate them through the shared scorer.
Under an explicit, unscoped acceptance contract, extracted page information can satisfy independent information checks. It cannot replace body coverage, comments, record counts or explicitly scoped content. Field values are never concatenated to manufacture a phrase. Returned link labels never count as page text, and legacy tasks without an acceptance contract keep body-only facts. The document title stays the
titlefield and is not declared as extracted page information. Native projections retain historical policies and support structural field-name aliases without site or case branches.Report pages show the evidence for each stable-text check: the located response excerpt, or the returned field that matched, with returned fields viewable on the result page.
Measured evidence, credentials and run-specific prose stay outside Git. No provider calls or online report updates are made.
Update 2026-11-09
cebd6aa1) are one commit here, resolved once against main's scorer changes.cjk-separate-paragraphs-fact-rejectedpasses again. Theplain-text-typographycontrol no longer depends on joining 中文 文本.code-migration.json:returned-link-labelis now a negative control, andreturned-link-fact-cross-pageis new.page_information.title, so it could pass title contracts that reject document titles.cebd6aa1. These changes can lower the API count. That paired replay must be rerun before any report uses these numbers.score_attempt, the native route baseline (policy source hash only), golden snapshots (source hashes only), and lint.Update 2026-11-10
test_returned_headings_respect_title_exclusions.View All, icons), catalog price-heading boundaries, Han spacing after©/Latin labels, and section-heading boundaries fromextra.section_headings. They address real HF review findings but belong in their own bound corrections;section_headingsis still projected and retained as evidence, not scored.code-migration.jsonhashes refreshed;dynamic_lists.pyanddocument_structure.pymatch main again. The golden snapshot changes only by the scorer source hash.cebd6aa1and need a replay on the final head before any report uses them.0c8ce9f1,3847a017,adbc6d01), all fixed:returned-records-duplicate-unique-count,returned-records-duplicate-with-body-copy,returned-records-duplicate-quote-with-body-copy.plain-text-cjk-punctuated-paragraphs-fact-rejected.article_comments.pyis unchanged from main.productrows keep only name and price, not optional shipping or financing.