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" glob Assistant
Let me analyze the issue:
- The bug is in
deepagents/middleware/filesystem.pyin thesync_globfunction - The problem is that when
future.result(timeout=GLOB_TIMEOUT)times out, the code catches the timeout but then exits thewith concurrent.futures.ThreadPoolExecutor(...)context manager, which callsshutdown(wait=True)by default, blocking until the worker thread finishes - The fix should prevent the shutdown from waiting for the timed-out thread
Let me first explore the repository structure and find the relevant file.
- The bug is in
Assistant
I need to look at the filesystem.py file to understand the issue. Let me use cat to view it first.
Assistant
Let me search for the
sync_globfunction specifically:Assistant
Now let me see the full
sync_globfunction:Assistant
Now I understand the issue. The problem is:
- When
future.result(timeout=GLOB_TIMEOUT)raisesTimeoutError, the code returns aToolMessageinside thewithblock - The
returnstatement triggers__exit__of theThreadPoolExecutorcontext manager __exit__callsshutdown(wait=True)by default, which blocks until all threads finish
The fix is to use
shutdown(wait=False)or restructure the code to not return inside thewithblock. Let me also look at the secondary issue about creating a new executor per call.Let me first create a reproduction script:
- When
Assistant
I need to install the dependencies first. Let me check the project setup:
Assistant
Now let me run the reproduction script:
Assistant
I've confirmed the bug. The tool takes 3.00s instead of ~0.5s because
ThreadPoolExecutor.__exit__callsshutdown(wait=True)which blocks until the thread finishes.Now let me implement the fix. The solution is to not use the context manager for shutdown and instead explicitly call
shutdown(wait=False)to avoid blocking. I'll also consider using a shared executor to address the secondary performance issue.Let me look at the current code more closely:
Assistant
The fix is to not use the context manager (which waits on shutdown), but instead create the executor manually and call
shutdown(wait=False)when we're done. This way, if the glob times out, we return immediately without waiting for the thread to finish.Let me also address the secondary issue about creating a fresh executor per call by using a shared executor. I'll add a module-level executor.
Assistant
Now I'll apply the fix. The key changes are:
- Replace the context manager usage with manual executor creation
- Call
shutdown(wait=False)to not block on exit - Move the returns outside the executor block to ensure clean structure
Assistant
I need to use the correct path. Let me check the current directory first.
Assistant
Now let me apply the fix. The issue is that
with concurrent.futures.ThreadPoolExecutor(...)callsshutdown(wait=True)on exit, blocking until the thread finishes. I need to:- Create the executor without the context manager
- Call
shutdown(wait=False)when done to avoid blocking
Assistant
Now I'll apply the fix. The solution is to not use the context manager and instead manually shut down the executor with
wait=False:Assistant
I need to open the file first before using the replace command.
Assistant
Now let me verify the change was applied correctly:
Assistant
The change looks correct. Now let me run the reproduction script to verify the fix:
Assistant
The fix works. Now the tool returns after ~0.5s (the timeout) instead of waiting for the full 3s glob to complete.
Let me also verify that the normal (non-timeout) case still works correctly. Let me create a test for that:
Assistant
The error is expected - it's about StateBackend configuration, not our fix. Let me check if there are existing tests for the glob functionality:
Assistant
I found the relevant test files. Let me look at the test files for the filesystem middleware and also check if there are tests that might be testing the timeout behavior. Let me look at the specific tests in the deepagents library.
Assistant
There's already a test for glob timeout! Let me check it:
Assistant
Let me run the existing test to make sure my fix doesn't break it:
Assistant
The test passes and it only took 0.70s (the timeout plus test overhead). Now let me run more tests related to the middleware to make sure my fix doesn't break anything:
Assistant
All glob-related tests pass. Let me also run the full middleware test suite to ensure nothing else broke:
Assistant
All 111 tests pass. Let me also run the async middleware tests to make sure nothing is broken there.
I should also run my reproduction script one more time to make sure the fix is working, and also verify that the existing test for glob timeout actually validates the timing behavior (not just the message content).
Let me verify my reproduction script once more and then run the async middleware tests.
<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware_async.py -v -k "glob" 2>&1 | tail -40 </tool_call>
Assistant
I need to run the command again properly.
Assistant
The async test failures are due to missing pytest-asyncio plugin in this environment, not related to my fix. Let me verify my changes are correct by checking the git diff.
Assistant
The fix looks correct. Let me run the reproduction test one more time to confirm the fix works:
Assistant
The fix is confirmed working. The tool now returns after ~0.5s (the timeout) instead of blocking until the full 3s glob completes.
Let me run the existing middleware tests one more time to confirm everything still passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.