fix: preserve Responses tool call correlation IDs#936
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe Responses adapters now preserve output item IDs separately from function call IDs, use canonical call IDs for AG-UI tool events, and replay both identifiers in subsequent server-tool requests. Tests, exports, Changesets metadata, and E2E provider support are updated. ChangesResponses tool-call identity
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ResponsesStream
participant ResponsesTextAdapter
participant ServerTool
participant NextResponsesRequest
ResponsesStream->>ResponsesTextAdapter: Emit function call with item ID and call ID
ResponsesTextAdapter->>ServerTool: Emit tool events correlated by call ID
ServerTool->>ResponsesTextAdapter: Return tool result
ResponsesTextAdapter->>NextResponsesRequest: Replay function call item ID and output call ID
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
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 `@packages/ai-openrouter/src/adapters/responses-text.ts`:
- Around line 1161-1168: Update the output_item.added backfill around
toolCallMetadata and the output_item.done backfill in
packages/ai-openrouter/src/adapters/responses-text.ts#L1161-L1168 and
`#L1281-L1288`: initialize metadata.name with an empty-string fallback when
item.name is missing, and only update an existing name when both metadata.name
is absent and item.name is truthy. Preserve valid names and satisfy the
StreamedFunctionCallMetadata string contract at both sites.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: b38e706c-aabd-4520-9ef4-c475e9ce27a9
📒 Files selected for processing (9)
.changeset/fuzzy-pandas-call.mdpackages/ai-openrouter/src/adapters/responses-text.tspackages/ai-openrouter/src/index.tspackages/ai-openrouter/src/message-types.tspackages/ai-openrouter/tests/openrouter-responses-adapter.test.tspackages/openai-base/src/adapters/responses-text.tspackages/openai-base/src/index.tspackages/openai-base/tests/responses-text.test.tstesting/e2e/src/lib/feature-support.ts
Summary
call_idas the canonical tool-call correlation IDidas provider metadataRoot cause
Responses function calls carry two opaque identifiers with different roles: output-item
idis referenced by streamed argument events, whilecall_idpairs the call with itsfunction_call_output. The adapters keyed stream state by the output-item ID and also exposed that value as the tool-call ID, which discarded the actual correlation ID.When the provider returned different values, the agent loop sent the output-item ID as
function_call_output.call_id. The follow-up request could no longer correlate the tool result with the original call.Tests
add a two-turn OpenRouter server-tool regression test with deliberately distinct item and call IDs
verify the follow-up request preserves both IDs before and after SDK serialization
update OpenAI Responses coverage to assert
call_idcorrelation and output-item metadatainclude OpenRouter Responses in the tool-calling E2E matrix
pnpm test:prtargeted Playwright
openrouter-responses — tool-callingscenario (1 passed)Summary by CodeRabbit
Bug Fixes
toolCallIdhandling and retained tool-call names.Tests