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 the synchronousglobtool doesn't actually bound wall-clock time becauseThreadPoolExecutor.__exit__callsshutdown(wait=True), which joins the worker thread. - The fix should make the timeout actually bound the wall-clock time, so the tool returns after ~
GLOB_TIMEOUTseconds even if the glob is still running. - There's also a secondary issue about reusing a shared executor to avoid per-call overhead.
Let me first explore the repository structure to understand the codebase.
- The
Assistant
Let me explore the repository structure more specifically, focusing on the
deepagentspackage and the filesystem middleware.Assistant
Let me look at the middleware/filesystem.py file specifically.
Assistant
Good, I found the relevant file. Let me open it.
<tool_call> <function=bash_terminal> <parameter=command> cat /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
Let me use the open command to read the file.
Assistant
The user wants me to fix a bug in the
GLOB_TIMEOUTimplementation. The issue is that the synchronousglobtool blocks until the glob finishes even when it times out, becauseThreadPoolExecutor.__exit__callsshutdown(wait=True)which joins the running thread.Let me first read the file to understand the current implementation.
Assistant
The file was long. Let me search for the specific
sync_globfunction to see the problematic code.Assistant
Let me read the specific section of code that contains the
sync_globfunction:Assistant
Assistant
Let me search for how tools are created and stored.
Assistant
Let me look at how tools are stored and see if there's an
__init__method where I can initialize a shared executor.Assistant
I see -
self.toolsis a list created in__init__, and_create_glob_toolis called once. So I can add the shared executor as a class-level or instance attribute.Let me find the
__init__method to see where I should add the executor initialization.Actually, looking at the code more carefully, the
_create_glob_toolmethod creates a closure that capturesself. So I can add the executor as an instance attribute in__init__before callingself._create_glob_tool().Let me look at the
__init__method more carefully.Actually, I think the best approach is to add the executor as an instance attribute in
__init__and reference it insync_globviaself._glob_executor.Let me look at the full
__init__method to understand its structure.Assistant
Let me look at the
__init__method to see where I can initialize the shared executor.Assistant
Now I have a clear picture of the issue. Let me create a test script first to reproduce the error, then implement the fix.
Assistant
Let me look at the existing test for glob timeout to understand how to reproduce and verify the fix.
Assistant
Let me create a reproduction script first to verify the bug exists, then fix it.
Assistant
Let me check the project setup and install dependencies.
Assistant
The user wants me to continue working on the issue. Let me try to install the dependencies for the deepagents package and then run the reproduction script.
I need to find the pyproject.toml for the deepagents package specifically.
Assistant
The user is asking me to continue working on the issue. I need to install the dependencies for the deepagents package and then run the reproduction script. Let me find the pyproject.toml for the deepagents package specifically.
Assistant
Let me install the dependencies and run the reproduction script to verify the bug exists.
Assistant
Good, the package is installed. Let me run the reproduction script to verify the bug exists.
Assistant
The bug is confirmed. The glob times out after 3.00s instead of 0.5s, exactly as described in the issue. Now let me implement the fix.
The issue is in the
sync_globfunction. WhenTimeoutErroris raised, the code returns inside thewith concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:block. This causesThreadPoolExecutor.__exit__to callshutdown(wait=True), which blocks until the thread finishes.Fix: Call
executor.shutdown(wait=False)before returning on timeout. This tells the executor not to wait for the thread, and sinceshutdownhas already been called,__exit__returns immediately (it short-circuits when_shutdownis already True).I'll also implement the secondary fix: use a shared executor to avoid per-call overhead.
Assistant
Now I understand the issue. Let me implement the fix:
- Add a shared
ThreadPoolExecutoras an instance attribute (initialized in__init__) - Modify
sync_globto use this shared executor instead of creating a new one per call - Fix the timeout case so it returns immediately without blocking on thread join
- Add a shared
Assistant
The user wants me to continue with the fix. I need to add a shared ThreadPoolExecutor and modify the sync_glob function to use it. Let me try the edit again with proper formatting.
Assistant
Let me try the edit with exact matching of the file content:
Assistant
I need to use the correct sed syntax. Let me try again with proper line range specification.
Assistant
I need to see the exact content around line 763 to understand the structure. Let me try a different approach.
Assistant
I need to see the exact content around line 763 to understand the structure. Let me try a different approach.
Assistant
I need to continue with the fix. Let me make the edits step by step. First, I'll add the shared executor initialization before the tools list.
Assistant
Let me verify the first fix was applied correctly and then apply the second fix to the sync_glob function.
Assistant
Let me verify the first fix was applied correctly.
Assistant
Good, fix 1 is applied. Now let me apply fix 2: modify the
sync_globfunction to use the shared executor and properly handle the timeout without blocking.Assistant
Now I need to modify the
sync_globfunction to use the shared executor and properly handle the timeout. Let me apply the fix:Assistant
Let me verify the fix was applied correctly:
Assistant
The fix is applied. Now let me verify it works by running the reproduction script again:
Assistant
The fix works! The tool now returns after ~0.5s (the timeout) instead of blocking for ~3.0s. The slow_glob completes in the background (we can see it ends at 4683383.309, 3s after it started), but the tool returns immediately.
Now let me run the existing tests to make sure nothing is broken:
Assistant
The existing test passes. Let me run more tests related to glob and the middleware to ensure nothing is broken:
Assistant
All glob tests pass. Let me also run the async version test and the full middleware test suite:
Assistant
Let me run the async tests with proper asyncio mode:
Assistant
The async tests need pytest-asyncio. Let me check how to run them properly:
Assistant
Let me try running the async tests with the proper asyncio configuration:
Assistant
Let me check the pytest configuration for asyncio:
Assistant
Let me install pytest-asyncio and run the async tests:
Assistant
Let me run the async tests with pytest-asyncio installed.
Assistant
All glob tests pass. Let me run the full middleware test suite to make sure nothing else is broken:
Assistant
The user wants me to continue. Let me install pytest-timeout and run the full middleware test suite.
Assistant
Let me continue running the full middleware test suite.
Assistant
All 111 middleware tests pass. Let me also run the async middleware tests:
Assistant
All tests pass. Let me run the reproduction script one more time to confirm the fix works correctly:
Assistant
The fix is working correctly. Let me verify the final state of the code changes:
Assistant
The fix is working correctly. Let me run a final comprehensive test to verify edge cases:
Assistant
Let me fix the test script:
Assistant
Let me check how StateBackend works:
Assistant
Let me simplify the test to use a more straightforward approach:
Assistant
All tests pass. Let me verify the final diff one more time and run the full middleware test suite to ensure everything is working:
Assistant
The fix looks correct. Let me run the full middleware test suite one more time to confirm everything works before submitting:
Assistant
All tests pass. Let me summarize what was fixed:
Summary of Changes
Issue: The
GLOB_TIMEOUTin the synchronousglobtool did not actually bound wall-clock time. The tool would block until the runaway glob finished, even though it returned a "timed out" error message.Root Cause: The
sync_globfunction used awith concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:block. Whenfuture.result(timeout=GLOB_TIMEOUT)raisedTimeoutError, thereturnstatement exited thewithblock, which triggeredexecutor.__exit__→shutdown(wait=True). This blocked the return until the worker thread (still running the glob) finished, defeating the purpose of the timeout.Fix:
- Added a shared
ThreadPoolExecutoras an instance attribute (self._glob_executor) in__init__(avoiding per-call creation overhead) - Removed the
withblock and now submit directly to the shared executor
- Added a shared
Assistant
Let me try the submit command again with proper formatting.
Assistant
The user wants me to submit my changes. Let me try the submit command again - it seems the system is having trouble extracting the command. Let me try again with the proper syntax.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.