Commit 29a4941
committed
fix(orchestrator): always use delta mode when statefulMarker exists
**Problem:**
Claude models were looping - repeating the same actions over and over.
Root cause: SAM sent FULL conversation history even when statefulMarker existed,
causing Claude to see its own previous responses and repeat them.
**Investigation:**
1. Studied VS Code Copilot Chat reference implementation
2. Found they ALWAYS slice messages when previous_response_id exists
3. SAM only sliced when hasToolResults=true (workflow mode)
4. Regular conversations sent full history + statefulMarker = loops!
**Solution:**
Changed stateful marker slicing from:
`if let marker = statefulMarker, hasToolResults {`
To:
`if let marker = statefulMarker {`
Now SAM ALWAYS uses delta-only mode when statefulMarker exists, matching
VS Code behavior. Server already knows history up to marker, only send new messages.
**Why This Prevents Loops:**
- Before: Claude sees "I listed directory" → repeats same action → loop
- After: Claude only sees NEW context since last response → continues forward
**Also Fixed:**
1. Trailing whitespace bug (trim content before sending to API)
2. Tool result preview filtering (don't send UI-only messages)
3. Added message ID field to OpenAIChatMessage for future enhancements
**Testing:**
✅ Build: PASS
Next: Test with Claude to verify loop prevention
**References:**
- VS Code: reference/vscode-copilot-chat/src/platform/endpoint/node/responsesApi.ts
- Archive fix: ai-assisted/archive/similar-bug-20241218/handoff/fix-details.md1 parent 822c12c commit 29a4941
3 files changed
Lines changed: 32 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4274 | 4274 | | |
4275 | 4275 | | |
4276 | 4276 | | |
4277 | | - | |
4278 | | - | |
4279 | | - | |
4280 | | - | |
4281 | | - | |
4282 | | - | |
4283 | | - | |
4284 | | - | |
4285 | | - | |
4286 | | - | |
| 4277 | + | |
| 4278 | + | |
| 4279 | + | |
| 4280 | + | |
| 4281 | + | |
| 4282 | + | |
| 4283 | + | |
| 4284 | + | |
| 4285 | + | |
| 4286 | + | |
| 4287 | + | |
| 4288 | + | |
| 4289 | + | |
| 4290 | + | |
| 4291 | + | |
4287 | 4292 | | |
4288 | 4293 | | |
4289 | 4294 | | |
4290 | 4295 | | |
4291 | 4296 | | |
4292 | | - | |
| 4297 | + | |
4293 | 4298 | | |
4294 | 4299 | | |
4295 | 4300 | | |
| |||
4299 | 4304 | | |
4300 | 4305 | | |
4301 | 4306 | | |
4302 | | - | |
4303 | | - | |
4304 | | - | |
4305 | | - | |
4306 | 4307 | | |
4307 | 4308 | | |
4308 | 4309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
233 | 234 | | |
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
238 | 239 | | |
239 | 240 | | |
| 241 | + | |
240 | 242 | | |
241 | 243 | | |
242 | 244 | | |
| |||
245 | 247 | | |
246 | 248 | | |
247 | 249 | | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
| |||
253 | 256 | | |
254 | 257 | | |
255 | 258 | | |
| 259 | + | |
256 | 260 | | |
257 | 261 | | |
258 | 262 | | |
259 | 263 | | |
260 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
261 | 274 | | |
262 | 275 | | |
263 | | - | |
| 276 | + | |
264 | 277 | | |
265 | 278 | | |
266 | 279 | | |
| |||
0 commit comments