[eric] telemetry: envelopes get real concurrency via a sessions provider, every turn opens with a baseline crumb

This commit is contained in:
ciregenz
2026-08-06 22:57:53 -07:00
parent 751747b293
commit d082af7e03
3 changed files with 13 additions and 1 deletions
+2
View File
@@ -46,6 +46,8 @@ class AgentManager(SessionLifecycle, SessionPersistence, Messaging, SessionContr
@typechecked
def __init__(self):
self.sessions: Dict[str, AgentSession] = {}
from backend.apps.agents.core.flight_recorder import set_sessions_provider
set_sessions_provider(lambda: self.sessions)
self.tasks: Dict[str, asyncio.Task] = {}
# Live mirror of the in-flight streamed assistant text per session, so a stop can persist the partial reply instantly instead of waiting out the multi-second SDK teardown the cancel handler sits behind.
self.live_partial: Dict[str, PartialReply] = {}
+9 -1
View File
@@ -13,6 +13,14 @@ from typeguard import typechecked
P_RING_SIZE = 64
p_lock = threading.Lock()
p_rings: Dict[str, deque] = {}
p_sessions_provider = None
def set_sessions_provider(provider) -> None:
"""agent_manager registers its live sessions dict once so envelopes built anywhere (error
handlers have no manager handle) still carry a real concurrency snapshot."""
global p_sessions_provider
p_sessions_provider = provider
@typechecked
@@ -92,7 +100,7 @@ def build_envelope(
"phase": phase,
"attempts": attempts,
"breadcrumbs": breadcrumbs(session_id),
"concurrency": concurrency_snapshot(sessions or {}),
"concurrency": concurrency_snapshot(sessions if sessions is not None else (p_sessions_provider() if p_sessions_provider else {})),
}
@@ -177,6 +177,8 @@ class TurnRunner(AgentManagerProtocol):
p_use_persistent = persistent_client_enabled()
capacity_retry_attempt = 0
p_router_retry_attempt = 0
# Baseline crumb so even a first-call failure's envelope names the turn it died in.
flight_recorder.crumb(session_id, "turn-start", model=resolved_model, api=api_type)
while True:
try:
if p_use_persistent: