"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix: correlation codes, macOS timeouts, paper messages, sdist tests
Haozhe Wu300c6960b30a
diff --git a/MANIFEST.in b/MANIFEST.inindex e0d6b8a4b..0e26ceda8 100644--- a/MANIFEST.in+++ b/MANIFEST.in@@ -17,11 +17,16 @@ include agent/.env.example# Alpha Zoo factor metadata and per-zoo LICENSE / NOTICE filesrecursive-include agent/src/factors *.yaml *.md-# Tests shipped so dev installs can run `pytest` against the package.-# Files prefixed with `_` are local debug scripts kept untracked — keep-# them out of the sdist even if present in the working tree.-recursive-include agent/tests *.py+# Tests shipped so dev installs can run `pytest` against the package, with+# the CSV / JSON fixtures they read. Files prefixed with `_` are local debug+# scripts and `test_e2e_*.py` local live harnesses, both kept untracked — keep+# them out of the sdist even if present in the working tree. `_*.py` also+# matches `__init__.py`, which the package-style test directories need, so it+# is re-included last.+recursive-include agent/tests *.py *.csv *.jsonrecursive-exclude agent/tests _*.py+recursive-exclude agent/tests test_e2e_*.py+recursive-include agent/tests __init__.py# Strip generated / VCS / editor noiseglobal-exclude __pycache__diff --git a/agent/backtest/correlation.py b/agent/backtest/correlation.pyindex bf8fa81d3..1a3acfb2d 100644--- a/agent/backtest/correlation.py+++ b/agent/backtest/correlation.py@@ -137,11 +137,13 @@ def _normalize_symbol(code: str, market: str) -> str:if market == "hk_equity":return f"{upper.zfill(4)}.HK"if market == "a_share":- # 6xxxxx -> Shanghai; 4xxxxx / 8xxxxx -> Beijing; else (0/3) Shenzhen.- if upper[:1] == "6":- return f"{upper}.SH"- if upper[:1] in ("4", "8"):+ # Same prefix rule as ``tools.tushare_fallbacks._ts_code``: Beijing+ # 4xxxxx / 8xxxxx / 920xxx (checked before the Shanghai 9 prefix),+ # Shanghai 5xxxxx funds / 6xxxxx / 9xxxxx B shares, else Shenzhen.+ if upper.startswith(("4", "8", "920")):return f"{upper}.BJ"+ if upper.startswith(("5", "6", "9")):+ return f"{upper}.SH"return f"{upper}.SZ"return cleaneddiff --git a/agent/src/tools/background_tools.py b/agent/src/tools/background_tools.pyindex ad9df0429..5e5f85652 100644--- a/agent/src/tools/background_tools.py+++ b/agent/src/tools/background_tools.py@@ -44,6 +44,12 @@ def _signal_posix_process_group(process: subprocess.Popen[str], sig: int) -> Nonos.killpg(process.pid, sig)except ProcessLookupError:pass+ except PermissionError:+ # macOS answers EPERM, not ESRCH, when every member of the group has+ # exited but is not yet reaped (verified 2026-10-21). The group is our+ # own, so nothing is left to signal; letting it raise turned a timed-out+ # command into status "error" on a loaded host.+ passdef _taskkill_windows_process_tree(process: subprocess.Popen[str]) -> None:diff --git a/agent/src/tools/paper_trade/accounts.py b/agent/src/tools/paper_trade/accounts.pyindex dd963ee01..05666927f 100644--- a/agent/src/tools/paper_trade/accounts.py+++ b/agent/src/tools/paper_trade/accounts.py@@ -199,7 +199,7 @@ class PaperAccounts:):raise AccountConflict("Account changed; reload before advancing")now = self._now(account["market"])- _, hour, minute = _MARKET_TIME[account["market"]]+ zone, hour, minute = _MARKET_TIME[account["market"]]latest = now.date() - timedelta(days=int((now.hour, now.minute) < (hour, minute)))@@ -208,13 +208,18 @@ class PaperAccounts:earliest = (datetime.fromisoformat(account["last_date"]).date() + timedelta(days=1)).isoformat()+ if earliest > latest.isoformat():+ raise ValueError(+ f"No completed session to settle yet. Execution dates start at {earliest}; "+ f"a session can be settled from {hour:02d}:{minute:02d} {zone} time"+ )if (not isinstance(to_date, str)or not earliest <= to_date <= latest.isoformat()):raise ValueError(f"Execution date must be between {earliest} and {latest.isoformat()}; "- "wait for a completed session after account creation"+ "later dates wait for a completed session")payload = {"account_id": account_id,diff --git a/agent/tests/test_background_tools.py b/agent/tests/test_background_tools.pyindex 424701285..e08aafcf9 100644--- a/agent/tests/test_background_tools.py+++ b/agent/tests/test_background_tools.py@@ -345,3 +345,35 @@ def test_timeout_kills_descendant_and_reaps_shell(assert processes[0].poll() is not Nonetime.sleep(1.0)assert not orphan_marker.exists()++[email protected](os.name == "nt", reason="POSIX process-group regression")+def test_signalling_a_group_that_only_holds_unreaped_children_is_not_an_error() -> None:+ """macOS answers EPERM for a group whose members exited but are unreaped."""+ import subprocess++ process = subprocess.Popen(["sh", "-c", "exit 0"], start_new_session=True)+ try:+ time.sleep(0.5)+ background_tools._signal_posix_process_group(process, __import__("signal").SIGKILL)+ finally:+ process.wait()++[email protected](os.name == "nt", reason="POSIX process-group regression")+def test_timeout_stays_timeout_when_the_final_group_signal_is_refused(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ real_killpg = os.killpg++ def killpg(pid: int, sig: int) -> None:+ if sig == __import__("signal").SIGKILL:+ raise PermissionError(1, "Operation not permitted")+ real_killpg(pid, sig)++ monkeypatch.setattr(background_tools, "_COMMAND_TIMEOUT_SECONDS", 0.5)+ monkeypatch.setattr(background_tools.os, "killpg", killpg)+ manager = BackgroundManager()+ task = _execute(manager, "slow", f"{shlex.quote(sys.executable)} -c 'import time; time.sleep(5)'")++ assert task["status"] == "timeout"diff --git a/agent/tests/test_correlation.py b/agent/tests/test_correlation.pyindex aea5ffdce..13e78e621 100644--- a/agent/tests/test_correlation.py+++ b/agent/tests/test_correlation.py@@ -134,6 +134,16 @@ class TestNormalizeSymbol:assert _normalize_symbol("300750", "a_share") == "300750.SZ"assert _normalize_symbol("830799", "a_share") == "830799.BJ"+ def test_bare_a_share_follows_the_tushare_prefix_rule(self):+ # Beijing's current 920xxx codes used to fall through to Shenzhen, and+ # so did Shanghai funds (5xxxxx) and B shares (9xxxxx).+ assert _normalize_symbol("920002", "a_share") == "920002.BJ"+ assert _normalize_symbol("430047", "a_share") == "430047.BJ"+ assert _normalize_symbol("510300", "a_share") == "510300.SH"+ assert _normalize_symbol("900901", "a_share") == "900901.SH"+ assert _normalize_symbol("200002", "a_share") == "200002.SZ"+ assert _normalize_symbol("159915", "a_share") == "159915.SZ"+def test_already_suffixed_passes_through(self):assert _normalize_symbol("AAPL.US", "us_equity") == "AAPL.US"assert _normalize_symbol("600000.SH", "a_share") == "600000.SH"diff --git a/agent/tests/test_paper_accounts.py b/agent/tests/test_paper_accounts.pyindex ce93d22e5..3b2038d06 100644--- a/agent/tests/test_paper_accounts.py+++ b/agent/tests/test_paper_accounts.py@@ -91,6 +91,18 @@ def test_no_backdating_future_or_incomplete_session(service):assert service.get(account["id"])["revision"] == 0+def test_an_account_with_no_settled_session_says_so_instead_of_an_inverted_range(service):+ account = create(service)+ service.clock = lambda: datetime(2026, 10, 20, 20, 10, tzinfo=timezone.utc)+ with pytest.raises(ValueError) as caught:+ service.advance(account["id"], expected_revision=0, to_date="2026-10-20", orders=[])+ message = str(caught.value)+ assert "No completed session to settle yet" in message+ assert "Execution dates start at 2026-10-20" in message+ assert "16:30 America/New_York" in message+ assert "between" not in message++def test_next_session_start_uses_market_timezone_and_skips_weekend(service):service.clock = lambda: datetime(2026, 10, 24, 1, tzinfo=timezone.utc