Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(grounding): preserve latest-date evidence timestamps

zeus2295d48e6f81b67
diff --git a/agent/src/agent/grounding/evidence.py b/agent/src/agent/grounding/evidence.py
index 72dedc9e6..93294e5bb 100644
--- a/agent/src/agent/grounding/evidence.py
+++ b/agent/src/agent/grounding/evidence.py
@@ -776,7 +776,7 @@ class _EvidenceMixin:
)
source = str(payload.get("source") or tool_name)
remaining = _MAX_GENERIC_EVIDENCE
- timestamp_fields = (*_TIMESTAMP_FIELDS, "as_of")
+ timestamp_fields = (*_TIMESTAMP_FIELDS, "latest_date", "as_of")
def visit(value: Any, path: str, timestamp: str | None = None) -> None:
nonlocal remaining
diff --git a/agent/tests/test_grounding_generic_timestamps.py b/agent/tests/test_grounding_generic_timestamps.py
index 9d8e28257..32a52d0b1 100644
--- a/agent/tests/test_grounding_generic_timestamps.py
+++ b/agent/tests/test_grounding_generic_timestamps.py
@@ -73,3 +73,85 @@ def test_generic_quote_without_timestamp_stays_undated(tmp_path: Path) -> None:
assert result.valid is False
assert [issue["code"] for issue in result.issues] == ["numeric_claim_unavailable"]
+
+def test_generic_snapshot_inherits_latest_date(tmp_path: Path) -> None:
+ ledger = GroundingLedger(
+ run_dir=tmp_path,
+ user_message="Show AAPL.US technical indicators by date",
+ )
+ ledger.ingest_tool_result(
+ tool_name="technical_indicators",
+ arguments={"symbol": "AAPL.US"},
+ result=json.dumps(
+ {
+ "ok": True,
+ "symbol": "AAPL.US",
+ "interval": "1d",
+ "latest_close": 214.0,
+ "latest_date": "2026-08-04",
+ "indicators": {
+ "rsi_14": 55.2,
+ "sma_20": 210.5,
+ "macd": {
+ "macd_line": 1.2,
+ "signal_line": 0.9,
+ "histogram": 0.3,
+ },
+ "volume": {
+ "latest": 1_500_000.0,
+ "sma_20": 1_250_000.0,
+ "ratio_20": 1.2,
+ },
+ },
+ }
+ ),
+ call_id="indicators",
+ success=True,
+ )
+
+ artifact = json.loads(
+ (tmp_path / "artifacts" / "grounding_evidence.json").read_text(encoding="utf-8")
+ )
+ timestamp_by_field = {
+ row["field"]: row["timestamp"]
+ for row in artifact["evidence"]
+ if row["tool"] == "technical_indicators"
+ }
+
+ assert timestamp_by_field["latest_close"] == "2026-08-04"
+ assert timestamp_by_field["indicators.rsi_14"] == "2026-08-04"
+ assert timestamp_by_field["indicators.sma_20"] == "2026-08-04"
+ assert timestamp_by_field["indicators.macd.macd_line"] == "2026-08-04"
+ assert timestamp_by_field["indicators.volume.latest"] == "2026-08-04"
+ assert timestamp_by_field["indicators.volume.sma_20"] == "2026-08-04"
+ assert timestamp_by_field["indicators.volume.ratio_20"] == "2026-08-04"
+
+
+def test_generic_latest_date_beats_as_of_but_local_date_wins(tmp_path: Path) -> None:
+ ledger = _ledger(
+ tmp_path,
+ {
+ "source": "external",
+ "as_of": "2026-08-05T09:00:00Z",
+ "latest_date": "2026-08-04",
+ "snapshot": {"close": 214.0},
+ "rows": [
+ {"trade_date": "2026-08-03", "close": 212.5},
+ {"date": "2026-08-04", "close": 214.0},
+ ],
+ },
+ )
+
+ artifact = json.loads(
+ (tmp_path / "artifacts" / "grounding_evidence.json").read_text(encoding="utf-8")
+ )
+ timestamp_by_field = {
+ row["field"]: row["timestamp"]
+ for row in artifact["evidence"]
+ if row["tool"] == "external_market_tool"
+ }
+
+ assert timestamp_by_field["snapshot.close"] == "2026-08-04"
+ assert timestamp_by_field["rows[0].close"] == "2026-08-03"
+ assert timestamp_by_field["rows[1].close"] == "2026-08-04"
+