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 start by understanding the repository structure and the issue better.
The issue is about
GLOB_TIMEOUTindeepagents/middleware/filesystem.py. The problem is that when a glob times out, the code blocks until the glob finishes becauseThreadPoolExecutor.__exit__callsshutdown(wait=True), which waits for the worker thread to finish. This means the timeout doesn't actually bound wall-clock time.Let me first explore the repository structure and then look at the specific file.
Assistant
Let me look at the specific file mentioned in the issue.
Assistant
Let me look at the file.
Assistant
Let me try to open it using the
opencommand properly.Assistant
Let me find the relevant sections -
GLOB_TIMEOUTandsync_glob.Assistant
Let me look at the
sync_globfunction in detailAssistant
Now I understand the issue clearly. Let me look at lines 1270-1280 more
Assistant
Now I have a clear understanding of the issue. Let me first create a reproduction script to confirm the behavior, then fix it
Assistant
I see - even with
shutdown(wait=False), the__exit__method callsshutdown(wait=True)again, which still joins threads. I need to restructure the code to avoid thewithblock's__exit__from blocking. Let me verify this quicklyAssistant
The fix works correctly. Now let me implement it in the actual file. The fix is to replace the
withblock with a manualtry/finallythat calls `executor.shutdown(wait=FalseAssistant
Let me use the proper edit syntax with the
--fileoptionAssistant
I see there are leftover lines from the old code (lines 1286-1287). Let me check the full context around the edit
Assistant
I see the problem - old lines 1281-1282 (
status="error",and)) were not replaced and are now duplicate remnants. Let me fix this by removing lines 1286-Assistant
Let me verify the code now
Assistant
The code looks correct. Now let me create a reproduction script using the actual codebase to verify the fix
Assistant
Let me install the dependencies first
Assistant
Let me try installing the package in development mode.
Assistant
Now let me run the test script again
Assistant
The fix works. The glob now returns after ~0.5s (the timeout) instead of blocking for the full 3s. Let me now run the existing tests for the filesystem middleware to make sure nothing is broken
Assistant
Let me run the most directly relevant tests for the filesystem
Assistant
Let me also run the integration tests and the broader middleware tests
Assistant
Let me check if these tests were already failing before my change by looking at one of the errors
Assistant
The integration tests fail due to missing API keys (Anthropic auth), not related to my change. Let me run the unit
Assistant
All glob-related tests pass, including
test_glob_timeout_returns_error_message. Let me run the full middleware unitAssistant
All 111 middleware tests pass. Let me also run the backend unit tests and related tests
Assistant
Let me check if these failures are pre-existing (unrelated to my change
Assistant
These tests were already failing before my change. Let me restore my fix
Assistant
Let me look at the
test_glob_timeout_returns_error_messagetest to understand what it expectsAssistant
Let me also verify the final state of my
Assistant
Let me run one more test to verify the fix with the exact scenario from the issue description
Assistant
Let me run the full middleware test suite one final time to confirm everything passes
Assistant
Everything looks good. Let me now go through the checklist:
-
If an error was reported in the issue description, I have successfully reproduced it. I confirmed that the
with ThreadPoolExecutorblock's__exit__callsshutdown(wait=True), which blocks until the worker thread finishes even after aTimeoutError. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. My reproduction script confirmed the fix returns after ~0.5s (the timeout) instead of the full 3s glob duration.
-
I have thought about edge cases and made sure my fix handles them as well. The
try/finallywithexecutor.shutdown(wait=False)handles: timeout case (returns immediately), success case (thread already done, shutdown returns immediately), executor.submit failure (finally still runs), and non-TimeoutError exceptions (propagate, finally still runs). -
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. All 111 middleware unit tests pass, including the 7 glob-related tests (
test_glob_timeout_returns_error_message,test_glob_search_*, etc.). The integration test failures are pre-existing and due to missing API keys.
The fix is minimal and focused: replacing the
withstatement context manager with a manualtry/finallyblock that callsexecutor.shutdown(wait=False)to prevent the worker thread from blocking on exit after a timeout.-
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 →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →