Skip to content

Fix Kilo Quota | OpenRouter error handling and retry flow#5847

Closed
Neonsy wants to merge 2 commits intoKilo-Org:mainfrom
Neonsy:fix/kimi-quota-failure
Closed

Fix Kilo Quota | OpenRouter error handling and retry flow#5847
Neonsy wants to merge 2 commits intoKilo-Org:mainfrom
Neonsy:fix/kimi-quota-failure

Conversation

@Neonsy
Copy link
Copy Markdown

@Neonsy Neonsy commented Feb 13, 2026

Context

A user reported repeated API Streaming Failed / Unknown API error failures on Moonshot (kimi-for-coding) with details like:

Provider ended the request: No output generated. Check the stream for errors.

This PR updates the earlier quota-focused direction and addresses the actual failing path:

  • MoonshotHandler uses the AI SDK OpenAICompatibleHandler stream path.
  • AI SDK error stream parts were not being escalated into actionable provider errors.
  • Task does not handle chunk.type === "error" in the stream switch, so those parts were effectively dropped.
  • Then await result.usage could throw generic "No output generated...", which caused downstream UI fallback to unknown/generic error handling.

Implementation

  • Updated src/api/providers/openai-compatible.ts:

  • Throw immediately when result.fullStream emits part.type === "error" instead of yielding a non-actionable chunk.

  • Wrap full stream iteration and await result.usage in try/catch and rethrow via:

    • handleProviderError(error, providerName, { messagePrefix: "streaming" })
  • Preserved existing tool-stream behavior (tool-input accumulation/flush and usage emission on success).

  • Hardened src/api/providers/utils/error-handler.ts:

  • Preserve status from status, statusCode, and $metadata.httpStatusCode.

  • Improve message extraction priority:

    • metadata.raw -> parsed responseBody/data/cause -> fallback error.message.
  • If top-level message is generic "No output generated. Check the stream for errors.", prefer nested provider message when present.

  • Preserve structured errorDetails from payloads (responseBody/data/cause) for retry/backoff/UI detail surfaces.

  • Added regression coverage:

  • src/api/providers/__tests__/moonshot.spec.ts

    • stream error part with statusCode + responseBody is normalized and thrown with preserved details.
    • generic usage rejection still surfaces nested provider context.
  • src/api/providers/utils/__tests__/error-handler.spec.ts

    • preserves statusCode.
    • extracts message/details from responseBody.
    • falls back to AWS metadata HTTP status when needed.

How to Test

  • Targeted regressions:

  • cd src && pnpm test api/providers/__tests__/moonshot.spec.ts

  • cd src && pnpm test api/providers/utils/__tests__/error-handler.spec.ts

  • Quality gates:

  • pnpm check-types

  • pnpm lint

  • pnpm build

  • Manual scenario:

  • Configure Moonshot with kimi-for-coding.

  • Trigger a request in a quota/credit-limited state (or equivalent provider-side failure).

  • Confirm the surfaced error includes actionable provider context (status/message/details), not only generic "No output generated...".

Validation Performed

  • pnpm check-types passed.
  • pnpm lint passed.
  • pnpm build passed.
  • cd src && pnpm test api/providers/__tests__/moonshot.spec.ts passed.
  • cd src && pnpm test api/providers/utils/__tests__/error-handler.spec.ts passed.

Note

This PR focuses on the Moonshot/AI-SDK stream error path and shared error normalization hardening, not the older OpenRouter/Kilo quota branch.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 13, 2026

🦋 Changeset detected

Latest commit: 718312c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Neonsy Neonsy changed the title Preserve quota error context and stop recursive retries Fix Kilo Quota | OpenRouter error handling and retry flow Feb 13, 2026
@Neonsy Neonsy force-pushed the fix/kimi-quota-failure branch 2 times, most recently from 08da2dd to 1973da5 Compare February 13, 2026 14:34
@Neonsy Neonsy marked this pull request as ready for review February 13, 2026 14:41
@Neonsy Neonsy force-pushed the fix/kimi-quota-failure branch from 1973da5 to 100c218 Compare February 13, 2026 14:41
@smetanokr
Copy link
Copy Markdown

smetanokr commented Feb 13, 2026

