Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(live): restore the market field default on non-market triggers

ImSevenstarse58173b58ffa
diff --git a/agent/src/live/runtime/triggers.py b/agent/src/live/runtime/triggers.py
index 40bf69826..da6611ae9 100644
--- a/agent/src/live/runtime/triggers.py
+++ b/agent/src/live/runtime/triggers.py
@@ -175,9 +175,14 @@ class Trigger:
return cls(kind=TriggerKind.INTERVAL, interval_ms=interval_ms, epoch_ms=epoch_ms)
@classmethod
- def market(cls, market: str) -> "Trigger":
+ def _market(cls, market: str) -> "Trigger":
"""Build a market-session trigger for a known market key.
+ Declared under a private name on purpose: ``market`` is a **field**, and
+ a classmethod of that name in this body would replace the field's
+ ``None`` default before ``@dataclass`` reads it. The public
+ ``Trigger.market`` is bound after the class body — see the note there.
+
Args:
market: A key into :data:`MARKET_SPECS` (e.g. ``"us_equity"``).
@@ -205,6 +210,21 @@ class Trigger:
return cls(kind=TriggerKind.EVENT, predicate=predicate)
+# ``market`` is both a dataclass field (default ``None``) and the MARKET
+# constructor. A classmethod of that name declared *inside* the class body
+# replaces the field's default before ``@dataclass`` reads it, so every
+# INTERVAL/EVENT trigger carried the bound method in ``market``. That is
+# invisible to :func:`due_now`, which reads ``market`` only for MARKET
+# triggers, but it is wrong in ``repr`` and fatal to ``dataclasses.asdict`` and
+# JSON — the shape run cards and live audit artifacts serialise.
+#
+# Binding the factory under its public name here, once the decorator has
+# already recorded the field, keeps both halves of the contract: the field
+# defaults to ``None`` and ``Trigger.market(...)`` still builds a MARKET
+# trigger.
+Trigger.market = Trigger._market # type: ignore[assignment]
+
+
# --------------------------------------------------------------------------- #
# Pure core #
# --------------------------------------------------------------------------- #
diff --git a/agent/tests/test_runtime_triggers.py b/agent/tests/test_runtime_triggers.py
index 9fb799593..846d32b96 100644
--- a/agent/tests/test_runtime_triggers.py
+++ b/agent/tests/test_runtime_triggers.py
@@ -7,6 +7,8 @@ epoch-millisecond instant and asserted deterministically.
from __future__ import annotations
+import dataclasses
+import json
from datetime import datetime, timezone
from typing import Mapping
@@ -123,6 +125,37 @@ def test_market_trigger_without_market_raises() -> None:
due_now(bad, 0)
+def test_non_market_triggers_leave_market_unset() -> None:
+ """``market`` is ``None`` on INTERVAL/EVENT triggers, not the factory.
+
+ ``Trigger.market`` is both a dataclass field and the MARKET constructor.
+ Declared inside the class body the constructor replaces the field's
+ ``None`` default before ``@dataclass`` reads it, so every INTERVAL/EVENT
+ trigger carried a bound method in ``market``. That is invisible to
+ :func:`due_now` (which only inspects ``market`` for MARKET triggers) but
+ wrong wherever the field is read or serialised on its own.
+ """
+ assert Trigger.interval(60_000).market is None
+ assert Trigger.event(lambda _state: True).market is None
+
+ # The MARKET factory keeps its public name and still fills the field.
+ assert Trigger.market("us_equity").market == "us_equity"
+
+
+def test_interval_trigger_serialises_to_json() -> None:
+ """An INTERVAL trigger must survive ``dataclasses.asdict`` + ``json.dumps``.
+
+ Run cards and live audit artifacts serialise the descriptors they carry.
+ ``market`` held a bound method before the field default was restored, which
+ made that raise ``TypeError``.
+
+ EVENT triggers are deliberately out of scope: their ``predicate`` is a
+ callable by design, so they are not a serialisable shape in the first place.
+ """
+ restored = json.loads(json.dumps(dataclasses.asdict(Trigger.interval(60_000))))
+ assert restored["market"] is None
+
+
# --------------------------------------------------------------------------- #
# due_now — INTERVAL #
# --------------------------------------------------------------------------- #