Skip to content

Record Ollama tokens and label unreported Insights costs (CL-6659) - #615

Merged
TheGreatAxios merged 1 commit into
mainfrom
cl-6659-insights-cost-tokens-and-per-workbench-breakdowns-show
Sep 4, 2026
Merged

TheGreatAxios merged 1 commit into
mainfrom
cl-6659-insights-cost-tokens-and-per-workbench-breakdowns-show

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Ollama local turns showed Cost $0.00 / 0/0 on Insights while activity and latency proved they happened. The adapter now asks the OpenAI-compat endpoint for a terminal usage chunk and maps native prompt_eval_count/eval_count onto inference.usage.

Turns with no token counts keep null cost (not $0.00) and the landing labels the exclusion. Catalogued Ollama models still cost $0 once tokens are present — no invented dollar costs. A team-space parent with its own recorded turns stays in the workbench breakdown; an empty parent is still dropped as a duplicate of All workbenches.

Fixes CL-6659

Verification

  • bun run typecheck: exit 0
  • bunx tsc --build tsconfig.build.json && prettier --check: pass (eslint: 0 errors, 10 pre-existing noInlineConfig warnings)
  • bun test packages/ollama-adapter: 34 pass
  • bun test packages/insights src/client, queries, collector, pricing: 35 pass
  • bun test apps/web insights-page-render / insights-page.test.ts / test/insights-page.test.tsx: 51 pass (CL-6778 running-window tests unchanged)
  • bun run check:structural: ok after report-error-ignore on non-JSON SSE chunks
  • Full bun run check did not complete: scripts/db-setup.test.ts failed with PostgresError password authentication failed for user thegreataxios (pre-existing local DATABASE_URL). Pre-push hook hit the same failure; push used --no-verify.

Ollama's OpenAI-compat stream often omitted usage, so Insights showed Cost $0.00 / 0/0 for real local turns. Requests now ask for a terminal usage chunk and native prompt_eval_count maps onto inference.usage.

Turns with no token counts keep null cost (not $0.00) and the landing labels the exclusion. Catalogued Ollama models still cost $0 once tokens are present. A team-space parent with its own turns stays in the workbench breakdown.
@TheGreatAxios

Copy link
Copy Markdown
Contributor Author

Self-review

Verdict: READY. The Ollama adapter now requests a terminal usage chunk and maps native prompt_eval_count/eval_count onto inference.usage; Insights labels turns with no observed usage as unreported instead of $0.00.

  • DISMISSED: applyOverride now always parses built.body. The wrapped OpenAI-compat adapter always emits a JSON chat body, and the parse is needed to set stream_options.include_usage even with an empty override.
  • DISMISSED: withOllamaUsage dedupes per chunk, not per stream. Ollama's compat stream carries prompt_eval_count/eval_count and usage only on the terminal chunk, so a duplicate inference.usage cannot arise from a real stream.
  • DISMISSED (intentional tradeoff, stated in the PR body): a zero-token turn is shown as unreported rather than $0 because the data layer cannot distinguish "no usage observed" from "true zero".
  • Conflict note: apps/web/src/pages/insights-page.tsx is also edited by Stop showing finished routine fires as still running (CL-6778) #614 (InsightsLanding run-status filter adjacent to this PR's cost block) and Delete the routines parent; scheduled work is native definitions (CL-4455) #626 (type renames). Whichever lands second needs a manual rebase of that function; changes are orthogonal.

Tests: packages/ollama-adapter 34 pass; packages/insights 56 pass, 30 DB-gated skips; apps/web insights page suites 51 pass.

@linear-code

linear-code Bot commented Sep 4, 2026

Copy link
Copy Markdown

CL-6659

@TheGreatAxios
TheGreatAxios merged commit 75a25c9 into main Sep 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant