Skip to content

feat(ingest): stamp model-call usage buckets and the llm-call marker - #1143

Merged
JeremyFunk merged 8 commits into
mainfrom
feat/ingest-usage-buckets
Sep 30, 2026
Merged

JeremyFunk merged 8 commits into
mainfrom
feat/ingest-usage-buckets

fix(agent-sessions): the detail page counts and fails a stamped span …

fb0e9c8
Select commit
Loading
Failed to load commit list.
Maple Review Bot / Maple / review succeeded Sep 29, 2026 in 2m 57s

Confidence 4/5 · No issues found

🟢 Confidence 4/5 · likely safe to merge
The read path (list, detail page and summary SQL) now derives every verdict from the same gateway stamp, and tests cover the stamped and pre-stamp paths.
quality 100/100 · no findings · tests covered · risk medium

This slice makes the Agent Sessions read path follow the ingest gateway's stamps: span usage, cost, classification, failure and tool-call counting all read maple_ai.* on a stamped span, keeping the pre-stamp heuristics for older rows. The changes are consistent between the page, the list and the summary query, and safe to merge.

  • spanTokenBuckets/spanCost read the gateway's maple_ai.usage.* on a stamped span
  • classifyAiSpan, isLlmCall, spanFailed and the new isCountedToolCall follow the stamps
  • The session summary SQL reads stamps for llmCalls, toolCalls, failed, model and buckets
  • mapAiSpan lifts the stamped maple_ai.agent.name into agentName

Fixed since the last review

  • ✅ F1 · Paused tool-call copy still counts as failed on the detail page
What was checked
  • spanTokenBuckets returns undefined only when all five gateway buckets are absent, so a stamped agent span reports nothing (session-summary.ts:448)
  • The gateway writes maple_ai.tool_call 0/1 only on a tool call and maple_ai.llm_call on every stamped span (apps/ingest/src/ai_session/usage.rs:149, facts.rs:350), which is what isCountedToolCall…
  • Counts, tool findings and read coverage all go through isCountedToolCall; the summary's inputTokens/outputTokens sum to the same total as the page's buckets

fb0e9c8 · Updated on every push. Reply "won't fix" to dismiss a finding, or mention @maple to ask about one.