fix: drain SSE buffers and key OpenAI tool-call index - #4
Merged
Merged
Conversation
Pin rs_ai_oauth to workspace 0.2.35, run cargo test --all-features in CI (matching Makefile), allow clippy::result_large_err on realtime/live WebSocket error types so stable clippy stays green, and add .agents setup/resume for Amp orbs. Co-authored-by: Max Carter <undivisible@vk.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a0a5f1-add5-707e-9a8f-326da4a2366c
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_467e4a13-5409-4727-8fc6-566c7e78dbba) |
|
Tick the box to add this pull request to the merge queue (same as
|
Amp-Thread-ID: https://ampcode.com/threads/T-01a0a5f1-add5-707e-9a8f-326da4a2366c Co-authored-by: Max Carter <undivisible@vk.com>
undivisible
force-pushed
the
maintenance/stream-and-cache
branch
from
September 15, 2026 17:04
33b8ae0 to
ba5661c
Compare
Portkey and Cloudflare were re-parsing the entire SSE buffer on every chunk, duplicating TextDelta events with quadratic cost. Drain completed lines like xAI. OpenAI-compatible streaming now keys pending tool calls by delta.tool_calls[].index so parallel tools do not collide. Cache keys include max_steps. Amp-Thread-ID: https://ampcode.com/threads/T-01a0a5f1-add5-707e-9a8f-326da4a2366c Co-authored-by: Max Carter <undivisible@vk.com>
undivisible
force-pushed
the
maintenance/stream-and-cache
branch
from
September 15, 2026 17:08
a4f941c to
12e9cc5
Compare
Merged
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.
Summary
TextDeltas (and[DONE]) with quadratic cost. They now drain completed newline-terminated frames the same way xAI already does.delta.tool_calls[].indexvalues collided. Parser now uses the tool-call index, with serde defaults for omitted delta fields (id/role/function.name).CacheMiddlewareincludesmax_stepsin the cache key so agent-loop depth cannot return a cached one-shot result.Tests
split_sse_chunks_emit_each_delta_onceon Portkey and Cloudflareparallel_tool_calls_use_tool_index_not_choice_indexdifferent_max_steps_is_a_cache_misscargo test --workspace --all-featuresNotes
Backward-compatible. Does not touch OAuth/auth. Safe to auto-merge after CI is green.
Made with Amp
Note
Medium Risk
Streaming and parallel tool-call parsing changes affect live provider behavior; cache key change only affects correctness of cached agent-loop results, not security.
Overview
Fixes SSE streaming for Cloudflare and Portkey: instead of re-parsing the full accumulated buffer on every chunk (which duplicated
TextDeltaevents and scaled poorly), each chunk now drains only newline-complete frames viaparse_stream_chunk, matching the incremental pattern used elsewhere.For OpenAI-compatible streaming, pending tool calls are keyed by
delta.tool_calls[].index(with choice index as fallback), so parallel tool streams no longer collide. API types gainserde(default)(and optionalindex) so partial tool-call deltas deserialize cleanly; outbound tool calls setindex: None.CacheMiddlewarenow hashesmax_stepsinto the cache key so different agent loop depths cannot share a cached response.Adds targeted tests for split SSE chunks, parallel tool-call indexing, and
max_stepscache misses.Reviewed by Cursor Bugbot for commit ba5661c. Configure here.