From 32ae0b43f105097f43bbf2e64a17efe8a60d2f91 Mon Sep 17 00:00:00 2001 From: Aleksei Menshutin Date: Fri, 4 Dec 2026 04:25:23 +0100 Subject: [PATCH 1/2] Verify crossed edge receipts in portable original comparisons --- .../public-operations/crossed_replay.py | 73 ++++++++++++++++++ .../experiments/public-operations/run.py | 74 +++++++++++++++---- .../experiments/public-operations/test_run.py | 53 +++++++++++++ 3 files changed, 186 insertions(+), 14 deletions(-) create mode 100644 usvm-ts-fast-check/experiments/public-operations/crossed_replay.py diff --git a/usvm-ts-fast-check/experiments/public-operations/crossed_replay.py b/usvm-ts-fast-check/experiments/public-operations/crossed_replay.py new file mode 100644 index 0000000000..b6ac4dc6f7 --- /dev/null +++ b/usvm-ts-fast-check/experiments/public-operations/crossed_replay.py @@ -0,0 +1,73 @@ +"""Select distinct, source-bound inputs from confirmed early goal crossings.""" +import json +from pathlib import Path + + +def input_key(inputs): + return json.dumps(inputs, sort_keys=True) + + +def admitted_crossing(candidate, native, case): + declaration = case["sourceSha256"] + sources = candidate.get("sources") or [] + source_pins = {entry["module"]: entry["sha256"] for entry in sources} + source_root = Path(case["sourceRoot"]).resolve() + source_hashes = {str(source_root / module): digest for module, digest in declaration.items()} + manifest_sha = candidate.get("manifestSha256") + property_id = case["property"]["id"] + coverage = native.get("coverage") or {} + identity = coverage.get("identity") or {} + provenance = coverage.get("provenance") or {} + + return ( + candidate.get("propertyId") == property_id + and len(sources) == len(source_pins) + and source_pins == declaration + and bool(manifest_sha) + and candidate.get("provenance") == "usvm:goal-crossing" + and native.get("admission") == "ADMITTED" + and native.get("outcome") == "HOLDS" + and not native.get("diagnostic") + and coverage.get("propertyId") == property_id + and coverage.get("admittedInvocations") == 1 + and provenance.get("sourceRoots") == [str(source_root)] + and provenance.get("request", {}).get("admittedOnly") is True + and identity.get("manifestSha256") == manifest_sha + and identity.get("sourceSha256") == source_hashes + ) + + +def crossed_inputs(result, case, completed_replays): + symbolic = result.get("symbolic") or {} + trace = symbolic.get("edgeGuidance") or {} + confirmed = { + input_key(item["inputs"]) for item in trace.get("replays", []) + if item.get("crossedBeforeCompletion") and item.get("status") == "CONFIRMED" + } + completed = {input_key(item["inputs"]) for item in symbolic.get("completedInputs", [])} + completed.update(input_key(item["inputs"]) for item in completed_replays) + needed = confirmed - completed + + accepted = {} + unexpected = set() + duplicates = 0 + receipts = result.get("symbolicGoalReplays", []) + for receipt in receipts: + candidate = receipt["candidate"] + inputs = candidate["inputs"] + key = input_key(inputs) + if key in completed or key in accepted: + duplicates += 1 + continue + if key not in needed: + unexpected.add(key) + continue + native = receipt["replay"] + if not receipt.get("completedWithinDeadline") or receipt.get("predictedOutcomes"): + continue + if admitted_crossing(candidate, native, case): + accepted[key] = {"inputs": inputs, "admission": "ADMITTED", "outcome": "HOLDS"} + + counts = {"confirmed": len(confirmed), "receipts": len(receipts), "duplicates": duplicates, + "alreadyCompleted": len(confirmed & completed), "omitted": len((needed - accepted.keys()) | unexpected)} + return list(accepted.values()), counts diff --git a/usvm-ts-fast-check/experiments/public-operations/run.py b/usvm-ts-fast-check/experiments/public-operations/run.py index 656d2a0a55..2defbfa4ad 100644 --- a/usvm-ts-fast-check/experiments/public-operations/run.py +++ b/usvm-ts-fast-check/experiments/public-operations/run.py @@ -1,5 +1,6 @@ """Acquire and replay the frozen public-class operation continuation experiment.""" import argparse +import gzip import hashlib import io import json @@ -8,6 +9,7 @@ import shutil import subprocess import sys +import time import tarfile import urllib.request from pathlib import Path @@ -16,6 +18,7 @@ SCRIPTS = HERE.parents[1] / "scripts" sys.path.insert(0, str(SCRIPTS)) from pbt_experiment import replay_inputs, verify_sources +from crossed_replay import crossed_inputs ORIGINAL_MODES = {"pbt": "PBT_ONLY", "sequential": "SEQUENTIAL", "guided": "COVERAGE_FEEDBACK"} OUTCOMES = {"holds": "HOLDS", "false": "FALSE", "threw": "THREW"} @@ -110,13 +113,30 @@ def expand(token): } -def run_process(command, folder, name, timeout, *, cwd=None): - with (folder / f"{name}.stdout").open("wb") as stdout, (folder / f"{name}.stderr").open("wb") as stderr: +def archive(path): + if path.exists() and path.stat().st_size: + zipped = path.with_name(f"{path.name}.gz") + with path.open("rb") as source, gzip.open(zipped, "wb", compresslevel=3) as destination: + shutil.copyfileobj(source, destination) + path.unlink() + + +def run_process(command, folder, name, timeout, *, cwd=None, compress=False): + started = time.monotonic() + stdout_path = folder / f"{name}.stdout" + stderr_path = folder / f"{name}.stderr" + with stdout_path.open("wb") as stdout, stderr_path.open("wb") as stderr: try: completed = subprocess.run(command, cwd=cwd or folder, timeout=timeout, stdout=stdout, stderr=stderr) - return {"exitCode": completed.returncode} + result = {"exitCode": completed.returncode} except subprocess.TimeoutExpired: - return {"timeoutSeconds": timeout} + result = {"timeoutSeconds": timeout} + + result["elapsedMillis"] = round(1000 * (time.monotonic() - started)) + if compress: + archive(stdout_path) + archive(stderr_path) + return result def replay(options, case, prepared, batch, folder): @@ -132,11 +152,11 @@ def replay(options, case, prepared, batch, folder): output = folder / f"{receipt}-response.json" save(request, dict(case, prepared=prepared, inputs=chunk, isolateInputs=batch.get("isolateInputs", False))) process = run_process([options.node, SCRIPTS / "class-coverage-replay.mjs", "replay", options.adapter, - request, output], folder, receipt, 60) - if process.get("exitCode") != 0 or not output.exists(): - failed += len(chunk) - continue - received = load(output)["records"] + request, output], folder, receipt, 60, compress=options.compress) + received = load(output)["records"] if process.get("exitCode") == 0 and output.exists() else [] + if options.compress: + archive(request) + archive(output) if len(received) != len(chunk): failed += len(chunk) continue @@ -202,7 +222,7 @@ def campaign(options, case, prepared, folder, mode, seed, budget, *, replay_symb launcher = [options.java, f"-Dorg.usvm.ts.pbt.fastcheck.runtime={options.adapter}", "-cp", str(library / "*"), "org.usvm.ts.pbt.cli.FastCheckCliKt"] process = run_process([*launcher, "campaign-file", request, output], folder, "campaign", - budget / 1000 + 10, cwd=options.distribution) + budget / 1000 + 10, cwd=options.distribution, compress=options.compress) cell = {"process": process, "mode": mode, "universeSha256": prepared["universe"]["sha256"], "batches": {}} if not output.exists(): cell["status"] = "NO_CAMPAIGN" @@ -210,10 +230,14 @@ def campaign(options, case, prepared, folder, mode, seed, budget, *, replay_symb return cell artifact = load(output) + if options.compress: + archive(output) result = artifact["result"] concrete_failure = (result.get("concrete") or {}).get("failure") or {} - cell.update(status="ARTIFACT", stop=result.get("stop"), concreteViolation=concrete_failure.get("kind") == "property", - symbolicStatus=(result.get("symbolic") or {}).get("status")) + cell.update(status="ARTIFACT", stop=result.get("stop"), campaignElapsedMillis=result.get("elapsedMillis"), + diagnostic=result.get("diagnostic"), concreteViolation=concrete_failure.get("kind") == "property", + symbolicStatus=(result.get("symbolic") or {}).get("status"), + symbolicDiagnostics=(result.get("symbolic") or {}).get("diagnostics", [])) if mode != "SYMBOLIC_ONLY": inputs, missing = captured_pbt(result.get("concrete") or {}, case["sourceSha256"]) pbt = replay(options, case, prepared, {"id": "pbt", "inputs": inputs}, folder) @@ -226,6 +250,13 @@ def campaign(options, case, prepared, folder, mode, seed, budget, *, replay_symb verified = replay(options, case, prepared, symbolic, folder) verified["omitted"] = sum(value for key, value in omissions.items() if key.startswith("symbolic")) cell["batches"]["symbolic"] = verified + crossings, counts = crossed_inputs(result, case, symbolic["inputs"]) + cell["crossings"] = counts + if counts["confirmed"] or counts["receipts"]: + batch = {"id": "crossed", "inputs": crossings, "isolateInputs": True} + verified = replay(options, case, prepared, batch, folder) + verified["omitted"] = counts["omitted"] + cell["batches"]["crossed"] = verified save(folder / "cell.json", cell) return cell @@ -345,6 +376,18 @@ def measure(options, specimen, recipe, seeds): +def complete_symbolic_evidence(batches, status): + completed = batches.get("symbolic") + crossed = batches.get("crossed") + if crossed is None: + return complete_symbolic(completed, status) + if not (complete(completed) and complete(crossed)): + return False + + verified = sum(batch["verified"] for batch in (completed, crossed)) + return complete_symbolic(dict(completed, offered=verified, verified=verified), status) + + def original_cell(cell): observed = cell["batches"] confirmed = set().union(*(set(batch["ids"]) for batch in observed.values())) @@ -353,11 +396,13 @@ def original_cell(cell): pbt_fault = cell.get("concreteViolation") and status is None and pbt.get("verifiedViolations", 0) > 0 no_continuation_needed = cell["mode"] == "PBT_ONLY" or pbt_fault full = cell["status"] == "ARTIFACT" and complete_pbt(observed.get("pbt")) and ( - no_continuation_needed or complete_symbolic(observed.get("symbolic"), status) + no_continuation_needed or complete_symbolic_evidence(observed, status) ) return {"status": cell["status"], "stop": cell.get("stop"), "symbolicStatus": cell.get("symbolicStatus"), "replayComplete": full, "coveredCount": len(confirmed), "coveredIds": sorted(confirmed), - "batches": observed, "process": cell["process"]} + "batches": observed, "process": cell["process"], "crossings": cell.get("crossings"), + "campaignElapsedMillis": cell.get("campaignElapsedMillis"), "diagnostic": cell.get("diagnostic"), + "symbolicDiagnostics": cell.get("symbolicDiagnostics", [])} def run_original_panel(options, manifest, recipes, cases): @@ -428,6 +473,7 @@ def main(): parser.add_argument("--adapter", type=Path, help="Override the distribution's bundled FastCheck adapter") parser.add_argument("--case", action="append", help="Optional subject slug, repeatable") parser.add_argument("--panel", choices=("operations", "original"), default="operations") + parser.add_argument("--compress", action="store_true", help="Compress raw campaign and replay files after reading") options = parser.parse_args() options.distribution = options.distribution.resolve() options.adapter = (options.adapter or options.distribution / "lib/fast-check-adapter").resolve() diff --git a/usvm-ts-fast-check/experiments/public-operations/test_run.py b/usvm-ts-fast-check/experiments/public-operations/test_run.py index 5cde248b55..de63ec2322 100644 --- a/usvm-ts-fast-check/experiments/public-operations/test_run.py +++ b/usvm-ts-fast-check/experiments/public-operations/test_run.py @@ -1,6 +1,8 @@ import unittest +from copy import deepcopy import run +from crossed_replay import crossed_inputs class MeasurementStatusTest(unittest.TestCase): @@ -52,6 +54,57 @@ def test_original_hybrid_keeps_empty_failed_phase_and_a_native_concrete_stop_dis complete_fault = run.original_cell(dict(cell, concreteViolation=True)) self.assertTrue(complete_fault["replayComplete"]) + def test_grants_coverage_only_to_confirmed_unique_source_bound_crossings(self): + case = {"sourceRoot": "/fixture", "property": {"id": "p"}, "sourceSha256": {"source.ts": "pinned"}} + sources = [{"module": "source.ts", "sha256": "pinned"}] + coverage = {"propertyId": "p", "admittedInvocations": 1, + "identity": {"manifestSha256": "registered", "sourceSha256": {"/fixture/source.ts": "pinned"}}, + "provenance": {"sourceRoots": ["/fixture"], "request": {"admittedOnly": True}}} + inputs = [{"kind": "boolean", "value": True}] + completed = [{"kind": "boolean", "value": False}] + emitted = {"candidate": {"inputs": inputs, "sources": sources, "propertyId": "p", + "manifestSha256": "registered", "provenance": "usvm:goal-crossing"}, + "replay": {"outcome": "HOLDS", "admission": "ADMITTED", "coverage": coverage}, + "completedWithinDeadline": True} + already_completed = dict(emitted, candidate=dict(emitted["candidate"], inputs=completed)) + result = { + "symbolic": {"completedInputs": [{"inputs": completed}], "edgeGuidance": {"replays": [ + {"inputs": value, "crossedBeforeCompletion": True, "status": "CONFIRMED"} + for value in (inputs, completed)]}}, + "symbolicGoalReplays": [emitted, already_completed, emitted], + } + + candidates, counts = crossed_inputs(result, case, []) + self.assertEqual(candidates, [{"inputs": inputs, "admission": "ADMITTED", "outcome": "HOLDS"}]) + self.assertEqual(counts, {"confirmed": 2, "receipts": 3, "duplicates": 2, "alreadyCompleted": 1, "omitted": 0}) + + altered = deepcopy(emitted) + altered["replay"]["coverage"]["identity"]["sourceSha256"]["/fixture/source.ts"] = "stale" + result["symbolicGoalReplays"] = [altered, already_completed] + candidates, counts = crossed_inputs(result, case, []) + self.assertEqual(candidates, []) + self.assertEqual(counts["omitted"], 1) + + result["symbolicGoalReplays"] = [] + self.assertEqual(crossed_inputs(result, case, [])[1]["omitted"], 1) + + def test_original_coverage_includes_crossed_ids_and_keeps_missing_crossings_partial(self): + def batch(ids, omitted=0): + return {"ids": ids, "offered": len(ids), "verified": len(ids), "failed": 0, "omitted": omitted} + + for mode in ("SEQUENTIAL", "COVERAGE_FEEDBACK"): + cell = {"mode": mode, "status": "ARTIFACT", "process": {}, "symbolicStatus": "TIMEOUT", + "batches": {"pbt": batch(["common"]), "symbolic": batch(["common", "terminal"]), + "crossed": batch(["common", "crossed"])}} + result = run.original_cell(cell) + self.assertTrue(result["replayComplete"]) + self.assertEqual(result["coveredIds"], ["common", "crossed", "terminal"]) + + cell["batches"]["crossed"] = batch([], omitted=1) + result = run.original_cell(cell) + self.assertFalse(result["replayComplete"]) + self.assertEqual(result["coveredIds"], ["common", "terminal"]) + def test_unsupported_captured_record_is_counted_only_once(self): sources = {"property.ts": "a" * 64} concrete = {"inputExport": {"verifiedSources": [{"module": "property.ts", "sha256": "a" * 64}], From ce2880ffe13ca5cbdc9c01fe2e90a8a1cad27c19 Mon Sep 17 00:00:00 2001 From: Aleksei Menshutin Date: Fri, 4 Dec 2026 04:53:38 +0100 Subject: [PATCH 2/2] Keep the shared replay driver on terminal inputs --- .../experiments/public-operations/run.py | 16 +++++++++++++++- .../experiments/public-operations/test_run.py | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/usvm-ts-fast-check/experiments/public-operations/run.py b/usvm-ts-fast-check/experiments/public-operations/run.py index 2defbfa4ad..4ea8b2ee6f 100644 --- a/usvm-ts-fast-check/experiments/public-operations/run.py +++ b/usvm-ts-fast-check/experiments/public-operations/run.py @@ -199,6 +199,20 @@ def captured_pbt(concrete, expected_sources): return inputs, missing +def terminal_replay_inputs(artifact): + # The shared Python driver can also replay crossed goals. Give it the terminal + # view so the portable panel can count those goals in its own batch once. + terminal_result = dict(artifact["result"]) + terminal_result.pop("symbolicGoalReplays", None) + symbolic = terminal_result.get("symbolic") + trace = symbolic.get("edgeGuidance") if symbolic else None + if trace: + terminal_trace = dict(trace, replays=[row for row in trace.get("replays", []) + if not row.get("crossedBeforeCompletion")]) + terminal_result["symbolic"] = dict(symbolic, edgeGuidance=terminal_trace) + return replay_inputs(dict(artifact, result=terminal_result)) + + def campaign(options, case, prepared, folder, mode, seed, budget, *, replay_symbolic=True): folder.mkdir() request = folder / "request.json" @@ -244,7 +258,7 @@ def campaign(options, case, prepared, folder, mode, seed, budget, *, replay_symb pbt["omitted"] = missing cell["batches"]["pbt"] = pbt if mode != "PBT_ONLY" and replay_symbolic: - batches, omissions = replay_inputs(artifact) + batches, omissions = terminal_replay_inputs(artifact) symbolic = next((batch for batch in batches if batch["id"] == "symbolic"), None) if symbolic is not None: verified = replay(options, case, prepared, symbolic, folder) diff --git a/usvm-ts-fast-check/experiments/public-operations/test_run.py b/usvm-ts-fast-check/experiments/public-operations/test_run.py index de63ec2322..e4d165606a 100644 --- a/usvm-ts-fast-check/experiments/public-operations/test_run.py +++ b/usvm-ts-fast-check/experiments/public-operations/test_run.py @@ -1,5 +1,6 @@ import unittest from copy import deepcopy +from unittest.mock import patch import run from crossed_replay import crossed_inputs @@ -88,6 +89,21 @@ def test_grants_coverage_only_to_confirmed_unique_source_bound_crossings(self): result["symbolicGoalReplays"] = [] self.assertEqual(crossed_inputs(result, case, [])[1]["omitted"], 1) + def test_terminal_parser_sees_neither_crossed_records_nor_their_confirmation_trace(self): + crossed = {"crossedBeforeCompletion": True, "inputs": ["crossed"]} + terminal = {"crossedBeforeCompletion": False, "inputs": ["terminal"]} + original = {"result": {"symbolicGoalReplays": [{"receipt": "crossed"}], + "symbolicInputReplays": [{"receipt": "terminal"}], + "symbolic": {"edgeGuidance": {"replays": [crossed, terminal]}}}} + snapshot = deepcopy(original) + expected = {"result": {"symbolicInputReplays": [{"receipt": "terminal"}], + "symbolic": {"edgeGuidance": {"replays": [terminal]}}}} + + with patch.object(run, "replay_inputs", return_value=([], {})) as shared: + self.assertEqual(run.terminal_replay_inputs(original), ([], {})) + shared.assert_called_once_with(expected) + self.assertEqual(original, snapshot) + def test_original_coverage_includes_crossed_ids_and_keeps_missing_crossings_partial(self): def batch(ids, omitted=0): return {"ids": ids, "offered": len(ids), "verified": len(ids), "failed": 0, "omitted": omitted}