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 start by understanding the repository structure and the issue. The issue is about
GLOB_TIMEOUTinFilesystemMiddleware- specifically that the synchronousglobtool blocks until the runaway glob finishes even after the timeout, becauseThreadPoolExecutor.__exit__callsshutdown(wait=True)which joins the worker thread.Let me first explore the repository structure and find the relevant file.
Assistant
Let me find the filesystem middleware file specifically.
Assistant
Let me open the file and examine the relevant sections
Assistant
Let me search for the GLOB_TIMEOUT and sync_glob function.
Assistant
Let me look at the sync_glob and async_glob functions in detail.
Assistant
Let me look at the FilesystemMiddleware class structure to understand where to put a shared executor.
Assistant
Let me look at the class init and surrounding code.
Assistant
Let me see the rest of the init
Assistant
Now let me create a reproduction script to confirm the issue
Assistant
Let me find the project structure and install the package.
Assistant
Let me install the package and then run the reproduction script.
Assistant
Now let's run the reproduction
Assistant
I've confirmed the issue. Now let me implement the fix. The problem is that
with ThreadPoolExecutorcallsshutdown(wait=True)when exiting the block, which blocks until the worker thread finishes — even if we already caughtTimeoutError.The fix: use a shared module-level executor that persists across calls. This solves both:
- Timeout returns immediately (no shutdown blocking)
- Avoids creating a new thread per call
Assistant
Now let me implement the fix. I'll add a shared executor and modify
sync_globAssistant
Let me use the replace command with heredoc syntax instead
Assistant
Good. Now let me modify
sync_globto use the shared executorAssistant
Now let me replace the
with ThreadPoolExecutorblock insync_globwith the shared executorAssistant
Now let's test the fix with the reproduction script
Assistant
The fix works. Now let me run the existing tests to make sure nothing is broken.
Assistant
Let me run the relevant test files
Assistant
All glob tests pass including the timeout test. Let me run the broader
Assistant
All 111 tests pass. Let me also run the other related test files
Assistant
The async test failure is a missing
pytest-asyncioplugin, not related to my change. Let me install it and re-run.Assistant
All tests pass. Let me also run the integration tests for the filesystem middleware and the end-to-end
Assistant
Integration test failure is due to missing API credentials (Anthropic), not related to my change. Let me run the end-to-end tests and also verify the final state of my changes.
Assistant
All tests pass. Let me verify the final diff of my changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.