Skip to content

fix(agents): read cannot open the full output of a large tool result under workspace-only read - #206972

Merged
obviyus merged 1 commit into
mainfrom
core/spill-read-scope
Nov 27, 2026
Merged

obviyus merged 1 commit into
mainfrom
core/spill-read-scope

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

#206880 saves the full output of a large tool result to a private file and tells the model Full output: <path> (page it with read offset/limit). exec and web_fetch already did the same for their own output. In host sessions with workspace-only file access (tools.fs.workspaceOnly, or guarded/read-only permission modes), read refuses that path: the file sits in the OS temp directory, outside the workspace. The model is told where the omitted output is but cannot open it, and falls back to rerunning the tool.

Review of #206880 flagged this in both rounds. The owner approved this follow-up with a fixed scope: read may open the session's own spill files, and nothing broader.

Fix

The private spill writer (sessions/tools/private-temp-file.ts) owns the allowlist:

  • writePrivateTempFile and openPrivateTempFileStream take an optional owner ({ agentId, sessionKey }). After the exclusive create, the writer records the file's realpath under that owner. Registration happens only there. A path taken from a tool result (details.spill.path, fullOutputPath) is never trusted, so a plugin cannot name an arbitrary file.
  • resolveOwnSpillFile(owner, path) admits a path only when its realpath was recorded for that same owner, and it is a regular file owned by this uid.
  • The list is process memory with caps: newest 64 paths per owner, 256 owners. A restart or eviction makes old paths unreadable again, and read then refuses them visibly.

The owner is computed once per embedded attempt, with the same expression tool construction already uses for its session key. The same value goes to the #206880 bound step, exec's output file, web_fetch's spill, and the read guard. web_fetch's result cache is scoped by owner, so a cached result never points one session at another session's file.

The read guard (wrapToolWorkspaceRootGuardWithOptions) gets ownFile. On an admitted path it skips only the root-containment check, and every other read step still runs. Only read receives it; ls, write, edit and apply_patch keep the plain workspace guard. Sandboxed sessions are unchanged: their spills are already staged inside the workspace.

Two existing helpers moved verbatim into sibling modules so the touched files stay under their line caps: assertSandboxPathWithinAnyRoot → agent-tools.workspace-roots.ts, sanitizeWebFetchUrl → web-fetch-utils.ts. One exec auto-review state block moved to bash-tools.exec-auto-review-state.ts.

Accepted edge cases (named, not coded):

  • After a restart or cap eviction, older spill paths are refused again.
  • A subagent cannot read its parent's spill files.
  • A same-uid local process could swap the file between the check and the open. It can already read everything.

User impact

Evidence

End to end, through openclaw agent --local on a cheap OpenAI model, in an isolated state dir and HOME, with tools.fs.workspaceOnly: true. The model runs head -c 4000000 /dev/urandom | base64 -b 76 | head -n 50000 (random lines, so line 30000 cannot be guessed) and is asked for line 30000:

  • Merge base 59e5c7309581: the 64 KB exec result keeps head and tail and names the full-output file. read on that file fails with Path escapes sandbox root (<workspace>): <tmp>/openclaw-exec-<id>.log, and the model replies UNKNOWN.
  • This PR: the same read (offset 30000, limit 3) succeeds. The reply equals line 30000 of the spill file on disk.

src/agents/sessions/tools/private-temp-file.test.ts, through the production createCoreCodingTools workspace-only read:

  • A session reads its own spill outside the workspace with offset/limit. Without an owner record, the same production read refuses the path with the workspace-containment error (the "fresh owner" and "plugin path" cases below), which is what main does for every spill path.
  • Denied:
    • a file at a plugin-chosen path;
    • an unissued file with a spill-like name;
    • another session's spill (same agent);
    • the same session key under another agent;
    • a fresh owner;
    • an admitted path replaced by a symlink or a directory;
    • a neighbour file reached through an alias;
    • write, edit, ls and apply_patch on an admitted spill;
    • a missing file, and a file owned by another uid.
  • Allowed: .. and /private/var aliases of exactly the issued file.
  • Caps: the newest 64 paths per owner and 256 owners are kept.

Also: exec and web_fetch register their own files (bash-tools.exec-approval-output.test.ts, web-fetch.provider-fallback.test.ts), and the attempt's bound step passes the owner (attempt-context-guards.test.ts).

The design was reviewed adversarially before coding; the rejected alternatives were session-tagged file names (they admit a name pattern) and a per-session directory root (it admits any file in the directory).

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: a2c68f822a66b8d2822cccdd373da27e9c2ddca9
  • Maintainer: @obviyus
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/bash-tools.exec-auto-review-state.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

Allows workspace-only read access to private spill files created for the same agent and session.

Example: A workspace-only session receives a large tool result and requests lines 2–3 from its advertised private spill file.

  • Before: read rejects the file because it is outside the workspace.
  • After: read returns the requested lines when the private writer registered that file for this session.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and source-consistent, but required real-behavior proof is absent and the failed ratchet check remains unattributed.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The agent receives a full-output file pointer but cannot read the omitted content under workspace-only permissions.
Reason: This maintainer-approved repair makes existing output-recovery instructions usable without adding configuration or broad filesystem access.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it addresses a confirmed current-main failure with approved scope, and no blocking correctness or security defect was found.

Reviewed head: aa25b108f72ca7d05a8aab23d18bf4b138332db4

Before merge

None.

Findings

  • [P3] Update the documented workspace-only spill restriction — docs/tools/exec.md:179
Agent review details

How this fits together

The embedded runtime passes session identity to output writers and file tools; writers register exact spill paths, and the read guard consumes those registrations before opening a file.

flowchart TD
  A[Embedded attempt] --> B[Agent and session identity]
  B --> C[Tool output writers]
  C --> D[Private spill file registry]
  B --> E[Workspace read guard]
  D --> E
  E --> F[Bounded file reader]
Loading

Technical review

Best possible solution:

Retain writer-owned exact-file registration and the read-only exception, with documentation reflecting its session and restart limits.

Do we have a high-confidence way to reproduce the issue?

Current-main source directly shows private host spills outside the workspace reaching a containment guard without an exception; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The repair uses the existing private writer as the single registration owner, threads one session identity through affected consumers, and avoids granting access from plugin-supplied output paths.

Full review comments:

  • [P3] Update the documented workspace-only spill restriction — docs/tools/exec.md:179
    The exec guide still states that workspace-only read cannot reach these temporary output files and instructs the agent to use exec instead. This PR makes that statement false for registered files in the originating session. Update the guidance to describe the new read path and its accepted restart/eviction limits: https://docs.openclaw.ai/tools/exec.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5aa4b8d4d291.

Provenance checked

  • Host workspace containment changes intended behavior with a stated reason (4b0d573: Workspace-scoped permission modes constrain file access; the approved follow-up deliberately adds only exact session-created spill reads.)
  • Sandbox mappings and linked worktrees keeps the original intent (0ab1513: File-tool admission must follow effective sandbox mounts; the moved helper retains those checks and linked-worktree handling.)
  • Private output files keeps the original intent (202514e: Preserve omitted exec output in an exclusively created private file named in results and exit wakes.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 202514e adds src/agents/sessions/tools/private-temp-file.ts:100 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 202514ee61a0; files: src/agents/sessions/tools/private-temp-file.ts)

PR surface

Source +111, Tests +307. Total +418 across 21 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 16 195 84 +111
Tests 5 314 7 +307
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 509 91 +418

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add the shipped-runtime evidence described in testingReview.missingE2e.
  • Obtain the provider-branching diagnostic and establish whether it is introduced or inherited.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 27, 2026, 5:12 PM ET / 22:12 UTC.

…pace-only read

The private spill writer records each file it creates under the session
that asked for it; the workspace read guard admits exactly those files
(realpath, regular file, same uid). Only read gets the exception.

Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus
obviyus force-pushed the core/spill-read-scope branch from aa25b10 to a2c68f8 Compare November 27, 2026 22:16
@obviyus
obviyus merged commit af3f48d into main Nov 27, 2026
135 checks passed
@obviyus
obviyus deleted the core/spill-read-scope branch November 27, 2026 22:33
obviyus added a commit that referenced this pull request Nov 27, 2026
…spill shape (#206984)

## What Problem This Solves

A tool result can point to a file holding its full output. Two shapes record that pointer:
- web_fetch and the record-time bound (#206880) use `details.spill { path, chars?, truncated? }`;
- exec uses flat `details.fullOutputPath` plus `details.spillTruncated`.

So every reader handles both shapes:
- `getToolResultSpillDetails` (history elision and the bound's producer-spill reuse) falls back to the flat fields. It also reads a `spilledChars` field that nothing writes.
- The persisted-details allowlists keep both shapes (6 extra keys).
- The tokenjuice plugin checks exec's flat field to leave spilled results alone.

## Fix

Exec records `details.spill { path, truncated? }`, the one shape. Exec has bytes, not chars, so it does not set `chars`. The flat fields and every reader of them are removed:
- the flat fallback, and the never-written `spilledChars`, in `getToolResultSpillDetails`;
- `fullOutputPath`, `spilledChars` and `spillTruncated` in both persistence allowlists;
- tokenjuice now checks `details.spill`.

Accepted edge case: no migration. Exec results recorded before this change keep their text footer (`Full output: <path>`), but history elision no longer finds their pointer in `details`. The owner approved this. Spill files live in the OS temp directory anyway, so old pointers rarely outlive the session.

Not touched: `fullOutputPath` on the session `BashResult`/`BashToolDetails` types and the agent-core bash-execution message. Those are a different, extension-facing contract, and exec never writes them.

## User impact

None visible. The exec result text is unchanged. Model-visible behavior is the same: elision and the bound reuse exec's file as before, through the shared shape.

## Evidence

- `session-tool-result-guard.test.ts`: an exec output file cut at its limit records `spill: { path, truncated: true }`.
- `tool-result-truncation.test.ts`: history elision with an exec-shaped spill keeps its pointer.
- `runtime.integration.test.ts` (tokenjuice): a spilled exec result is left to the host.
- `tool-result-bounds.test.ts` (owner, unchanged) and `session-tool-result-guard.tool-result-persist-hook.test.ts` (fallback keeps `spill`) still pass.
- `bash-tools.exec-approval-output.test.ts`: a real exec spill path, read through workspace-only `read` (#206972), comes from `details.spill.path`.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…under workspace-only read (openclaw#206972)

## What Problem This Solves

openclaw#206880 saves the full output of a large tool result to a private file and tells the model `Full output: <path> (page it with read offset/limit)`. exec and web_fetch already did the same for their own output. In host sessions with workspace-only file access (`tools.fs.workspaceOnly`, or guarded/read-only permission modes), `read` refuses that path: the file sits in the OS temp directory, outside the workspace. The model is told where the omitted output is but cannot open it, and falls back to rerunning the tool.

Review of openclaw#206880 flagged this in both rounds. The owner approved this follow-up with a fixed scope: `read` may open the session's own spill files, and nothing broader.

## Fix

The private spill writer (`sessions/tools/private-temp-file.ts`) owns the allowlist:
- `writePrivateTempFile` and `openPrivateTempFileStream` take an optional `owner` (`{ agentId, sessionKey }`). After the exclusive create, the writer records the file's realpath under that owner. Registration happens only there. A path taken from a tool result (`details.spill.path`, `fullOutputPath`) is never trusted, so a plugin cannot name an arbitrary file.
- `resolveOwnSpillFile(owner, path)` admits a path only when its realpath was recorded for that same owner, and it is a regular file owned by this uid.
- The list is process memory with caps: newest 64 paths per owner, 256 owners. A restart or eviction makes old paths unreadable again, and `read` then refuses them visibly.

The owner is computed once per embedded attempt, with the same expression tool construction already uses for its session key. The same value goes to the openclaw#206880 bound step, exec's output file, web_fetch's spill, and the `read` guard. web_fetch's result cache is scoped by owner, so a cached result never points one session at another session's file.

The `read` guard (`wrapToolWorkspaceRootGuardWithOptions`) gets `ownFile`. On an admitted path it skips only the root-containment check, and every other read step still runs. Only `read` receives it; `ls`, `write`, `edit` and `apply_patch` keep the plain workspace guard. Sandboxed sessions are unchanged: their spills are already staged inside the workspace.

Two existing helpers moved verbatim into sibling modules so the touched files stay under their line caps: `assertSandboxPathWithinAnyRoot` → `agent-tools.workspace-roots.ts`, `sanitizeWebFetchUrl` → `web-fetch-utils.ts`. One exec auto-review state block moved to `bash-tools.exec-auto-review-state.ts`.

Accepted edge cases (named, not coded):
- After a restart or cap eviction, older spill paths are refused again.
- A subagent cannot read its parent's spill files.
- A same-uid local process could swap the file between the check and the open. It can already read everything.

## User impact

- Gateway and one-shot users on the embedded runtime with workspace-only file access can now page the full output that a large tool result points to, instead of rerunning the tool.
- No new config, no schema change, no new retention rule. The spill location and lifetime stay those of openclaw#206880: the OS temp directory, 0600, OS cleanup.

## Evidence
End to end, through `openclaw agent --local` on a cheap OpenAI model, in an isolated state dir and HOME, with `tools.fs.workspaceOnly: true`. The model runs `head -c 4000000 /dev/urandom | base64 -b 76 | head -n 50000` (random lines, so line 30000 cannot be guessed) and is asked for line 30000:
- Merge base `8744e6101f66`: the 64 KB exec result keeps head and tail and names the full-output file. `read` on that file fails with `Path escapes sandbox root (<workspace>): <tmp>/openclaw-exec-<id>.log`, and the model replies UNKNOWN.
- This PR: the same `read` (offset 30000, limit 3) succeeds. The reply equals line 30000 of the spill file on disk.

`src/agents/sessions/tools/private-temp-file.test.ts`, through the production `createCoreCodingTools` workspace-only `read`:
- A session reads its own spill outside the workspace with offset/limit. Without an owner record, the same production `read` refuses the path with the workspace-containment error (the "fresh owner" and "plugin path" cases below), which is what main does for every spill path.
- Denied:
  - a file at a plugin-chosen path;
  - an unissued file with a spill-like name;
  - another session's spill (same agent);
  - the same session key under another agent;
  - a fresh owner;
  - an admitted path replaced by a symlink or a directory;
  - a neighbour file reached through an alias;
  - `write`, `edit`, `ls` and `apply_patch` on an admitted spill;
  - a missing file, and a file owned by another uid.
- Allowed: `..` and `/private/var` aliases of exactly the issued file.
- Caps: the newest 64 paths per owner and 256 owners are kept.

Also: exec and web_fetch register their own files (`bash-tools.exec-approval-output.test.ts`, `web-fetch.provider-fallback.test.ts`), and the attempt's bound step passes the owner (`attempt-context-guards.test.ts`).

The design was reviewed adversarially before coding; the rejected alternatives were session-tagged file names (they admit a name pattern) and a per-session directory root (it admits any file in the directory).

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…spill shape (openclaw#206984)

## What Problem This Solves

A tool result can point to a file holding its full output. Two shapes record that pointer:
- web_fetch and the record-time bound (openclaw#206880) use `details.spill { path, chars?, truncated? }`;
- exec uses flat `details.fullOutputPath` plus `details.spillTruncated`.

So every reader handles both shapes:
- `getToolResultSpillDetails` (history elision and the bound's producer-spill reuse) falls back to the flat fields. It also reads a `spilledChars` field that nothing writes.
- The persisted-details allowlists keep both shapes (6 extra keys).
- The tokenjuice plugin checks exec's flat field to leave spilled results alone.

## Fix

Exec records `details.spill { path, truncated? }`, the one shape. Exec has bytes, not chars, so it does not set `chars`. The flat fields and every reader of them are removed:
- the flat fallback, and the never-written `spilledChars`, in `getToolResultSpillDetails`;
- `fullOutputPath`, `spilledChars` and `spillTruncated` in both persistence allowlists;
- tokenjuice now checks `details.spill`.

Accepted edge case: no migration. Exec results recorded before this change keep their text footer (`Full output: <path>`), but history elision no longer finds their pointer in `details`. The owner approved this. Spill files live in the OS temp directory anyway, so old pointers rarely outlive the session.

Not touched: `fullOutputPath` on the session `BashResult`/`BashToolDetails` types and the agent-core bash-execution message. Those are a different, extension-facing contract, and exec never writes them.

## User impact

None visible. The exec result text is unchanged. Model-visible behavior is the same: elision and the bound reuse exec's file as before, through the shared shape.

## Evidence

- `session-tool-result-guard.test.ts`: an exec output file cut at its limit records `spill: { path, truncated: true }`.
- `tool-result-truncation.test.ts`: history elision with an exec-shaped spill keeps its pointer.
- `runtime.integration.test.ts` (tokenjuice): a spilled exec result is left to the host.
- `tool-result-bounds.test.ts` (owner, unchanged) and `session-tool-result-guard.tool-result-persist-hook.test.ts` (fallback keeps `spill`) still pass.
- `bash-tools.exec-approval-output.test.ts`: a real exec spill path, read through workspace-only `read` (openclaw#206972), comes from `details.spill.path`.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant