fix(responses): preserve DeepSeek reasoning across tool turns - #623
Conversation
📝 WalkthroughWalkthroughThe PR adds reasoning replay for tool-call inputs, reasoning output items for non-streaming responses, and reasoning delta handling for streaming Responses conversion. It also normalizes usage fields and adds coverage for ordering, suppression, and malformed usage. ChangesReasoning content support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ModelStream
participant ResponsesStreamConverter
participant ResponsesOutputEventState
ModelStream->>ResponsesStreamConverter: send reasoning_content delta
ResponsesStreamConverter->>ResponsesOutputEventState: reserve and append reasoning
ResponsesOutputEventState-->>ResponsesStreamConverter: emit reasoning delta event
ModelStream->>ResponsesStreamConverter: send assistant or tool-call delta
ResponsesStreamConverter->>ResponsesOutputEventState: complete reasoning
ResponsesStreamConverter->>ResponsesOutputEventState: start later output item
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/providers/responses_converter.go`:
- Around line 488-514: Update chatUsageToResponsesUsage to remove the
bytes.Contains checks and represent the three required token counts as pointer
fields in the local JSON-unmarshal struct. Unmarshal once, return false when any
pointer is nil or unmarshalling fails, and dereference the validated pointers
when constructing responsesStreamUsage; preserve the existing omission behavior
for malformed usage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 87c6d21e-82dc-4ba0-9dc0-7b783c8a6a3b
📒 Files selected for processing (7)
internal/providers/deepseek/deepseek_test.gointernal/providers/responses_adapter_test.gointernal/providers/responses_converter.gointernal/providers/responses_converter_test.gointernal/providers/responses_input.gointernal/providers/responses_output.gointernal/providers/responses_output_state.go
Confidence Score: 3/5
What T-Rex did
Comments Outside Diff (2)
Reviews (1): Last reviewed commit: "fix(responses): preserve reasoning acros..." | Re-trigger Greptile |
|
Addressed the review findings in 7abcc27:
Validation passed: go test ./..., contract replay tests, race tests, lint, and the hot-path performance guard (87 allocations/op, 10,296 bytes/op). |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/providers/responses_converter_test.go`:
- Around line 286-315: Convert the new assistant-after-started-tool case at
internal/providers/responses_converter_test.go:286-315 into an entry in the
relevant table-driven converter test, preserving its expected output indexes.
Also convert the nested required usage-field omission case at
internal/providers/responses_converter_test.go:597-620 into an entry in the
appropriate table-driven test, retaining its expected behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 3fb82e59-1a06-4c00-891f-01e7d933cb0d
📒 Files selected for processing (3)
internal/providers/responses_converter.gointernal/providers/responses_converter_test.gotests/contract/testdata/golden/groq/responses_stream.golden.json
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/providers/responses_converter_test.go`:
- Around line 269-285: Update the test’s event tracking around the
response.output_item.added handling to preserve insertion order in an addedTypes
slice instead of relying only on addedIndexes. Add the expected added-item
sequence to each table-driven case, then assert the observed sequence; for
“assistant after started tool call,” require reasoning, function_call, then
message while retaining the existing index and reasoning assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 0fcf1267-4ceb-488e-9cd1-7c4207de3dc2
📒 Files selected for processing (1)
internal/providers/responses_converter_test.go
Summary
Validation
Summary by CodeRabbit
New Features
Bug Fixes