Skip to content

fix(deepagents): return backend errors from the file tools to the model - #1082

Closed
Baihao Wang (byhow) wants to merge 2 commits into
mainfrom
fix/execute-tool-sandbox-errors
Closed

Baihao Wang (byhow) wants to merge 2 commits into
mainfrom
fix/execute-tool-sandbox-errors

Conversation

@byhow

@byhow Baihao Wang (byhow) commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

When a backend throws inside a file tool, the tool now returns the error to the model as an error tool message. This covers ls, read_file, write_file, edit_file, delete, glob, grep and execute. Before this change the error left the tool and ended the whole run, so the model never saw what went wrong and could not try something else.

Two ways to reach it on a sandbox backend. A command leaves a background job holding stdout open, and the sandbox service rejects the request. Or a grep over a large tree outlives the sandbox client's request timeout. Either way the backend's client throws. The model now gets a tool message with error status and the content Error: followed by the backend's message. An error a backend returns, and a command that exits non-zero, are unchanged.

The catch is in the tools, not in one backend, so it covers every backend that throws, including backends outside this repo. Without it the throw is fatal because the filesystem middleware registers a wrapToolCall hook, and the tool node rethrows an error that passes through such a hook unless the agent sets handleToolErrors.

What to check

  • Start at callBackend in fs.ts. It is the only new logic. Each tool makes its backend call through it and returns early when it gets a tool message back. The rest of the fs.ts diff is those call sites, and much of it is re-indentation, so hide whitespace when you read it.
  • The rethrow rule. Interrupts, other graph control flow and an aborted run are not backend failures, so they still propagate. The helper rethrows when isGraphBubbleUp is true for the error or the run was aborted. The parent notifier middleware already used the same pair of checks.
  • A client timeout is not an abort. A TimeoutError from the backend's own request timeout is reported to the model, because the run's signal is not aborted.
  • Why a helper and not the middleware's wrapToolCall hook. That hook wraps every tool call in the agent, not only this middleware's tools, and it does not run when a tool is invoked directly.
  • Callers that relied on the throw. These tools now return on a backend error, so middleware that retries a tool call only when it throws, such as toolRetryMiddleware, no longer retries them for that error. Code that invokes a tool directly gets the error text back instead of a rejection. Errors a backend returns already behaved this way.
  • An error named AbortError still propagates even when no signal is aborted, as before. A backend client that times out its own request with that name would still end the run. The backends in this repo use TimeoutError or their own error types.
  • wasAborted moved, unchanged, from parent_notifier.ts to middleware/utils.ts so both callers share it. It is not exported from the package.

Not in this PR

  • A backend factory that throws while a tool resolves its backend still ends the run.
  • So does a throw from the write the middleware makes when it moves an oversized tool result to the backend.
  • The sandbox grep command has no time limit or output cap of its own, so a slow search still runs until the client's timeout before the model sees the error.

Tests

New cases in fs.test.ts, on the file's existing mock sandbox backend. For each tool, a backend that rejects yields an error tool message and the tool does not throw. A GraphInterrupt and an error named AbortError are rethrown as the same object. A TimeoutError from grep is reported, and an agent run with a fake model continues to a second model turn after it. wasAborted has direct cases in utils.test.ts.

Python counterpart: langchain-ai/deepagents#7820

🤖 Generated with Claude Code

… model

When the sandbox backend rejected a command, the error left the `execute`
tool and ended the whole run. The tool now returns it as an error tool
message, as the other filesystem tools do for backend errors, so the
model can read it and try another command.

Interrupts, other graph control flow and aborted runs still propagate.
The abort check that the parent notifier already used moves to the
shared middleware utils so both callers use the same one.
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
deepagentsjs-ui Ready Ready Preview Nov 18, 2026 10:49pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 646f96f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
deepagents Patch
deepagents-acp Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@robin-agent robin-agent 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.

✅ Robin Review: No issues found

Robin reviewed this PR and found no potential bugs to report.

Open in Robin

@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

npm i https://pkg.pr.new/deepagents-acp@1082

deepagents

npm i https://pkg.pr.new/deepagents@1082

@langchain/sandbox-standard-tests

npm i https://pkg.pr.new/@langchain/sandbox-standard-tests@1082

@langchain/daytona

npm i https://pkg.pr.new/@langchain/daytona@1082

@langchain/deno

npm i https://pkg.pr.new/@langchain/deno@1082

@langchain/modal

npm i https://pkg.pr.new/@langchain/modal@1082

@langchain/node-vfs

npm i https://pkg.pr.new/@langchain/node-vfs@1082

@langchain/quickjs

npm i https://pkg.pr.new/@langchain/quickjs@1082

commit: 646f96f

When a backend method threw inside `ls`, `read_file`, `write_file`,
`edit_file`, `delete`, `glob` or `grep`, the error left the tool and
ended the whole run. A sandbox request that timed out during a `grep`
was enough to do it. Each tool now returns the error as an error tool
message, so the model can read it and try something else.

The tools make their backend call through one helper, and `execute`
uses it in place of its own catch. Interrupts, other graph control flow
and aborted runs still propagate. A request timeout raised by the
backend's own client is not an aborted run, so it is reported.
@byhow Baihao Wang (byhow) changed the title fix(deepagents): return sandbox errors from the execute tool to the model fix(deepagents): return backend errors from the file tools to the model Nov 18, 2026

This branch was successfully deployed

1 active deployment
Preview — 646f96f3 Deployed Nov 18, 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