Skip to content

fix(kiro): trigger Claude compact for overlength requests#9

Merged
acking-you merged 2 commits into
masterfrom
fix/kiro-prompt-too-long-reactive-compact
May 30, 2026
Merged

fix(kiro): trigger Claude compact for overlength requests#9
acking-you merged 2 commits into
masterfrom
fix/kiro-prompt-too-long-reactive-compact

Conversation

@acking-you
Copy link
Copy Markdown
Owner

Summary

  • Normalize Kiro content-length/context-window failures into Anthropic-compatible 413 errors whose message starts with Prompt is too long.
  • Handle both upstream HTTP failures and Kiro eventstream ContentLengthExceededException before returning normal assistant/SSE output.
  • Preserve usage recording for these failures with client-visible 413 status.

Root cause

Claude Code 2.1.156 only enters its reactive compact path when its API-error assistant text is normalized to Prompt is too long. The gateway was exposing Kiro overlength failures as generic 400 Input is too long / Input content length exceeds threshold, and eventstream exceptions could still be treated like normal assistant responses or max_tokens.

What changed

  • Added Kiro overlength detection for HTTP error bodies and eventstream error/exception frames.
  • Return invalid_request_error JSON with HTTP 413 and parseable <actual> tokens > <limit> tokens details.
  • Map ContentLengthExceededException stop reasons to model_context_window_exceeded.

Test Plan

  • cargo test -p llm-access-kiro --jobs 4
  • cargo test -p llm-access --jobs 4 -- --test-threads=1
  • cargo clippy -p llm-access-kiro -p llm-access --jobs 4 -- -D warnings

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request maps upstream content length exceeded errors and exceptions to a specific "prompt too long" error with a 413 Payload Too Large status code, and updates the stream stop reason to "model_context_window_exceeded". Feedback suggests expanding the detection logic in kiro_text_is_content_length_exceeded to also match the generic "input is too long" string to ensure robust error handling.

Comment thread llm-access/src/provider.rs
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6733c094b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread llm-access/src/provider.rs Outdated
@acking-you acking-you merged commit 0ae9123 into master May 30, 2026
3 checks passed
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