Repository navigation
Keep run and window summaries out of the AiRequest store - #1701
Conversation
A v2 event with the ai block that sums several model calls (the CI autofix reporter sends one per run and model) became one AiRequest row, so a whole run's duration read as one slow request in the performance view. Only single-call events (requests absent or 1, no window) now get a row. The summaries are still aggregated and priced as before. Refs UM-1592 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
🤔 Insufficient Task ContextI found a task linked to this PR, but it only contains minimal information (title only, no description or acceptance criteria). To perform a meaningful business rules validation, I need more details. 🔍 What I need to validate:
💡 How to improve the task context:
|
Summary
Restricts the AiRequest per-request store (UM-1592 ingest path) to events that describe a single model call. Run and window summaries are still ingested, aggregated, and priced, but they no longer create an AiRequest row — so a run or window total duration cannot be misinterpreted as one request's duration.
What changed
src/lib/ai-usage-metadata.tsAiRequestSourceEventwith optionalrequests,windowStart, andwindowEndfields.aiRequestFromUsageEventnow returnsnull(no AiRequest row) when:requestsis present and not equal to1(e.g.0or12), orwindowStart/windowEndis provided.requestsvalue keep the previous behavior, preserving backward compatibility for existing single-call producers.src/app/api/ingest/usage/route.tsrequests,windowStart, andwindowEndthroughpersistIngestAiRequestsinto the event passed to the mapping, so the new eligibility rule applies on the ingest path.docs/api-contract.mdaiblock creates one AiRequest row only when it is a single call (requestsabsent or1, no window). Run/window summaries must setrequeststo their call count (or0) or provide the window so their duration is not read as a single request.src/lib/__tests__/ai-usage-metadata.test.tsrequests: 1produces a row whilerequests: 0,requests: 12,windowStart, andwindowEnddo not.Functional impact
Test coverage
New unit coverage in
ai-usage-metadata.test.tsexercises the single-call vs. summary boundaries.Review note
The automated review flagged that the business/eligibility rules are not fully described in the task context. The intended behavior is captured in
docs/api-contract.md; reviewers should confirm the contract doc reflects the agreed product rules for what qualifies as a single request.