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
GLOB_TIMEOUTin theFilesystemMiddlewaredoesn't actually bound wall-clock time becauseThreadPoolExecutor.__exit__callsshutdown(wait=True), which joins the worker thread even after a timeout exception. -
The fix should ensure that when a timeout occurs, the tool returns immediately without waiting for the thread to finish.
-
There's also a secondary issue about the overhead of creating a new
ThreadPoolExecutorper call.
Let me start by exploring the repository structure and finding the relevant code.
-
Assistant
Let me find the filesystem middleware file mentioned in the issue.
Assistant
I need to figure out why the open command is not being recognized. Let me try without the "open" word and see what happens. It looks like I need to provide a proper command string.
Actually, looking at the system prompt more carefully, the special commands should work. Let me try a different approach.
Assistant
Let me search for the relevant
sync_globfunction and theGLOB_TIMEOUTusage:Assistant
Let me look at the specific code around line 1247-1300 to understand the
sync_globfunction fully.Assistant
Now I understand the issue. The problem is:
- When
future.result(timeout=GLOB_TIMEOUT)raisesTimeoutError, the code returns early - But the
returnis inside awith concurrent.futures.ThreadPoolExecutor(...) as executor:block - When exiting the
withblock,executor.__exit__callsshutdown(wait=True), which blocks until the worker thread finishes - So even though we return the timeout error message, we still block until the glob completes
Let me first reproduce the issue, then fix it:
- When
Assistant
I need to install the deepagents package first. Let me find the setup.py or pyproject.toml in the libs directory.
Assistant
Now let me run the reproduction script:
Assistant
Good, I've confirmed the issue. The problem is clear:
future.result(timeout=GLOB_TIMEOUT)raisesTimeoutErrorafter 0.5s- The
returnstatement is executed inside thewithblock - Python's context manager
__exit__callsexecutor.shutdown(wait=True), blocking until the thread finishes - The tool waits the full 3 seconds despite the timeout error being returned
Now let me fix this. The solution is to not use a
withblock and instead explicitly callexecutor.shutdown(wait=False)when a timeout occurs, so we don't wait for the thread to finish.Assistant
Now I understand the issue completely. The fix is to:
- Move the executor creation outside the
withblock - On timeout, explicitly call
executor.shutdown(wait=False)instead of letting the context manager callshutdown(wait=True) - Use a try/finally to ensure the executor is always shut down
- Move the executor creation outside the
Assistant
Let me first see the exact lines I need to replace:
Assistant
Let me try using a different approach - I'll use a Python script to make the edit:
Assistant
Let me verify the changes were applied correctly:
Assistant
Good, the changes look correct. Now let me run the reproduction script to verify:
Assistant
The fix works. The tool now returns after ~0.5s instead of ~3.0s. Let me verify the fix handles all edge cases properly and run existing tests.
First, let me think about edge cases:
-
Normal case (no timeout):
future.result(timeout=GLOB_TIMEOUT)succeeds, thenfinallyblock callsexecutor.shutdown(wait=False). Since the future already completed, this is a no-op wait. -
Timeout case:
TimeoutErroris caught, we callexecutor.shutdown(wait=False)explicitly before returning, then thefinallyblock also callsexecutor.shutdown(wait=False)- this is safe since callingshutdown()twice on the same executor is a no-op after the first call. -
Other exceptions: The
finallyblock ensures cleanup happens regardless.
Now let me check if there are existing tests related to the glob timeout functionality:
-
Assistant
The user wants me to run existing tests to make sure my changes don't break anything. Let me find and run the relevant tests.
Assistant
Let me run the relevant tests to make sure the fix doesn't break anything:
Assistant
All 7 glob-related tests pass, including
test_glob_timeout_returns_error_message. Let me also run the full middleware test suite and the async tests to ensure nothing is broken:Assistant
The async tests fail due to a missing
pytest-asyncioplugin (pre-existing issue, not related to my fix). Let me run just the sync middleware tests to confirm my fix doesn't break anything:Assistant
All 111 sync middleware tests pass. The async test failures are pre-existing (missing
pytest-asyncioplugin, not my fix). Let me run the reproduction script once more to confirm and then review my changes:Assistant
Let me verify the complete diff of my changes:
Assistant
The changes look correct. Here's a summary of the fix:
Problem: The synchronous
globtool usedwith concurrent.futures.ThreadPoolExecutor(...) as executor:, which callsshutdown(wait=True)on exit. When a timeout occurred, even though the error message was returned, thereturninside thewithblock triggeredshutdown(wait=True), blocking until the runaway thread finished.Solution:
- Replace the
withcontext manager with explicit executor creation +try/finally - On
TimeoutError: explicitly callexecutor.shutdown(wait=False)to detach from the running thread before returning - In
finally: always callexecutor.shutdown(wait=False)to ensure cleanup
This ensures the tool returns immediately when a timeout occurs, rather than blocking until the glob completes.
- Replace the
Assistant
I have successfully fixed the issue. Let me provide a final summary:
Summary
Problem: The
GLOB_TIMEOUTinFilesystemMiddleware.sync_globdid not bound wall-clock time. When a glob operation timed out, the tool returned the timeout error message but then blocked until the runaway glob thread actually finished. This was because:- The code used
with concurrent.futures.ThreadPoolExecutor(...) as executor: - When
future.result(timeout=GLOB_TIMEOUT)raisedTimeoutError, thereturnstatement triggeredexecutor.__exit__ __exit__callsshutdown(wait=True), which blocks until the worker thread (still running the glob) finishes
Fix: Changed the executor management from a
withcontext manager to explicittry/finallypattern:- On timeout: explicitly call
executor.shutdown(wait=False)before returning to detach from the running thread - In
finally: always call to ensure cleanup
- The code used
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.