mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-02 14:28:59 +02:00
[eric] agents: strip the temporary TTFT probes (pool drift-diag stays, gated OPENSWARM_POOL_DIAG)
This commit is contained in:
@@ -28,7 +28,6 @@ from backend.apps.agents.manager.RunSupport import RunSupport
|
||||
from backend.apps.agents.manager.run.handle_run_error import handle_run_error
|
||||
from backend.apps.agents.manager.run.TurnRunner import TurnRunner
|
||||
from backend.apps.agents.manager.run.RunOptions import RunOptions
|
||||
from backend.apps.agents.manager.ttft_probe import ttft_probe
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -57,7 +56,6 @@ class AgentManager(SessionLifecycle, SessionPersistence, Messaging, SessionContr
|
||||
session = self.sessions.get(session_id)
|
||||
if not session:
|
||||
return
|
||||
ttft_probe(session_id, "loop_start", fork=fork_session, model=session.model, msgs=len(session.messages))
|
||||
|
||||
from backend.apps.agents.providers.registry import get_api_type as p_get_api_type
|
||||
p_api = p_get_api_type(session.model)
|
||||
@@ -65,7 +63,6 @@ class AgentManager(SessionLifecycle, SessionPersistence, Messaging, SessionContr
|
||||
prompt, images, context_paths, forced_tools, attached_skills,
|
||||
api_type=p_api, model=session.model,
|
||||
)
|
||||
ttft_probe(session_id, "prompt_built")
|
||||
|
||||
try:
|
||||
# SDK presence check: fall to mock mode here, before the options build, so a missing SDK is a clean mock run, not an error card. The real use is in run_options / turn_runner (lazy-imported there).
|
||||
@@ -98,7 +95,6 @@ class AgentManager(SessionLifecycle, SessionPersistence, Messaging, SessionContr
|
||||
session, session_id, prompt, prompt_content, builtin_perms,
|
||||
selected_browser_ids, selected_app_output_ids, selected_setting_ids,
|
||||
fork_session, p_router_model_id, p_api_type_for_session)
|
||||
ttft_probe(session_id, "options_built")
|
||||
resolved_model = p_router_model_id
|
||||
api_type = p_api_type_for_session
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ from backend.apps.agents.manager.session.session_store import load_session_data
|
||||
from backend.apps.agents.manager.session.apply_context_window import apply_context_window
|
||||
from backend.apps.agents.manager.prompt.tool_catalog import get_all_tool_names
|
||||
from backend.apps.agents.manager.prompt.prompt_context import resolve_mode
|
||||
from backend.apps.agents.manager.ttft_probe import ttft_probe
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -45,7 +44,6 @@ class Messaging(AgentManagerProtocol):
|
||||
client_message_id: Optional[str] = None,
|
||||
):
|
||||
"""Send a follow-up message to an existing session."""
|
||||
ttft_probe(session_id, "msg_received")
|
||||
session = self.sessions.get(session_id)
|
||||
if not session:
|
||||
data = load_session_data(session_id)
|
||||
|
||||
@@ -16,7 +16,6 @@ from backend.apps.agents.manager.streaming.state import ThinkingState, TurnState
|
||||
from backend.apps.agents.manager.streaming.handle_stream_event import handle_stream_event
|
||||
from backend.apps.agents.manager.streaming.handle_assistant_message import handle_assistant_message
|
||||
from backend.apps.agents.manager.streaming.handle_result_message import handle_result_message
|
||||
from backend.apps.agents.manager.ttft_probe import ttft_probe
|
||||
from backend.apps.agents.manager.run.client_pool import (
|
||||
acquire_client,
|
||||
boot_fingerprint,
|
||||
@@ -42,7 +41,6 @@ class TurnRunner(AgentManagerProtocol):
|
||||
global_settings: AppSettings, force_respawn: bool = False) -> None:
|
||||
from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, ResultMessage
|
||||
from claude_agent_sdk.types import StreamEvent, SystemMessage
|
||||
ttft_probe(session_id, "query_enter")
|
||||
|
||||
async def prompt_stream():
|
||||
yield {
|
||||
@@ -94,7 +92,6 @@ class TurnRunner(AgentManagerProtocol):
|
||||
logger.exception("pre-emit thinking pill failed; continuing")
|
||||
|
||||
if turn.first_event:
|
||||
ttft_probe(session_id, "first_event", type=type(message).__name__)
|
||||
logger.info(f"[MCP-DEBUG] First event received: {type(message).__name__}")
|
||||
turn.first_event = False
|
||||
|
||||
@@ -113,7 +110,6 @@ class TurnRunner(AgentManagerProtocol):
|
||||
message, session, session_id, turn, thinking, self.live_partial, self.sessions
|
||||
)
|
||||
elif isinstance(message, ResultMessage):
|
||||
ttft_probe(session_id, "result", chars=turn.assistant_text_chars)
|
||||
await handle_result_message(
|
||||
message, session, session_id, turn, thinking, self.sessions,
|
||||
resolved_model, api_type, global_settings,
|
||||
|
||||
@@ -45,7 +45,8 @@ def boot_fingerprint(options_kwargs: Dict, session: AgentSession) -> str:
|
||||
frozen = {k: v for k, v in options_kwargs.items() if k not in P_NON_BOOT_KEYS}
|
||||
frozen["p_branch"] = session.active_branch_id
|
||||
frozen["p_compacted_through"] = session.compacted_through_msg_id
|
||||
if os.environ.get("OSW_TTFT_PROBE") == "1":
|
||||
# Pool diagnostics (OPENSWARM_POOL_DIAG=1): on a respawn, names WHICH boot field drifted; the tool for debugging respawn churn (e.g. the thinking short/long-prompt flip) in the field.
|
||||
if os.environ.get("OPENSWARM_POOL_DIAG") == "1":
|
||||
digests = {k: hashlib.sha256(json.dumps(v, sort_keys=True, default=str).encode()).hexdigest()[:10] for k, v in frozen.items()}
|
||||
prev = p_last_field_digests.get(session.id)
|
||||
if prev is not None:
|
||||
|
||||
@@ -14,7 +14,6 @@ from backend.apps.agents.core.models import AgentSession
|
||||
from backend.apps.agents.core.ws_manager import ws_manager
|
||||
from backend.apps.agents.manager.streaming.state import ThinkingState, TurnState
|
||||
from backend.apps.agents.manager.streaming.PartialReply import PartialReply
|
||||
from backend.apps.agents.manager.ttft_probe import ttft_probe
|
||||
|
||||
try:
|
||||
from claude_agent_sdk.types import StreamEvent
|
||||
@@ -45,7 +44,6 @@ async def handle_stream_event(
|
||||
|
||||
if block_type == "text":
|
||||
if turn.stream_text_msg_id is None:
|
||||
ttft_probe(session_id, "first_text_block")
|
||||
turn.stream_text_msg_id = uuid4().hex
|
||||
await ws_manager.send_to_session(session_id, "agent:stream_start", {
|
||||
"session_id": session_id,
|
||||
@@ -56,8 +54,6 @@ async def handle_stream_event(
|
||||
|
||||
elif block_type == "thinking":
|
||||
# Reasoning trace from thinking-capable models (GPT-5.3 Codex, Gemini 3 Pro/Flash, Claude with extended thinking). Rendered as a collapsible "thinking" message in the UI via the existing stream infrastructure, the frontend already handles role="thinking" for the DynamicIsland/agent card rendering.
|
||||
if not thinking.block_starts:
|
||||
ttft_probe(session_id, "first_thinking_block")
|
||||
thinking_msg_id = uuid4().hex
|
||||
turn.stream_block_index_map[index] = thinking_msg_id
|
||||
# Server-stamp start so we can accumulate per-turn elapsed_ms across multiple thinking blocks (think → tool → think → answer turns sum correctly).
|
||||
@@ -89,8 +85,6 @@ async def handle_stream_event(
|
||||
|
||||
if msg_id and delta_type == "text_delta":
|
||||
text_chunk = delta.get("text", "")
|
||||
if turn.assistant_text_chars == 0:
|
||||
ttft_probe(session_id, "first_text_delta", chars=len(text_chunk))
|
||||
turn.assistant_text_chars += len(text_chunk)
|
||||
turn.stream_text_accum += text_chunk
|
||||
live_partial[session_id] = PartialReply(
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
"""Temporary time-to-first-token phase probe for the send->first-token A/B sweep. A no-op unless
|
||||
OSW_TTFT_PROBE=1, so it never spams a normal run. Strip once the persistent-client work lands."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
|
||||
from typeguard import typechecked
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
P_TTFT_ENABLED = os.environ.get("OSW_TTFT_PROBE") == "1"
|
||||
|
||||
|
||||
@typechecked
|
||||
def ttft_probe(session_id: str, phase: str, **extra: object) -> None:
|
||||
"""One monotonic phase stamp for the TTFT breakdown; the A/B parser reads `phase=<name> mono=<t>`.
|
||||
A no-op unless OSW_TTFT_PROBE=1, and it swallows any error so instrumentation can NEVER break a turn."""
|
||||
if not P_TTFT_ENABLED:
|
||||
return
|
||||
try:
|
||||
tail = " ".join(f"{k}={v}" for k, v in extra.items())
|
||||
logger.warning(f"[TTFT] sid={session_id} phase={phase} mono={time.monotonic():.4f} {tail}".rstrip())
|
||||
except Exception:
|
||||
pass
|
||||
Reference in New Issue
Block a user