Skip to content

fix: complete visible thinking items on the streaming Responses surface - #5150

Merged
akshaydeo merged 6 commits into
maximhq:devfrom
fus3r:fix-responses-stream-thinking-completion
Jul 18, 2026
Merged

fix: complete visible thinking items on the streaming Responses surface#5150
akshaydeo merged 6 commits into
maximhq:devfrom
fus3r:fix-responses-stream-thinking-completion

Conversation

@fus3r

@fus3r fus3r commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #5149.

On streamed /v1/responses from Anthropic-family backends with extended thinking enabled, visible thinking blocks stream their deltas but are never completed: reasoning_summary_text.done carries an empty text, output_item.done for the reasoning index degrades to an empty "message" shell that contradicts its own output_item.added, and response.completed omits the reasoning item (and the signature) entirely. Clients that treat response.completed as the authoritative final snapshot (the openai-python streaming helper does, and so does the openai-node version Bifrost's integrations pin) lose the reasoning block, and a tool loop that echoes the output back silently drops the model's thinking from its own conversation history.

The cause is that the completion side of the visible-thinking lifecycle was never implemented: the thinking start case doesn't persist its item into state.OutputItems (every other item type does), thinking deltas aren't buffered anywhere, and state.ReasoningSignatures has been write-only since #895. #5094 fixed the same gap for redacted_thinking only.

Changes

  • core/providers/anthropic/responses.go
    • add ReasoningTextBuffers to the stream state (mirror of TextBuffers), covered in the pool New/acquire/flush resets
    • persist the reasoning item into state.OutputItems at content_block_start, mirroring the redacted_thinking case
    • buffer thinking_delta text per output index (with a defensive lazy map init, same pattern as the input-JSON buffers)
    • at content_block_stop, fold the accumulated text and the stored signature into the item using the exact shape the non-streaming converter produces (reasoning_text content block with text + signature), emit reasoning_summary_text.done with the full text and content_part.done with the completed part (mirroring the text-block path); the generic done path then emits a correct output_item.done and response.completed carries the item
  • core/providers/anthropic/visiblethinkingresponses_test.go: four behavior tests covering full lifecycle completion, JSON round-trip replay of the streamed done item through ToAnthropicResponsesRequest (thinking with signature must precede tool_use), interleaved multi-block isolation, and signature-less thinking
  • core/changelog.md: changelog entry

All four tests fail on current dev with the exact reported symptoms and pass with the fix. The redacted_thinking suite, the passthrough suite, and the full anthropic package are green; go vet clean; golangci-lint findings identical before/after.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Affected areas

  • Core (Go)
  • Providers / Integrations

How to test

cd core
go test ./providers/anthropic/ -run "VisibleThinking" -count=1 -v

To see the wire difference live, stream a Responses request with reasoning enabled and a tool against an Anthropic key and inspect reasoning_summary_text.done, the reasoning output_item.done, and response.completed before and after this change; then echo response.completed.output back with a function_call_output as the next turn: before the fix the echoed history carries no reasoning item, after it the thinking block and its signature are preserved.

Breaking changes

None. Additive on the streaming completion path; the added/delta events are unchanged, and the completed item uses the same shape the non-streaming converter already produces (which the request converter already replays).

Related issues

Fixes #5149. Sibling of #5094, which covered the redacted_thinking variant of the same lifecycle gap.

Security considerations

None. No new inputs are parsed; the change only carries already-received stream content into the completion events.

Checklist

  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged and published

@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
core/providers/anthropic/responses.go Adds buffering and completion logic so streamed visible thinking is included in done events and final Responses output.
core/providers/anthropic/visiblethinkingresponses_test.go Adds tests for visible thinking completion, replay, interleaved blocks, and signature-less thinking.
core/changelog.md Adds a changelog note for the visible thinking streaming fix.

Reviews (3): Last reviewed commit: "Merge branch 'dev' into fix-responses-st..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 835560a5-beb5-4f77-82cf-96b09eef7f22

📥 Commits

Reviewing files that changed from the base of the PR and between ef380f9 and 802ea6b.

📒 Files selected for processing (1)
  • core/providers/anthropic/responses.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Fixed streaming “visible thinking” so completed/done fields now include the full accumulated reasoning text and any signature (when present).
    • Ensured reasoning is folded into completion events with the correct structure and ordering, including across interleaved thinking blocks and tool calls.
  • Tests
    • Added integration-style coverage for visible-thinking streaming completion, replaying into requests, multiple blocks, and signature vs. no-signature behavior.

Walkthrough

Anthropic Responses streaming now buffers visible-thinking text per output index, preserves signatures, completes reasoning output items, includes them in response.completed, and supports replay into subsequent Anthropic requests. Regression tests cover ordering, interleaving, replay, and unsigned reasoning.

Changes

Visible-thinking streaming

Layer / File(s) Summary
Reasoning stream state lifecycle
core/providers/anthropic/responses.go
Adds per-output-index reasoning buffers and integrates them into stream-state initialization, reset, and cleanup.
Reasoning completion flow
core/providers/anthropic/responses.go
Persists thinking items, accumulates deltas, folds text and signatures into completed reasoning content, and emits completed reasoning events and output.
Visible-thinking replay and regression coverage
core/providers/anthropic/visiblethinkingresponses_test.go, core/changelog.md
Tests completion events, output ordering, request replay, multiple thinking blocks, missing signatures, and documents the fix.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Anthropic as Anthropic SSE
  participant Converter as ToBifrostResponsesStream
  participant State as AnthropicResponsesStreamState
  participant Client as Responses client
  Anthropic->>Converter: thinking block start and text deltas
  Converter->>State: persist item and buffer reasoning text
  Anthropic->>Converter: thinking block stop and signature
  Converter->>State: fold text and signature into reasoning item
  Converter->>Client: completed reasoning events
  Converter->>Client: response.completed with reasoning output
Loading

Possibly related PRs

  • maximhq/bifrost#5286: Updates Anthropic thinking streaming conversion and reasoning item lifecycle/order coverage.

Suggested reviewers: akshaydeo, tejasghatte, r-droid101, danpiths, roroghost17

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix for completing visible thinking items on the streaming Responses surface.
Description check ✅ Passed The PR description matches the template well, covering summary, changes, testing, related issues, breaking changes, security, and checklist items.
Linked Issues check ✅ Passed The changes address #5149 by buffering reasoning text, preserving signatures, and fixing completion events and replay behavior.
Out of Scope Changes check ✅ Passed The added tests and changelog entry are directly related to the fix, with no unrelated or extraneous changes apparent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix-responses-stream-thinking-completion

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.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 13, 2026
@akshaydeo
akshaydeo dismissed coderabbitai[bot]’s stale review July 14, 2026 08:11

The merge-base changed after approval.

@akshaydeo
akshaydeo requested a review from a team as a code owner July 14, 2026 08:11
akshaydeo and others added 4 commits July 14, 2026 21:59
## Summary

Briefly explain the purpose of this PR and the problem it solves.

## Changes

- What was changed and why
- Any notable design decisions or trade-offs

## Type of change

- [ ] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

Describe the steps to validate this change. Include commands and expected outcomes.

```sh
# Core/Transports
go version
go test ./...

# UI
cd ui
pnpm i || npm i
pnpm test || npm test
pnpm build || npm run build
```

If adding new configs or environment variables, document them here.

## Screenshots/Recordings

If UI changes, add before/after screenshots or short clips.

## Breaking changes

- [ ] Yes
- [ ] No

If yes, describe impact and migration instructions.

## Related issues

Link related issues and discussions. Example: Closes maximhq#123

## Security considerations

Note any security implications (auth, secrets, PII, sandboxing, etc.).

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
Signed-off-by: Akshay Deo <akshay@akshaydeo.com>
@fus3r
fus3r force-pushed the fix-responses-stream-thinking-completion branch from 6ee13ff to ef380f9 Compare July 15, 2026 08:37
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 15, 2026
@akshaydeo
akshaydeo dismissed coderabbitai[bot]’s stale review July 17, 2026 23:27

The merge-base changed after approval.

@akshaydeo
akshaydeo force-pushed the dev branch 2 times, most recently from 44564de to 493bff0 Compare July 18, 2026 01:10
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ fus3r
✅ SahilChoudhary22
❌ akshaydeo
You have signed the CLA already but the status is still pending? Let us recheck it.

akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
…ce (maximhq#5150)

* add support for clickhouse for enterprise logstore tables

* Revert "add support for clickhouse for enterprise logstore tables" (maximhq#5225)

* Delete 1

Signed-off-by: Akshay Deo <akshay@akshaydeo.com>

* fix: complete visible thinking items on the streaming Responses surface

---------

Signed-off-by: Akshay Deo <akshay@akshaydeo.com>
Co-authored-by: Sahil Choudhary <sahil.codes.it@gmail.com>
Co-authored-by: Akshay Deo <akshay@akshaydeo.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

4 participants