"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(report-audit): fail closed when nothing was verified; unusable fetches fail, not vanish
cgycoreyfc780704cce0
diff --git a/agent/src/tools/report_audit_tool.py b/agent/src/tools/report_audit_tool.pyindex 93c654e44..7ecba1d39 100644--- a/agent/src/tools/report_audit_tool.py+++ b/agent/src/tools/report_audit_tool.py@@ -272,7 +272,9 @@ def render_verdict(results: list[dict[str, Any]], report_name: str = "") -> dictA point whose ``reported_value`` is missing, ``None``, or non-finite isunverifiable, so it fails with an explicit ``reason`` instead of being- treated as a reported zero. A genuine reported ``0`` stays valid.+ treated as a reported zero. A genuine reported ``0`` stays valid. A+ supplied but non-finite ``fetched_value`` fails the point the same way+ (unverifiable evidence), while an absent one is skipped as "not verified".Args:results: List of verification objects — ``{id, label, reported_value,@@ -281,7 +283,10 @@ def render_verdict(results: list[dict[str, Any]], report_name: str = "") -> dictreport_name: Optional report name for display.Returns:- Verdict dict: ``verdict`` is ``PASS`` (zero failures) or ``FAIL``.+ Verdict dict: ``verdict`` is ``PASS`` (zero failures, at least one+ verified point) or ``FAIL``. A call in which nothing was verified+ fails closed — a report certified with zero evidence is the failure+ mode this gate exists to prevent."""fail_items: list[dict[str, Any]] = []warn_items: list[dict[str, Any]] = []@@ -289,9 +294,33 @@ def render_verdict(results: list[dict[str, Any]], report_name: str = "") -> dicttotal = 0for item in results:- fetched = item.get("fetched_value")+ raw_fetched = item.get("fetched_value")+ if raw_fetched is None:+ continue # not verified — skip, do not count (pinned design)+ # Coerce through _finite_number so a non-numeric fetched value (a+ # string, NaN, …) is treated as unusable evidence, not a crash.+ fetched = _finite_number(raw_fetched)if fetched is None:- continue # not verified — skip, do not count+ # Supplied but unusable is NOT "not verified" (which is silently+ # skipped): fail the point. Otherwise a junk fetch could be used+ # to drop a hard-to-verify number from the audit entirely.+ total += 1+ label = item.get("label", "?")+ fail_items.append({+ "id": item.get("id"), "label": label,+ "reported": _finite_number(item.get("reported_value")),+ "unit": item.get("unit", ""),+ "fetched": None, "source": item.get("fetched_source", "?"),+ "fetched2": None, "source2": item.get("fetched_source2", ""),+ "diff1_pct": None, "diff2_pct": None,+ "reason": (+ f"fetched value is not a finite number ({raw_fetched!r}) "+ "— cannot verify"+ ),+ "raw_text": item.get("raw_text", ""),+ "line_number": item.get("line_number", 0),+ })+ continuetotal += 1label = item.get("label", "?")unit = item.get("unit", "")@@ -306,7 +335,7 @@ def render_verdict(results: list[dict[str, Any]], report_name: str = "") -> dictfail_items.append({"id": item.get("id"), "label": label,"reported": None, "unit": unit,- "fetched": _finite_number(fetched), "source": source,+ "fetched": fetched, "source": source,"fetched2": _finite_number(item.get("fetched_value2")),"source2": item.get("fetched_source2", ""),"diff1_pct": None, "diff2_pct": None,@@ -320,10 +349,11 @@ def render_verdict(results: list[dict[str, Any]], report_name: str = "") -> dict})continue- fetched = float(fetched)diff1 = _pct_diff(reported, fetched)- fetched2 = item.get("fetched_value2")+ # A non-finite second source is ignored (single-source semantics)+ # instead of crashing the verdict; a garbage source verifies nothing.+ fetched2 = _finite_number(item.get("fetched_value2"))source2 = item.get("fetched_source2", "")pass1 = diff1 <= _TOLERANCE@@ -344,7 +374,7 @@ def render_verdict(results: list[dict[str, Any]], report_name: str = "") -> dictelse:# Two sources: PASS only if both agree within tolerance; FAIL if# both miss; otherwise WARN (a caliber / GAAP mismatch, not a fail).- f2 = float(fetched2)+ f2 = fetched2 # already coerced finite abovediff2 = _pct_diff(reported, f2)pass2 = diff2 <= _TOLERANCEif pass1 and pass2:@@ -368,6 +398,18 @@ def render_verdict(results: list[dict[str, Any]], report_name: str = "") -> dict"diff2_pct": _pct_diff_for_json(diff2),})+ if total == 0:+ # Fail closed: zero verified points means the audit gathered no+ # evidence at all. Certifying that as PASS would let an unaudited+ # report — or an agent that fetched nothing — through the gate.+ fail_items.append({+ "id": None, "label": "audit", "reported": None, "unit": "",+ "fetched": None, "source": "", "fetched2": None, "source2": "",+ "diff1_pct": None, "diff2_pct": None,+ "reason": "no data points were verified — every result lacked a fetched_value",+ "raw_text": "", "line_number": 0,+ })+fail_count = len(fail_items)verdict = "PASS" if fail_count == 0 else "FAIL"return {diff --git a/agent/tests/test_report_audit_tool.py b/agent/tests/test_report_audit_tool.pyindex debf2e590..81fa225b9 100644--- a/agent/tests/test_report_audit_tool.py+++ b/agent/tests/test_report_audit_tool.py@@ -231,7 +231,70 @@ def test_verdict_skips_points_without_fetched_value() -> None:assert out["verdict"] == "PASS"-# ── tool contract ─────────────────────────────────────────────────────────+def test_verdict_zero_verified_points_fails_closed() -> None:+ """A verdict where NOTHING was verified must not certify the report."""+ out = render_verdict([+ {"id": 1, "label": "a", "reported_value": 100, "fetched_value": None},+ {"id": 2, "label": "b", "reported_value": 200, "fetched_value": None},+ ])+ assert out["verdict"] == "FAIL"+ assert out["total"] == 0+ assert out["fail_count"] == 1+ assert "no data points were verified" in out["fail_items"][0]["reason"]+++def test_verdict_garbage_fetched_value_fails_point() -> None:+ """A supplied-but-unusable fetched value fails the point, not a crash.++ Junk is NOT the same as an absent fetch: skipping it would let an agent+ drop a hard-to-verify number by padding it with a garbage fetch.+ """+ out = render_verdict([+ {"id": 1, "label": "a", "reported_value": 100,+ "fetched_value": "about 100", "fetched_source": "s"},+ ])+ assert out["verdict"] == "FAIL"+ assert out["total"] == 1+ assert out["fail_count"] == 1+ assert "fetched value is not a finite number" in out["fail_items"][0]["reason"]+++def test_verdict_garbage_fetch_cannot_pad_a_clean_report() -> None:+ """One good point does not launder a garbage-fetch sibling."""+ out = render_verdict([+ {"id": 1, "label": "good", "reported_value": 100,+ "fetched_value": 100, "fetched_source": "m"},+ {"id": 2, "label": "hard", "reported_value": 500,+ "fetched_value": "see above", "fetched_source": "s"},+ ])+ assert out["verdict"] == "FAIL"+ assert out["total"] == 2+ assert out["fail_count"] == 1+++def test_verdict_absent_fetched_with_good_point_still_passes() -> None:+ """Absent fetch is legitimately 'not verified' and stays skippable."""+ out = render_verdict([+ {"id": 1, "label": "a", "reported_value": 100, "fetched_value": None},+ {"id": 2, "label": "b", "reported_value": 100,+ "fetched_value": 100, "fetched_source": "m"},+ ])+ assert out["verdict"] == "PASS"+ assert out["total"] == 1+++def test_verdict_garbage_second_source_falls_back_to_single() -> None:+ """A non-finite second source degrades to single-source, not a crash."""+ out = render_verdict([+ {"id": 1, "label": "a", "reported_value": 100,+ "fetched_value": 100, "fetched_source": "m",+ "fetched_value2": "n/a", "fetched_source2": "x"},+ ])+ assert out["verdict"] == "PASS"+ assert out["total"] == 1+++# ── tool contract ─────────────────────────────────────────────────────def test_tool_metadata() -> None: