Skip to content

fix(web-extract): bind replacement source receipts - #437

Open
Maisiqi wants to merge 7 commits into
mainfrom
codex/web-extract-source-replacement-receipts
Open

Maisiqi wants to merge 7 commits into
mainfrom
codex/web-extract-source-replacement-receipts

Conversation

@Maisiqi

@Maisiqi Maisiqi commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Bind replacement-source coverage to the locked original task URL, exact task-population hash, replacement page identity, timezone-aware observation time and authored evidence. The existing source-inventory command accepts the optional receipt; original URLs remain explicit when a historical catalog uses a replacement URL.

Malformed JSON roots, case rows, replacement objects, schema labels and source IDs fail with ValueError before output is written. Source hashes must match the authored source; capture hashes must match its bound source, rendered document or navigation capture. A syntactically valid but unrelated hash cannot authorize coverage. This new optional receipt boundary rejects historical capture-only records that lack a matching authored evidence binding; the historical dataset files remain unchanged.

Validation: the full query suite passed (443 tests). All Python CI shards, static checks, packaging checks and automated review pass on the final head. Ruff and git diff --check passed. Paired tests accept matched source/capture hashes and reject well-formed mismatches, alongside invalid timestamps, forged URLs and malformed receipt variants, including invalid source IDs on rows without replacements. Both Python and CLI entry points retain their valid-receipt coverage.

This PR changes source-inventory validation only; it does not change extraction scoring or activate a dataset selection. The 811-question live proposal uses original URLs and does not need replacement receipts.

@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 · 42930f2

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

Comment thread src/harness/web_extract/queries.py Outdated
Comment on lines +1288 to +1289
or not isinstance(replacement.get("observed_at"), str)
or not replacement["observed_at"].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
A nonempty value such as "unknown" passes this check and authorizes replacement coverage despite not recording an observation timestamp. Unlike qualify_page, this path never parses the value, so the generated inventory can mark the task draft_annotated_replacement with invalid observation evidence. Parse observed_at as an ISO-8601 datetime and require timezone information before accepting the receipt; add regression cases for malformed and timezone-less timestamps.

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.

Fixed in 36fbabf. Replacement receipts now parse observed_at with datetime.fromisoformat and require timezone information. Regression coverage rejects both unknown and a timezone-less ISO timestamp. Local query tests pass (443) and the complete PR CI is green.

@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 · 36fbabf

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

Comment on lines +1272 to +1276
for row in receipt["cases"]:
replacement = row.get("proposed_replacement")
if replacement is None:
continue
observed_at = replacement.get("observed_at")

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
Validate object types before calling .get(). read_json() only parses JSON, so a receipt containing "cases": [null] or "proposed_replacement": [] raises AttributeError here instead of the intended validation ValueError; the later isinstance(replacement, dict) check cannot handle these inputs. Check each row and each non-null replacement before accessing their fields, and add malformed-object tests to preserve the validation exception contract.

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

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

Comment on lines +1326 to +1329
replacement_matches = replacement is not None and (
replacement["replacement_id"] == page["id"]
and replacement["replacement_url"] == page["url"]
)

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
Replacement coverage is accepted solely on page ID and URL; the receipt's content hash is only checked for hexadecimal syntax. Consequently, a receipt with source_sha256 different from page["source"]["sha256"] still marks the task as draft_annotated_replacement. query_contract.validate_dataset() does not verify this association either. Compare the supplied source/capture hash with the corresponding authored-page evidence before counting replacement coverage, and add a regression test using a well-formed but mismatched hash.

@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 · 8b463dd

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

source.get("sha256"), str
):
raise ValueError("Replacement page requires source evidence")
capture_hashes = [source["sha256"], source.get("rendered_sha256")]

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
An explicitly null capture_sha256 is accepted when source_sha256 is valid and the authored source omits rendered_sha256 (as the article fixture does). The initial any(...) succeeds on the source hash, while capture_hashes contains None, so the capture comparison also passes and writes draft_annotated_replacement. Validate every supplied hash as a 64-character hexadecimal string, while requiring at least one hash, and exclude missing hashes from the evidence candidates. Add a regression asserting that a valid source hash plus a null capture hash raises ValueError before output is written.

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

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

Comment on lines +1277 to +1279
replacement = row.get("proposed_replacement")
if replacement is None:
continue

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
Rows without a replacement bypass source-ID validation. For example, appending {"source_task_id": []} or {"source_task_id": "unknown", "proposed_replacement": null} to an otherwise valid receipt still allows output to be written, contrary to the requirement that malformed source IDs fail with ValueError. Validate each row's source_task_id type and membership in the locked population before this early continue, and add tests for absent/null replacements with invalid IDs.

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

No findings in this incremental review.

This branch has not been deployed

No deployments
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