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
Let me analyze the issue:
- The bug is in
deepagents/middleware/filesystem.pyin thesync_globfunction - The problem is that after a timeout occurs with
future.result(timeout=GLOB_TIMEOUT), thewith concurrent.futures.ThreadPoolExecutor(...)block triggers__exit__which callsshutdown(wait=True), blocking until the worker thread finishes - The fix should prevent the shutdown from waiting for the timed-out task
Let me start by exploring the repository structure and finding the relevant file.
- The bug is in
Assistant
Let me find the specific file mentioned in the issue.
Assistant
The user is pointing out that my tool call format is incorrect. I need to use the proper bash_terminal format. Let me look at the filesystem.py file using cat instead.
Assistant
Let me search for the
sync_globfunction specifically:Assistant
Now let me see the full
sync_globfunction to understand the issue:Assistant
Now I understand the issue clearly. The problem is in the
sync_globfunction:- When a
TimeoutErroris raised, the code returns inside thewith concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:context manager block. - The
returnstatement triggersThreadPoolExecutor.__exit__()which callsshutdown(wait=True)by default. - This causes the thread to block until the worker thread (still running the slow glob) actually finishes.
The fix is to call
executor.shutdown(wait=False)before returning in the timeout case, or to restructure the code so the shutdown doesn't wait. Let me also check if there are existing tests I need to be aware of:- When a
Assistant
Now let me first create a script to reproduce the issue:
Assistant
I need to install the dependencies first. Let me check how the project is set up:
Assistant
I need to see how the project is set up and install its dependencies
Assistant
Let me check the project setup and install dependencies properly.
Assistant
Let me check if the dependencies are already installed or if I need to install them.
Assistant
Now let me run the reproduction script to confirm the bug:
Assistant
I've confirmed the bug. The tool returns the timeout message but blocks for the full 3 seconds instead of returning after 0.5 seconds, because
ThreadPoolExecutor.__exit__()callsshutdown(wait=True)which blocks until the worker thread finishes.Now let me look at the exact lines to edit and apply the fix:
Assistant
Now I understand the issue. The problem is that when
TimeoutErroris caught inside thewithblock and wereturn, the context manager's__exit__method callsshutdown(wait=True)which blocks until the worker thread finishes.The fix is to restructure the code so that on timeout, we call
executor.shutdown(wait=False)before returning. Let me apply the fix:Assistant
The fix is to replace the
withstatement with atry/finallyblock and callexecutor.shutdown(wait=False)in thefinallyblock. This way, when we return from inside thetryblock on timeout, thefinallyblock runsshutdown(wait=False)which doesn't block, allowing the function to return immediately.Assistant
The user seems to have encountered an error with my tool call. Let me check what happened and continue with the fix. I need to use the edit command to fix the sync_glob function.
The issue is that when a timeout occurs in the
withblock, returning triggersThreadPoolExecutor.__exit__()which callsshutdown(wait=True), blocking until the worker thread finishes.The fix is to replace the
withstatement with atry/finallyblock and callexecutor.shutdown(wait=False)in thefinallyblock, so the function returns immediately on timeout without waiting for the worker thread to finish.Let me apply the fix using the edit command.
Assistant
I need to use the
bash_terminalto invoke the edit command properly. Let me try a different approach using sed to make the replacement.Assistant
Let me create a Python script to do the replacement since the edit command seems to have issues:
Assistant
Now let me verify the fix was applied correctly:
Assistant
The fix looks correct. Now let me run the reproduction script to verify the fix works:
Assistant
Excellent! The fix works! The tool now returns after ~0.5s (the timeout) instead of waiting until the full 3s glob operation completes.
Now let me run the existing tests to make sure I haven't broken anything:
Assistant
Let me run the relevant tests related to the filesystem middleware to make sure the fix doesn't break anything.
Assistant
The 3 test failures are unrelated to my change - they're all failing because
langchain-openaipackage is missing (which is a test dependency issue). The 337 passing tests include filesystem-related tests. Let me specifically run the tests most relevant to the glob timeout fix to confirm nothing is broken:Assistant
All relevant filesystem middleware tests pass. Now let me run the reproduction script one more time to confirm the fix, and also test edge cases:
Assistant
Now let me also test an edge case - make sure the normal (non-timeout) path still works correctly:
Assistant
<arg_key>command</arg_key> <arg_value>cat > /tmp/test_normal.py << 'PYEOF' import sys sys.path.insert(0, "/deepagents/libs/deepagents")
from deepagents.backends.protocol import GlobResult from deepagents.middleware.filesystem import FilesystemMiddleware from unittest.mock import MagicMock
class FakeRuntime: tool_call_id = "demo" state = {"files": {}} store = None context = None stream_writer = None config = {}
Test normal (non-timeout) glob operation with a mock backend
backend = MagicMock() backend.glob.return_value = GlobResult( matches=[ {"path": "/test.py", "size": 100}, {"path": "/test2.py", "size": 200}, ], error=None )
middleware = FilesystemMiddleware(backend=backend) glob_tool = next(t for t in middleware.tools if t.name == "glob")
Test normal glob
msg = glob_tool.invoke({"pattern": "*.py", "runtime": FakeRuntime()}) print(f"Normal glob result: {msg.content!r}") print(f"Status: {msg.status}")
Verify it found the files
assert "test.py" in msg.content or "test2.py" in msg.content, f"Expected to find .py files, got: {msg.content}" assert msg.status == "success", f"Expected success status, got: {msg.status}"
print("Normal glob test PASSED!")
Test that the executor is properly shut down (wait=False should be fine)
by calling glob multiple times
for i in range(5): msg = glob_tool.invoke({"pattern": "*.py", "runtime": FakeRuntime()}) assert msg.status == "success", f"Call {i+1} failed: {msg.content}"
print("Multiple glob calls test PASSED!") PYEOF python3 /tmp/test_normal.py </tool_call>
Assistant
I need to use the proper bash_terminal function call format.
Assistant
Let me fix the mock setup:
Assistant
The normal glob path works correctly. Let me run one final comprehensive test to confirm everything:
Assistant
All tests pass. Let me verify the exact changes I made to the file:
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 →
- 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 →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →