Part of epic #8286 (Phase 3 — AI observability). Follow-up to #10198.
Problem
Two AMS Agent-SDK surfaces make real model calls and emit no $ai_* telemetry at all, so their spend, latency and failure rate are invisible in PostHog.
1. runChatGrounding — never instrumented
packages/loopover-engine/src/miner/chat-grounding.ts drives a full query() session (up to CHAT_MAX_TURNS) with MCP tools attached, and folds the stream into wire events. Nothing on that path captures a generation. A failure becomes a chat_grounding_failed wire event and a provider-config problem becomes an error event — neither reaches PostHog.
Note this driver does not currently surface a usage/result frame at all, so instrumenting it also means folding the SDK's result message (its usage and total_cost_usd) rather than only the assistant/user messages it reads today.
2. runCodingAgentAttempt bypasses the capture wrapper
withCodingAgentAiGenerationCapture is applied inside constructProductionCodingAgentDriver (packages/loopover-miner/lib/coding-agent-construction.ts). The runCodingAgentAttempt path calls createCodingAgentDriver directly (packages/loopover-engine/src/miner/driver-factory.ts), so it never passes through that construction site and every attempt it runs is uncaptured.
That placement is why the bypass is silent: the wrapper is attached at one of two construction sites, and the other one is a plain factory call that looks complete on its own.
Deliverables
Part of epic #8286 (Phase 3 — AI observability). Follow-up to #10198.
Problem
Two AMS Agent-SDK surfaces make real model calls and emit no
$ai_*telemetry at all, so their spend, latency and failure rate are invisible in PostHog.1.
runChatGrounding— never instrumentedpackages/loopover-engine/src/miner/chat-grounding.tsdrives a fullquery()session (up toCHAT_MAX_TURNS) with MCP tools attached, and folds the stream into wire events. Nothing on that path captures a generation. A failure becomes achat_grounding_failedwire event and a provider-config problem becomes anerrorevent — neither reaches PostHog.Note this driver does not currently surface a usage/result frame at all, so instrumenting it also means folding the SDK's
resultmessage (itsusageandtotal_cost_usd) rather than only theassistant/usermessages it reads today.2.
runCodingAgentAttemptbypasses the capture wrapperwithCodingAgentAiGenerationCaptureis applied insideconstructProductionCodingAgentDriver(packages/loopover-miner/lib/coding-agent-construction.ts). TherunCodingAgentAttemptpath callscreateCodingAgentDriverdirectly (packages/loopover-engine/src/miner/driver-factory.ts), so it never passes through that construction site and every attempt it runs is uncaptured.That placement is why the bypass is silent: the wrapper is attached at one of two construction sites, and the other one is a plain factory call that looks complete on its own.
Deliverables
runChatGroundingwith an$ai_generationcapture carrying real model/provider/latency, and tokens + cost from the SDK's result frame.