Skip to content

Commit 40c41fb

Browse files
byapparovclaude
andcommitted
fix(session): drop rejections from discarded retry streams (#179 review 2)
A retryable stream error rolls the attempt's parts back, but the blocked set kept the rejected tool. The retried turn then stopped and, in schema mode, got a "Tool call rejected" corrective turn and an attempt for a call the model never saw. Clear the set on rollback. Also reword the structured_output_rejected intro around corrective-budget attempts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 716edb5 commit 40c41fb

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎EVENTS.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,10 @@ value in the terminal event below.
560560

561561
### `structured_output_rejected`
562562

563-
Emitted once per rejected StructuredOutput attempt, including an unusable result
564-
file, a model turn that finishes in prose without a final tool call, and a step
565-
stopped by a rejected tool call (such as a headless permission rejection):
563+
Emitted once per rejected attempt against the corrective budget: a rejected
564+
StructuredOutput call (including an unusable result file), a model turn that
565+
finishes in prose without a final tool call, or a step stopped by a rejected
566+
tool call (such as a headless permission rejection):
566567

567568
```json
568569
{

‎packages/cli/src/session/processor.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ export namespace SessionProcessor {
484484
const retry = SessionRetry.retryable(error)
485485
if (retry !== undefined) {
486486
reset?.()
487+
// The discarded attempt's rejections never reach the model's history.
488+
blocked.clear()
487489
// Keep the failed attempt's file changes available to revert tooling.
488490
await patch()
489491
retried.push(

‎packages/cli/test/session/output-schema.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,14 @@ test("permission rejection beside an invalid call with no budget left reports ex
660660
expect(result.outcomes).toEqual([{ status: "failed", reason: "exhausted", attempts: 1 }])
661661
}, 15000)
662662

663+
test("permission rejection in a discarded stream does not reach the corrective turn", async () => {
664+
const result = await run(["unused", "prose", '{"result":"accepted"}'], 2, { denied: true, retry: true })
665+
expect(result.requests, JSON.stringify(result.info)).toHaveLength(3)
666+
expect(JSON.stringify(result.requests[2].messages)).not.toContain("Tool call rejected")
667+
expect(result.rejected).toMatchObject([{ attempt: 1, errors: [{ keyword: "missing" }] }])
668+
expect(result.outcomes).toEqual([{ status: "accepted", attempts: 2, value: { result: "accepted" } }])
669+
}, 15000)
670+
663671
test("permission rejection without a schema still stops the loop", async () => {
664672
const result = await run(["prose"], 0, { denied: true, plain: true })
665673
expect(result.requests).toHaveLength(1)

0 commit comments

Comments
 (0)