Repository navigation
fix(responses): keep reasoning item IDs consistent across streaming events - #51243
Conversation
PR overviewNo security issues were found in this pull request. Reviews
|
|
@greptileai review |
|
bugbot run |
|
@veria-ai Please review 8e536f8 for consistent reasoning item IDs across streaming, WebSocket, and bridge responses, including deployment affinity compatibility |
[Medium impact] The reviewed changes appear safe to merge. SummaryThis PR keeps reasoning item IDs consistent across streamed events and completed Responses output.
Reviews (2) · Last reviewed commit: "fix(responses): use immutable affinity i..." · Reviewed by Greptile |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 8e536f8. Configure here.
|
@greptileai review |
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Handwritten 1-3 sentence description
Details
TLDR
Problem this solves:
How it solves it:
Intentional product change: With encrypted-content affinity enabled, reasoning and compaction items carry encoded IDs before ciphertext arrives, including items returned without ciphertext. This keeps event correlation and ID-only deployment affinity consistent
User Flow
Before, the client stores two copies of one reasoning item
rs_IDs on item events andencitem_IDs in the completed responseAfter, the client stores one reasoning item
encitem_ID on item events, reasoning deltas and the completed responseRelevant issues
Fixes #47881
Pre-Submission checklist
Screenshots / Proof of Fix
Baseline
deb7697a8e515671774b3ccda6dd6d67123e41cc, head8e536f868b7298e8b457d7f98bce7ebfccfc696fIndependent Devin verification used source checkouts at both SHAs, two proxy workers and dedicated Redis instances. Both runs logged two started worker processes, with no reload worker-count exception. No tracked source was changed by the verifier
Before (deb7697)
HTTP and completions bridge
WebSocket
With the baseline source proxy serving port 4882, run the complete
live_ws_two_turn.pyclient embedded belowObserved output, with variable IDs truncated
After (8e536f8)
HTTP and completions bridge
WebSocket
With source commit
8e536f868b7298e8b457d7f98bce7ebfccfc696fserving port 4881, run the same clientObserved output, with variable IDs truncated
The live Anthropic completions bridge and WebSocket path show the same two-IDs-to-one-ID change. Six ID-only replay requests remained pinned to the originating deployment at both SHAs. Non-streaming output still carries encoded IDs. Ciphertext can differ between provider events, so identity comparisons use IDs
Executed HTTP and bridge verification client and configuration
Set
OPENAI_API_KEY,ANTHROPIC_API_KEY,LITELLM_MASTER_KEY,LITELLM_SALT_KEYandDATABASE_URLin the environment. Install the frozen proxy-dev and e2e-dev environment and rebuild the source package for each tested SHASave this as
config_47881.yaml. The baseline run used the same model configuration with Redis port 6882redis-server --port 6881 --save "" --appendonly no --daemonize yes LITELLM_LOCAL_MODEL_COST_MAP=True python litellm/proxy/proxy_cli.py --config config_47881.yaml --port 4881 --num_workers 2 --detailed_debug --reload --use_v2_migration_resolverSave the exact executed client below as
compact_verify.py. RunPROXY_URL=http://127.0.0.1:4881 python compact_verify.py gpt-reasoningand repeat withclaude-bridge. For the baseline, use its port 4882Executed WebSocket and item-reference clients
Executed scripts, verbatim (only env var names; the scripts print id prefixes only, no ciphertext). Both ran unchanged at baseline (:4882) and head 8e536f8 (:4881).
live_ws_two_turn.py(run:PROXY_URL=http://127.0.0.1:4881 python live_ws_two_turn.py <outdir> gpt-reasoning):Output baseline | head:
live_item_reference.py(run:PROXY_URL=... LITELLM_MASTER_KEY=... REPS=6 python live_item_reference.py gpt-reasoning <outdir>):Head output (
RAW_IDis the done id, which isencitem_at head so R2/R4 equal R1/R3; at baseline R2 was rawrs_and not pinned):Bridge:
live_bridge_rust.py claude-bridge <outdir> bothis the same request body ascompact_verify.pywithmodel: claude-bridge, recording added/done/scoped/completed reasoning ids andencrypted_contentpresence.Regression checks
At head, the four changed unit files pass 630 tests. Running those head tests against baseline source produces eight failures in the new identity and affinity regressions, with 622 passing
The broader caller selection passes 3,100 tests, and the Rust crate passes 80 tests. Canonical source/test Ruff, formatting, strict-rule, type-discipline, test-quality, OpenAPI docs and basedpyright budget gates all pass against the merge base in the frozen remote environment
Python changed executable-line coverage is 77/77, or 100%, with no uncovered branches originating on changed lines. New and changed utility functions are fully branch-covered. The larger existing
_process_chunkand_wrap_response_eventfunctions retain unchanged uncovered branches, at 81.8% and 84.6% branch coverage respectively. These numbers are distinct from repository-wide coverage. The current-tip unit workflow passed all 56 jobs. Codecov reports all modified coverable lines covered in its PR reportRust instrumented coverage at the same head hits 11/11 changed executable lines and all 27 LLVM regions on those lines. The affected file has 241/248 lines covered, with seven pre-existing misses. The instrumented crate run passes 80 tests. Stable Rust 1.98.0 rejects the nightly-only branch instrumentation flag, so Rust branch-counter coverage is unavailable and is not reported as passing
rustup component add llvm-tools cargo install cargo-llvm-cov --version 0.9.1 --locked cd litellm-rust cargo llvm-cov -p litellm-inference-responses --no-report cargo llvm-cov report -p litellm-inference-responses --lcov --output-path lcov.infoType
Bug Fix
Caveats
Medium
8e536f868b7298e8b457d7f98bce7ebfccfc696f, with 121 checks passed and five integration suites failed. All 56 unit jobs passed. Seven integration suites passed, while five suites contain 11 unrelated failures, classified using logs, source inspection and the paired execution results belowtotal_spendfield in the unchanged auto-router session response. Extensions failed chat guardrail finish_reason, S3 chat-log delivery, and OTEL chat attribute-shedding assertions. None exercises the changed Responses handlingGreptile reviewed
8e536f868b7298e8b457d7f98bce7ebfccfc696fwith confidence 5/5 and no findings after the WebSocket proof was added. Cursor Bugbot and Veria completed with no new issues on the same commit. The addressed WebSocket proof thread is resolvedLow
Integration failure comparison
The focused comparison ran the eight unique cases behind the 11 CI failures. The three configuration cases ran in both management modes. Direct baseline
deb7697a8e515671774b3ccda6dd6d67123e41ccand PR head8e536f868b7298e8b457d7f98bce7ebfccfc696fproduced identical results, six failed and five passed across the 11 executions. No candidate-only failure was observedtotal_spendfield rejected by unchanged assertionmaturin==1.15.0with networking disabled. Devin cache contains itfinish_reasoninModelResponseIterator, producingcontent_filterwhere test expectsstopCI tested merge
e0126e01d4c7b52ba11ef38563c990b07960017a, whose parents are mainb63656a5de6a95487d2f4826e2cbe4cccca0d02eand the PR head. The merge diff against its main parent contains exactly this PR's eight files. The guardrail case failed withassert 'content_filter' == 'stop'on both that main parent and mergeBoth direct commits used native extensions built from their matching source. The additional main-parent and merge runs reused the corresponding extensions only after verifying identical Rust trees. Commands used
tests/integration/run.py <group> --results <directory> <exact node IDs>with the canonical integration environment and suite worker counts. Suites were limited to the failing cases, with no source edits or test weakeningThe paired environment used PostgreSQL 14 and Redis 8.10, while CI used PostgreSQL 16 and Redis 7. It did not apply CI's egress iptables guard. These differences limit conclusions about CI-only timing and telemetry failures. Seven failed CI executions were reproduced without this PR, two are explicit missing-cache failures, and two did not reproduce in either paired run. This supports the unrelated classification but does not claim every CI failure was reproduced on baseline
Integration comparison commands
Run in each source checkout after provisioning the disposable integration database and matching native extension. Database passwords below are the test harness defaults, not production credentials
Final Attestation