Skip to content

fix(agents): preserve spill-file pointers through elision and spill truncated web_fetch output - #100135

Merged
obviyus merged 3 commits into
mainfrom
codex/spill-to-file-recovery
Jul 5, 2026
Merged

obviyus merged 3 commits into
mainfrom
codex/spill-to-file-recovery

Conversation

@obviyus

@obviyus obviyus commented Jul 5, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes #100112.

This is a follow-up to #100077/#100042. Truncation could destroy recoverable output: history elision discarded live exec spill-file pointers, and web_fetch discarded overflow at fetch time.

Why This Change Was Made

This reuses the shipped spill seam. Elision markers preserve details.fullOutputPath when the file still exists, but only when the same Full output: <path> footer was already present in model-visible tool text.

That footer-visibility guard is enforced, not assumed: details-only paths are not surfaced, and JSON-escaped visible footers are detected so Windows-style paths stay recoverable without creating a new disclosure. Partial-spill honesty is preserved too: capped or source-truncated spills are labeled partial and are never claimed as full output.

web_fetch now spills truncated extracted content through owner-only private temp files, using the wrapped untrusted-content form rather than raw page text. Spills are capped at 2,000,000 chars, byte-capped/source-capped responses are marked partial, and the returned footer shares the exec footer contract through formatFullOutputFooter. Marker rendering degrades full -> compact -> plain rerun text, with a compact-pointer floor for valid spill pointers so recovery paths are not budget-starved.

The E2E scratch test initially caught that budget-starvation flaw: real temp paths were long enough that both aggregate clearing and recovery suffix truncation could drop the pointer. This revision treats the pointer as recovery-critical metadata while keeping pointerless results on the existing budget-sliced plain-marker behavior.

User Impact

Models can recover full command output and fetched web content after truncation/elision instead of re-running expensive commands or losing vanished web content.

No config surface was added. Existing exec footers remain byte-identical.

Evidence

Post-rebase onto current origin/main:

pnpm tsgo
Exit 0.

pnpm check:test-types
Exit 0.

node scripts/run-vitest.mjs src/agents/embedded-agent-runner/tool-result-truncation.test.ts src/agents/tools/web-tools.fetch.test.ts src/agents/session-tool-result-guard.tool-result-persist-hook.test.ts
Exit 0. Test Files: 3 passed. Tests: 104 passed.

Temporary production-path scratch E2E:
node scripts/run-vitest.mjs src/agents/spill-recovery.scratch.test.ts --reporter=verbose
Exit 0. Test Files: 1 passed. Tests: 1 passed. It exercised real bash capture, real web_fetch through a local HTTP proxy/server, aggregate elision, spill-file recovery, deleted-spill fallback, and details-without-visible-footer non-disclosure. The scratch file was deleted and was not committed.

Autoreview:
.agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main
Final actionable finding was fixed with an abort recheck after web_fetch spill writes; rerun exited 0 with no accepted/actionable findings before the final no-conflict rebase. The required verification above was rerun after that final rebase.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Jul 5, 2026
@clawsweeper

clawsweeper Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 4, 2026, 10:14 PM ET / 02:14 UTC.

Summary
The branch preserves existing spill-file footers through aggregate tool-result elision, adds private-temp-file spilling for truncated web_fetch output, and persists spill metadata.

PR surface: Source +220, Tests +332. Total +552 across 10 files.

Reproducibility: yes. for the blocking patch defect: source inspection shows web_fetch writes a host tmpdir spill and advertises it in tool text, while sandboxed read tools are rooted through the sandbox filesystem bridge. I did not run a live sandboxed web_fetch scenario in this read-only review.

Review metrics: 1 noteworthy metric.

  • Model-visible file path footer: 1 added. web_fetch now emits a Full output footer with a filesystem path, so reviewers must verify the active read boundary before merge.

