Skip to content

fix(web): handle bot credit errors at source - #5195

Closed
chrarnoldus wants to merge 1 commit into
mainfrom
fix/bot-usage-limit-sentry-source
Closed

fix(web): handle bot credit errors at source#5195
chrarnoldus wants to merge 1 commit into
mainfrom
fix/bot-usage-limit-sentry-source

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Summary

  • classify only AI SDK 402 responses carrying the Kilo gateway usage_limit_exceeded contract
  • handle expected credit exhaustion in Kilo Bot instead of forwarding it to Sentry
  • terminate callback continuations cleanly and post the gateway credit message to the user
  • preserve Sentry reporting for provider 402s, malformed responses, network failures, and server errors

This is a source-level alternative to #5058 and avoids a global Sentry beforeSend filter.

Verification

  • pnpm --filter web test -- --runInBand src/lib/ai-gateway/usage-limit-error.test.ts
  • pnpm exec oxlint --config .oxlintrc.json apps/web/src/lib/ai-gateway/usage-limit-error.ts apps/web/src/lib/ai-gateway/usage-limit-error.test.ts apps/web/src/lib/bot/agent-runner.ts apps/web/src/lib/bot/run.ts apps/web/src/app/api/internal/bot-session-callback/[botRequestId]/route.ts
  • pnpm --filter web typecheck
  • pnpm format
  • git diff --check

@chrarnoldus chrarnoldus self-assigned this Aug 11, 2026
@kilo-code-bot

kilo-code-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed all 5 changed files: the new getKiloUsageLimitErrorMessage classifier matches the gateway's usageLimitExceededResponse 402 contract exactly (literal error_type + non-empty error.message, verified against llm-proxy-helpers.ts), the callback route's new catch correctly rethrows non-usage-limit errors so Sentry reporting is preserved for provider 402s and unexpected failures, and error propagation from runBotAgent through handleCompletedCallback is confirmed; unit tests cover the positive, wrong-status, malformed-body, and unrelated-error paths.

Files Reviewed (5 files)
  • apps/web/src/lib/ai-gateway/usage-limit-error.ts
  • apps/web/src/lib/ai-gateway/usage-limit-error.test.ts
  • apps/web/src/lib/bot/agent-runner.ts
  • apps/web/src/lib/bot/run.ts
  • apps/web/src/app/api/internal/bot-session-callback/[botRequestId]/route.ts

Reviewed by kimi-k3 · Input: 55.4K · Output: 14.5K · Cached: 741.9K

Review guidance: REVIEW.md from base branch main

@chrarnoldus
chrarnoldus deleted the fix/bot-usage-limit-sentry-source branch August 11, 2026 09:47
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