From 87db6a8a2baa8bf93bf00a4338e7eaba279e4529 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Thu, 25 Jun 2026 01:57:12 -0700 Subject: [PATCH] [eric] agents: drop orphaned compaction comment block (code moved in refactor) + tighten a 15-line narrow-wrapped comment to 3 --- backend/apps/agents/agent_manager.py | 21 ------------------- .../manager/streaming/handle_stream_event.py | 18 +++------------- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/backend/apps/agents/agent_manager.py b/backend/apps/agents/agent_manager.py index af049e1a..5dfae80f 100644 --- a/backend/apps/agents/agent_manager.py +++ b/backend/apps/agents/agent_manager.py @@ -50,27 +50,6 @@ class AgentManager(SessionLifecycle, SessionPersistence, Messaging, SessionContr self.cancel_events: Dict[str, asyncio.Event] = {} - - - # ------------------------------------------------------------------ - # Compaction & token guard (Phase 2) - # - # Triggered by *live* context-usage ratio, not turn count. The signal - # is the same `ctx_used_pct` we already broadcast to the UI on every - # turn: input_tokens / context_window. Three escalating thresholds: - # - compact_threshold_pct (default 0.65): summarize stale tool_results - # and old user/assistant pairs before the next query() call - # - context_soft_cap_pct (default 0.90): pre-send hard guard. After - # compaction, if still over, LRU-trim active_mcps - # - >= 1.0 hits the proxy/Anthropic 200K ceiling, friendly card - # surfaces from the catch-all - # ------------------------------------------------------------------ - - - - - - @typechecked async def run_agent_loop(self, session_id: str, prompt: str, images: Optional[List] = None, context_paths: Optional[List] = None, forced_tools: Optional[List[str]] = None, attached_skills: Optional[List] = None, fork_session: bool = False, selected_browser_ids: Optional[List[str]] = None, selected_app_output_ids: Optional[List[str]] = None, selected_setting_ids: Optional[List[str]] = None): """Run the Claude Agent SDK query loop for a session.""" diff --git a/backend/apps/agents/manager/streaming/handle_stream_event.py b/backend/apps/agents/manager/streaming/handle_stream_event.py index 085bd227..bfdbb627 100644 --- a/backend/apps/agents/manager/streaming/handle_stream_event.py +++ b/backend/apps/agents/manager/streaming/handle_stream_event.py @@ -80,21 +80,9 @@ async def handle_stream_event( tool_msg_id = uuid4().hex turn.stream_tool_msg_ids_ordered.append(tool_msg_id) turn.stream_block_index_map[index] = tool_msg_id - # Stream-level tool count for the - # consolidated thinking pill. The - # AssistantMessage path (further down) - # ALSO increments turn.tool_count when - # ToolUseBlocks fully arrive, but for - # OpenAI/Gemini through 9Router the - # AssistantMessage envelope is sometimes - # incomplete, so this stream-level count - # is what guarantees the "N tools used" - # segment renders cross-provider. To - # avoid double-counting we DON'T also - # increment on AssistantMessage when - # this code path already fired, see - # the dedupe at the AssistantMessage - # block below. + # Stream-level tool count for the thinking pill. OpenAI/Gemini-through-9Router + # AssistantMessage envelopes are sometimes incomplete, so this stream count guarantees + # "N tools used" renders cross-provider; the AssistantMessage path dedupes against it. turn.tool_count += 1 await ws_manager.send_to_session(session_id, "agent:stream_start", { "session_id": session_id,