Stored data model
Persistent data-model change detected: serialized state: src/agents/session-tool-result-guard.tool-result-persist-hook.test.ts, serialized state: src/agents/sessions/tools/bash.ts, serialized state: src/agents/sessions/tools/private-temp-file.ts, serialized state: src/agents/sessions/tools/tool-contracts.ts, serialized state: src/agents/tools/web-tools.fetch.test.ts, unknown-data-model-change: src/agents/sessions/tools/bash.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #100112
Summary: This PR is the open candidate fix for the canonical truncation-recovery issue; the earlier merged aggregate-budget PR is related predecessor work, not a replacement.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦪 silver shellfish
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Gate or reroute web_fetch spill footers for sandboxed/no-read contexts.
  • [P1] Add redacted live proof showing the after-fix web_fetch recovery path.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body lists typechecks and focused Vitest only; it still needs a redacted live OpenClaw web_fetch recovery run, terminal output, logs, or an artifact, and updating the PR body should trigger re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging as-is can advertise host tmpdir spill paths to sandboxed or no-read model contexts, making the recovery instruction unusable while exposing host filesystem layout.
  • [P1] The PR body only reports typechecks and focused tests; it still lacks after-fix real behavior proof from a live web_fetch recovery path.

Maintainer options:

  1. Fix sandbox-readable spill routing (recommended)
    Pass the needed sandbox/read context into web_fetch spill handling so it writes to a readable safe location or suppresses the footer when no safe read path exists, then cover that case.
  2. Accept the host-path disclosure deliberately
    Maintainers could explicitly accept host tmp paths for web_fetch only after documenting why sandboxed/no-read sessions may see unusable paths and why that disclosure is acceptable.
  3. Pause behind the canonical issue
    If the read-capability contract needs broader design, keep the PR open but treat Truncation discards recoverable output: history elision drops exec spill-file pointers; web_fetch never spills #100112 as the canonical decision point.

Next step before merge

  • [P1] The protected maintainer label plus the sandbox/read-capability security decision make this a human review item rather than a safe automated repair from this pass.

Security
Needs attention: web_fetch spill recovery exposes host temp-file paths without sandbox/read-capability gating.

Review findings

  • [P1] Gate web_fetch spill paths for sandboxed reads — src/agents/tools/web-fetch.ts:318-330
Review details

Best possible solution:

Keep the spill recovery goal, but make web_fetch recovery capability-aware and prove a live sandboxed and non-sandboxed recovery path before merge.

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

Yes for the blocking patch defect: source inspection shows web_fetch writes a host tmpdir spill and advertises it in tool text, while sandboxed read tools are rooted through the sandbox filesystem bridge. I did not run a live sandboxed web_fetch scenario in this read-only review.

Is this the best way to solve the issue?

No. The aggregate-elision preservation is plausible, but the web_fetch spill path is not the best fix until it either writes to a path the active read tool can read or suppresses the footer in sandboxed/no-read contexts.

Full review comments:

  • [P1] Gate web_fetch spill paths for sandboxed reads — src/agents/tools/web-fetch.ts:318-330
    This still writes every truncated web_fetch spill with writePrivateTempFile, which uses the host temp directory, and then emits Full output: <path> in model-visible text. Sandboxed runs use a read tool rooted through the sandbox filesystem bridge, so that host tmp path may be unreadable while disclosing host layout. Please write to a readable safe location or suppress the footer when the active session cannot safely read it.
    Confidence: 0.89

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7d3cfa85dca1.

Label changes

Label justifications:

  • P2: This is a bounded agent tool-output recoverability fix with a concrete merge blocker, not an emergency runtime outage.
  • merge-risk: 🚨 security-boundary: The diff can expose host temp-file paths to sandboxed model contexts without proving those paths are safe or readable there.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body lists typechecks and focused Vitest only; it still needs a redacted live OpenClaw web_fetch recovery run, terminal output, logs, or an artifact, and updating the PR body should trigger re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +220, Tests +332. Total +552 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 250 30 +220
Tests 4 339 7 +332
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 589 37 +552

Security concerns:

  • [medium] Host spill path exposed across sandbox boundary — src/agents/tools/web-fetch.ts:318
    The new web_fetch spill file is written under the host temp directory and surfaced in the model-visible footer even when the session is sandboxed, which can disclose host filesystem layout and produce an unusable recovery instruction.
    Confidence: 0.89

What I checked:

  • Repository policy read: Root AGENTS.md and scoped src/agents guidance were read; the root security-boundary and whole-surface review rules apply to this agent/tool PR. (AGENTS.md:1, 7d3cfa85dca1)
  • Current main still lacks web_fetch spill recovery: Current main wraps and truncates web_fetch output in memory without emitting a full-output spill path, so the PR is not obsolete on main. (src/agents/tools/web-fetch.ts:666, 7d3cfa85dca1)
  • PR emits host temp-file paths in model-visible web_fetch text: The PR writes truncated web_fetch content with writePrivateTempFile and appends a Full output footer containing that path to returned tool text. (src/agents/tools/web-fetch.ts:318, ef79db60ec6c)
  • Spill helper provenance: git blame ties the new spill helper and footer emission to commit 0a2eefd93be31416e1faf836f0452802179396d3 on the current PR branch. (src/agents/tools/web-fetch.ts:306, 0a2eefd93be3)
  • Sandboxed read tools are workspace-bridged: Sandboxed runs construct the read tool with createSandboxedReadTool rooted at sandboxRoot and a sandbox filesystem bridge, not with arbitrary host tmpdir read access. (src/agents/agent-tools.ts:743, 7d3cfa85dca1)
  • Sandbox path resolver rejects unmounted host paths: Sandbox filesystem resolution maps only configured mounts and throws a sandbox-root escape error when a path is outside the mounted workspace/bind roots. (src/agents/sandbox/fs-paths.ts:172, 7d3cfa85dca1)

Likely related people:

  • obviyus: Authored the merged predecessor aggregate tool-result truncation work and the current branch's spill-recovery commits, so they are closest to this follow-up behavior. (role: recent area contributor; confidence: high; commits: 168a4890bb4b, 0a2eefd93be3; files: src/agents/embedded-agent-runner/tool-result-truncation.ts, src/agents/tools/web-fetch.ts)
  • steipete: Recent web_fetch history includes multiple config/runtime refactors by this handle, including the config reader path that this PR reuses. (role: adjacent web_fetch contributor; confidence: medium; commits: e2c41df0b9eb, 49aef6044708; files: src/agents/tools/web-fetch.ts)
  • vincentkoc: Feature history shows provider-boundary and runtime-boundary work on the web_fetch surface that is relevant to safe fallback/spill behavior. (role: web_fetch provider-boundary contributor; confidence: medium; commits: 38d2faee20af, 6eca1949d5; files: src/agents/tools/web-fetch.ts, src/agents/tools/web-fetch-utils.ts)
  • Gio Della-Libera: Current blame in this checkout ties sandbox read-tool wiring and web_fetch enablement baseline lines to this author, but the shallow boundary makes this weaker routing evidence. (role: sandbox/read boundary source-history contributor; confidence: low; commits: 144e5894f6; files: src/agents/agent-tools.ts, src/agents/agent-tools.read.ts, src/agents/sandbox/fs-paths.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (1 earlier review cycle)
  • reviewed 2026-07-05T01:48:00.925Z sha f66cb58 :: needs real behavior proof before merge. :: [P1] Gate web_fetch spill paths for sandboxed reads

@obviyus
obviyus force-pushed the codex/spill-to-file-recovery branch from 8a8e647 to f66cb58 Compare July 5, 2026 01:39
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 5, 2026
@obviyus
obviyus force-pushed the codex/spill-to-file-recovery branch 2 times, most recently from ef79db6 to 58109e8 Compare July 5, 2026 02:21
obviyus added 3 commits July 4, 2026 19:21
Keep aggregate elision recoverable by preserving existing spill pointers only when the original model-visible footer already disclosed the path. This commit also keeps partial-spill markers honest, handles JSON-escaped footers, and resolves full-clear markers from the original tool-result message after partial aggregate shrinking.
Write truncated web_fetch extracted content to owner-only private temp files using the shared Full output footer contract. Spills use the wrapped untrusted-content form, cap recoverable content at 2,000,000 chars, and label capped or source-truncated spills as partial instead of full output.
Preserve fullOutputPath plus partial-spill metadata when oversized tool-result details are summarized for persistence. This keeps aggregate elision from relabeling capped or source-truncated web_fetch spill files as complete after reload.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Truncation discards recoverable output: history elision drops exec spill-file pointers; web_fetch never spills

1 participant