# Durable tool results

Normal screenshots and long text are kept in full; display and model input are managed separately. Payload size alone never turns a successful tool action into a failure. Available resources still apply.

| Scenario | Codex | Claude Code | OpenCode | OpenProgram |
| --- | --- | --- | --- | --- |
| Large screenshots | Outside the text truncation budget | Subject to MCP output token limits | Not verified | Full images kept. Model adaptation and region inspection are separate work. |
| Long logs | Model-visible text truncated to budget | Oversized non-image output saved, path returned; default 25,000 tokens, configurable | Default 2,000 lines or 50 KiB, configurable; full text saved, preview and path returned | Full results kept. Unified previews, search and partial reads are directions. |
| Large display and event results | MCP event copies above 1 MiB become text previews and stay successful; no full-retention guarantee | Oversized non-image results become session tool-results references | Preview includes the full-output path | Display paged, large text by reference, tool success unchanged |
| Interruption and recovery | Not verified | Not verified | Not verified | Result and completion record published atomically; the completed-tool frontier is restored, so a persistence failure causes no re-execution |

Codex and OpenCode from public source, Claude Code from official documentation, which does not establish its private persistence. Not verified does not mean unsupported. Thresholds describe the cited paths only. Sources: [Codex output](https://github.com/openai/codex/blob/main/codex-rs/utils/output-truncation/src/lib.rs), [Codex events](https://github.com/openai/codex/blob/main/codex-rs/core/src/mcp_tool_call.rs), [Codex event threshold](https://github.com/openai/codex/blob/main/codex-rs/utils/pty/src/lib.rs), [Claude Code MCP](https://code.claude.com/docs/en/mcp#mcp-output-limits-and-warnings), [OpenCode output](https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/tool/truncate.ts).

## Storage

| Part | Rule |
| --- | --- |
| Assistant responses, tool results | Content-addressed blobs, free of the 64 KiB execution-stream frame limit |
| 1 MiB | Display-page or producer-chunk target. Blob storage does not reject at it. |
| Kept | Checkpoint metadata, reference counts, control-message budgets, content hashes, execution ownership checks |
| Model input policy | Unchanged |

## Preview cap

- The cap is the larger of the configured limit (default 30,000 characters) and the 2,000-character minimum, applied before deciding on truncation or a file.
- A result within the cap is returned once, with no marker and no file.
- Longer text keeps a non-overlapping head (70% by default) and tail, with a positive elided count. A zero-length tail adds no text.
- The shared normalizer does this for registered functions and Agent methods.

## Full-result files

- A whole text is kept in the running conversation's directory, at `tool_results/<sha256>.txt`, named by its content. It is deleted and backed up with the conversation. Outside a conversation (a one-off CLI call) it goes to the profile state directory's `tool_results/`.
- The same text is kept once; two different texts never share a name, whichever call or layer saved them. A raw provider call ID can repeat and plays no part in the name.
- An existing file is reused, since its name says it holds that text. A new one is written to a temporary file and moved into place, so the path is returned only after the complete file is written.
- Files written earlier under other names stay readable, without migration.

## Failure signals

Each tool sets `is_error` on the existing `ToolReturn` from its own execution branch. The common normalizer never infers failure from text, so a success beginning `Error:` stays a success.

| Tool | Error when | Stays as it was |
| --- | --- | --- |
| `execute_code` | Nonzero Python exit or timeout, keeping stdout, stderr and the exit code or timeout | Success; structured sandbox denials; no retry, no repeated subprocess, same backend choice. Timeout adapters keep partial output. |
| `image_analyze`, `image_generate`, `mixture_of_agents` | Provider or model unavailable, invalid explicit model reference, failed provider call, failed save, all references failed, failed aggregation | Partial reference failure keeps its synthesis or single-reference answer. Plain `execute` keeps its signature and string result; the registered tool is `_execute_result`. |
| Canvas | Validation, path policy, permission, missing block | Successful block bodies. Plain `execute` as above. Aliases, path admission, cancellation. |
| `ask_user_question` | Invalid question, unavailable infrastructure, noninteractive frontend, each with its original text | Valid answers stay strings; decline and timeout; same decorated `AgentTool`, name, schema, metadata and interaction manifest. Answers nothing automatically and changes no approval policy. |

Schemas, registered names, backend selection, paths, retry budgets, usage labels and cancellation are unchanged throughout.

## Pause before dispatch

- A pause accepted between completed actions is consumed before the next provider or tool dispatch.
- A planned operation that never started is recorded `not_started` and stays pending in the Agent resume cursor.
- A live owner paused before its first effect resumes the original durable admission, with no synthetic model response.
- A control command changing the execution version during result persistence retries only checkpoint publication under the same attempt fence. The external operation is not repeated.

## Reading results at the delegation limit

- `read_conversation` stays discoverable and reads an execution id at `agent.max_messages`. Reading creates no execution, branch or delivery and spends no allowance.
- Session and ancestor ownership checks still apply, before any wait.
- Exhausted chains still hide `agent`; `send_message` keeps its delivery-time guard. There is no separate cancellation tool.

**Acceptance**

| Subject | How it is exercised |
| --- | --- |
| `execute_code` | Registered tool through `AgentTool.execute` with real successful, failing and timed-out snippets |
| `read_conversation` | Public tool catalog resolved at the limit, an owned completed Job read, a foreign Job refused before waiting |
| Auxiliary providers | Registered wrappers with controlled official-provider transport and owned PNG files; unknown references, unavailable backends, sandbox denial before backend access, cancellation |
| Canvas | Registered tool on owned files; explicit flags, unchanged text, successful `Error:` data, plain-call compatibility |
| `ask_user_question` | Unavailable input and a controlled frontend answer through `AgentTool.execute`, with no real prompt |

## Implementation status

| State | Items |
| --- | --- |
| Implemented | Full image and text persistence, fresh-store restoration, completion-record reference reuse, corruption detection, everything above |
| Not implemented | Unified model-facing previews and on-demand reads, image-region inspection; existing capabilities need an audit first. Existing `reconciliation_required` executions are not repaired automatically. |
| Awaiting acceptance | Real credentials and remote model or image capabilities; installed-App display of `execute_code`, Canvas and full-result files; the preview-cap host and native checks |
