GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [WRONG BRANCH] fix(adapters): preserve upstream finish_reason as stopReason in openai-chat adapter by xiangyingchang · Pull Request #339 · lidge-jun/opencodex Conversation
|
finish_reason |
stopReason |
Responses terminal status |
|---|---|---|
stop |
stop |
response.completed |
tool_calls |
tool_calls |
response.completed |
length |
length |
response.completed* |
max_tokens |
max_tokens |
response.incomplete |
content_filter |
content_filter |
response.completed* |
| missing | undefined |
response.completed |
* The bridge currently only maps max_tokens to incomplete. length and content_filter are not yet handled. This PR focuses on the adapter fix; bridge-side length/content_filter mapping can be added separately if needed.
15 new tests in tests/openai-chat-finish-reason.test.ts:
stop/length/max_tokens/tool_calls/content_filter → correct stopReason[DONE] after finish_reason=length preserves captured stopReason[DONE] without finish_reason → stopReason=undefinedfinish_reason → error (fail-closed)stopReason=undefinedfinish_reason values + missing → correct stopReasonAll 15 pass. 90 tests across 5 related files pass with 0 regressions. tsc --noEmit clean.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…i-chat adapter The openai-chat adapter collapsed all non-empty finish_reason values into a boolean sawFinish, discarding the original reason. The bridge already maps stopReason=max_tokens to response.incomplete (issue lidge-jun#246), but the adapter never provided the value. This means providers like ark-coding/glm-5.2 that return finish_reason=length when the model hits its 4096 output token cap were silently treated as normal completions - Codex received task_complete on truncated responses. - Replace sawFinish boolean with finishReason string in streaming path - Propagate finish_reason as stopReason on all done events (streaming + non-streaming) - Preserve [DONE] without finish_reason -> stopReason=undefined (backward compat) - Preserve EOF fail-closed behavior: no finish_reason + no usage -> error - 15 tests covering stop/length/max_tokens/tool_calls/content_filter/EOF scenarios
|
This pull request currently targets Its title has been prefixed with @xiangyingchang Please retarget this PR to the This pull request is being kept as a draft automatically. Once the target branch is corrected, it will be marked ready for review again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
📝 WalkthroughWalkthroughThe OpenAI chat adapter now propagates upstream ChangesOpenAI chat finish reason propagation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
src/adapters/openai-chat.ts (1)
745-769: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winValidate
finish_reasonbefore emitting it asstopReason.Line 745 is only a TypeScript assertion; it does not validate the provider JSON. A malformed OpenAI-compatible response such as
finish_reason: 1passes the truthiness check on Line 769 and emits a numericstopReason, violating theAdapterEventcontract insrc/types.ts.Proposed fix
- ...(choices[0].finish_reason ? { stopReason: choices[0].finish_reason } : {}), + ...(typeof choices[0].finish_reason === "string" && choices[0].finish_reason + ? { stopReason: choices[0].finish_reason } + : {}),Add a regression case with a non-string
finish_reasonand assert thatdone.stopReasonisundefined.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/adapters/openai-chat.ts` around lines 745 - 769, Validate choices[0].finish_reason at runtime before adding it to the done event’s stopReason in the response parsing flow. Only include stopReason when finish_reason is a non-empty string, while leaving it undefined for malformed values such as numbers; add a regression case covering a non-string finish_reason and verify the emitted done event has no stopReason.
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/adapters/openai-chat.ts`:
- Around line 745-769: Validate choices[0].finish_reason at runtime before
adding it to the done event’s stopReason in the response parsing flow. Only
include stopReason when finish_reason is a non-empty string, while leaving it
undefined for malformed values such as numbers; add a regression case covering a
non-string finish_reason and verify the emitted done event has no stopReason.
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 206fedf0-2a48-47fe-8b4c-e681e99a6a66
src/adapters/openai-chat.tstests/openai-chat-finish-reason.test.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d2ef85035
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // no delta) is a graceful close and must mark sawFinish even though we skip it below. | ||
| if (typeof choices[0].finish_reason === "string" && choices[0].finish_reason) { | ||
| sawFinish = true; | ||
| finishReason = choices[0].finish_reason; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Normalize length finish reasons before done
When an OpenAI-compatible upstream returns finish_reason: "length" (the Chat Completions signal for hitting the output-token limit), this stores and later emits stopReason: "length". The Responses bridge only converts stopReason === "max_tokens" to response.incomplete (src/bridge.ts), so both streaming here and the analogous non-streaming spread at line 769 still surface token-exhausted OpenAI-chat completions as response.completed instead of response.incomplete. Please normalize length to max_tokens before emitting the done event, or teach the bridge to treat length as the same truncation reason.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The underlying truncation bug is real, but this PR targets main instead of dev and is now behind the terminal-truth work already on dev. It also preserves OpenAI finish_reason=length as length, while the bridge only marks max_tokens incomplete, so a capped response is still reported completed. Please rebuild on current dev, normalize length to max_tokens (or update the shared bridge contract with regression coverage), validate finish_reason types, and re-request review.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR targets |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing: this PR targets |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
- 24 open PRs + 22 open issues triaged into 6 tiers - 3 wrong-branch PRs closed (#419, #365, #339) - 3 fixed issues closed (#331, #320, #398) - 5 review-ready PRs investigated (all NEEDS-CHANGES/BLOCKED) - HaydernCenterpoint batch dependency analysis - Recent merge history (20 PRs, 7/23-7/24) included - Completed devlog folders archived to _fin
- 24 open PRs + 22 open issues triaged into 6 tiers - 3 wrong-branch PRs closed (lidge-jun#419, lidge-jun#365, lidge-jun#339) - 3 fixed issues closed (lidge-jun#331, lidge-jun#320, lidge-jun#398) - 5 review-ready PRs investigated (all NEEDS-CHANGES/BLOCKED) - HaydernCenterpoint batch dependency analysis - Recent merge history (20 PRs, 7/23-7/24) included - Completed devlog folders archived to _fin
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.