From 6f0237af0c7a1c13f9742282e2f45c0238b2635f Mon Sep 17 00:00:00 2001 From: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:43:38 +0000 Subject: [PATCH] fix(experiments): reject malformed PCAP receipts as failed facts Parse required receipt and nested view containers before indexing, preserving unsupported/conflicting identities as unknown instead of raising while grading. Compare cited page coverage and same-ID envelope conflicts as JSON to preserve boolean, integer and float distinctions. Reproduce prior crashes and false passes, then verify 22 context/grading and six comparator regressions plus factual regrading of all four original model answers without reruns. SDK and production contracts remain unchanged. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> --- .../pcap-small-captures.md | 14 ++++++-- .../analysis-efficiency/review-model.py | 12 +++++-- .../analysis-efficiency/test_codex_context.py | 36 +++++++++++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/experiments/analysis-efficiency/pcap-small-captures.md b/experiments/analysis-efficiency/pcap-small-captures.md index c745e9fa1..76bb794a4 100644 --- a/experiments/analysis-efficiency/pcap-small-captures.md +++ b/experiments/analysis-efficiency/pcap-small-captures.md @@ -126,7 +126,7 @@ validated. Both real CLI complete results match full MCP normalized results, subjects, parameters, IDs and limitations. Portable CLI summary/URI views match MCP retained normalized facts and subjects; source forms/caller parameters remain distinct. -Source bytes stay unchanged. Twenty context/grading regressions pass, including +Source bytes stay unchanged. Twenty-two context/grading regressions pass, including cited complete metadata/counts/UTF-16 diagnostics and exact ordered response ID lists that reject parent lookups, duplicates and nested representations. URI prefix coverage must come from its cited page, even if an uncited page has the @@ -159,7 +159,7 @@ the preceding driver accepts inconsistent coverage, while the corrected driver rejects wrong status, next offset or exhaustion. Unmodified exhausted and continuable URI pages still pass. The grader also requires each cited receipt's subject digest and local path to identify the reference capture, and uses the -reference page's verified coverage. Twenty grading/context regressions pass, +reference page's verified coverage. Twenty-two grading/context regressions pass, including missing or malformed subjects and faithful but inconsistent coverage; all four original model answers still pass factual regrading. Strict resource grades remain false where terminal whole-scope counters are unknown. @@ -182,6 +182,16 @@ private SDK operation faults are rejected while real complete/summary controls and all four stored model factual grades still pass. No operation is rewritten to make the tool name and delegated Evidence operation identical. +The receipt index parses the required envelope/nested-view containers before +allowing lookup, so missing or malformed normalized results/limitations become +failed facts with a written report. Coverage uses type-sensitive JSON comparison +to distinguish booleans, integers and floats. Receipt-identity conflict checks +use the same type-sensitive rule, so a scalar type change cannot hide in a +repeated ID. Existing PCAP scope-alias checks already preserve JSON types. +Negative regressions reproduce +prior crashes and false passes; all original real-model factual grades still +pass without model reruns. The SDK workflow is unchanged by these grader fixes. + **Decision: keep existing complete defaults; add no production optimization.** For these compact recordings and this question, summary/page costs more total input in both real-model pairs. No stable speed or CPU/memory benefit justifies diff --git a/experiments/analysis-efficiency/review-model.py b/experiments/analysis-efficiency/review-model.py index b2b45a9b3..30216b3dc 100644 --- a/experiments/analysis-efficiency/review-model.py +++ b/experiments/analysis-efficiency/review-model.py @@ -187,10 +187,16 @@ def main(): if not isinstance(value, dict) or not isinstance(value.get('evidence_id'), str): continue identity = value['evidence_id'] - entry = (tool, value) + normalized = value.get('normalized_result') + supported = isinstance(normalized, dict) and isinstance(value.get('limitations'), list) + if supported and normalized.get('kind') == 'summary': + supported = isinstance(normalized.get('summary'), dict) + elif supported and normalized.get('kind') == 'pcap': + supported = isinstance(normalized.get('page'), dict) + entry = (tool, value) if supported else None if identity not in records: records[identity] = entry - elif records[identity] != entry: + elif json.dumps(records[identity], sort_keys=True) != json.dumps(entry, sort_keys=True): # An ID with conflicting producers or envelopes is ambiguous. records[identity] = None observations = answer.get('delivery_observations') @@ -304,7 +310,7 @@ def main(): and selected_page.get('facet') == 'http-uris' and json.dumps(selected_page.get('items'), sort_keys=True) == json.dumps(prefix, sort_keys=True) and page.get('source_coverage') == capture.get('coverage') - and page.get('coverage') == reference['delivery_observations'][-1].get('coverage') + and json.dumps(page.get('coverage'), sort_keys=True) == json.dumps(reference['delivery_observations'][-1].get('coverage'), sort_keys=True) and page.get('artifact') == {key: capture['target'][key] for key in ['path', 'sha256']} ) else: diff --git a/experiments/analysis-efficiency/test_codex_context.py b/experiments/analysis-efficiency/test_codex_context.py index 0f035debe..f3334aa0d 100644 --- a/experiments/analysis-efficiency/test_codex_context.py +++ b/experiments/analysis-efficiency/test_codex_context.py @@ -251,6 +251,39 @@ class PcapGraderWorkflowTests(unittest.TestCase): self.assertFalse(report['factual_checks']['pcap_cited_source_supports_uri_prefix']) self.assertFalse(report['all_factual_checks_pass']) + def test_cited_coverage_preserves_exact_json_scalar_types(self): + for field, wrong in [('exhausted', 0), ('examined', 2.0), ('total', 3.0), ('next_offset', 2.0)]: + with self.subTest(field=field): + answer, records, reference = self.fixture() + records[-1]['normalized_result']['coverage'][field] = wrong + answer['delivery_observations'][-1] = self.observation(records[-1]) + answer['http_request_uris_first2']['coverage'][field] = wrong + report = self.grade(answer, records, reference) + self.assertTrue(report['factual_checks']['pcap_original_delivery_observations']) + self.assertTrue(report['factual_checks']['pcap_prefix_coverage_observed']) + self.assertFalse(report['all_factual_checks_pass']) + + def test_malformed_receipt_envelopes_write_failed_facts_instead_of_crashing(self): + tools = ['inspect_pcap_capture', 'inspect_analysis_view'] + for index in [0, 1]: + for field, wrong in [('normalized_result', None), ('normalized_result', []), + ('normalized_result', 'capture'), ('limitations', None), + ('limitations', {})]: + with self.subTest(index=index, field=field, wrong=wrong): + answer, records, reference = self.fixture();records[index][field] = wrong + report = self.grade(answer, records, reference, tools) + self.assertTrue(report['factual_checks']['capture']) + self.assertFalse(report['all_factual_checks_pass']) + for field in ['normalized_result', 'limitations']: + with self.subTest(index=index, missing=field): + answer, records, reference = self.fixture();records[index].pop(field) + self.assertFalse(self.grade(answer, records, reference, tools)['all_factual_checks_pass']) + for index, field in [(0, 'summary'), (1, 'page')]: + for wrong in [None, [], 'view']: + with self.subTest(index=index, nested=field, wrong=wrong): + answer, records, reference = self.fixture();records[index]['normalized_result'][field] = wrong + self.assertFalse(self.grade(answer, records, reference, tools)['all_factual_checks_pass']) + def test_retained_parents_require_declared_distinct_evidence_links(self): for index in [0, 1]: for links in [None, [], ['ev_' + 'f' * 64], {'parent': 'ev_' + 'a' * 64}]: @@ -293,6 +326,9 @@ class PcapGraderWorkflowTests(unittest.TestCase): tools = ['unrelated_tool', 'inspect_pcap_capture', 'inspect_analysis_view'] if duplicate_first else \ ['inspect_pcap_capture', 'inspect_analysis_view', 'unrelated_tool'] self.assertFalse(self.grade(answer, items, reference, tools)['all_factual_checks_pass']) + duplicate = copy.deepcopy(records[-1]);duplicate['normalized_result']['coverage']['exhausted'] = 0 + for items in [[*records, duplicate], [records[0], duplicate, records[-1]]]: + self.assertFalse(self.grade(answer, items, reference)['all_factual_checks_pass']) def test_reported_ids_are_only_the_ordered_unique_response_receipts(self): answer, records, reference = self.fixture()