Repository navigation
fix(runtime): offload tool output into the sandbox workspace; fail closed when a spill fails - #1048
Merged
Merged
Conversation
…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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
blove
enabled auto-merge (squash)
October 20, 2026 19:28
…ages Co-Authored-By: Claude Fable 5.1 <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Observed live in the software factory's builder (agent route, managed Docker sandbox via
sandbox.thread): a 1,724,820-byterunBashresult was inlined into the model context and the next call failed with "Input tokens exceed the configured limit of 272000 tokens".Root cause:
buildOffloadinpackages/cli/src/lib/runtime/execute-route-core.tsbuilt theOffloadStorewithworkspaceRoot = <appRoot>/workspace(a host path) while the backend for a sandboxed route is the sandbox filesystem, rooted at/workspaceand path-jailed. Every write threw, andoffloadToolOutputdidcatch { return content }, so the guard failed open, without any warning, for every sandboxed app.Fix
buildOffloadnow takes the admitted sandbox workspace root (handle.workspaceRoot). Spills go through the sandbox backend to/workspace/tool-outputs/…, and the stub'stool-outputs/…path is readable by the sandboxedreadFiletool (core's readFile byte-cap exemption applies unchanged). Local workspaces are unchanged.offloadToolOutputfails closed. A failed write returns a bounded stub: the firstpreviewLineslines, 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 optionalonErrorcallback lets the runtime warn once per distinct cause throughconsole.warn.buildStubpreviews 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.context-management.mdx(sandboxed workspaces, fail-closed truncation) and theOffloadToolOutputCtxcontract inapi/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 attool-outputs/dump-call_dump.txt, the file exists at/workspace/tool-outputs/…in the sandbox, andreadFilereads it back in full. Before the fix it failed with the full content inlined. The test fixture's managed provider gains an opt-injailthat 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 passedpnpm --filter @b4run/cli test: 2819 passed, 4 skipped; no timeoutsnode scripts/check-docs.mjs: passednode scripts/check-changesets.mjs: passed (patch for cli and langchain)🤖 Generated with Claude Code