ISSUE DESCRIPTION GLOBTIMEOUT does not bound wall-clock time — tool blocks until the…
- User
ISSUE DESCRIPTION
GLOB_TIMEOUTdoes not bound wall-clock time — tool blocks until the runaway glob finishesSubmission checklist
- This is a bug, not a usage question.
- I added a clear and descriptive title.
- I searched existing issues and didn't find this.
- I can reproduce this with the latest released version.
- I included a minimal reproducible example and steps to reproduce.
Area (Required)
- deepagents (SDK)
- cli
- code
- talon
- acp
- evals
- harbor
- daytona
- modal
- quickjs
- runloop
- langsmith-sandbox
- Other / not sure / general
Related Issues / PRs
No response
Reproduction Steps / Example Code (Python)
import time from unittest.mock import patch from deepagents.backends import StateBackend from deepagents.middleware import filesystem as fs_mw from deepagents.middleware.filesystem import FilesystemMiddleware class FakeRuntime: tool_call_id = "demo" state = {"files": {}} store = None context = None stream_writer = None config = {} backend = StateBackend() real_glob = backend.glob middleware = FilesystemMiddleware(backend=backend) glob_tool = next(t for t in middleware.tools if t.name == "glob") def slow_glob(*args, **kwargs): time.sleep(3) # a glob that takes 3s (stand-in for a huge tree / slow mount) return real_glob("*.none") with ( patch.object(fs_mw, "GLOB_TIMEOUT", 0.5), # 20s in production; shortened for the repro patch.object(backend, "glob", side_effect=slow_glob), ): start = time.monotonic() msg = glob_tool.invoke({"pattern": "**/*", "runtime": FakeRuntime()}) print(f"returned after {time.monotonic() - start:.2f}s: {msg.content!r}") # Expected: returns after ~0.5s (the timeout) # Actual: returns after ~3.0s -- the full duration of the "timed out" globError Message and Stack Trace (if applicable)
returned after 3.01s: 'Error: glob timed out after 0.5s. Try a more specific pattern or a narrower path.'Description
- The synchronous
globtool created byFilesystemMiddlewareenforcesGLOB_TIMEOUT(20s) by running the backend glob on a worker thread:future.result(timeout=GLOB_TIMEOUT)inside awith concurrent.futures.ThreadPoolExecutor(max_workers=1)block (deepagents/middleware/filesystem.py,sync_glob). - I expect a glob that exceeds the timeout to make the tool return the "timed out" error after ~
GLOB_TIMEOUTseconds. - Instead, the
returninside thewithblock triggersThreadPoolExecutor.__exit__->shutdown(wait=True), which joins the worker thread still running the glob (threads can't be cancelled). The tool builds the "timed out after 20s" message but then blocks until the glob actually finishes — however long that takes. The timeout changes the message the model sees, not the latency, so a glob over a huge tree or slow network mount hangs the agent loop unboundedly. - Secondary issue with the same code: constructing a fresh
ThreadPoolExecutor(and spawning a thread) per glob call adds ~5x dispatch overhead per call vs. reusing a shared executor. - The async variant (
async_glob) is not affected —asyncio.wait_forcancels and returns immediately.
Environment / System Info
OS: macOS 14 (Darwin 23.6.0, arm64) Python: 3.13.5 deepagents: 0.6.8 (also reproducible on main @ 676abecf)
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /deepagents, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant file. Let's first see what's in the current directory.
- Assistant
Let me explore the repository structure more to find the relevant files.
- Assistant
Now let me examine the filesystem middleware file where the issue is reported.
- Assistant
Let me search for the relevant code around the GLOB_TIMEOUT and sync_glob function.
- Assistant
Let me examine the sync_glob function more closely.
- Assistant
Now I need to understand the issue more clearly. Let me check the exact lines around the timeout handling and look for existing tests:
- Assistant
Let me first create a reproduction script to confirm the issue:
- Assistant
It seems the current directory is already
/deepagents/libs/deepagents. Let me check. - Assistant
Let me check the project structure and install dependencies.
- Assistant
Let me check how to run tests in this repo.
- Assistant
Let me look at the project structure and find the right way to install dependencies.
- Assistant
Let me try reproducing the issue:
- Assistant
Good, I've confirmed the bug. Now let me examine the sync_glob function more closely to understand the fix needed:
- Assistant
The open command takes a single line number. Let me use it differently.
- Assistant
Now I understand the issue. The
returninside theexcept concurrent.futures.TimeoutErrorblock causes thewithblock's__exit__to callexecutor.shutdown(wait=True), which blocks until the worker thread finishes (since Python threads can't be cancelled). The fix is to callexecutor.shutdown(wait=False)before returning on timeout.Let me also check if there are similar patterns elsewhere in the file that need the same fix:
- Assistant
Now I'll apply the fix. The problem is that the
withblock callsexecutor.shutdown(wait=True)on exit, which blocks even when we hit a timeout. The fix is to use the executor without a context manager and callshutdown(wait=False)when a timeout occurs: - Assistant
Now I'll make the edit to fix the issue:
- Assistant
Now let me run the reproduction script again to see if the fix works:
- Assistant
Excellent! The fix works. Now let me also verify that normal (non-timeout) glob operations still work correctly, and then run the existing tests to make sure nothing is broken:
- Assistant
That error is just because of the FakeRuntime setup, not related to our change. Let me run the existing tests to ensure we haven't broken anything:
- Assistant
Let me run the filesystem middleware tests.
- Assistant
Let me remove the --timeout flag.
- Assistant
All tests pass. Let me also run the async middleware tests and the filesystem-specific tests:
- Assistant
That failure is unrelated (missing pytest-asyncio plugin). Let me run the filesystem backend tests:
- Assistant
All tests pass. Let me also run the filesystem middleware init tests:
- Assistant
All tests pass. Let me now verify the final state of the change by looking at the git diff:
- Assistant
Let me run the reproduction test one more time to confirm the fix works:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →