Skip to content

[AISAGE-733] fix(ai-gateway): record upstream embedding errors instead of reporting missing usage - #8876

Merged
chrarnoldus merged 3 commits into
mainfrom
fix/gateway-embedding-error-usage
Oct 26, 2026
Merged

chrarnoldus merged 3 commits into
mainfrom
fix/gateway-embedding-error-usage

Conversation

@chrarnoldus

@chrarnoldus chrarnoldus commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

"SUSPICIOUS: No embedding usage information" (KILOCODE-WEB-28DC, previously -1FK7) comes from upstream 4xx responses (400/429). parseEmbeddingUsageFromResponse read json.usage.prompt_tokens from 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 typecheck
  • jest packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.test.ts packages/web-shared/src/lib/ai-gateway/handlers/embeddings
  • New tests: 400 and 429 error bodies, an empty 502 body and an HTML 502 page are recorded as errored zero-usage rows without a report; a 200 without usage is reported.

Models: Claude Opus 5.5 (kilo/anthropic/claude-opus-5.5), no subagents.

…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.
Comment thread packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.ts
@kilo-code-bot

kilo-code-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The 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: [INFERENCE] Response.text() returning '' for an empty body still leaves clonedResponse.body non-null, so the empty-body test exercises the parse path rather than the bodyless early return; a literal JSON null error body would still throw on property access, but that shape is not produced by the targeted upstreams and predates this change.

Files Reviewed (2 files)
  • packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.ts
  • packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.test.ts
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 Summary

No blocking defects; one residual gap where non-JSON upstream embedding error bodies still trigger the SUSPICIOUS: No embedding usage information alert this PR removes.

Assumptions: [INFERENCE] Upstream embedding providers return JSON error bodies for the 400/429 cases targeted here; non-JSON bodies (empty body, HTML edge/CDN error page) are not confirmed from captured payloads but remain reachable through the parse-failure path.

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.ts 1347 Suppression only covers JSON-parsable error bodies; a non-JSON 4xx/429 still throws and falls through to the caller's report without recording an errored row
Files Reviewed (2 files)
  • packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.ts - 1 issue
  • packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 40.1K · Output: 5.4K · Cached: 268.2K

Review guidance: REVIEW.md from base branch main

chrarnoldus and others added 2 commits October 24, 2026 19:19
… 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.
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.

2 participants