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
I'll start by exploring the repository structure to understand the codebase and locate the relevant files. Let's begin.
- Assistant
Let me look for the filesystem middleware file more specifically.
- Assistant
Good, let me examine the filesystem middleware file:
- Assistant
Let me search for the
sync_globfunction specifically: - Assistant
Let me look at the sync_glob function:
- Assistant
Let me examine the rest of the file to see the async_glob function and understand the full context.
- Assistant
Let me look at the existing tests to understand the test structure:
- Assistant
Let me check the existing test for the glob timeout to understand the current behavior and what's being tested.
- Assistant
Now let me see the exact
sync_globfunction to understand the exact code flow: - Assistant
Now I understand the issue clearly. Let me analyze the code:
- The
sync_globfunction uses awith concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:context manager. - When a
TimeoutErroroccurs, the code returns theToolMessageinside thewithblock. - When the return statement executes inside the
withblock, Python's context manager protocol calls__exit__()on theThreadPoolExecutor. ThreadPoolExecutor.__exit__()callsself.shutdown(wait=True), which blocks until the worker thread finishes.- Since the worker thread is still running the slow glob, the
returnstatement blocks until the glob completes.
Let me check the async version to see how it handles timeout:
- The
- Assistant
Now I understand the issue clearly. The problem is in
sync_glob: when aTimeoutErroroccurs, thereturnstatement is inside thewith concurrent.futures.ThreadPoolExecutorcontext manager. Whenreturnis executed inside thewithblock, Python's context manager protocol calls__exit__()on theThreadPoolExecutor, which callsshutdown(wait=True), blocking until the worker thread finishes.Let me first reproduce the issue as described:
- Assistant
Let me check how to set up the environment properly.
- Assistant
Let me check the project structure and find the venv.
- Assistant
Let me check if there's a virtual environment or if we need to install the package.
- Assistant
Let me check the virtual environment and try to run the reproduction script.
- Assistant
Good, let me create a reproduction script and run it to confirm the bug.
- Assistant
Good, I've reproduced the bug. Now I understand the issue:
- The
sync_globfunction creates aThreadPoolExecutorwithwithstatement - It submits the glob work and calls
future.result(timeout=GLOB_TIMEOUT) - When a
TimeoutErroris raised, it returns the error message inside thewithblock - When Python processes the
returnstatement inside thewithblock, it first calls__exit__on the context manager (ThreadPoolExecutor) ThreadPoolExecutor.__exit__callsshutdown(wait=True), which waits for the submitted task to complete- Since the glob task is still running (it takes 3s), the
returnblocks for the remaining ~2.5s
Let me now fix the issue:
- The
- Assistant
The fix needs to:
- Not return inside the
withblock (which would triggershutdown(wait=True)via__exit__) - Instead, manage the executor manually so we can call
shutdown(wait=False)on timeout
Let me apply the fix:
- Not return inside the
- Assistant
Now I understand the problem. The
returnstatement inside thewithblock causesThreadPoolExecutor.__exit__to callshutdown(wait=True), which blocks until the timed-out glob finishes. Let me fix this: - Assistant
Let me try using the edit command with the heredoc syntax.
- Assistant
Good, the fix is in place. Now let me check if there are any existing tests that test the timeout behavior:
- Assistant
Now let me run the reproduction script to see if the fix resolves the issue:
- Assistant
Excellent! The fix works. The tool now returns after ~0.5s (the timeout) instead of waiting for the glob to finish. Now let me run the existing tests to make sure I didn't break anything:
- Assistant
Let me check how to run tests
- Assistant
Let me try running with the system pytest.
- Assistant
Let me install the dependencies.
- Assistant
Let me check if there's a uv environment or something else.
- Assistant
Let me check if uv is available.
- Assistant
Let me try to run the tests using uv.
- Assistant
Let me check the pyproject.toml and the dev dependencies:
- Assistant
The tests depend on langchain but it's not installed in the venv. Let me install the dev dependencies.
- Assistant
Now let me try running the tests again.
- Assistant
All glob tests pass. Let me run the full test suite for the middleware module to make sure I didn't break anything:
- Assistant
All 111 tests pass. Let me also run the async test suite:
- Assistant
Let me also check that the
concurrentimport was already present and the code still compiles: - Assistant
Let me verify the final state of the code:
- Assistant
Let me also run the full async test suite:
- Assistant
All tests pass. Let me check the diff to confirm my changes:
- Assistant
Let me clean up the temp file:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.