Repository navigation
feat(ingest): sessions, models, tokens and cost for Codex and Grok CLI agents - #167
Merged
Merged
Conversation
…I agents
Paperclip's Codex (codex-app-server) and Grok (grok-cli) agents export
spans that ingest stored with no session, model or tokens: neither
harness uses Claude Code's attribute names, and both emit several spans
per event. They never reached the Sessions page and cost $0.
- internal/ingest/producers.go: one adapter per harness, chosen by
service.name, run after the generic extraction and before cost is
derived. Claude Code spans are untouched.
- Codex: session from conversation.id, else thread.id when it is a
UUID (elsewhere it is the OS thread number); usage from the turn
span's codex.turn.token_usage.* with cached input split out; the
per-request gen_ai.usage.* copies are not read (they sum to the
turn); a tool call is a span with tool_name and call_id.
- Grok: session from session_id, model from model_id; tokens only on
session.process_conversation_turn, with cache_read_tokens taken out
of its inclusive input_tokens; only tool.execution is a tool call.
- Prices for gpt-5.6-sol ($4/$0.40/$20) and grok-4.7, grok-4.6
($2/$0.50/$6), base rates, from third-party rate cards citing the
providers.
- Session counts (actors, overview, history) ignore an empty session_id,
which was counted as one session.
Already-stored spans are not rewritten: session_id is an indexed column.
Grok still lands on Anonymous (it carries no paperclip.agent.id); Cursor
exports nothing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
The dashboard lowercases the Paperclip agent id it stores, but the ingest lookup compared the id as the sender sent it, so an uppercase UUID left that agent's spans on Anonymous. Raised by CodeRabbit on #166. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
A ping to the Paperclip agents on 2026-11-15 (FLO-1172..1174) showed how non-Claude harnesses reach cotel:
codex-app-server0.160)paperclip.agent.idon the spangrok-cli1.0.77)Neither harness uses Claude Code's attribute names, so every span was stored with an empty
session_id. That is why Aldric is missing from Sessions. Both also emit several spans per logical event, so the fields cannot simply be renamed without double counting.What
internal/ingest/producers.go: one adapter per harness, chosen byservice.name. Each runs after the generic extraction and before cost is derived. Claude Code spans are untouched (covered by a test).conversation.id, or fromthread.idwhen it is a UUID. On most spansthread.idis the tracing layer's OS thread number, an integer.codex.turn.token_usage.*:non_cached_input_tokensas input andcached_input_tokensas cache read. The per-requestgen_ai.usage.*onhandle_responsesis not read, because it sums to the turn total.tool_nameandcall_id.code_mode.broker.invoke_toolrepeats the nested call without acall_id.session_id, model frommodel_id.session.process_conversation_turn, becausesampling.stream_decoderepeatsoutput_tokensper sample.cache_read_tokensis taken out of the inclusiveinput_tokens.tool.executioncounts as a tool call, nottool.decision.gpt-5.6-solat $4 input, $0.40 cached, $20 output;grok-4.7andgrok-4.6at $2, $0.50, $6. These are base rates; the long-prompt tiers are not modelled, as with Haiku 5.5. They come from third-party rate cards citing the providers, because openai.com/api/pricing and docs.x.ai were not reachable. Worth a check before merge.COUNT(DISTINCT NULLIF(session_id, '')). A span without a session was being counted as one session: Aldric showed 1 session on Actors and none on Sessions.Not in scope
session_idis ART-indexed, and bulk updates to an indexed column are the pattern behind the September corruption. Only new Codex and Grok runs get sessions.paperclip.agent.id, either because it ignoresOTEL_RESOURCE_ATTRIBUTESor because the adapter does not pass it. To be looked at separately.fs.get_metadata,handle_responsesandreceiving. Filtering them at ingest is a separate decision.Testing
New
internal/ingest/producers_test.gocovers both harnesses, built on the real span shapes with synthetic ids: sessions, token split, cost, non-sessionthread.id, no double counting, and tool selection.TestActorSessionsIgnoreEmptySessionIDfails onmain(1 and 2 sessions instead of 0 and 1) and passes here.Replaying today's production Codex and Grok spans (export, run locally) through the new ingest gives:
gpt-5.6-sol, 44k input, 130k cached, 934 output, ≈$0.25;grok-4.7, ≈$0.01 and ≈$0.16.No tokens remain on sessionless spans.
go test ./...is green withTZ=UTC. In a non-UTC zone,TestHistory_TenMinuteGranularityandTestRollupAndPurge_BoundaryDayNotSplitfail. They fail identically onmain.🤖 Generated with Claude Code