Skip to content

fix(anthropic): normalize tool call continuation deltas#3588

Open
punyaslokdutta wants to merge 1 commit into
maximhq:devfrom
punyaslokdutta:codex-fix-anthropic-stream-toolcall-deltas
Open

fix(anthropic): normalize tool call continuation deltas#3588
punyaslokdutta wants to merge 1 commit into
maximhq:devfrom
punyaslokdutta:codex-fix-anthropic-stream-toolcall-deltas

Conversation

@punyaslokdutta
Copy link
Copy Markdown

Summary

  • suppress empty Anthropic tool input deltas when converting to OpenAI chat-completions streams
  • omit repeated tool_calls[].type metadata on continuation argument chunks
  • add regression coverage for first-chunk metadata, empty delta suppression, and continuation chunk semantics

Testing

  • Focused pass:
    • `docker run --rm -v /Users/punyslokdutta/Desktop/git-projects/bifrost:/workspace -w /workspace/core golang:1.26.2-alpine3.23 sh -lc '/usr/local/go/bin/go test ./providers/anthropic -run "TestToBifrostChatCompletionStream_|TestToAnthropicChatRequest_"'

Notes

  • go test ./providers/anthropic ./providers/vertex still shows unrelated existing anthropic package failures that also reproduce on clean origin/main; this PR does not touch those areas.

Closes #3443.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 19, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad8477cd-4f0c-4647-809e-71c8c725c4f8

📥 Commits

Reviewing files that changed from the base of the PR and between ddf4747 and a8b4ea8.

📒 Files selected for processing (2)
  • core/providers/anthropic/chat.go
  • core/providers/anthropic/chat_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved tool interaction streaming by eliminating unnecessary empty markers and optimizing metadata handling in streaming responses for better performance and reliability.
  • Tests

    • Added comprehensive unit tests for tool-use streaming scenarios to ensure proper handling of edge cases and metadata transmission.

Walkthrough

This PR fixes Anthropic→OpenAI streaming tool-call delta handling by suppressing empty partial_json chunks immediately after tool-use starts and removing the Type field from continuation deltas, ensuring compliance with OpenAI's Chat Completions streaming specification.

Changes

Anthropic tool-call streaming delta normalization

Layer / File(s) Summary
Empty tool input delta suppression
core/providers/anthropic/chat.go, core/providers/anthropic/chat_test.go
Early return in InputJSON handler skips emitting tool-call chunks when PartialJSON is empty string, preventing spurious empty argument deltas that break strict clients. Test validates empty delta is suppressed.
Tool-call continuation metadata normalization
core/providers/anthropic/chat.go, core/providers/anthropic/chat_test.go
Type field is removed from ChatAssistantMessageToolCall in streaming deltas while Index, ID, and Function.Arguments are populated. Initial setup chunk includes full metadata (type/id/name) with empty arguments; continuation chunks omit repeated metadata and only include incremental arguments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A streaming tale of tools so fine,
Empty chunks now skip in line,
Types stay home on second call,
OpenAI spec complies to all!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: normalizing tool call continuation deltas in Anthropic streaming conversion, which is the core objective of the PR.
Description check ✅ Passed The description includes summary of changes, testing instructions, and related issue reference, covering the essential aspects. While some template sections are not filled (e.g., detailed change rationale, type of change checkboxes, affected areas), the provided content adequately communicates the PR's purpose and validation approach.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #3443: suppresses empty tool input deltas, omits repeated tool_calls[].type metadata on continuation chunks, and includes regression test coverage validating the OpenAI streaming spec compliance.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the requirements in issue #3443. Modifications to ToBifrostChatCompletionStream for tool-use delta handling and corresponding test coverage are within the stated objectives; unrelated anthropic package failures are explicitly noted as pre-existing.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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 and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 19, 2026

Confidence Score: 5/5

Safe to merge — both changes are narrowly scoped to the streaming conversion path and are guarded by existing nil checks.

The two logic changes are small, well-tested, and fix observable protocol mismatches. The empty-delta guard sits inside the already-nil-checked PartialJSON block, and the Type removal only affects continuation chunks where the field is already present on the first chunk. The new tests exercise all three affected code paths directly and would catch regressions.

No files require special attention.

Important Files Changed

Filename Overview
core/providers/anthropic/chat.go Adds two targeted fixes: suppress empty partial_json deltas early (before any structured-output / tool-call path is reached), and drop the repeated Type field from continuation tool-input delta chunks to match OpenAI streaming semantics.
core/providers/anthropic/chat_test.go Adds three focused regression tests covering first-chunk metadata, empty-delta suppression, and continuation-chunk omission of type/id/function-name fields.

Reviews (1): Last reviewed commit: "fix(anthropic): normalize tool call cont..." | Re-trigger Greptile

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 19, 2026
@punyaslokdutta punyaslokdutta changed the base branch from main to dev May 19, 2026 16:04
@punyaslokdutta punyaslokdutta dismissed coderabbitai[bot]’s stale review May 19, 2026 16:04

The base branch was changed.

@punyaslokdutta
Copy link
Copy Markdown
Author

@akshaydeo I have signed the license/cla, still "Waiting for status to be reported"

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]: Anthropic→OpenAI streaming tool_call deltas violate OpenAI spec on continuation chunks (breaks strict clients)

2 participants