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 start by exploring the repository structure to understand the codebase
Assistant
Let me search for the
sync_globandasync_globfunctions in the file:Assistant
Let me explore more of the codebase to understand the existing patterns and find other similar code:
Assistant
Let me look at the existing test to understand the test structure. Now let me check the imports and existing test_middleware.py setup
Assistant
Let me first reproduce the issue to confirm it:
Assistant
Now let me create a reproduction script for the issue:
Assistant
reproduced. Now let me check the test files structure and the broader middleware code:
Assistant
Let me check how the existing tests behave. Note that the test sleeps for 2 seconds but with a 0.5s timeout, so the current test should take ~2s, not 0.5s. Let me time the test to confirm:
Assistant
Now let me design and implement the fix. Let me look at the surrounding code one more time and understand the full context:
Assistant
Now I understand the issue clearly. Let me implement the fix. The approach is to use a module-level shared
ThreadPoolExecutorwhich:- Fixes the primary issue: The shared executor is never explicitly shut down, so the tool can return immediately when a timeout occurs (the runaway thread continues but doesn't block the caller).
- Fixes the secondary issue: Reusing the executor avoids the per-call thread spawn overhead.
Let me make the change:
Assistant
Let me use a different approach. The issue might be with the way I'm passing arguments. Let me try with proper syntax
Assistant
Now I understand the command. Let me use it properly with heredoc syntax:
Assistant
need to use the bash_terminal tool to invoke the
editcommand properly:Assistant
constant has been added. Now let me update the
sync_globfunction to use the shared executor:Assistant
see there's an issue - my edit duplicated the
backend_pathline and theif glob_result.errorblock was not properly handled. Let me look at the actual current state and fix it:Assistant
I need to fix the duplicate line and restore the
if glob_result.errorcheck that got lost:Assistant
There's a stray
)on line 1300-1301. Let me fix that:Assistant
Let me see the broken section and fix everything at once:
Assistant
I see I removed too much. Let me take a different approach and rewrite the entire sync_glob function. First, let me view the current state:
Assistant
Let me rewrite the broken portion in one edit:
Assistant
I need to add back the
contentline in the finalToolMessage:Assistant
still a duplicate
tool_call_idat lines 1305-1306. Let me fix it:Assistant
me take a step back and just reset the file to apply a clean fix:
Assistant
Let me clean up by removing the duplicate
name="glob",line:Assistant
me reset and apply a clean fix from scratch:
Assistant
Now let me apply the fix cleanly. First, let me look at the precise current state of the file:
Assistant
Now let me apply the edits one at a time, carefully. First, add the executor constant:
Assistant
Now let me find the new line numbers for the
withblock:Assistant
me use
replaceinstead since it's more robust for multi-line edits:Assistant
Let me check the exact indentation of the lines:
Assistant
me try a smaller search-replace first to debug:
Assistant
Let me navigate to the relevant line first then try the replace:
Assistant
Now I can see the lines clearly. Let me do the edit with line ranges:
Assistant
The fix looks clean now. Let me verify with a diff:
Assistant
The diff is clean and exactly what we want. Now let me run the reproduction script to verify the fix:
Assistant
The fix works. The glob now returns after
0.50sinstead of3.00s. Let me also run the existing tests to make sure nothing is broken:Assistant
Let me also run only the timeout test to verify the timing improvement:
Assistant
The timeout test went from 2.21s to 0.55s. Let me also run the async glob tests to make sure they still work:
Assistant
All async tests pass too. Now let me think about edge cases and write some more comprehensive tests:
Assistant
error in test 2 is because
StateBackendrequires aRunnableConfig. Let me fix the edge case tests to useStoreBackendlike the existing tests:Assistant
The edge case 2 took 1.5s because the previous test's
slow_globwas still running in the worker thread. This is expected behavior with the shared executor. Let me update the test:Assistant
Most edge cases pass. Edge case 5 has wrong API. Let me fix it:
Assistant
edge cases pass. Let me run the full middleware test suite to ensure nothing else is broken:
Assistant
All 139 tests pass. Let me also run other related test files:
Assistant
244 tests pass. Let me run the entire test suite:
Assistant
1748 tests pass. Let me run the reproduction script one more time to confirm:
Assistant
Let me check the linter for the modified file:
Assistant
There's just a minor formatting issue - let me apply the format fix
Assistant
The diff is clean. Let me run the reproduction script and the test suite once more to confirm everything works:
Assistant
Let me also test a few more edge cases related to concurrent glob calls:
Assistant
Concurrent calls work fine. Let me also test concurrent slow globs (where some time out):
Assistant
4 concurrent threads return within 0.5s. The fix works perfectly even under concurrent load. Let me clean up the temp files and verify the fix one more time:
Assistant
Let me run the original reproduction one more time to verify the fix:
Assistant
The fix returns after
0.50sinstead of3.00s(matching theGLOB_TIMEOUT). Let me clean up the temp file:Assistant
Let me do a final review of the modified code:
Assistant
The fix is clean. Let me also run the type check tool if available:
Assistant
All checks pass. Let me do a final run of the reproduction script and the related tests:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.