before fix :

image

Date/time: 2026-02-13T13:50:09.047Z
Extension version: 5.7.0
Provider: moonshot
Model: kimi-for-coding

Provider ended the request: No output generated. Check the stream for errors.

Date/time: 2026-02-13T13:50:09.047Z
Extension version: 5.7.0
Provider: moonshot
Model: kimi-for-coding

No output generated. Check the stream for errors.

after fix:

image

Date/time: 2026-02-13T14:27:19.132Z
Extension version: 5.7.0
Provider: moonshot
Model: kimi-for-coding

403
moonshot streaming error: You've reached your usage limit for this billing cycle. Your quota will be refreshed in the next cycle. Upgrade to get more: https://www.kimi.com/code/console?from=quota-upgrade

TLDR: this fix correctly handles case, when kimi code weekly quota is 100%, by correctly providing error code and message
image

@Neonsy
Copy link
Copy Markdown
Author

Neonsy commented Feb 13, 2026

@kevinvandijk

@Neonsy Neonsy force-pushed the fix/kimi-quota-failure branch 2 times, most recently from ce5c579 to 9369dec Compare February 14, 2026 11:03
jeremylongshore added a commit to jeremylongshore/kilocode that referenced this pull request Feb 15, 2026
jeremylongshore added a commit to jeremylongshore/kilocode that referenced this pull request Feb 15, 2026
Mirror: Fix Kilo Quota OpenRouter error handling and retry flow (Kilo-Org#5847)
@Neonsy Neonsy force-pushed the fix/kimi-quota-failure branch from 9369dec to 258a399 Compare February 15, 2026 18:46
jeremylongshore added a commit to jeremylongshore/kilocode that referenced this pull request Feb 15, 2026
@Neonsy Neonsy force-pushed the fix/kimi-quota-failure branch 4 times, most recently from a6255bd to 1fc28c5 Compare February 18, 2026 11:59
@Neonsy Neonsy force-pushed the fix/kimi-quota-failure branch from 1fc28c5 to 718312c Compare February 22, 2026 00:46
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Feb 22, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR improves error handling for Kilo Quota / OpenRouter failures by:

  1. Enhanced error extraction (error-handler.ts): New extractErrorPayload() digs into responseBody, data, and cause to find the real provider error message hidden behind AI SDK's generic "No output generated" wrapper. resolveErrorStatus() resolves HTTP status from status, statusCode, or AWS $metadata.httpStatusCode.

  2. Stream error handling (openai-compatible.ts): The stream processing loop is now wrapped in a try/catch that normalizes errors via handleProviderError. AI SDK error stream parts are detected and re-thrown so they flow through the same normalization path. The result.usage await is also inside the try/catch, ensuring rejected usage promises are properly handled.

  3. Good test coverage: Tests cover stream error parts, usage rejection with partial output, statusCode preservation, responseBody payload extraction, and AWS $metadata fallback.

The implementation is defensive, handles edge cases well, and the error priority chain (metadataRawnestedMessageerror.message with "No output generated" override) is sound.

Files Reviewed (5 files)
  • .changeset/slow-pillows-tap.md - Changeset
  • src/api/providers/__tests__/moonshot.spec.ts - 2 new test cases for stream error handling
  • src/api/providers/openai-compatible.ts - Stream processing wrapped in try/catch with error part handling
  • src/api/providers/utils/__tests__/error-handler.spec.ts - 3 new test cases for error extraction
  • src/api/providers/utils/error-handler.ts - New error payload extraction and status resolution utilities

@markijbema
Copy link
Copy Markdown
Contributor

Hi! Thank you for taking the time to contribute to this project—we really appreciate it.

We are currently working on re-platforming the core of our VS Code and JetBrains extensions to be based on our new Kilo CLI, with a complete rebuild based on OpenCode as our new foundation, which means this PR unfortunately won't be compatible with the new architecture.

If you think this feature or fix is still relevant, we'd love for you to check out the new version and consider contributing it there. The new code is now in this repository. Alternatively, if you think this is an urgent fix to the old vscode extension (like a recent model change, or an urgent bug fix), we’d welcome the PR at https://github.com/Kilo-Org/kilocode-legacy

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.

3 participants