"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(channels): dedupe progress against what the channel shows
alex4282bc0ae845
diff --git a/agent/src/channels/attempt_progress.py b/agent/src/channels/attempt_progress.pyindex 4e218839a..e30e4c900 100644--- a/agent/src/channels/attempt_progress.py+++ b/agent/src/channels/attempt_progress.py@@ -1,7 +1,7 @@"""Forward attempt status to IM adapters without releasing unchecked answers."""from __future__ import annotations-from typing import Any+from typing import Any, Callablefrom src.channels.bus.events import InboundMessage, OutboundMessage@@ -10,12 +10,14 @@ class AttemptProgress:"""Poll buffered session events with an attempt-scoped replay cursor."""def __init__(self, bus: Any, event_bus: Any, msg: InboundMessage,- session_id: str, attempt_id: str) -> None:+ session_id: str, attempt_id: str,+ is_visible: Callable[..., bool] | None = None) -> None:self.bus = busself.events = event_busself.msg = msgself.session_id = session_idself.attempt_id = attempt_id+ self.is_visible = is_visibleself.cursor: str | None = Noneself.streaming = bool(msg.metadata.get("_wants_stream"))self.stream_started = False@@ -67,10 +69,14 @@ class AttemptProgress:}.get(kind)# Arbitrary progress payloads, tool results and text_delta may# contain unvalidated figures. Only these status labels go out.+ hint = kind in {"tool_call", "tool_heartbeat"}if not status or status == self.last_status:continue+ # A status the channel hides must not become last_status, or the+ # next visible repeat of the previous status is not deduped.+ if self.is_visible is not None and not self.is_visible(tool_hint=hint):+ continueself.last_status = status- hint = kind in {"tool_call", "tool_heartbeat"}flags = {"_progress": True, "_tool_hint": hint}if self.streaming:flags["_stream_delta"] = Truediff --git a/agent/src/channels/manager.py b/agent/src/channels/manager.pyindex e9cdac817..ea85fab15 100644--- a/agent/src/channels/manager.py+++ b/agent/src/channels/manager.py@@ -223,7 +223,7 @@ class ChannelManager:name,)- def _should_send_progress(self, channel_name: str, *, tool_hint: bool = False) -> bool:+ def should_send_progress(self, channel_name: str, *, tool_hint: bool = False) -> bool:"""Return whether progress (or tool-hints) may be sent to *channel_name*."""ch = self.channels.get(channel_name)if ch is None:@@ -485,15 +485,10 @@ class ChannelManager:continue# Progress / tool-hint filtering- if msg.metadata.get("_progress"):- if msg.metadata.get("_tool_hint") and not self._should_send_progress(- msg.channel, tool_hint=True,- ):- continue- if not msg.metadata.get("_tool_hint") and not self._should_send_progress(- msg.channel, tool_hint=False,- ):- continue+ if msg.metadata.get("_progress") and not self.should_send_progress(+ msg.channel, tool_hint=bool(msg.metadata.get("_tool_hint")),+ ):+ continueif msg.metadata.get("_retry_wait"):continuediff --git a/agent/src/channels/runtime.py b/agent/src/channels/runtime.pyindex 037a00dab..46b75bbdc 100644--- a/agent/src/channels/runtime.py+++ b/agent/src/channels/runtime.py@@ -9,6 +9,7 @@ import timefrom contextlib import suppressfrom collections.abc import Iterable, Mappingfrom dataclasses import dataclass+from functools import partialfrom pathlib import Pathfrom typing import Any@@ -195,7 +196,10 @@ class ChannelRuntime:from src.channels.attempt_progress import AttemptProgressevents = getattr(self.session_service, "event_bus", None)- progress = (AttemptProgress(self.bus, events, msg, session_id, attempt_id)+ is_visible = (partial(self.manager.should_send_progress, msg.channel)+ if self.manager is not None else None)+ progress = (AttemptProgress(self.bus, events, msg, session_id, attempt_id,+ is_visible=is_visible)if events is not None and attempt_id else None)try:reply = await self._wait_for_reply(session_id, attempt_id, progress=progress)diff --git a/agent/tests/test_channels_attempt_progress.py b/agent/tests/test_channels_attempt_progress.pyindex d74d229c4..00f219453 100644--- a/agent/tests/test_channels_attempt_progress.py+++ b/agent/tests/test_channels_attempt_progress.py@@ -1,5 +1,6 @@"""Session events reach IM during a run, without leaking unchecked answers."""import asyncio+from types import SimpleNamespacefrom unittest.mock import Mockfrom src.channels.bus.events import InboundMessage@@ -114,3 +115,45 @@ def test_real_reasoning_tails_are_incremental_and_redaction_stays_private():assert any(m.content == "Reasoning…\n" for m in sent)assert any(m.content == "Waiting for the model…\n" for m in sent)asyncio.run(scenario())+++def test_hidden_tool_hints_do_not_break_status_dedupe():+ from src.channels.attempt_progress import AttemptProgress++ async def scenario():+ bus, events = MessageBus(), EventBus()+ message = InboundMessage(channel="feishu", chat_id="c", sender_id="u", content="q", metadata={})+ progress = AttemptProgress(bus, events, message, "s", "a",+ is_visible=lambda *, tool_hint: not tool_hint)+ for kind, data in [+ ("llm_waiting", {"iter": 1}),+ ("tool_call", {"tool": "session_search"}),+ ("llm_waiting", {"iter": 2}),+ ("tool_call", {"tool": "read_file"}),+ ("llm_waiting", {"iter": 3}),+ ]:+ events.emit("s", kind, {**data, "attempt_id": "a"})+ await progress.poll()+ sent = []+ while bus.outbound_size:+ sent.append(await bus.consume_outbound())+ assert [m.content for m in sent] == ["Waiting for the model…\n"]+ asyncio.run(scenario())+++def test_runtime_applies_the_channel_progress_settings(tmp_path):+ async def scenario():+ bus, service = MessageBus(), _Service()+ manager = ChannelManager({}, bus)+ # Channel defaults: progress shown, tool hints hidden.+ manager.channels['feishu'] = SimpleNamespace(send_progress=True, send_tool_hints=False)+ runtime = ChannelRuntime(bus=bus, session_service=service, manager=manager,+ session_map_path=tmp_path/'sessions.json', poll_interval_s=.001)+ service.messages.append(Message(session_id='s', role='assistant', content='Checked answer', linked_attempt_id='a'))+ await runtime._handle_inbound(InboundMessage(channel='feishu', chat_id='c', sender_id='u', content='q', metadata={}))+ contents = []+ while bus.outbound_size:+ contents.append((await bus.consume_outbound()).content)+ assert 'Working on your request…\n' in contents+ assert not any('Using get_market_data' in c for c in contents)+ asyncio.run(scenario())