Commit 74793bc
authored
fix: strip provider-specific IDs from Responses API content blocks (#170)
The v0.3.8 fix (#168) only cleared additional_kwargs and
response_metadata, but when using the OpenAI Responses API
(use_responses_api=True), the rs_ IDs live inside content blocks:
content=[{"type": "text", "text": "...", "id": "rs_abc123", ...}]
langchain_openai extracts these block-level IDs and passes them as
Responses API item IDs. When both original and cached messages share
the same rs_ IDs in checkpoint state, the next LLM call fails with
"Duplicate item found with id rs_...".
Changes:
- Add _strip_content_ids() helper to remove 'id' fields from content
blocks when content is a list (semantic_cache.py)
- Apply it during cache deserialization in _deserialize_response()
- Add _sanitize_request() safety net in composition.py that strips
provider IDs from all AIMessages before they reach the LLM handler,
protecting against stale checkpoint data from before the fix
- Wrap MiddlewareStack.awrap_model_call handler with sanitization
- Add integration tests with realistic Responses API message format1 parent cba5b70 commit 74793bc
4 files changed
Lines changed: 1017 additions & 3 deletions
File tree
- langgraph/middleware/redis
- tests/integration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
39 | 95 | | |
40 | 96 | | |
41 | 97 | | |
| |||
99 | 155 | | |
100 | 156 | | |
101 | 157 | | |
102 | | - | |
103 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
104 | 166 | | |
105 | 167 | | |
106 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
32 | 50 | | |
33 | 51 | | |
34 | 52 | | |
| |||
101 | 119 | | |
102 | 120 | | |
103 | 121 | | |
| 122 | + | |
104 | 123 | | |
105 | 124 | | |
106 | 125 | | |
| |||
0 commit comments