Patch Changes
- 680268e: Send PostHog AI feedback in the shape its LLM analytics feedback view actually reads. A thumbs vote now answers the survey's first question with PostHog's choice index (
1up,2down) instead of the string"thumbs_up", and the free text after a thumbs-down answers the follow-up question ($survey_response_1) rather than overwriting the rating. A vote and the text it opens share one submission id per rated message, so PostHog joins them into a single response, and the vote stays marked incomplete until the follow-up arrives.POSTHOG_AI_FEEDBACK_SURVEY_IDis the whole configuration;POSTHOG_AI_FEEDBACK_SURVEY_QUESTION_IDis no longer read. - 680268e: Fix PostHog LLM analytics showing the assistant's reply as part of the prompt. The agent loop appends its own turns to the message array it is handed, and the trace read that array after the run, so
$ai_input/$ai_input_statecarried the run's final transcript instead of its request — PostHog rendered the same assistant message in both Input and Output. The request is now snapshotted before the loop can grow it. - 680268e: Stop sending the app's tool definitions to PostHog.
$ai_toolsshipped the whole catalogue — for a large app, dozens of tools with full descriptions — on every generation, and it is identical on every call. The calls that actually happened are already named in$ai_output_choicesand carry their own spans. - 680268e: Report failures at the layer that failed, and never as a bare flag.
$ai_is_errorcould travel without any$ai_error— every failed tool span did exactly that with the defaultcaptureToolResults: false, so PostHog showed "error" and nothing else. All three emitters now fall back to a stated reason, add PostHog's$ai_error_type, and say when a tool's error text was withheld rather than never reported. The levels mean distinct things: a generation is failed only when the model call itself failed (a provider error or a stream dropped mid-call), a span when the tool crashed or returned an error, and the trace for everything else — step budgets, timeouts, no-progress cut-offs. A tool that stopped the run no longer marks the model call that preceded it as failed, and a run's terminal outcome rides only the layer that actually failed. - 680268e: Send each PostHog event's own time at the payload root instead of inside
properties, where PostHog treated it as an ordinary custom property and stamped the event with its ingestion time. An agent run emits its trace, generation, and every tool span in one burst when the run ends, so a five-minute run rendered as a 100ms waterfall with its steps in flush order rather than the order they ran. - 680268e: Emit one
$ai_generationper model round-trip instead of one per run, and parent each tool span under the generation that requested it. A multi-step agent run rendered in PostHog as a single generation spanning the whole run — a 15-call, 5-minute run drew one 5-minute "model call" — because the run's aggregate usage was reported as if it were one request. Each generation now carries its own prompt, answer, tools, latency, tokens and cost, and$ai_request_countcounts that call rather than the run, so per-request pricing is right. Run totals (llm_calls,tool_calls,successful_tools,failed_tools,time_to_first_token_ms,latency_source) moved to$ai_trace. An engine that never brackets its calls withmodel_streamstill falls back to a single aggregate generation. The trace no longer carries$ai_input_state/$ai_output_state: with every round-trip carrying its own prompt and answer, those repeated the first call's prompt and the last call's answer on a second event. A generation is also no longer marked failed when the run failed after the model answered — a tool that aborted the run, a step budget, or a cut-off now shows on the tool span and the trace, not on a model call that succeeded. - 680268e: Three fixes to per-round-trip generations. A tool the run's death interrupts is now associated with the call that requested it — the association is recorded when the tool starts, since an interrupted tool never reaches the completion path and used to hang under the trace root, missing from its generation's counts. A model call the provider failed is marked failed even though its stream bracket closes on the way out, so a provider error is no longer reported as a healthy call and a retry no longer leaves the failed attempt green. And a call that reported its tokens keeps them when a later call throws: usage was gated on the loop's aggregate return value, which never arrives on a throw, so every call that had succeeded lost its tokens and cost.
- 680268e: Report
$ai_stop_reasonon each generation, and stop discarding an oversized trace payload wholesale. The engine already knew why every model call ended (end_turn,tool_use,max_tokens, …) and never passed it on, so a truncated answer was indistinguishable from a finished one; themodel_streamclose event now carries it. Content over the 128KB ceiling used to be replaced entirely by a placeholder — a 244KB conversation left nothing at all in the trace. An oversized message list now keeps the last user message behind a marker naming how much was dropped — what was asked is what a trace is opened for, and it stays small.input_truncated/output_truncatedstill mark anything cut, so a partial payload can never read as a complete one.