Promote finishReason/reasoningTokens to first-class trace + Model Hub fields - #227
Open
anilguleroglu wants to merge 1 commit into
Open
Promote finishReason/reasoningTokens to first-class trace + Model Hub fields#227anilguleroglu wants to merge 1 commit into
anilguleroglu wants to merge 1 commit into
Conversation
… fields They used to ride inside each event's `metadata` JSON blob, invisible to projections, queries and the UI. Both are now real columns/fields across every write path (external HTTP + OTLP ingest, the internal agent sink, and the Model Hub gateway), every read path (session/event APIs, the tracing UI, the Model Hub logs UI), and the usage_daily rollup. reasoningTokens is always a SUBSET of outputTokens — never billed or summed on top of it. A shared src/lib/shared/finishReason.ts normalizes and classifies provider values (stop/length/tool_calls/...) consistently across server and client code. Old rows fall back to their metadata location until scripts/backfill-trace-fields.ts is run, which also adds the updateAgentTracingEvent DB primitive needed to migrate them in place. Co-Authored-By: Claude Opus 5 (1M context) <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.
Summary
finishReasonandreasoningTokenswere folded into each tracing event'smetadataJSON blob — invisible to Mongo projections, unqueryable, and never surfaced in the Model Hub gateway at all. Both are now first-class fields/columns end to end:agent_tracing_events,agent_tracing_sessions(+totalReasoningTokens/truncatedEvents),model_usage_logs,usage_daily, withensureTableColumnmigrations for existing tenant DBs.?truncated=truesession filter), the tracing detail UI (Reasoning token card, TRUNCATED badges), the Model Hub logs UI (Finish column + reasoning sub-line), i18n (en/tr).src/lib/shared/finishReason.tsnormalizes/classifies provider values consistently server + client.scripts/backfill-trace-fields.tsmigrates already-stored rows (metadata → column) and recomputes session totals; added theupdateAgentTracingEventDB primitive it needs (events were previously write-once).reasoningTokensis a SUBSET ofoutputTokens— never added intototalTokensor any cost calculation.Test plan
npx tsc --noEmit— cleannpx vitest run— 3285 passed, 4 skipped, 0 failednpx eslinton all changed files — 0 errorsnpm run build— production build succeedsmetadata-only rows fall back correctly, sessiontotalReasoningTokens/truncatedEventsaccumulate correctly,totalOutputTokensis unaffected by reasoning tokens (no double count),truncated=truefilter and the newupdateAgentTracingEventbackfill primitive both worknpm run backfill:trace-fieldsneeds a real run against staging/prod data once merged (not run here — local env points at prod)🤖 Generated with Claude Code