Skip to content

fix(runtime): offload tool output into the sandbox workspace; fail closed when a spill fails - #1048

Merged
blove merged 2 commits into
mainfrom
blove/offload-managed-workspace
Oct 21, 2026
Merged

blove merged 2 commits into
mainfrom
blove/offload-managed-workspace

Conversation

@blove

@blove blove commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Problem

Observed live in the software factory's builder (agent route, managed Docker sandbox via sandbox.thread): a 1,724,820-byte runBash result was inlined into the model context and the next call failed with "Input tokens exceed the configured limit of 272000 tokens".

Root cause: buildOffload in packages/cli/src/lib/runtime/execute-route-core.ts built the OffloadStore with workspaceRoot = <appRoot>/workspace (a host path) while the backend for a sandboxed route is the sandbox filesystem, rooted at /workspace and path-jailed. Every write threw, and offloadToolOutput did catch { return content }, so the guard failed open, without any warning, for every sandboxed app.

Fix

  • buildOffload now takes the admitted sandbox workspace root (handle.workspaceRoot). Spills go through the sandbox backend to /workspace/tool-outputs/…, and the stub's tool-outputs/… path is readable by the sandboxed readFile tool (core's readFile byte-cap exemption applies unchanged). Local workspaces are unchanged.
  • offloadToolOutput fails closed. A failed write returns a bounded stub: the first previewLines lines, capped at 8,192 chars, plus the error message with absolute paths elided and a note that the output was truncated and not saved. A new optional onError callback lets the runtime warn once per distinct cause through console.warn.
  • buildStub previews are capped at 8,192 chars, so one giant line can't ride inline in the success stub either. A JSON-string tool result (a tool that returns a string) is previewed by its real lines.
  • Docs: context-management.mdx (sandboxed workspaces, fail-closed truncation) and the OffloadToolOutputCtx contract in api/langchain.mdx.

Tests (written first, failing before the fix)

  • packages/cli/test/managed-workspace-runtime.test.ts: "offloads an oversized tool result into the sandbox workspace and reads it back through readFile". A sandboxed agent route's tool returns about 99k chars. The ToolMessage is a stub pointing at tool-outputs/dump-call_dump.txt, the file exists at /workspace/tool-outputs/… in the sandbox, and readFile reads it back in full. Before the fix it failed with the full content inlined. The test fixture's managed provider gains an opt-in jail that models the real path jail.
  • packages/langchain/test/offload-tool-output.test.ts: a store write failure yields the bounded stub, never the content, and no host path appears; the stub stays bounded for a single giant line. This replaces the old "returns original content" test, which encoded the defect.
  • packages/langchain/test/offload-stub.test.ts: preview char cap; JSON-string preview.

Gates

  • pnpm --filter @b4run/langchain test: 567 passed
  • pnpm --filter @b4run/cli test: 2819 passed, 4 skipped; no timeouts
  • typecheck and lint (langchain, cli): clean
  • node scripts/check-docs.mjs: passed
  • node scripts/check-changesets.mjs: passed (patch for cli and langchain)

🤖 Generated with Claude Code

…osed when a spill fails

A sandboxed agent route's tool-output offload store was built with the host
`<appRoot>/workspace` root while its backend was the managed sandbox's
filesystem (root `/workspace`, path-jailed). Every spill threw at the jail, and
offloadToolOutput's `catch { return content }` inlined the full result: a 1.7 MB
runBash grep went straight into the model context and the next call exceeded
the input-token limit.

- execute-route-core: buildOffload takes the admitted sandbox workspace root, so
  spills go through the sandbox backend to /workspace/tool-outputs/ and the
  stub's tool-outputs/ path is readable by the sandboxed readFile tool.
- offloadToolOutput: a failed write returns a bounded stub (preview lines,
  capped at 8,192 chars, plus the error message with absolute paths elided),
  never the full content; the runtime warns once per distinct cause.
- buildStub: preview capped at 8,192 chars; a JSON string result is previewed
  by its real lines.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
b4-run Ready Ready Preview Oct 20, 2026 7:57pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
navlog-web Skipped Skipped Oct 20, 2026 7:57pm UTC

Request Review

@blove
blove enabled auto-merge (squash) October 20, 2026 19:28

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval for repository bookkeeping. The maintainer reviews and merges this PR.

@vercel
vercel Bot temporarily deployed to Preview – navlog-web October 20, 2026 19:56 Inactive
@blove
blove temporarily deployed to vercel-preview October 20, 2026 19:56 — with GitHub Actions Inactive
@blove
blove merged commit bb8da42 into main Oct 21, 2026
30 checks passed
@blove
blove deleted the blove/offload-managed-workspace branch October 21, 2026 00:36

This branch was successfully deployed

1 active and 2 inactive deployments
Preview – b4-run — bd43bfaf Deployed Oct 20, 2026 by vercel[bot]
vercel-preview — bd43bfaf Deployed Oct 20, 2026 by blove via vercel-native #3064
Preview – navlog-web — bd43bfaf Deployed Oct 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant