You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 716edb5
Browse filesBrowse the repository at this point in the historyBrowse files
fix(run): count one attempt per step and name rejected calls neutrally (#179 review)
- A step that rejects a StructuredOutput file and also stops on a rejected
tool call already spent its attempt; do not count a second `rejected`
diagnostic, but still send the corrective reminder. Exhaustion then reports
`exhausted`, not `missing`.
- Question.RejectedError also stops the loop, so word the reminder and
diagnostic as a rejected tool call (keyword `rejected`) instead of a denied
permission, and document both sources in EVENTS.md.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copy file name to clipboardExpand all lines: EVENTS.md
+17-14Lines changed: 17 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -562,7 +562,7 @@ value in the terminal event below.
562
562
563
563
Emitted once per rejected StructuredOutput attempt, including an unusable result
564
564
file, a model turn that finishes in prose without a final tool call, and a step
565
-
stopped by a headless permission rejection:
565
+
stopped by a rejected tool call (such as a headless permission rejection):
566
566
567
567
```json
568
568
{
@@ -600,14 +600,17 @@ asks it to fix the file at the JSON-encoded path. Malformed tool arguments (not
600
600
A prose-only finish emits the fixed diagnostic
601
601
`{ "path": "", "keyword": "missing", "message": "write the final result as JSON to a file in the working directory, then call StructuredOutput with its path" }`
602
602
and receives an ephemeral reminder before the next turn while budget remains.
603
-
A step that stops because a tool call's permission was auto-rejected (headless
604
-
mode has no user to approve; see `permission_rejected`) is handled the same way.
605
-
It emits the fixed diagnostic
606
-
`{ "path": "", "keyword": "denied", "message": "a tool call was denied; write the final result as JSON to a file in the working directory, then call StructuredOutput with its path" }`.
607
-
The reminder names the denied tools, not their arguments, and asks the model to
608
-
finish with what it already has. Both corrective turns force the StructuredOutput
609
-
tool choice. Without `--output-schema`, a permission rejection
610
-
still ends the run.
603
+
A step that stops on a rejected tool call is handled the same way. In headless
604
+
mode this is a permission auto-rejected because there is no user to approve it
605
+
(see `permission_rejected`); through the SDK it can also be a dismissed
606
+
question. It emits the fixed diagnostic
607
+
`{ "path": "", "keyword": "rejected", "message": "a tool call was rejected; write the final result as JSON to a file in the working directory, then call StructuredOutput with its path" }`.
608
+
The reminder names the rejected tools, not their arguments, and asks the model to
609
+
finish with what it already has. If the same step contains a rejected
610
+
StructuredOutput call, that call is the step's attempt: no `rejected` diagnostic
611
+
is added, but the corrective reminder still follows. Both corrective turns force
612
+
the StructuredOutput tool choice. Without `--output-schema`, a rejected tool
613
+
call still ends the run.
611
614
Other tools remain usable until a valid final result; their outputs are not final
612
615
results. Only the `{ path }` tool schema is sent to the provider; local validation
613
616
of the file always uses the canonical schema.
@@ -628,20 +631,20 @@ or:
628
631
```
629
632
630
633
`attempts` counts StructuredOutput calls, including rejected/unparseable ones,
631
-
prose-only finishes without a final call, and steps stopped by a permission
632
-
rejection. Other tool calls do not count.
634
+
prose-only finishes without a final call, and steps stopped by a rejected tool
635
+
call without a StructuredOutput call. Other tool calls do not count.
633
636
Compaction turns do not consume a missing-result attempt. Discarded provider
634
637
streams restore the budget and captured result; their rejection events remain
635
638
as telemetry. A valid call in a parallel step wins regardless of call order if
636
639
that step started with budget remaining. The attempt count includes every call
637
640
in that step and can exceed `maxAttempts`; the N+1 bound applies to corrective
638
641
turns.
639
642
When the budget is spent, the last rejection determines the reason: `missing`
640
-
for a prose-only finish or a permission rejection, otherwise `exhausted`.
643
+
for a prose-only finish or a rejected tool call, otherwise `exhausted`.
641
644
Failure reasons are:
642
645
643
646
-`exhausted`: invalid or unparseable calls spent the corrective budget.
644
-
-`missing`: prose finishes or permission rejections spent the budget, or the
647
+
-`missing`: prose finishes or rejected tool calls spent the budget, or the
645
648
session ended normally without an accepted result.
646
649
-`step_limit`: the agent reached its configured step cap without a result.
647
650
-`aborted`: the invocation was cancelled, including SIGINT/SIGTERM.
@@ -657,4 +660,4 @@ Exit codes are **0** on accepted results, **2** for schema configuration errors,
657
660
timeouts keep **1**; SIGINT and SIGTERM keep **130** and **143**.
658
661
`StructuredOutputError.data.retries` records the number of corrective
659
662
attempts used (initial attempt excluded), including corrective turns after a
Copy file name to clipboardExpand all lines: packages/cli/src/session/prompt.ts
+13-9Lines changed: 13 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ IMPORTANT:
61
61
constSTRUCTURED_OUTPUT_MISSING=
62
62
"write the final result as JSON to a file in the working directory, then call StructuredOutput with its path"
63
63
64
-
constSTRUCTURED_OUTPUT_DENIED=`a tool call was denied; ${STRUCTURED_OUTPUT_MISSING}`
64
+
constSTRUCTURED_OUTPUT_REJECTED=`a tool call was rejected; ${STRUCTURED_OUTPUT_MISSING}`
65
65
66
66
constSTRUCTURED_OUTPUT_SYSTEM_PROMPT=`IMPORTANT: The user has requested structured output. Write your final result as JSON to a file in the working directory, then call the StructuredOutput tool with that file's path. Do NOT respond with plain text.`
Copy file name to clipboardExpand all lines: packages/cli/test/cli/run-output-schema.test.ts
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -763,8 +763,8 @@ test("JSON mode without output-result carries the accepted value only in termina
763
763
])
764
764
},25000)
765
765
766
-
constDENIED_REMINDER=
767
-
"<system-reminder>Permission denied for read. Using what you already have, write the final result as JSON to a file in the working directory, then call StructuredOutput with its path</system-reminder>"
766
+
constREJECTED_REMINDER=
767
+
"<system-reminder>Tool call rejected: read. Using what you already have, write the final result as JSON to a file in the working directory, then call StructuredOutput with its path</system-reminder>"
768
768
769
769
test("headless permission rejection gets a corrective turn that can still succeed",async()=>{
770
770
constresult=awaitrun({
@@ -778,8 +778,8 @@ test("headless permission rejection gets a corrective turn that can still succee
0 commit comments