Repository navigation
Commit 6417797
committed
fix: bound denied tool call retries with cross-message doom loop detection
Reworks the previous attempt (b6c640b) after reproducing the actual bug
from anomalyco#31108: with experimental.continue_loop_on_deny: true and a plugin
that auto-rejects permission asks via the v1 SDK (e.g. kimaki subagent
auto-reject), the model can retry the same denied tool call forever.
Root cause: a denied tool call ends the provider step, so the model's
retry always lands in a NEW assistant message. The doom loop guard only
scanned parts of the current assistant message, so identical denied
retries never accumulated and the guard never fired.
Fix:
- processor.ts: add a cross-message doom loop check. When the same-message
scan does not match, look at the trailing tool parts across the session
(MessageV2.lastParts, bounded window). If the last DOOM_LOOP_THRESHOLD
tool parts are identical errored calls matching the incoming call,
trigger the doom_loop permission ask. Only errored runs count, so
routine successful repeats (e.g. periodic status checks) do not trip
the guard. The part of the call being evaluated is excluded by
messageID + callID since provider tool call IDs are only unique within
a single response.
- message-v2.ts: add lastParts(sessionID, limit) querying the most recent
parts of a session via the part_session_idx index.
Reverted from the previous attempt, with reasons:
- tools.ts catchDefect converting permission defects to typed failures:
a no-op. Effect v4 runPromise rejects with the squashed cause, which is
the original error object for both Fail and Die, so error identity
already survives Effect.orDie all the way to failToolCall. Verified by
instrumentation.
- processor.ts blocking on DeniedError/CorrectedError: behavior change
that contradicts the original design (7368342). CorrectedError carries
user feedback the model should act on; DeniedError is a static ruleset
deny the model should adapt to. Both now documented in a comment.
Tests (the previous test was vacuous: a blanket pattern "*" deny removes
the tool from the tool list entirely via Permission.disabled, so no
permission ask ever fired and it passed on unpatched upstream):
- rejected permission continues loop when continue_loop_on_deny is true
- rejected permission blocks loop by default
- repeated identical rejected calls trigger doom loop guard across
messages (fails without this fix: 7 LLM calls instead of 4)
Fixes anomalyco#31108
Session: ses_15eee3980ffe5eK2RPweao3nyU1 parent a6e5538 commit 6417797
4 files changed
Lines changed: 191 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
517 | 539 | | |
518 | 540 | | |
519 | 541 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
247 | 249 | | |
248 | 250 | | |
249 | 251 | | |
| |||
525 | 527 | | |
526 | 528 | | |
527 | 529 | | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
532 | 533 | | |
533 | 534 | | |
534 | 535 | | |
535 | 536 | | |
536 | 537 | | |
537 | 538 | | |
538 | | - | |
539 | | - | |
540 | | - | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
541 | 581 | | |
542 | 582 | | |
543 | 583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
90 | 89 | | |
91 | 90 | | |
92 | 91 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 92 | + | |
98 | 93 | | |
99 | 94 | | |
100 | 95 | | |
| |||
209 | 204 | | |
210 | 205 | | |
211 | 206 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | 207 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
2279 | 2280 | | |
2280 | 2281 | | |
2281 | 2282 | | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
2282 | 2306 | | |
2283 | | - | |
| 2307 | + | |
2284 | 2308 | | |
2285 | 2309 | | |
2286 | 2310 | | |
2287 | 2311 | | |
2288 | 2312 | | |
2289 | 2313 | | |
2290 | 2314 | | |
| 2315 | + | |
2291 | 2316 | | |
2292 | 2317 | | |
2293 | 2318 | | |
2294 | | - | |
2295 | | - | |
| 2319 | + | |
| 2320 | + | |
2296 | 2321 | | |
2297 | | - | |
2298 | 2322 | | |
2299 | 2323 | | |
2300 | 2324 | | |
2301 | 2325 | | |
2302 | 2326 | | |
2303 | 2327 | | |
2304 | | - | |
2305 | | - | |
| 2328 | + | |
2306 | 2329 | | |
2307 | 2330 | | |
2308 | 2331 | | |
2309 | 2332 | | |
2310 | 2333 | | |
2311 | 2334 | | |
2312 | 2335 | | |
2313 | | - | |
2314 | | - | |
2315 | | - | |
2316 | | - | |
2317 | | - | |
2318 | | - | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
2319 | 2341 | | |
2320 | 2342 | | |
2321 | | - | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
2322 | 2424 | | |
0 commit comments