Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Streaming tool calls can lose their identity or complete before their arguments finish. Responses deltas use an output item ID while completion uses a call ID; the shared stream builder also splits interleaved A/B/A/B chunks into four incomplete calls.
Map Responses item IDs to call IDs and names, with state isolated per collection. In the shared builder, retain pending calls by index or ID, fill in late identity fields, and emit complete calls in first-seen order at the existing flush boundaries. Starting another call no longer completes the previous one. Ambiguous anonymous continuations and conflicting identities are rejected.
The underlying fixes are already included in Kroog and working in production applications using Kroog: Responses identity and interleaved calls. This adaptation adds per-collection isolation to the Responses fix and keeps the builder's atomic-reference structure with an immutable pending-call list rather than importing Kroog's mutex. Responses request construction now occurs on collection. No dependencies or public signatures change.
Credit to Jewoo Shin (@jewoodev) for identifying and testing late-arriving IDs in #2134. This implementation also covers that case, and its regression test credits that PR. We tested #2134 unchanged: it fixes late IDs but still fails interleaving. Maintainers can merge this PR directly, or merge #2134 first and we can rebase this PR while retaining its regression coverage. No commit from #2134 is included here.
Validation: the interleaving and late-ID regressions fail before the builder change and pass afterwards. All 27 builder tests pass. Full JVM suites: prompt-model 200 passed with three existing ignored Markdown tests; OpenAI client 210 passed with no skips. Both modules' JVM JAR, ktlint and publication metadata checks pass, and compiled JVM ABIs exactly match their checked-in dumps. Responses regressions also cover cancelled recollection. Repository-wide, live-provider, simultaneous-emitter and non-JVM validation were not run.
Closes #2271.