Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(agent): preserve strategy provenance after rebase

Haozhe Wudf7bfd92c871
diff --git a/agent/src/agent/loop.py b/agent/src/agent/loop.py
index 754a0177d..53d4b0c4a 100644
--- a/agent/src/agent/loop.py
+++ b/agent/src/agent/loop.py
@@ -2938,10 +2938,54 @@ class AgentLoop:
if not p.is_absolute() and self.memory.run_dir:
p = Path(self.memory.run_dir) / p
try:
- self._written_files.add(str(p.resolve()).casefold())
+ resolved = p.resolve()
+ self._written_files.add(str(resolved).casefold())
except (OSError, ValueError):
+ resolved = p
self._written_files.add(str(p).casefold())
+ if not self.memory.run_dir:
+ return
+ run_root = Path(self.memory.run_dir).resolve()
+ try:
+ relative = resolved.relative_to(run_root).as_posix()
+ except ValueError:
+ return
+ if relative not in {"config.json", "code/signal_engine.py"}:
+ return
+
+ metadata_path = run_root / "strategy_provenance.json"
+ try:
+ metadata = json.loads(metadata_path.read_text(encoding="utf-8"))
+ except FileNotFoundError:
+ files = {}
+ except (OSError, json.JSONDecodeError) as exc:
+ logger.warning(
+ "Could not read strategy model provenance; update skipped: %s",
+ exc,
+ )
+ return
+ else:
+ if not isinstance(metadata, dict):
+ logger.warning("Invalid strategy model provenance; update skipped.")
+ return
+ files = metadata.get("files", {})
+ if not isinstance(files, dict):
+ logger.warning("Invalid strategy model provenance files; update skipped.")
+ return
+ files[relative] = {
+ "provider": self._llm_runtime.provider or None,
+ "model_id": self._active_model_id or None,
+ "model_source": self._active_model_source,
+ }
+ try:
+ metadata_path.write_text(
+ json.dumps({"files": files}, ensure_ascii=False, sort_keys=True) + "\n",
+ encoding="utf-8",
+ )
+ except OSError as exc:
+ logger.warning("Could not write strategy model provenance: %s", exc)
+
def _pending_write_directive(
self, user_message: str, run_started_wall: float
) -> str:
diff --git a/agent/tests/test_run_card_content_filter.py b/agent/tests/test_run_card_content_filter.py
index 4a121d644..b09ef2bf7 100644
--- a/agent/tests/test_run_card_content_filter.py
+++ b/agent/tests/test_run_card_content_filter.py
@@ -18,6 +18,7 @@ def test_content_filter_warnings_surfaced_in_run_card(tmp_path: Path) -> None:
"end_date": "2025-01-06",
"source": "yfinance",
"engine": "options",
+ "model_training_cutoff": "2020-01-01",
"content_filter_warnings": [
"3/10 LLM responses (30%) were blocked by content moderation."
" Consider switching to a provider with less aggressive filtering"
@@ -50,6 +51,7 @@ def test_no_content_filter_warnings_yields_empty_warnings(tmp_path: Path) -> Non
"end_date": "2025-02-01",
"source": "yfinance",
"engine": "daily",
+ "model_training_cutoff": "2020-01-01",
}
warnings = config.get("content_filter_warnings") or None
@@ -113,6 +115,7 @@ def test_options_engine_surfaces_content_filter_warnings(tmp_path: Path) -> None
"source": "yfinance",
"engine": "options",
"initial_cash": 100_000,
+ "model_training_cutoff": "2020-01-01",
"content_filter_warnings": [
"2/10 LLM responses (20%) were blocked by content moderation."
" Consider switching to a provider with less aggressive filtering"
@@ -177,6 +180,7 @@ def test_options_engine_no_warnings_yields_empty(tmp_path: Path) -> None:
"source": "yfinance",
"engine": "options",
"initial_cash": 100_000,
+ "model_training_cutoff": "2020-01-01",
},
FakeLoader(),
SignalEngine(),
diff --git a/agent/tests/test_run_card_structured_metrics.py b/agent/tests/test_run_card_structured_metrics.py
index f2f1a6426..7455bf17e 100644
--- a/agent/tests/test_run_card_structured_metrics.py
+++ b/agent/tests/test_run_card_structured_metrics.py
@@ -120,7 +120,13 @@ def test_engine_warnings_are_not_mistaken_for_the_card_warnings(tmp_path: Path)
engine_warnings = ["Annual return requires at least two observations."]
card = write_run_card(
tmp_path,
- {"codes": ["SPY"], "source": "auto"},
+ {
+ "codes": ["SPY"],
+ "source": "auto",
+ "start_date": "2025-01-01",
+ "end_date": "2025-01-02",
+ "model_training_cutoff": "2020-01-01",
+ },
{"sharpe": None, "warnings": engine_warnings},
warnings=["from config: content filter"],
)