Cut PostHog event volume with generation aggregates and subagent rollups - #694
Merged
TheGreatAxios merged 16 commits intoAug 26, 2026
Conversation
Unknown project and plugin profile ids still collapse to custom so employer-named agents never leave the process.
Emit one $ai_generation per turn with tool and subagent counts instead of an $ai_span per call. CORBITS_TELEMETRY_AI_SPANS restores per-call spans for debugging; CORBITS_TELEMETRY_GENERATION_SAMPLE_RATE samples successful generations while errors always ship.
Accumulate turn, token, and tool counts in runSubAgent and send them on ambient subagent_end so dashboards stay answerable without leaf AI observability events.
Ambient capture sets $process_person_profile false so PostHog batch events stay anonymous; intentional survey capture omits the flag. Emit plugin_loaded once per plugin identity per process.
TheGreatAxios
commented
Aug 26, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Primary · Request changes
This aggregates parent-turn telemetry, rolls worker activity into subagent_end, and makes ambient capture anonymous.
Findings
src/telemetry/ai-observability.ts:207— A recoverable inference error always emits a failed generation before the successful retry, so one completed parent turn can emit two generations or look failed-only when success sampling is zero.src/telemetry/ai-observability.ts:47— Onlytaskis classified as a subagent call, so preferredspawn_agentdispatches inflatetool_call_countand leavesubagent_call_countat zero.src/subagent/run.ts:1147— Worker failures rethrow before accumulated turn, token, tool, and error totals reachsubagent_end; clean completion also omits the required stop reason.src/subagent/agent-fleet.ts:575— Fleet setup failure returns aftersubagent_startbut before the terminal emitter is registered; fusedtasksetup failure reports the default completed status atsrc/subagent/task-tool.ts:936.src/exec/runner.ts:660— Exec mode does not install the turn-start observer used to capture the active parent trace, so worker terminal events omitparent_trace_id.src/telemetry/product-events.ts:73— Plugin dedupe records identity even when capture uses the no-op telemetry handle, permanently suppressing a later realplugin_loadedevent in the same process.commit 75df24f6— The subject includesCL-6816, which the repository commit rules prohibit.CL-6816— The representative before/after event-count measurement remains unchecked, so the target reduction is not demonstrated.
Notes
bun run checkexits 0 across lint, typecheck, build, and tests.- GitHub prevents a formal self-request-changes action because the PR author and authenticated reviewer are both
TheGreatAxios; this comment review records the substantive request-changes verdict.
TheGreatAxios
commented
Aug 26, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Critic · Request changes
This reshapes AI observability around parent-turn aggregates and per-dispatch worker rollups.
Findings
src/session/run-sink.ts:178—inference.errorimmediately emits a failed generation even when the run sink retries. At sample rate zero, an eventually successful turn is recorded only as failed; at rate one, the same trace emits both failed and successful generations.src/telemetry/ai-observability.ts:47— The subagent tool-name check excludesspawn_agent, so its calls and optional spans are recorded as ordinary tools instead of subagent calls.src/subagent/run.ts:1147— A worker that fails after prior activity throws away its accumulated rollups before callers can enrichsubagent_end;src/subagent/run.ts:1071also returns clean completion without a stop reason.src/subagent/task-tool.ts:936— Fused setup failures inherit a default completed status, whilesrc/subagent/agent-fleet.ts:575returns before fleet dispatch installs itssubagent_endemitter. These paths create false-success or unmatched start/end telemetry.src/exec/runner.ts:660— Exec parent turns never update the current turn trace used by subagent dispatch, sosrc/telemetry/product-events.ts:44cannot attachparent_trace_id.src/plugins/loader.ts:143— Loads without a telemetry handle still pass through global dedupe withNOOP_TELEMETRY; the identity is consumed without capture and later enabled telemetry cannot emit the plugin event.
Notes
- Permanent coverage should include recovered retries at sample rates zero and one, both dispatch tool names, worker failure after prior activity, clean stop reason, setup failures for both dispatch primitives, exec trace linkage, and no-op-then-enabled plugin loading.
- Targeted telemetry tests pass with 75 tests and zero failures; the independent full
bun run checkalso exits 0.
Update the event table and AI section for generation aggregates, opt-in spans, subagent_end rollups, director allowlisting, anonymous ambient processing, plugin_loaded dedupe, and generation sampling.
Capture parent_trace_id at task/spawn dispatch from the current turn noted at inference.start, instead of the last completed turn. Treat an empty generation sample-rate env as unset, and document that sampling drops opt-in spans with the generation.
TheGreatAxios
force-pushed
the
cl-6816-cut-posthog-event-volume-aggregate-tool-spans-into-the-turn
branch
from
August 26, 2026 20:47
3f6a859 to
2ce256f
Compare
TheGreatAxios
force-pushed
the
cl-6816-cut-posthog-event-volume-aggregate-tool-spans-into-the-turn
branch
from
August 26, 2026 21:16
2ce256f to
aed3ec0
Compare
TheGreatAxios
commented
Aug 26, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Primary · Approve
This reduces ambient telemetry volume with parent-turn aggregates, truthful worker rollups, anonymous processing, and conservative fallback attribution.
No findings.
Notes
bun run checkexits 0 atba4c34ad.- Required GitHub checks and CLA pass.
- The deterministic representative fixture records
98 → 18billable events, an 81.6% reduction. - GitHub prevents formal self-approval because the PR author and authenticated reviewer are both
TheGreatAxios; this comment review records the approval verdict.
TheGreatAxios
commented
Aug 26, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Critic · Approve
This emits one terminal parent generation, enriches one worker terminal event per dispatch, and avoids false provider attribution when runtime source identity is unavailable.
No findings.
Notes
- Retry, sampling, setup failure, cancellation, interruption, plugin dedupe, exec linkage, and privacy paths have permanent regression coverage.
- Pre-usage fallback failures retain the attempted model and use the fixed
unknownprovider bucket instead of claiming a stale selected provider. - The final diff contains no Interchange, vendor, dependency, or lockfile changes.
TheGreatAxios
deleted the
cl-6816-cut-posthog-event-volume-aggregate-tool-spans-into-the-turn
branch
August 26, 2026 23:26
TheGreatAxios
added a commit
that referenced
this pull request
Aug 27, 2026
…ume-aggregate-tool-spans-into-the-turn Cut PostHog event volume with generation aggregates and subagent rollups
TheGreatAxios
added a commit
that referenced
this pull request
Aug 27, 2026
…ume-aggregate-tool-spans-into-the-turn Cut PostHog event volume with generation aggregates and subagent rollups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$ai_spans into$ai_generationaggregates by default (tool_call_count,tool_error_count,subagent_call_count); opt-in spans viaCORBITS_TELEMETRY_AI_SPANSsubagent_endwith run rollups (model, turns, tokens, tool counts,stop_reason, spawn-timeparent_trace_id) and allowlists first-party director ids$process_person_profile: falseon ambient events, dedupesplugin_loadedper plugin per process, and documents a generation sample-rate knob (default 1.0)Verification
bun run typecheck,bun run build, andbun run testpass (bun run checkexit 0 locally)parent_trace_idfixFixes CL-6816