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 9d4d6f3
Browse filesBrowse the repository at this point in the historyBrowse files
fix(run): give schema runs a corrective turn after a permission rejection (#135)
In --output-schema mode a step that stopped on a headless permission
auto-reject ended the run as structured_output failed/missing with the
repair budget unspent. Treat it like a prose-only finish: it counts as an
attempt, emits structured_output_rejected with the fixed `denied`
diagnostic, and the next turn forces StructuredOutput with a reminder that
names the denied tools (never their arguments). The existing budget still
bounds it; exhaustion keeps reason `missing` and exit 3. Runs without a
schema still stop on a rejection.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copy file name to clipboardExpand all lines: EVENTS.md
+18-6Lines changed: 18 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -580,7 +580,8 @@ value in the terminal event below.
580
580
### `structured_output_rejected`
581
581
582
582
Emitted once per rejected StructuredOutput attempt, including an unusable result
583
-
file and a model turn that finishes in prose without a final tool call:
583
+
file, a model turn that finishes in prose without a final tool call, and a step
584
+
stopped by a headless permission rejection:
584
585
585
586
```json
586
587
{
@@ -618,6 +619,14 @@ asks it to fix the file at the JSON-encoded path. Malformed tool arguments (not
618
619
A prose-only finish emits the fixed diagnostic
619
620
`{ "path": "", "keyword": "missing", "message": "write the final result as JSON to a file in the working directory, then call StructuredOutput with its path" }`
620
621
and receives an ephemeral reminder before the next turn while budget remains.
622
+
A step that stops because a tool call's permission was auto-rejected (headless
623
+
mode has no user to approve; see `permission_rejected`) is handled the same way.
624
+
It emits the fixed diagnostic
625
+
`{ "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" }`.
626
+
The reminder names the denied tools, not their arguments, and asks the model to
627
+
finish with what it already has. Both corrective turns force the StructuredOutput
628
+
tool choice. Without `--output-schema`, a permission rejection
629
+
still ends the run.
621
630
Other tools remain usable until a valid final result; their outputs are not final
622
631
results. Only the `{ path }` tool schema is sent to the provider; local validation
623
632
of the file always uses the canonical schema.
@@ -638,19 +647,21 @@ or:
638
647
```
639
648
640
649
`attempts` counts StructuredOutput calls, including rejected/unparseable ones,
641
-
and prose-only finishes without a final call. Other tool calls do not count.
650
+
prose-only finishes without a final call, and steps stopped by a permission
651
+
rejection. Other tool calls do not count.
642
652
Compaction turns do not consume a missing-result attempt. Discarded provider
643
653
streams restore the budget and captured result; their rejection events remain
644
654
as telemetry. A valid call in a parallel step wins regardless of call order if
645
655
that step started with budget remaining. The attempt count includes every call
646
656
in that step and can exceed `maxAttempts`; the N+1 bound applies to corrective
647
657
turns.
648
658
When the budget is spent, the last rejection determines the reason: `missing`
649
-
for a prose-only finish, otherwise `exhausted`. Failure reasons are:
659
+
for a prose-only finish or a permission rejection, otherwise `exhausted`.
660
+
Failure reasons are:
650
661
651
662
-`exhausted`: invalid or unparseable calls spent the corrective budget.
652
-
-`missing`: prose finishes spent the budget, or the session ended normally
653
-
without an accepted result (including headless permission rejection).
663
+
-`missing`: prose finishes or permission rejections spent the budget, or the
664
+
session ended normally without an accepted result.
654
665
-`step_limit`: the agent reached its configured step cap without a result.
655
666
-`aborted`: the invocation was cancelled, including SIGINT/SIGTERM.
656
667
-`error`: a provider or session error, including stream idle timeout or an
@@ -664,4 +675,5 @@ Exit codes are **0** on accepted results, **2** for schema configuration errors,
664
675
**3** for exhausted attempts, missing output and step limits. Provider errors and
665
676
timeouts keep **1**; SIGINT and SIGTERM keep **130** and **143**.
666
677
`StructuredOutputError.data.retries` records the number of corrective
667
-
attempts used (initial attempt excluded), including prose-only corrective turns.
678
+
attempts used (initial attempt excluded), including corrective turns after a
Copy file name to clipboardExpand all lines: packages/cli/src/session/prompt.ts
+24-8Lines changed: 24 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,8 @@ IMPORTANT:
58
58
constSTRUCTURED_OUTPUT_MISSING=
59
59
"write the final result as JSON to a file in the working directory, then call StructuredOutput with its path"
60
60
61
+
constSTRUCTURED_OUTPUT_DENIED=`a tool call was denied; ${STRUCTURED_OUTPUT_MISSING}`
62
+
61
63
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.`
@@ -762,22 +763,78 @@ test("JSON mode without output-result carries the accepted value only in termina
762
763
])
763
764
},25000)
764
765
765
-
test("headless permission rejection reports missing output with no session error",async()=>{
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>"
768
+
769
+
test("headless permission rejection gets a corrective turn that can still succeed",async()=>{
0 commit comments