Repository navigation
feat(webfetch): retain native Lexmount API execution evidence - #224
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]>
Review of #224 found that validate_release returned early for any directory with saved-matrix-audit.json, so audit matrices and compositions could be packaged and published without the presentation, certification and review checks. Main refuses them as diagnostic evidence. Remove the early return and assert the refusal for both saved matrices and compositions.
There was a problem hiding this comment.
This review found 5 issue(s), including 5 blocking issue(s).
| 'links': {'pointer': ['result', 'links'], 'format': 'identity', 'default': []}, | ||
| 'images': {'pointer': ['result', 'images'], 'format': 'identity', 'default': []}}} |
There was a problem hiding this comment.
P2: Explicit null resource fields do not replay the adapter's output. For example, with {"result":{"main_text":"body","links":null,"images":null}}, fetch() stores both metadata fields as [] via or [], but the identity projection returns None: its default only applies to missing pointers. require_native_answer_projection() consequently raises during artifact persistence and stops the run. Align the adapter and projection's handling of null fields, and cover this response with a persistence/replay regression.
| "raw_response_sha256": hashlib.sha256(response.body).hexdigest(), | ||
| "raw_response_bytes": len(response.body), | ||
| "api_http_status": response.status, | ||
| "native_answer_projection": native_answer_projection(self.type, case, payload, response.status)} |
There was a problem hiding this comment.
P2: This unconditionally attaches a JSON projection even when response.json() failed above. A non-JSON response such as an HTML HTTP 502 is converted to an empty failed result here, but persist_result_artifacts() then calls require_native_answer_projection(), which runs json.loads() on the retained original bytes and raises before saving the failure. Thus an ordinary API/proxy failure aborts the cohort instead of retaining its execution evidence. Use a replayable empty byte projection for non-JSON responses (with the corresponding frozen policy/route support), and test persistence of an HTML error response.
| check_saved_matrix(source) | ||
| return False |
There was a problem hiding this comment.
P2: Packaging a composition with a provider subset fails when the retained source contains attempts for an excluded provider. The complete source report is copied under evidence/saved-reports, but report_package._build_content processes every directory named attempts using by_attempt[path.stem] from the top-level selected results. An excluded attempt is absent from that index, causing KeyError. Keep nested evidence HTML out of the top-level lazy-page transformation (preserving its original bytes), and add a test that packages the selected-provider composition rather than only the all-provider composition.
| return {k: _project(v, paths) for k, v in value.items()} | ||
| if isinstance(value, list): | ||
| return [_project(v, paths) for v in value] | ||
| return paths.get(value, value) if isinstance(value, str) else value |
There was a problem hiding this comment.
P2: Path projection also rewrites non-path values whenever they happen to equal an audited filename. For example, a valid task with name: "index.html" has its row name changed to evidence/saved-reports/<id>/index.html, while its immutable case file retains the original name. _saved_renderer_projection then rejects the composition with Saved case metadata differs from matrix. Restrict replacement to declared path fields, including nested evidence paths, rather than all strings; add a non-path filename-collision regression.
| receipt_paths = {row['score_revision']['receipt_path'] for row in model['rows'] | ||
| if row.get('score_revision')} |
There was a problem hiding this comment.
P2: This collects receipts from excluded providers as well as selected ones. Independently valid sources can both contain review-assets/notes.json with different contents; if one receipt belongs only to an excluded method, its attachment still gets promoted to the composition root and causes Conflicting saved review attachments. Filter rows by the validated provider selection before collecting receipts for root-level attachments. Preserve the full source snapshot and its validation, and retain conflict detection for attachments actually referenced by selected rows.
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]>
There was a problem hiding this comment.
This review found 2 issue(s), including 2 blocking issue(s).
src/harness/web_fetch/report_saved_composition.py(token_budget_reached): stopped group "src/harness/web_fetch/report_saved_composition.py" mid-review: used 537685 tokens exceeds budget 500000
| 'links': {'pointer': ['result', 'links'], 'format': 'identity', 'default': []}, | ||
| 'images': {'pointer': ['result', 'images'], 'format': 'identity', 'default': []}}} |
There was a problem hiding this comment.
P2: Explicit null resource fields cannot be replayed. For example, a 200 response with {"result":{"main_text":"body","links":null,"images":null}} is accepted by LexmountProvider.fetch, which stores both metadata fields as [] via result.get(...) or []. These identity projections instead return None: default applies only to missing pointers, not explicit nulls. Consequently, require_native_answer_projection raises Scored answer differs from its declared native field projection, preventing evidence validation for an otherwise accepted response. Align the adapter and projection handling of empty/null fields and add a replay regression for explicit nulls.
| selected = snapshot.get('providers') | ||
| if selected is not None: |
There was a problem hiding this comment.
P2 — An explicit "providers": null bypasses selection validation and includes every method. The public build path preserves this value in the snapshot and performs no earlier selection validation, so a malformed selection silently broadens the comparison instead of failing like other non-list values. Distinguish an absent key from a present null (for example, validate whenever 'providers' in snapshot) and add None to the invalid-selection regression cases. This is a localized input-validation defect affecting the reported method population.
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]>
There was a problem hiding this comment.
This review found 3 issue(s), including 3 blocking issue(s).
| 'links': {'pointer': ['result', 'links'], 'format': 'identity', 'default': []}, | ||
| 'images': {'pointer': ['result', 'images'], 'format': 'identity', 'default': []}}} |
There was a problem hiding this comment.
P2: Explicit null resource fields do not replay the adapter's output. For a response such as {"result":{"main_text":"body","links":null,"images":null}}, LexmountProvider.fetch() stores both fields as [] (result.get(...) or []), but these identity projections return None: _selected() applies default only when the pointer is missing. Consequently require_native_answer_projection() raises during persist_result_artifacts() instead of retaining the call. Align the projection and adapter normalization for null fields, and add a replay/persistence regression covering explicit null as well as omitted fields.
| return {k: _project(v, paths) for k, v in value.items()} | ||
| if isinstance(value, list): | ||
| return [_project(v, paths) for v in value] | ||
| return paths.get(value, value) if isinstance(value, str) else value |
There was a problem hiding this comment.
P2 — This recursively relocates non-path values as well as evidence paths. For example, a valid task with name: "matrix.json" has its row name changed to evidence/saved-reports/<id>/matrix.json, because every source audit includes that filename. The frozen case remains unchanged, so the final check_saved_matrix rejects the composition with Saved case metadata differs from matrix. Restrict relocation to the row schema's evidence-path fields instead of matching arbitrary strings, and cover a task name matching an audited filename.
| selected = snapshot.get('providers') | ||
| if selected is not None: |
There was a problem hiding this comment.
P2 — An explicit "providers": null bypasses selection validation and includes every method, whereas other non-list selections are rejected. build_composition preserves this value in the snapshot, so this is reachable through the public build entry and can silently broaden the ranking. Test key presence separately from its value and require a nonempty list whenever providers is supplied; add None to the invalid-selection regression cases.
…on-JSON responses Bot review of #224: - A non-JSON body such as a proxy's HTML 502 got a JSON answer projection, so saving the failure raised. Declare a projection only for JSON bodies. - Explicit null links/images were stored as [] but projected as None. Declare resource fields only when the API returned lists. - An explicit null method selection silently included every method. Validate the selection whenever the key is present.
There was a problem hiding this comment.
This review found 3 issue(s), including 3 blocking issue(s).
| **({"native_answer_projection": native_answer_projection(self.type, case, payload, response.status)} | ||
| if parsed else {})} |
There was a problem hiding this comment.
P2: Non-JSON failures cannot pass saved-evidence validation. For an HTML 502, this branch retains the raw bytes but omits the projection. Later, verify_saved_native_answer() calls _expected_native_declaration() for those bytes; that function does not special-case Lexmount malformed envelopes, converts the parse failure to {}, and receives a non-None declaration from the new Lexmount projection branch. It therefore raises Native answer declaration differs from its pre-call selection policy, preventing aggregation of an otherwise legitimate failed call. Align saved replay with this acquisition behavior for both lexmount and lexmount_cn, and add a persist/reload validation test for non-JSON and non-object responses (the current test only checks the immediate projection validator).
| return {k: _project(v, paths) for k, v in value.items()} | ||
| if isinstance(value, list): | ||
| return [_project(v, paths) for v in value] | ||
| return paths.get(value, value) if isinstance(value, str) else value |
There was a problem hiding this comment.
P2: This rewrites non-path values as well as evidence links. For example, a valid frozen case named matrix.json produces a row whose name is changed to evidence/saved-reports/<id>/matrix.json, while the copied case retains its original name. The final saved-matrix check then rejects the composition with Saved case metadata differs from matrix; filename-like error text or acceptance-check values can suffer the same problem. Restrict relocation to the row schema's evidence-path fields, including nested provenance paths, and preserve other strings verbatim.
| if spec_path is not None and _public_spec(_read(Path(spec_path))) != stored['spec']: | ||
| raise ValueError('Saved composition specification changed') |
There was a problem hiding this comment.
P2: Validation against the original specification never checks its saved_reports bindings or provider selections: _public_spec() drops both, and reconstruction trusts the stored snapshots. A composition rebuilt with a different provider selection (or different valid source reports) can therefore pass check_saved_matrix(..., spec_path=original_spec) after its audit's spec_sha256 is set to the original hash. Compare snapshot IDs, source audit hashes, and provider selections with the supplied specification before reconstructing the model. Otherwise the original-spec check does not establish that the caller's selected evidence was used.
Acquisition now declares no answer for a non-JSON Lexmount body, but saved
replay still parsed it as {} and expected a projection, so a legitimate
HTML 502 failure could not be aggregated. Treat malformed Lexmount
envelopes like the other adapters that keep them as evidence only.
There was a problem hiding this comment.
This review found 4 issue(s), including 4 blocking issue(s).
| parsed = isinstance(payload, dict) | ||
| payload = payload if parsed else {} |
There was a problem hiding this comment.
P2 — Native acquisition and replay use different JSON decoding rules. response.json() decodes the declared charset with replacement characters, whereas _expected_native_declaration() now requires strict UTF-8 for Lexmount. For example, b'{"result":{"main_text":"\xff"}}' is accepted here as a successful result with a projection, but raw-byte projection validation raises a UnicodeDecodeError (and saved replay expects no declaration). A malformed response therefore cannot be retained/replayed as a normal failed attempt. In native mode, parse response.body with the shared parse_utf8_json helper and treat decoding failures as malformed envelopes, while preserving non-native behavior.
| return {k: _project(v, paths) for k, v in value.items()} | ||
| if isinstance(value, list): | ||
| return [_project(v, paths) for v in value] | ||
| return paths.get(value, value) if isinstance(value, str) else value |
There was a problem hiding this comment.
P2: Relocate only evidence-path fields, rather than every matching string. A valid case named matrix.json produces a row whose name is matrix.json; because that filename is in audit['files'], this function changes the name to evidence/saved-reports/<id>/matrix.json while leaving the frozen case unchanged. The final check_saved_matrix() then rejects the composition with Saved case metadata differs from matrix. Error text and other non-path metadata can collide similarly. Preserve scalar metadata and restrict projection to the row schema's evidence references; add a regression case with a filename-valued task name.
| receipt_paths = {row['score_revision']['receipt_path'] for row in model['rows'] | ||
| if row.get('score_revision')} |
There was a problem hiding this comment.
P2: Apply the validated provider selection before collecting attachments for report-root copies. This loop reads every source row, whereas composition_model() later discards excluded providers. Consequently, an excluded provider's revision attachment can conflict with a selected provider's attachment from another report and raise Conflicting saved review attachments, rejecting an otherwise compatible selected-provider composition. Keep the complete source snapshot immutable, but collect these extra root-level attachments only from selected rows. Cover an excluded revised provider with a conflicting attachment in a regression test.
| check_composition(output, spec_path) | ||
| spec_path = None |
There was a problem hiding this comment.
P2: Preserve the caller's source and method-selection bindings when checking a composition. check_composition(output, spec_path) compares only _public_spec, which excludes saved_reports; it reconstructs the result from the report's own snapshots. Clearing spec_path here then skips the original-source checks. Consequently, a valid composition built with a different provider selection (or different source reports), but identical public presentation settings, passes against the original specification if its audit's spec_sha256 is replaced with that specification's hash. This defeats the explicit caller-authority check even though the portable files remain internally consistent. Before discarding spec_path, compare the snapshot IDs, source audit hashes, and provider selections against its saved_reports entries. Add a negative test using two otherwise identical specifications with different selections.
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]>
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): 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]>
Lexmount Web Fetch can now participate in fixed-parameter cohorts with native request receipts, retained API response bytes, and replayable answer projections. The adapter sends the nested
extract.urlrequest, preserves the declared text/title/URL/link/image fields, and rejects error envelopes as page content. Optional diagnostic trace can be omitted, allowing a minimalengine_preference: autorequest while keeping the prior trace default for existing callers.Saved comparisons can be composed into one ranking. Composition preserves immutable source reports, verifies matching frozen tasks and case populations, rejects duplicate methods, and optionally selects named methods from a source report. Unknown, duplicate, or empty method selections fail validation. Shared review attachments are copied once per distinct revision receipt, with conflict detection and source evidence checks.
Saved matrices and compositions remain diagnostic. The Web Fetch release gate (
report_package.validate_release) still refuses them, as on main; tests assert the refusal for both. No online publication is part of this change.The methodology card now distinguishes all-final-call latency from passing-task and shared-success populations, in the English-source message catalog with its Chinese translation.
Benchmark inputs, measured outputs, credentials, and report instances remain outside Git.
Update 2026-11-09
validate_releaselet audit matrices and compositions skip the release checks. Removed it; packaging a saved matrix or composition now fails with the existing diagnostic-evidence error.nulllinks/images and for non-JSON bodies, such as a proxy's HTML 502. Both acquisition and saved replay declare no answer for a malformed envelope. An explicitproviders: nullselection is now rejected.Compositions remain diagnostic and cannot be packaged.