Repository navigation
[AISAGE-733] fix(ai-gateway): record upstream embedding errors instead of reporting missing usage - #8876
Conversation
…g missing usage
Upstream embedding error bodies ({ error: {...} }) carry no usage object, so
parseEmbeddingUsageFromResponse threw on json.usage.prompt_tokens and every
4xx was reported as "No embedding usage information". Record them as errored,
zero-usage rows like chat, edit and transcription errors, and keep the report
for successful responses without usage.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe incremental change wraps the embedding response parse so non-JSON bodies on 4xx/5xx statuses become errored zero-usage rows instead of falling through to the missing-usage report; the previously reported gap is fixed and the new tests cover empty and HTML error bodies. Assumptions: Files Reviewed (2 files)
Previous Review Summary (commit 5c89908)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 5c89908)Status: 1 Issue Found | Recommendation: Address before merge Executive SummaryNo blocking defects; one residual gap where non-JSON upstream embedding error bodies still trigger the Assumptions: Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (2 files)
Reviewed by deepseek-flash-latest · Input: 40.1K · Output: 5.4K · Cached: 268.2K Review guidance: REVIEW.md from base branch |
… usage An upstream error can arrive without a JSON body, such as an empty 429 or an edge proxy's HTML error page. JSON.parse threw on it, so the request was still reported as missing usage and recorded nothing. Treat such error bodies like a JSON error body; a successful non-JSON response is still a parse failure.
Summary
"SUSPICIOUS: No embedding usage information" (KILOCODE-WEB-28DC, previously -1FK7) comes from upstream 4xx responses (400/429).
parseEmbeddingUsageFromResponsereadjson.usage.prompt_tokensfrom an error body such as{ "error": { ... } }and threw, so every upstream error was reported.Error bodies are now recorded as errored rows with zero usage, the same way chat, edit and transcription errors are recorded. A successful response without usage is still reported.
An upstream error without a JSON body, such as an empty 429 or an edge proxy's HTML error page, is recorded the same way. A successful response that isn't JSON still fails parsing and is reported.
Split out of #8791.
Verification
pnpm --filter @kilocode/web-shared typecheckjest packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.test.ts packages/web-shared/src/lib/ai-gateway/handlers/embeddingsModels: Claude Opus 5.5 (
kilo/anthropic/claude-opus-5.5), no subagents.