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)
python Assistant
Let me analyze the issue:
-
The problem is that
GLOB_TIMEOUTdoesn't actually bound wall-clock time - the tool blocks until the runaway glob finishes, even though it reports a "timed out" error. -
The issue is in the
sync_globfunction indeepagents/middleware/filesystem.py. It uses aThreadPoolExecutorwithfuture.result(timeout=GLOB_TIMEOUT), but when the timeout occurs,ThreadPoolExecutor.__exit__callsshutdown(wait=True), which joins the worker thread. Since Python threads can't be cancelled, it waits for the glob to finish. -
There's also a secondary issue about the overhead of creating a fresh
ThreadPoolExecutorper glob call.
Let me first explore the repository structure and find the relevant file.
-
Assistant
The file was truncated. Let me search for the specific
sync_globfunction:Assistant
Let me see more of this function:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1290,1350p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
Let me continue reading the sync_glob function:
Assistant
Now I understand the issue. The
sync_globfunction usesThreadPoolExecutorwithfuture.result(timeout=GLOB_TIMEOUT), but when the timeout occurs, thewithblock exits and callsshutdown(wait=True), which blocks until the thread finishes.The issue is:
- The
future.result(timeout=GLOB_TIMEOUT)raisesTimeoutErrorafter the timeout - But then the
withblock callsexecutor.__exit__()which callsshutdown(wait=True)by default - This causes the main thread to block waiting for the worker thread to finish
The fix should be to:
- Cancel the executor's pending work by calling
shutdown(wait=False)before returning - Or use a different approach that doesn't rely on
ThreadPoolExecutorfor timeout
Also, the second issue is about performance - creating a new
ThreadPoolExecutorper glob call adds overhead. We should reuse a shared executor.Let me look at how this class is structured to understand the best fix:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '700,850p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
- The
Assistant
I need to continue searching for the FilesystemMiddleware class structure to understand where to add the shared executor.
Assistant
Now let me look at the init method of FilesystemMiddleware to understand its structure:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '639,720p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
I need to keep making tool calls. Let me continue reading the file.
Assistant
Now let me see more of the init method:
Assistant
Now I understand the structure. I need to:
- Add a shared
ThreadPoolExecutoras an instance attribute toFilesystemMiddleware - Modify the
sync_globfunction to use this shared executor and callshutdown(wait=False)when a timeout occurs
Let me also check if there are any tests related to glob to ensure my fix doesn't break existing tests:
<tool_call> <function=bash_terminal> <parameter=command> find /deepagents -name "*.py" -type f | xargs grep -l "GLOB_TIMEOUT" 2>/dev/null | head -10 </tool_call>
- Add a shared
Assistant
I need to keep making tool calls. Let me search for GLOB_TIMEOUT in the codebase.
Assistant
Good. There are existing tests that check the GLOB_TIMEOUT behavior. Let me check the test files to see what they expect:
<tool_call> <function=bash_terminal> <parameter=command> grep -B5 -A30 "GLOB_TIMEOUT" /deepagents/libs/deepagents/tests/unit_tests/test_middleware.py </tool_call>
Assistant
I need to continue making the tool call to see the test code.
Assistant
Now I understand the test. The test is checking that the glob times out after 0.5s, but based on the issue description, it actually returns after 2s (the full duration of the slow glob). Let me also check the async test:
<tool_call> <function=bash_terminal> <parameter=command> grep -B5 -A30 "GLOB_TIMEOUT" /deepagents/libs/deepagents/tests/unit_tests/test_middleware_async.py </tool_call>
Assistant
Let me keep making the tool call to see the async test code.
Assistant
Now I understand the issue. Let me create a reproduction script first to confirm the problem, then implement the fix.
Assistant
Let me install the package first:
Assistant
Now let me run the reproduction script again:
Assistant
Now I've reproduced the issue. The glob tool returned after 3.00s instead of the expected 0.5s. Now let me implement the fix.
The issue is in the
sync_globfunction. When usingThreadPoolExecutorwith a context manager, the__exit__method callsshutdown(wait=True)by default, which blocks until all pending futures are completed.The fix should:
- Create a shared
ThreadPoolExecutoras an instance attribute ofFilesystemMiddleware - When a timeout occurs, call
shutdown(wait=False)to cancel waiting on the executor - Return immediately with the error message
Let me also add
cancel()method call to try to cancel the future.Wait, I need to check if Python has a way to cancel a submitted future. Actually,
concurrent.futures.Futuredoesn't support cancellation - you can only prevent new tasks from starting.- Create a shared
Assistant
I need to make the tool call to see the file content.
Assistant
Now I need to modify the
__init__method to add a shared executor and then modifysync_globto use it properly.Assistant
Now let me make the changes. First, I'll add a shared executor in the
__init__method and then modifysync_glob:Assistant
Now let me implement the fix. I'll:
- Add a shared
_glob_executorThreadPoolExecutor in__init__ - Modify
sync_globto use the shared executor and callshutdown(wait=False)when timeout occurs - Clean up the executor when the middleware is garbage collected (or add a close method)
- Add a shared
Assistant
I need to use the special commands to edit the file. Let me use the edit command to modify the init method first.
Assistant
I need to first open the file before editing it.
<tool_call> <function=bash_terminal> <parameter=command> open /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
I need to keep using the tool calls properly. Let me open the file first.
Assistant
Now the file is open and I can see the content. I need to go to line 763 (around where
self.tools =is) and edit the code to add a shared executor. Let me first see the exact line number where I need to make changes.Assistant
Let me see lines 764-780 to understand the structure better before making changes.
Assistant
Now I need to:
- Add a shared
_glob_executorafter theself.toolsinitialization - Modify the
sync_globfunction to use the shared executor and properly handle timeout
Let me first add the shared executor in
__init__:- Add a shared
Assistant
Now I need to add the shared executor after the closing
]ofself.tools = [...]. That's line 772. I'll replace line 772 to add a new line with the executor initialization.Assistant
Good, the first change is done. Now I need to go to the
sync_globfunction and modify it to use the shared executor and handle the timeout properly.Let me find the
sync_globfunction:<tool_call> <function=bash_terminal> <parameter=command> grep -n "def sync_glob" /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
I need to continue using the tool calls. Let me search for sync_glob again.
Assistant
Let me see the sync_glob function now. I need to go to around line 1249.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1249,1300p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
I need to keep making tool calls. Let me continue to view the sync_glob function.
Assistant
I can see the
sync_globfunction on lines 1249-1299. The key issue is around lines 1274-1283 where it useswith concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:and thenfuture.result(timeout=GLOB_TIMEOUT).The fix should:
- Use
self._glob_executorinstead of creating a new executor - When a timeout occurs, call
shutdown(wait=False)to not block waiting for the executor
- Use
Assistant
The edit command was sent but I need to keep making tool calls to see the result. Let me verify the changes.
Assistant
The edit didn't work. Let me try again with the correct line range. I need to view more context first and then make the edit.
Let me try a different approach - I'll use the
replacecommand instead.Assistant
Now let me see the exact lines I need to replace. I'll use the replace command to make the changes:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '1273,1286p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
I need to continue with tool calls. Let me view the exact lines to replace.
Assistant
Now I understand the exact structure. I need to replace lines 1274-1285 with the new code that uses the shared executor and calls
shutdown(wait=False)on timeout.Let me use the
editcommand with the correct line range:<tool_call> <function=bash_terminal> <parameter=command> edit 1274:1285 << 'EOF' future = self._glob_executor.submit(lambda: ctx.run(resolved_backend.glob, pattern, path=backend_path)) try: glob_result = future.result(timeout=GLOB_TIMEOUT) except concurrent.futures.TimeoutError: # Don't wait for the executor to shut down - the worker thread # is still running but we've returned the error message to the user. self._glob_executor.shutdown(wait=False) return ToolMessage( content=f"Error: glob timed out after {GLOB_TIMEOUT}s. Try a more specific pattern or a narrower path.", name="glob", tool_call_id=runtime.tool_call_id, status="error", ) EOF </tool_call>
Assistant
The edit command was sent. Let me check if it worked by viewing the relevant lines.
Assistant
The edit didn't work. The issue is that the
editcommand expects the exact text with correct indentation. Let me use a different approach - I'll replace the specific text patterns.Assistant
Let me try using a different approach - directly writing a Python script to make the replacement:
Assistant
Now let me verify that the changes were applied correctly:
Assistant
The changes look good. Now let me test the fix by running the reproduction script again:
<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents && python repro.py </tool_call>
Assistant
The tool call was made but I need to see if it executed. Let me run the test again.
Assistant
The fix works! The glob tool now returns after 0.50s (the timeout) instead of blocking for the full 3.0s. The error message is correct.
Now let me check if there are any edge cases I need to handle:
- What happens if multiple timeouts occur in quick succession? The
shutdown(wait=False)can only be called once on an executor, and subsequent calls will raise an error.
Let me check what happens if we call
shutdown(wait=False)on an already shut down executor:<tool_call> <function=bash_terminal> <parameter=command> python << 'EOF' import concurrent.futures
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1) executor.shutdown(wait=False)
try: executor.shutdown(wait=False) print("No error on second shutdown") except Exception as e: print(f"Error: {type(e).name}: {e}") EOF </tool_call>
- What happens if multiple timeouts occur in quick succession? The
Assistant
Let me continue testing by running the Python script to check if calling shutdown twice on an executor causes an error.
Assistant
Good - calling
shutdown(wait=False)multiple times is safe; it's a no-op if the executor is already shut down.Now I need to think about what happens if the user calls glob again after a timeout. The executor is still running (the thread was cancelled but the worker thread itself is still alive). Let me check if we can reuse an executor after calling
shutdown(wait=False):<tool_call> <function=bash_terminal> <parameter=command> python << 'EOF' import concurrent.futures import time
def slow_task(): time.sleep(10) return "done"
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
Submit a task
future = executor.submit(slow_task) print("Submitted task")
Wait briefly and then cancel with timeout
time.sleep(0.5) try: future.result(timeout=0.3) except concurrent.futures.TimeoutError: executor.shutdown(wait=False) print("Shutdown after timeout")
Try to submit another task
try: future2 = executor.submit(slow_task) print("Successfully submitted second task") # Cancel immediately executor.shutdown(wait=False) except Exception as e: print(f"Error: {type(e).name}: {e}") EOF </tool_call>
Assistant
I need to keep making tool calls. Let me test the executor behavior after shutdown.
Assistant
Assistant
I need to keep making the tool calls to see the result of the replacement. Let me verify the changes were made.
Assistant
Let me try a different approach to make the replacement - using a file and sed:
Assistant
Let me fix the syntax error in my Python script:
Assistant
Let me verify the changes were made correctly:
Assistant
Now let me fix the comment to be complete:
Assistant
The sed command failed due to the complex regex. Let me use Python to fix the comment instead.
Assistant
Let me verify the changes:
Assistant
Now let me test the fix again to make sure it still works:
<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents && python repro.py </tool_call>
Assistant
I need to keep making tool calls to run the reproduction script.
Assistant
Great, the fix is working! The glob tool returns after 0.50s (the timeout) instead of blocking for 3.0s.
Now let me test a few edge cases:
- Test that multiple glob calls work correctly (the shared executor can handle multiple calls)
- Test that normal glob calls (without timeout) still work correctly
Let me create a more comprehensive test:
Assistant
The test failed because the assertion string was wrong - it should check if the elapsed time is less than 1.0, not check if "< 1.0" is in the formatted string. Let me fix the test and run it again:
Assistant
Assistant
I need to keep making tool calls. Let me run the test script again.
Assistant
The CompositeBackend also requires config. Let me check the existing test file to see how they handle this:
<tool_call> <function=bash_terminal> <parameter=command> grep -A30 "def slow_glob" /deepagents/libs/deepagents/tests/unit_tests/test_middleware.py | head -40 </tool_call>
Assistant
I need to keep making tool calls to see the existing test file.
Assistant
The existing tests use mocking with
patch.object(middleware, "_get_backend", return_value=backend_obj). Let me look at how the backend_obj is set up in the test:<tool_call> <function=bash_terminal> <parameter=command> grep -B20 "def slow_glob" /deepagents/libs/deepagents/tests/unit_tests/test_middleware.py | head -30 </tool_call>
Assistant
Let me keep making tool calls to see the setup code for the backend_obj.
Assistant
I can see the existing tests use
backend, _ = _make_backend(). Let me check what_make_backenddoes:Assistant
Now I understand. The existing tests use
StoreBackendwith anInMemoryStore. Let me update my test to use this approach, but actually, let me just run the existing tests to make sure my fix doesn't break them:Assistant
Let me find the correct test name:
Assistant
Let me run the glob timeout test:
Assistant
The test passed. However, the existing test only checks the error message but doesn't check that the tool actually returns after the timeout duration. Let me run all the glob-related tests:
Assistant
All glob tests pass. Now let me also run the async glob tests:
Assistant
The async test failed due to pytest configuration, not due to my changes. Let me check if there's an asyncio plugin requirement:
<tool_call> <function=bash_terminal> <parameter=command> cat /deepagents/libs/deepagents/pyproject.toml | grep -A20 "pytest" </tool_call>
Assistant
I need to check the pytest configuration in the pyproject.toml file to understand the async test requirements.
Assistant
The pytest config has
asyncio_mode = "auto". The test failure seems to be an issue with the test discovery, not the actual test. Let me run the test with the proper markers:<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware_async.py::TestFilesystemMiddlewareAsync::test_aglob_timeout_returns_error_message -xvs 2>&1 | head -60 </tool_call>
Assistant
I need to continue making tool calls to run the async glob timeout test.
Assistant
The test method wasn't found with that exact name. Let me search for the actual test names in the async test file:
Assistant
The async test requires pytest-asyncio but it's not being loaded properly. This is a test environment issue, not related to my fix. The async glob implementation uses
asyncio.wait_for()which doesn't have the same issue as the sync version.Let me verify the async test content to make sure my fix didn't affect it:
Assistant
The async test checks the same thing as the sync test - that the error message is correct. The async test uses
asyncio.wait_for()which properly cancels the task on timeout, so it should work correctly.Let me try installing pytest-asyncio and running the test again:
<tool_call> <function=bash_terminal> <parameter=command> pip install pytest-asyncio -q && cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware_async.py::TestFilesystemMiddlewareAsync::test_glob_timeout_returns_error_message_async -xvs 2>&1 | head -60 </tool_call>
Assistant
I need to keep making tool calls to install pytest-asyncio and run the async test.
Assistant
The async test passed. Now let me run all the async glob tests to make sure my changes didn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware_async.py -k "glob" -xvs 2>&1 | head -80 </tool_call>
Assistant
I need to run all the async glob tests. Let me continue with the tool call to execute the tests.
Assistant
All async glob tests pass. Now let me run the full middleware test suite to make sure my fix doesn't break anything else:
<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware.py -x 2>&1 | tail -30 </tool_call>
Assistant
I need to run the full middleware test suite to ensure my changes don't break anything. Let me continue with the tool call.
Assistant
All 111 tests in test_middleware.py passed! Now let me also run the async middleware tests to make sure everything is working:
<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware_async.py -x 2>&1 | tail -30 </tool_call>
Assistant
I need to run the async middleware tests. Let me continue with the tool call.
Assistant
All tests pass! Let me now verify that my fix handles the edge cases correctly by running the reproduction script one more time:
<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents && python repro.py </tool_call>
Assistant
The tool call was made. Let me check the output of the reproduction script.
Assistant
The fix works correctly. The glob tool returns after 0.50s (the timeout) instead of blocking for 3.0s.
Let me clean up the temporary test files:
Assistant
Now let me review the changes I made to the file and create a summary. Let me view the final state of the changed code:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "glob_executor" /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
Let me check the changes I made to the file. I need to grep for glob_executor to see where I added the shared executor.
Assistant
The changes look good. Let me verify the exact changes by showing the diff:
<tool_call> <function=bash_terminal> <parameter=command> cd /deepagents && git diff libs/deepagents/deepagents/middleware/filesystem.py </tool_call>
Assistant
I need to use the bash_terminal tool to run the git diff command.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.