Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(scheduling): preserve async cleanup across concurrent stops

Haozhe Wu747984ea224f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a317d5b1a..88091910f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,21 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## [Unreleased]
+### Maintenance — 2026-10-18
+
+- Preserve explicit zero financial-rigor parameters and hypothesis backtest
+ validation evidence; accept Shanghai ETF `.SS` aliases (#1906, #1902, #1907).
+- Respect `VIBE_TRADING_HOME` for autopilot runs, alpha-bench caches/reports and
+ Gildata code mappings; keep overflowed Calmar ratios finite, consistent with
+ the existing risk-ratio fallback (#1904, #1901).
+- Tolerate incomplete JSON/UTF-8 Swarm event tails while still rejecting complete
+ invalid records. Deliver Matrix final replies when preview sending failed;
+ CI installs the Matrix extra and executes the regression (#1908, #1903).
+- Match explicit currency identities to financial evidence, including SEC XBRL
+ units and magnitude-scaled amounts. Bare `$` and `¥` remain ambiguous (#1905).
+- Adopt the shared scheduler kernel for live scheduling with adaptive wakeups;
+ concurrent stops await cleanup without cancelling it a second time (#1899).
+
### Maintenance — 2026-10-17
- Surface provider-reported LLM usage and cache counts in Run Detail, live chat
diff --git a/agent/src/scheduling/kernel.py b/agent/src/scheduling/kernel.py
index ee7bd29fc..11074846b 100644
--- a/agent/src/scheduling/kernel.py
+++ b/agent/src/scheduling/kernel.py
@@ -232,10 +232,13 @@ class SchedulerKernel:
task = self._task
if task is None:
return
- self._stopping = True
- if self._wakeup is not None:
- self._wakeup.set()
- task.cancel()
+ if not self._stopping:
+ self._stopping = True
+ if self._wakeup is not None:
+ self._wakeup.set()
+ # A second cancellation interrupts the tick's async finally block.
+ # Concurrent callers share the first cancellation and await cleanup.
+ task.cancel()
try:
await task
except asyncio.CancelledError:
diff --git a/agent/tests/scheduling/test_kernel_concurrent_stop.py b/agent/tests/scheduling/test_kernel_concurrent_stop.py
new file mode 100644
index 000000000..07aae05cc
--- /dev/null
+++ b/agent/tests/scheduling/test_kernel_concurrent_stop.py
@@ -0,0 +1,34 @@
+"""Concurrent shutdown callers must not interrupt a tick's cleanup."""
+import asyncio
+
+from src.scheduling.kernel import SchedulerKernel
+
+
+def test_concurrent_stops_wait_for_cleanup_without_recancelling():
+ async def scenario():
+ entered, cleaning, release = asyncio.Event(), asyncio.Event(), asyncio.Event()
+ cleaned = []
+
+ async def tick(now):
+ entered.set()
+ try:
+ await asyncio.Event().wait()
+ finally:
+ cleaning.set()
+ await release.wait()
+ cleaned.append(True)
+
+ kernel = SchedulerKernel(on_tick=tick)
+ kernel.start()
+ await asyncio.wait_for(entered.wait(), 1)
+ first = asyncio.create_task(kernel.stop())
+ await asyncio.wait_for(cleaning.wait(), 1)
+ second = asyncio.create_task(kernel.stop())
+ await asyncio.sleep(0)
+ await asyncio.sleep(0)
+ release.set()
+ await asyncio.wait_for(asyncio.gather(first, second), 1)
+ assert cleaned == [True]
+ assert kernel.task is None
+
+ asyncio.run(scenario())