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 first check the current directory and see what's there.
- Assistant
Let me look at the specific file mentioned in the issue:
deepagents/middleware/filesystem.py. I need to understand the structure and locate it. Let's search for it: - Assistant
Let me open the filesystem middleware file to understand the issue:
- Assistant
Let me search for the
sync_globfunction andGLOB_TIMEOUTin this file: - Assistant
Let me look at the sync_glob function implementation:
- Assistant
Let me look at the async_glob implementation as well to see how it handles timeout:
- Assistant
Let me check if there are tests for this behavior:
- Assistant
Let me search for test files specifically for the filesystem middleware:
- Assistant
Let me search specifically for tests related to glob timeout:
- Assistant
Let me check if there are any tests for the filesystem middleware:
- Assistant
Now let me write a reproduction script based on the issue description:
- Assistant
Let me run the reproduction script to confirm the bug:
- Assistant
I need to run the script from within the repository or install the package.
- Assistant
Let me check how to run the script with the correct module path:
- Assistant
Good, the package is installed. Now let me run the reproduction script:
- Assistant
The bug is confirmed. Now let me understand the root cause by examining the exact code structure:
- Assistant
Now I understand the problem. The issue is in
sync_glob(lines 1272-1282): thereturnstatement inside thewithblock triggersThreadPoolExecutor.__exit__->shutdown(wait=True), which waits for the worker thread to finish even though the future has timed out.The fix should:
- Move the return outside the
withblock so we don't wait for the executor to shut down - Use a shared executor to reduce thread creation overhead
Let me look at how the code is structured to understand the right approach:
- Move the return outside the
- Assistant
I need to understand the exact fix. The problem is that the
returnstatement is inside thewithblock, which triggersexecutor.__exit__->shutdown(wait=True), blocking until the thread finishes.The fix needs to:
- Move the timeout error return outside the
withblock - Use
shutdown(wait=False)so we don't wait for the thread to finish - Optionally use a shared executor to avoid thread creation overhead
Let me restructure the code:
- Move the timeout error return outside the
- Assistant
Now I understand the problem. The root cause is that the
returnstatement in theexcept concurrent.futures.TimeoutError:block is inside thewith concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:block. Whenreturnexecutes, it triggers__exit__→shutdown(wait=True), which waits for the thread to finish even though we've already timed out.The fix is to:
- Move the return outside the
withblock by using a flag - Use
shutdown(wait=False)so we don't wait for the orphaned thread to finish
Let me implement the fix:
- Move the return outside the
- Assistant
Good! Now let me reinstall the package and test the fix:
- Assistant
Now let me run the reproduction script again to verify the fix:
- Assistant
Excellent! The fix works - it now returns in ~0.5s (the timeout) instead of ~3s (the slow glob). Now let me run the existing tests to make sure I haven't broken anything:
- Assistant
Let me try running tests excluding benchmarks:
- Assistant
Let me ignore both benchmarks and integration tests:
- Assistant
The async test failure is pre-existing (missing pytest-asyncio plugin). Let me run only the sync glob tests:
- Assistant
All glob-related tests pass. Let me run a broader test suite to make sure I haven't broken anything:
- Assistant
Let me check if the failing test is related to my changes:
- Assistant
The failing test is an async test that fails because pytest-asyncio is not installed. This is not related to my changes. Let me check if this test was already failing before my changes:
- Assistant
Let me check if the test was already failing before my changes:
- Assistant
Good, the test was already failing before my changes. Let me restore my changes:
- Assistant
Let me run the sync tests again with my fix applied to confirm everything passes:
- Assistant
Let me skip all async tests:
- Assistant
Let me skip all the async tests from the protocol module:
- Assistant
Most failures seem to be async-related (missing pytest-asyncio). Let me check if these are pre-existing failures by reverting and running again.
- Assistant
Good - same 16 failures in both cases (pre-existing). Let me restore my changes:
- Assistant
Let me check the diff to see exactly what changed:
- Assistant
Let me reinstall and run the reproduction script one more time to confirm:
- Assistant
Let me create a more comprehensive test to verify edge cases:
- Assistant
Let me run this comprehensive test:
- Assistant
Let me look at the existing test for glob timeout to see how it's done:
- Assistant
Let me look at how
_runtime()and_make_backend()work: - Assistant
Let me look at those function definitions:
- Assistant
Let me run the existing test to make sure it still passes with my changes:
- Assistant
The existing test passes. Let me run the original reproduction script one final time to confirm the fix:
- Assistant
Let me verify the final state of the file to make sure the changes are correct:
- Assistant
The changes look good. Let me run the existing glob timeout test one more time to make sure everything is working:
- Assistant
All 79 tests pass. Let me run the reproduction script one final time to confirm the fix:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.