Skip to content

fix(session): preserve reasoning across empty tool-call deltas - #47880

Open
yixiao5428 wants to merge 1 commit into
anomalyco:devfrom
lihaokun:empty-tool-calls
Open

fix(session): preserve reasoning across empty tool-call deltas#47880
yixiao5428 wants to merge 1 commit into
anomalyco:devfrom
lihaokun:empty-tool-calls

Conversation

@yixiao5428

Copy link
Copy Markdown

Issue for this PR

Closes #47875

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Backports vercel/ai#20253, released in compatible 3.0.44, to OpenCode's pinned @ai-sdk/openai-compatible@2.0.41.

The parser currently ends active reasoning for tool_calls: [], splitting consecutive reasoning deltas into separate persisted parts. Requiring a nonempty array before entering the tool branch removes that false boundary while preserving real text/tool boundaries and normal stream completion.

  • Keeps the current SDK interface, updating source, ESM and CJS in the existing patch and retaining its structured-error fix.
  • Preserves genuine text/tool boundaries without content-rewriting heuristics or processor coalescing. No dependency upgrade or processor, adapter or UI production-code changes.
  • Adds 26 tests through the real SDK, adapter and persisted session parts, including error/interruption cleanup.

Related work and differences

This targets the empty-array case in #47875, not every symptom in #40865 or general reasoning/text coalescing.

How did you verify your code works?

  • Confirmed six regression failures before the fix; the same 15-test regression/control set passed afterward with unchanged assertions. Expanded coverage: 26/26 passed.
  • Full session/permission/provider run: 1,258 passed, 0 failed; 7 existing skips and 1 todo.
  • Package typecheck passed; forced workspace typecheck passed all 30 tasks.
  • Verified three-target patch application, actual Node ESM/CJS entrypoints, formatting and whitespace.

Commands below use workspace-relative paths. Validation ran in a source tree matching this commit, installed with bun install --frozen-lockfile:

env -u ANTHROPIC_BASE_URL bun test --cwd packages/opencode --timeout 30000 test/session test/permission test/provider
bun run --cwd packages/opencode typecheck
bun run typecheck --force

The test subprocess unsets an inherited custom Anthropic endpoint that interferes with the Gateway routing fixtures. No tests or user configuration were changed to accommodate it.

Screenshots / recordings

N/A — no UI code changes; regression coverage verifies stream events and persisted reasoning parts.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

Backport the nonempty tool-call guard from vercel/ai#20253 to the
pinned @ai-sdk/openai-compatible@2.0.41 source, ESM and CJS targets.
Preserve the existing structured-error patch and real text/tool
boundaries without changing processor or adapter production code.

Add 26 regression and boundary tests through the real SDK, stream
adapter and session persistence, including error/interruption cleanup.

Upstream: vercel/ai#20253
Refs: anomalyco#47875

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Empty tool_calls arrays split continuous reasoning into separate parts

1 participant