Skip to content

feat(core): Attribute the cost of every core model call - #2926

Merged
dcramer merged 3 commits into
mainfrom
feat/attributed-model-calls
Nov 8, 2026
Merged

dcramer merged 3 commits into
mainfrom
feat/attributed-model-calls

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Several core model calls dropped their costUsd: titles, catch-ups, vision summaries, image prompt enrichment, and review reply matching. Now no core call can skip cost attribution.

Core code calls completeText, completeObject, and completeDecision from the new chat/core-model.ts. Each call must pass:

  • operation: a closed union such as conversation_title or vision_summary. It also sets gen_ai.prompt.name to junior.<operation>, so span names stay the same.
  • cost: where the cost goes.
    • { conversationId, turnId? }: the host appends one junior/<operation> structured_event with content.costUsd for each priced call. The write is best effort, like plugin onCost.
    • { owner: "caller" }: allowed only for brief_update, guardian_action_review, and passive_reply_route. Their own events (brief_updated, guardian_action_reviewed, passive_reply_routed) already store the cost, so nothing is counted twice.
    • { owner: "none" }: no stored Conversation. The cost stays on the span.

A new ast-grep rule (no-direct-core-model-calls) blocks imports of those three functions from @/chat/pi/client everywhere in packages/junior/src except core-model.ts and plugins/model.ts.

The auxiliary cost reader already counts any structured_event with content.costUsd, so auxiliary-costs.ts needs no change. The new operations get labels in TelemetryMetrics.tsx.

Call sites

  • Record on the Conversation: conversation and run titles, task titles (spawnAgent and createAutomation), catch-up (api/conversations/catch-up.ts), vision summaries (attachments and thread backfill), image prompt enrichment, and review item reply matching.
  • Caller-owned, unchanged accounting: Guardian, Brief task, passive reply routing.
  • No Conversation: the junior briefs run CLI uses owner: "caller" because its report sums each version's cost. The catch-up eval harness uses owner: "none". A vision call made without a Conversation id, such as a local run, also uses none.

Not covered: image generation and web search bill through other gateway paths, not these three functions. Compaction is handled in #2925.

Checks

  • Extended tests/integration/api/conversations/catch-up.test.ts: after a catch-up, the Conversation detail shows a junior/conversation_catch_up auxiliary cost.
  • Ran the affected unit, component, and integration suites (59 files) and pnpm ast-grep:lint. Ran tsc for junior, junior-evals, and the dashboard, plus oxlint and prettier on the changed files.

via @dcramer.

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 8, 2026 6:43pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

11 screenshot changes — 11 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment · Mobile
Conversation Attachment · Mobile
Changed
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Conversation Attachment Zoom · Desktop
Conversation Attachment Zoom · Desktop
Changed
Conversation Captured Memories Popover · Desktop
Conversation Captured Memories Popover · Desktop
Changed
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Show 5 more changed screenshots
Conversation Details Watched Linked Work · Mobile
Conversation Details Watched Linked Work · Mobile
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Conversation Stop Active · Mobile
Conversation Stop Active · Mobile
Changed
Memories · Mobile
Memories · Mobile
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@dcramer

dcramer commented Nov 8, 2026

Copy link
Copy Markdown
Member

rebase this

sentry-junior Bot and others added 3 commits November 8, 2026 18:40
Core code now calls completeText, completeObject, and completeDecision
through chat/core-model. Each call names its operation and where its
cost goes. Calls bound to a Conversation append one junior cost event
per priced call, so titles, catch-ups, vision summaries, image prompt
enrichment, and review reply matching show up in Conversation cost and
the auxiliary breakdown. An ast-grep rule blocks direct imports from
chat/pi/client.

Co-Authored-By: David Cramer <[email protected]>
A real turn now stores a cost event for its title. Loaded history spends
nothing, so the row comparison skips cost events.
@sentry-junior
sentry-junior Bot force-pushed the feat/attributed-model-calls branch from dc055d9 to 93cc672 Compare November 8, 2026 18:42
@dcramer
dcramer merged commit 114ddd3 into main Nov 8, 2026
50 of 51 checks passed
@dcramer
dcramer deleted the feat/attributed-model-calls branch November 8, 2026 18:58

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 93cc6727 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant