GLOB_TIMEOUT does not bound wall-clock time — tool blocks until the runaway glob finishes
Submission 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)
python
Assistant
Now update the imports — concurrent.futures is no longer used, threading and GlobResult are needed:
Assistant
Now strengthen the existing timeout test to assert the wall-clock bound (the regression this issue is about):
Assistant
Now run the issue's repro script against the fix:
Assistant
Returns after 0.50s instead of 3.01s. Now run the glob-related unit tests, sync and async:
Assistant
That's the expected behavior — the RuntimeError re-raises on the calling thread exactly as future.result() did before, with the worker-thread frame preserved in the traceback. The fix is complete.
Summary
Root cause (libs/deepagents/deepagents/middleware/filesystem.py): sync_glob ran the backend glob inside with concurrent.futures.ThreadPoolExecutor(max_workers=1). On timeout, future.result(timeout=GLOB_TIMEOUT) raised at 20s, but the then triggered → , which joined the worker thread still running the glob. So the timeout only changed the message, not the latency.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
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
Error Message and Stack Trace (if applicable)
shell
returned after 3.01s: 'Error: glob timed out after 0.5s. Try a more specific pattern or a narrower path.'
Description
The synchronous glob tool created by FilesystemMiddleware enforces GLOB_TIMEOUT (20s) by running the backend glob on a worker thread: future.result(timeout=GLOB_TIMEOUT) inside a with 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_TIMEOUT seconds.
Instead, the return inside the with block triggers ThreadPoolExecutor.__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_for cancels 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)
Interface
No new interfaces are introduced.
return
ThreadPoolExecutor.__exit__
shutdown(wait=True)
Fix (filesystem.py:1272-1297): run the glob on a raw daemon threading.Thread and join(timeout=GLOB_TIMEOUT):
On timeout the worker is abandoned (threads can't be cancelled) and the tool returns immediately — the runaway glob finishes in the background without blocking anyone.
daemon=True also means a truly stuck glob can't block interpreter shutdown, which any concurrent.futures thread would via its atexit join — so a shared executor was deliberately not used.
No per-call executor construction (the secondary overhead noted in the issue); a bare thread spawn is cheaper than executor + thread.
Result/exception passed back via a shared list; checking not outcome instead of is_alive() avoids a race where the glob completes exactly at the deadline. Backend exceptions still re-raise on the calling thread, preserving prior behavior.
Dropped the now-unused import concurrent.futures, added threading and GlobResult imports. async_glob untouched (already correct via asyncio.wait_for).
Test (tests/unit_tests/test_middleware.py::test_glob_timeout_returns_error_message): strengthened to assert the tool returns in <1.5s while the mocked glob sleeps 2s — this fails on the old code (~2s) and passes now (~0.5s).
Verification: the issue's repro now prints returned after 0.50s (was 3.01s); all 139 sync+async middleware unit tests pass; ruff check, ruff format --check, and ty check are clean.