Skip to content

fix(claude): normalize direct context overflow errors - #812

Closed
luvs01 wants to merge 2 commits into
devfrom
codex/fix-generic-overflow-error-handling
Closed

luvs01 wants to merge 2 commits into
devfrom
codex/fix-generic-overflow-error-handling

Conversation

@luvs01

@luvs01 luvs01 commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Transferred upstream

The completed fix and regression coverage continue in lidge-jun/opencodex#8148, targeting dev, from this same branch at f13774704a72178e687f9304097002f2d10f3868. The upstream PR is ready for review and contains the current validation results and resolved source-review findings. This fork-local PR is closed as transferred; the branch remains the upstream PR's source.


Motivation

  • A recent change broadened the context-overflow classifier so anthropicFailedStatus() returns 400 for generic-coded overflow errors, but the direct Anthropic Messages encoder did not synthesize the context_length_exceeded code or the "prompt is too long" wording, causing direct-stream clients to receive a fatal unrecoverable error instead of a compaction-triggering response.
  • The intent is to restore parity between the direct encoder and the legacy Responses converter so upstream generic-coded overflow errors are normalized and clients can compact and recover.

Description

  • Imported and used isContextOverflowError() in src/protocols/encoders/messages.ts to detect broadened generic-coded overflow assertions.
  • When isContextOverflowError() is true, the direct encoder now synthesizes the context_length_exceeded code (unless the original error is the deterministic undeclared-tool code) so anthropicErrorBody() produces the "prompt is too long" wording.
  • Added a regression test in tests/responses/protocol-direct-encoders-messages.test.ts that feeds a generic server_error overflow and asserts parity between the direct encoder and the legacy bridge/converter for both streamed frames and folded (non-stream) responses.
  • Changes are minimal and focused to preserve existing behavior in all other paths.

Testing

  • Ran bun test tests/responses/protocol-direct-encoders-messages.test.ts and observed 52 pass, 0 fail confirming the new regression case and existing parity tests passed.
  • Ran bun run typecheck (via bun check --no-script --noEmit) with no type errors reported across the tree.
  • Ran git diff --check with no issues found, and attempted bun run test:changed which could not run due to this checkout lacking a dev comparison ref (no upstream/dev present).

Codex Task


Devin Review

@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 4, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Preserve the existing direct-encoder fix and cover four generic error codes across streaming and folded responses.

Verified tree matches local commit 25f1104c7631e713199de631505c1dba01ff49d3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant