Repository navigation
Reject token-length-truncated OpenAI-compatible answers - #1151
sanketpatel32 wants to merge 4 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
PR Summary by QodoReject token-length-truncated OpenAI-compatible answers
AI Description
Merge Risk
|
There was a problem hiding this comment.
ℹ️ No blocking issues — one non-blocking finding below.
Approach: sound — it mirrors the existing Claude token-limit path (controller.abort() + throw from onMessage), so the partial text stays on the card while the turn is neither recorded nor reported as done.
Reviewed changes
openai-compatible-core— treatsfinish_reason: 'length'as terminal in the shared chat/completion stream, aborting and throwing beforefinish()canpushRecord/postdone.- Azure OpenAI — same check in
generateAnswersWithAzureOpenaiApi, replacing the bare truthiness test with an explicitfinishReason === 'length'branch. - Tests — one regression test per adapter asserting the rejection message, that the partial answer was streamed, that no
done/record was produced, and that port listeners are cleaned up.
Non-blocking
- The new token-limit error is a hardcoded interpolated English string, so it skips the localization and plain-text formatting the Claude equivalent gets.
handlePortErrorruns the message throughformatErrorMessage, whoserichErrorTextPatternmatches the parentheses around the count, soConversationCardrenders the whole message as adiagnosticcode fence andgetDisplayErrorTextreturns it untranslated — unlikeClaude reached the response token limit..., a static key present in all 13 locales and rendered as plain localized text (core, azure). A static key (dropping the count) or acoderouted throughhandlePortError's existing%sinterpolation would fix both and de-duplicate the two copies.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
Code Review by Qodo
1. Long error lines break the width rule
|
| if (finishReason === 'length') { | ||
| controller.abort() | ||
| throw new Error( | ||
| `The answer reached Max Response Token Length (${config.maxResponseTokenLength}). Increase it in Advanced settings and try again.`, |
There was a problem hiding this comment.
1. Long error lines break the width rule 📘 Rule violation ⚙ Maintainability
The added throw new Error(...) template literal in generateAnswersWithAzureOpenaiApi sits on one physical line of roughly 140 characters, well past the 100-character limit. The same overlong line appears in openai-compatible-core.mjs (line 152, about 135 characters), and the new test titles and regex assertions in both test files also exceed 100 columns. A formatter cannot wrap a template literal, so the message has to be split with string concatenation to conform.
Agent Prompt
## Issue description
The added error message in the Azure OpenAI stream handler is a single template literal on one physical line of roughly 140 characters, exceeding the 100-character source line limit. The same issue appears in the OpenAI-compatible core handler and in the new test titles and regex assertions.
## Fix Focus Areas
- src/services/apis/azure-openai-api.mjs[66-72]
- src/services/apis/openai-compatible-core.mjs[148-154]
- tests/unit/services/apis/azure-openai-api.test.mjs[231-231]
- tests/unit/services/apis/openai-api-compat.test.mjs[491-491]
## Recommended Fix
Split each long template literal into two or more shorter literals joined with `+`, for example `'The answer reached Max Response Token Length (' + config.maxResponseTokenLength + '). Increase it in Advanced settings and try again.'`, keeping each physical line at 100 characters or fewer. Apply the same wrapping to the overlong `test(...)` titles and the regex assertion lines in the two new regression tests.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge; the previous localization issue is fixed. SummaryOpenAI-compatible and Azure OpenAI answers that hit the token limit remain visible but are not saved as completed answers.
Reviews (2) · Last reviewed commit: "Use localized token-limit error in OpenA..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4b7b6a189d
ℹ️ 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".
| if (finishReason === 'length') { | ||
| controller.abort() | ||
| throw new Error( | ||
| `The answer reached Max Response Token Length (${config.maxResponseTokenLength}). Increase it in Advanced settings and try again.`, |
There was a problem hiding this comment.
Localize the interpolated token-limit error
When the UI language is non-English and this branch (or the duplicate Azure branch) receives finish_reason: "length", the fully interpolated sentence is passed to getDisplayErrorText(..., t), but no stable key for it exists in src/_locales/en/main.json or the translated resources; because the numeric value is part of the lookup key, i18next falls back to displaying this English text. Use a localization key with interpolation (and add it to the locale resources) so this newly user-facing failure is translated like the existing Claude token-limit error.
AGENTS.md reference: AGENTS.md:L211-L212
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the two commits pushed since the prior pullfrog review (3d010a1, be6beb2), which replace the hardcoded token-limit string with a localized, interpolated error.
- Localized token-limit error —
shared.mjsnow exportsMAX_RESPONSE_TOKEN_LENGTH_ERROR_KEYpluscreateMaxResponseTokenLengthError(maxTokens), which attachestranslationKey/translationParamsto the thrown error. - Translation at the port boundary —
handlePortErrorpoststranslate(err.translationKey, err.translationParams)for keyed errors, so the message renders as plain localized text instead of a diagnostic code fence. - All 13 locales — the
{{maxTokens}}template key was added to every locale inresources.mjs; interpolation resolves in each one. - Tests — adapter regressions now assert the shared key and
{ maxTokens }params, and a newhandlePortErrortest covers the keyed-error branch.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
|
Thanks for the feedback. In be6beb2, the token-limit error now uses a shared i18n key with |

Fixes #1148
Summary
OpenAI-compatible and Azure OpenAI streams now treat
finish_reason === 'length'as a terminal error instead of a completed answer. The partial text already streamed to the card remains visible, but the request is aborted and the truncated turn is not written withpushRecord()or reported asdone; other finish reasons keep the existing completion behavior.The error uses one shared localization key with a
{{maxTokens}}interpolation placeholder, translations in every locale, andhandlePortError()interpolation before display, so users see the configured response-token limit in their selected language.Added regression coverage for both providers showing that a length-limited partial answer rejects, is not saved to
conversationRecords, and does not post a successful completion. Also addedhandlePortError()coverage for interpolated translation.Validation
npm run pretty— passednpm run lint— passednpm test— 1125 passednpm run build— passed; expected Chromium build artifacts verified