|
15 | 15 |
|
16 | 16 | ## Local Contracts |
17 | 17 |
|
18 | | -- Core leaked-call recovery runs first. Return on `skip_default_processing`; read its `params_temporary["leaked_tool_call"]` decision instead of classifying again. Recovered calls pass through as canonical JSON; quoted examples use the existing raw-text fallback without JSON repair. Rejected/truncated and multiple envelopes never reach this plugin's repair helpers. |
19 | | -- The core rejection path stores `{}` instead of rejected syntax and removes replayable output/continuation state before retrying. This applies with or without this plugin; `suppress_xml` continues to govern this plugin's non-tool XML fallback. |
| 18 | +- Core leaked-call classification runs first. Return on `skip_default_processing`; read its `params_temporary["leaked_tool_call"]` decision instead of classifying again. Recovered calls pass through as canonical JSON; quoted examples use the existing raw-text fallback without JSON repair. Rejected/truncated and multiple envelopes never enter JSON repair or become executable calls. |
| 19 | +- For rejected/truncated leaked calls, set `result_data["tool_call_retry_response"]` and refresh the generating log before core retry handling. Use `{}` by default; when `suppress_xml` is off, retain rejected XML-like text as thoughts through `format_fallback`, respecting `split_thoughts`. Rejected non-XML JSON stays `{}`. Core owns history insertion, removal of replayable output/continuation state, the counted warning and skipping dispatch, with `{}` as its fallback when this plugin is disabled. |
20 | 20 | - Leave canonical `LLMResult.function_calls` and their accompanying text untouched in either transport. The agent dispatches those calls through the normal tool-policy gate; text repair must not suppress them or reinterpret a textual follow-up as another call. |
21 | 21 | - Repaired and fallback JSON is always minified. |
22 | 22 | - Leave results already handled by an earlier `message_loop_result` extension (`skip_default_processing`) untouched, such as output-limit truncation retries. |
23 | 23 | - Usable Responses output text stays untouched for the core response-tool dispatcher. Recognizable tool intent still enters repair; Chat Completions non-tool output becomes `{"thoughts":[raw]}` and XML-like output becomes `{}` when suppression is enabled. |
24 | 24 | - Blank-line-separated thoughts expand into separate entries after repair when the split strategy is enabled (default on). This rewrites model-authored thoughts for every repaired turn by design, not only the raw-text fallback branch. |
25 | | -- `_select_value` returns only repaired tool calls or model-authored partial responses; `transform_response` wraps otherwise-raw output as thoughts afterward. `looks_like_tool_call` rejects that synthesized wrapper, so it reaches the fallback branch. Repaired output is usable only with a non-empty thoughts list, headline/tool name string, or tool-args dict. |
| 25 | +- `_select_value` returns only repaired tool calls or model-authored partial responses; `transform_response` uses the repair-free `format_fallback` for otherwise-raw output. `looks_like_tool_call` rejects that synthesized wrapper, so it reaches the fallback branch. Repaired output is usable only with a non-empty thoughts list, headline/tool name string, or tool-args dict. |
26 | 26 | - A raw-text fallback conversion must emit a `fw.msg_thoughts_fallback.md` history warning and a separate `fw.msg_thoughts_fallback_response.md` user notice, refresh the generating log and response item with the transformed thoughts JSON, and set `skip_default_processing` so the retry advances the unusable-response counter. |
27 | 27 | - The fallback passes the repaired `llm_result` to `hist_add_ai_response`, which owns Responses-API state advancement (`_remember_llm_result_state`); do not call the state method directly. The fallback turn's `response_id` is recorded so the next turn's `previous_response_id` chain stays intact. |
28 | 28 | - The fallback warning is counted by the core stop-unusable-response loop alongside `fw.msg_misformat.md`, `fw.msg_repeat.md`, `fw.msg_empty_response.md`, and `fw.msg_reasoning_only.md`. |
|
37 | 37 |
|
38 | 38 | ## Verification |
39 | 39 |
|
40 | | -- Run `pytest plugins/_context_doctor/tests`. |
| 40 | +- Run `pytest plugins/_context_doctor/tests tests/test_leaked_tool_call_integration.py`. |
41 | 41 |
|
42 | 42 | ## Child DOX Index |
43 | 43 |
|
|
0 commit comments