Skip to content

fix(chat): restore DeepSeek reasoning on native tool continuations (#7118) - #7140

Merged
lidge-jun merged 3 commits into
devfrom
fix/7118-native-deepseek-reasoning
Oct 15, 2026
Merged

lidge-jun merged 3 commits into
devfrom
fix/7118-native-deepseek-reasoning

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #7118.

Native Chat → Chat previously forwarded assistant history verbatim and bypassed both reasoning replay and preserveReasoningContentModels. A client that omitted the provider's reasoning_content after 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.

  • Capture original upstream JSON/SSE reasoning per choice and parallel tool-call id, then restore omitted assistant tool-call reasoning before native serialization. Preserve supplied reasoning and the caller's body; retries and combo siblings cannot inherit a mutated history.
  • Reuse the bounded conversation/provider/destination/adapter/model/physical-credential cache and rebind before each native request build, including key rotation. Failed or truncated tool streams cannot seed replay. Headerless, restarted, expired or foreign scopes use only the configured placeholder.
  • Share version-agnostic DeepSeek Flash/Pro detection across native and translated Chat, independent of provider name. Explicit preserve and placeholder lists, including empty opt-outs, remain authoritative. Update public documentation and the owning structure contracts.

The reproduction uses a local HTTP upstream implementing the reported rejection and checks the actual native wire, including a Chat-only logit_bias field 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.

  • Independent review correction: tool-enabled DeepSeek requests apply the configured placeholder to earlier plain assistant answers too; supplied reasoning, preserve/placeholder opt-outs, other providers, and requests without tools keep their existing behavior. The HTTP fixture now sends actual tool definitions and enforces the documented requirement on all assistant turns.

Verification

Independent review round 1, final head 196ae96f75a957d132491d30a907c0b7e3a09ecf (draft state preserved):

  • Fixed one correctness finding in 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. Commit 196ae96f7 adds 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.
  • Mutation proof: reverted all PR src/ changes to the merge base, ran bun 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.
  • 176 pass / 0 fail, 13 files: 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.
  • Passed: bun run typecheck (including after the final fixture edit), bun run structure:check, bun run privacy:scan, git diff --check.
  • Passed: cd docs-site && bun install --frozen-lockfile && bun run build — 577 pages, 81,203 internal links checked.
  • Reviewed native/translated policy, capture lifecycle, exact replay ownership and credential rebinding, privacy/no added runtime logging, core/Lab boundary, file-size and layout registration, owning structure/public docs, dev targeting and all PR template sections. No other confirmed defect found. No live WorkBuddy/OpenCode Go claim is made.
  • Per the review task's shared-machine constraint, neither the full suite nor test:changed was 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):

  • Red before implementation: the new native HTTP reproduction had 9 failures / 3 passes, rejecting missing reasoning with the reported HTTP 400; supplied-reasoning and opt-out controls passed. After implementation, its final expanded form has 13 passes / 0 failures: bun test tests/responses/chat-native-reasoning-replay.test.ts.
  • 112 passes / 0 failures: 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.
  • Passed: bun run typecheck, bun run structure:check, bun run privacy:scan.
  • 36 passes / 0 failures: bun test tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts.
  • Passed, 577 pages: cd docs-site && bun install --frozen-lockfile then bun 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.
  • Resource exception: no separate full bun run test was 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

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. Existing replay ownership and HMAC helpers are reused; no global/unscoped cache fallback, raw request logging, credential destination or authentication-policy changes were introduced.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

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

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 15, 2026
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration into dev (MAINTAINERS.md dev maintainer-integration policy; batch integration authorized by @lidge-jun on 2026-10-15).

  • Head: 140a8f9dd763946ca7fbf93cdd3699618480e2a8 (tree 03d967d23128b5db15e926aecc722a942fcf4f57) = this branch merged with origin/dev a3dfe75f03.
  • Exact-head evidence: GitHub-hosted Actions for this account have not been assigning runners since 2026-10-15 13:30 UTC, so by owner decision the evidence is a full bun run test (Bun 1.4.3 test runner, root and GUI dependencies installed, GUI built) of this exact tree on a maintainer host (Linux x86_64): exit 1, 7 min, 31 failing test(s), each also failing in the same host's baseline run of dev 60bf4c7 (environment-only): Codex shim install readiness > a refused install exits unsuccessfully and preserves its re, Codex shim install readiness > keeps install advisory when the Codex config cannot be read, Codex shim install readiness > the install command surfaces readiness warnings without lea, GUI pairing client > sends one bodyless origin-bound capability and redacts rejected bodie, Node launcher PATH fallback activation > broken bundle reaches validated PATH Bun, Node launcher PATH fallback activation > inspection bundle reaches validated PATH Bun, Node launcher PATH fallback activation > missing bundle reaches validated PATH Bun, a secondary ensure parent preserves shared Grok, Codex and Claude agent bytes, ….
  • Local gates on the same tree: bun run typecheck, file-size ratchet, test-layout and structure:check.
  • Hosted CI checks for this head may still be queued; they are not claimed as evidence.

@lidge-jun
lidge-jun marked this pull request as ready for review October 15, 2026 18:17
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 15, 2026 18:17
@lidge-jun
lidge-jun merged commit 9d4c82a into dev Oct 15, 2026
5 of 6 checks passed
@lidge-jun
lidge-jun deleted the fix/7118-native-deepseek-reasoning branch October 15, 2026 18:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T18:21:10.013051Z 140a8f9 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment on lines +71 to +73
const reservation = budget.reserveTransient(Buffer.byteLength(previous) * 2, accounting);
try {
budget.chargeRetained(added, accounting);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant