Repository navigation
fix(agents): read cannot open the full output of a large tool result under workspace-only read - #206972
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: passed. What this changesAllows 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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: Before mergeNone. Findings
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5aa4b8d4d291. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +111, Tests +307. Total +418 across 21 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment 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]>
aa25b10 to
a2c68f8
Compare
…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]>
…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]>
…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]>
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),readrefuses 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:
readmay open the session's own spill files, and nothing broader.Fix
The private spill writer (
sessions/tools/private-temp-file.ts) owns the allowlist:writePrivateTempFileandopenPrivateTempFileStreamtake an optionalowner({ 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.readthen 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
readguard. web_fetch's result cache is scoped by owner, so a cached result never points one session at another session's file.The
readguard (wrapToolWorkspaceRootGuardWithOptions) getsownFile. On an admitted path it skips only the root-containment check, and every other read step still runs. Onlyreadreceives it;ls,write,editandapply_patchkeep 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 tobash-tools.exec-auto-review-state.ts.Accepted edge cases (named, not coded):
User impact
Evidence
End to end, through
openclaw agent --localon a cheap OpenAI model, in an isolated state dir and HOME, withtools.fs.workspaceOnly: true. The model runshead -c 4000000 /dev/urandom | base64 -b 76 | head -n 50000(random lines, so line 30000 cannot be guessed) and is asked for line 30000:59e5c7309581: the 64 KB exec result keeps head and tail and names the full-output file.readon that file fails withPath escapes sandbox root (<workspace>): <tmp>/openclaw-exec-<id>.log, and the model replies UNKNOWN.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 productioncreateCoreCodingToolsworkspace-onlyread:readrefuses the path with the workspace-containment error (the "fresh owner" and "plugin path" cases below), which is what main does for every spill path.write,edit,lsandapply_patchon an admitted spill;..and/private/varaliases of exactly the issued file.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).