Commit 01d5c10
committed
Disambiguate tool_call vs tool_result item_id fallback
cursor[bot] 3151054134 (Low): _map_tool_call and _map_tool_output
both used ``item_id = str(getattr(raw, "id", "") or call_id)``. When
the SDK's raw item lacks an ``id``, both fall back to the same
``call_id``, so the two AgentContextItems collide on item_id.
AgentContext._index is keyed by item_id, so the second append()
silently overwrites the first — get_context_item then returns the
wrong item even though both still live in self.items.
Namespace the fallback: tool-call-{call_id} for the assistant call
and tool-result-{call_id} for the tool result. Items with intact
raw.id are unaffected. Includes a regression test that constructs
a tool_call/tool_output pair without raw.id and asserts distinct
item_ids; verified the test fails when the fix is reverted.1 parent b60f620 commit 01d5c10
2 files changed
Lines changed: 41 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
156 | 160 | | |
157 | 161 | | |
158 | 162 | | |
| |||
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
184 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
185 | 191 | | |
186 | 192 | | |
187 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
0 commit comments