Repository navigation
fix(chat): restore DeepSeek reasoning on native tool continuations (#7118) - #7140
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. Comment |
|
✅ Deterministic PR hygiene checks passed. |
|
Maintainer integration into
|
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 140a8f9dd7
ℹ️ 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".
| const reservation = budget.reserveTransient(Buffer.byteLength(previous) * 2, accounting); | ||
| try { | ||
| budget.chargeRetained(added, accounting); |
There was a problem hiding this comment.
Disable capture when its budget reservation fails
When a non-streaming caller is folding a large SSE response, the collector already retains accumulated output against this same 32 MiB budget; if the optional replay collector's reservation or charge crosses the remaining limit, this exception propagates through onChunk and converts an otherwise valid upstream response into translation_buffer_limit. Catch budget-overflow errors here, discard/disable only the replay collector, and continue relaying the response as the collector's documented optional behavior requires.
AGENTS.md reference: src/AGENTS.md:L15-L17
Useful? React with 👍 / 👎.
| const observe = (value: Rec) => { | ||
| if (disabled || !Array.isArray(value.choices)) return; | ||
| for (const [ordinal, raw] of value.choices.entries()) { | ||
| if (!isChatRecord(raw) || !isChatRecord(raw.delta)) continue; |
There was a problem hiding this comment.
Capture SSE message snapshots as well as deltas
For gateways that stream a full choices[].message snapshot instead of incremental delta objects, nativeChatSse already recognizes and relays snapshot tool calls, but this guard skips the event entirely. Consequently its reasoning_content and tool-call IDs are never cached, so a client that omits the extension on the continuation receives only a placeholder (or an upstream 400 when placeholders are disabled). Inspect both raw.delta and raw.message, treating the latter as a snapshot, as the surrounding native SSE logic does.
Useful? React with 👍 / 👎.
Summary
Closes #7118.
Native Chat → Chat previously forwarded assistant history verbatim and bypassed both reasoning replay and
preserveReasoningContentModels. A client that omitted the provider'sreasoning_contentafter executing tools therefore sent a bare continuation upstream. Both DeepSeek V4 and V4.1 are already in OpenCode Go's preserve list: the missing native replay path, rather than a missing V4.1 list entry, explains why adding the model did not help.The reproduction uses a local HTTP upstream implementing the reported rejection and checks the actual native wire, including a Chat-only
logit_biasfield that would be lost through translation. It does not claim a live WorkBuddy/OpenCode Go confirmation. DeepSeek's thinking/tool-call contract requires returning the original reasoning.Verification
Independent review round 1, final head
196ae96f75a957d132491d30a907c0b7e3a09ecf(draft state preserved):src/adapters/openai-chat/reasoning-replay.ts: tool-call-only repair skipped prior plain assistant answers, although DeepSeek's tool contract requires reasoning on those turns too. Commit196ae96f7adds the configured fallback and regressions. Original reasoning on turns without call ids still requires the client to retain it; a placeholder cannot recover the original reasoning.src/changes to the merge base, ranbun test tests/responses/chat-native-reasoning-replay.test.ts, observed 10 fail / 3 pass, and restored the source. The added all-assistant-turn HTTP case separately failed on the initial PR (1 fail / 13 pass) and passed after the review fix.bun test tests/responses/chat-native-reasoning-replay.test.ts tests/responses/chat-native-reasoning-scope.test.ts tests/responses/chat-inbound-reasoning-replay.test.ts tests/providers/deepseek-reasoning-replay.test.ts tests/providers/deepseek-reasoning-replay-gaps.test.ts tests/adapters/openai/openai-chat-native-policy.test.ts tests/responses/chat-native-lenient-finish.test.ts tests/responses/chat-native-sse-stall.test.ts tests/lib/reasoning-replay-scope-source.test.ts tests/lab/core-lab-boundary.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts. After correcting the new policy fixture's tool definitions to valid schema definitions, its final isolated run also passed: 11 pass / 0 fail,bun test tests/responses/chat-native-reasoning-scope.test.ts.bun run typecheck(including after the final fixture edit),bun run structure:check,bun run privacy:scan,git diff --check.cd docs-site && bun install --frozen-lockfile && bun run build— 577 pages, 81,203 internal links checked.devtargeting and all PR template sections. No other confirmed defect found. No live WorkBuddy/OpenCode Go claim is made.test:changedwas run in this review. Full integration coverage remains with CI; the original implementation-stage broad-run failure below remains historical failed evidence.Implementation-stage evidence at
f18960db96cb757fdc4d3c603ddfd0ed2709a106(before review corrections):bun test tests/responses/chat-native-reasoning-replay.test.ts.bun test tests/responses/chat-native-reasoning-replay.test.ts tests/responses/chat-native-reasoning-scope.test.ts tests/responses/chat-inbound-reasoning-replay.test.ts tests/providers/deepseek-reasoning-replay.test.ts tests/providers/deepseek-reasoning-replay-gaps.test.ts tests/adapters/openai/openai-chat-native-policy.test.ts tests/responses/chat-native-lenient-finish.test.ts tests/responses/chat-native-sse-stall.test.ts tests/lib/reasoning-replay-scope-source.test.ts. This run preceded one additional JSON-to-SSE regression and extra assertions, which passed in the final 13-test HTTP run above.bun run typecheck,bun run structure:check,bun run privacy:scan.bun test tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts.cd docs-site && bun install --frozen-lockfilethenbun run build.bun run test:changed: 19,080 pass / 35 skip / 4 fail / 3 errors, 821 files in 220.56 seconds. The failures were the existing Desktop picker disable case (409 vs 200) and three live-audio non-readiness cases (5-second timeouts plus late close assertions). Both unrelated files subsequently passed together in isolation:bun test tests/claude-integration/claude-desktop-picker-routes.test.ts tests/cli/cli-access-audio-live.test.ts. The broad run remains recorded as failed; it has not been rerun to obtain green.bun run testwas launched because multiple bundle lanes share one 16-core machine. Import-graph coverage was already broad; Ubuntu CI is the remaining independent validation. No macOS/Windows workflow was dispatched.Checklist