"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(memory): read offset-less frontmatter timestamps as utc
Rudy Celekli7499ef36f0f8
diff --git a/agent/src/memory/persistent.py b/agent/src/memory/persistent.pyindex 37f5a5250..f67b48c09 100644--- a/agent/src/memory/persistent.py+++ b/agent/src/memory/persistent.py@@ -10,7 +10,7 @@ import sysimport time as _timefrom contextlib import contextmanagerfrom dataclasses import dataclass-from datetime import datetime+from datetime import datetime, timezonefrom pathlib import Pathfrom typing import Generator, List, Optional@@ -192,6 +192,9 @@ def _parse_timestamp(value: object, fallback: float) -> float:if isinstance(value, str):try:dt = datetime.fromisoformat(value.replace("Z", "+00:00"))+ if dt.tzinfo is None:+ # Memory writers stamp time.gmtime() without an offset.+ dt = dt.replace(tzinfo=timezone.utc)return dt.timestamp()except (ValueError, TypeError):passdiff --git a/agent/tests/test_persistent_memory.py b/agent/tests/test_persistent_memory.pyindex 8a05da56b..1ed19923c 100644--- a/agent/tests/test_persistent_memory.py+++ b/agent/tests/test_persistent_memory.py@@ -663,3 +663,24 @@ class TestMemoryEntryNewFields:assert len(entries) == 1assert entries[0].category == "user"assert entries[0].compression_level == "daily"+++def test_offsetless_frontmatter_timestamp_is_read_as_utc(monkeypatch) -> None:+ """Writers stamp ``time.gmtime()`` with no offset; reading it back must not+ shift it by the host's UTC offset."""+ import time+ from datetime import datetime, timezone++ from src.memory.persistent import _parse_timestamp++ monkeypatch.setenv("TZ", "Asia/Shanghai")+ time.tzset()+ try:+ stamp = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(1_800_000_000))+ assert _parse_timestamp(stamp, 0.0) == 1_800_000_000+ assert _parse_timestamp("2026-01-01T00:00:00", 0.0) == datetime(+ 2026, 1, 1, tzinfo=timezone.utc+ ).timestamp()+ finally:+ monkeypatch.undo()+ time.tzset()