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
I'll start by exploring the repository structure to understand the codebase and locate the relevant file mentioned in the issue:
deepagents/middleware/filesystem.py. Let's first check the current directory and then look for that file. - Assistant
Let me look at the filesystem middleware file to understand the current implementation.
- Assistant
Let me search for the
sync_globfunction specifically: - Assistant
Let me look at the specific implementation of
sync_globandasync_globto understand the issue. - Assistant
Now I can see the issue clearly. The problem is in the
sync_globfunction (lines 1272-1281):pythonwith concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit(lambda: ctx.run(resolved_backend.glob, pattern, path=backend_path)) try: glob_result = future.result(timeout=GLOB_TIMEOUT) except concurrent.futures.TimeoutError: 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", )The issue is that the
returnstatement is inside thewithblock. When aTimeoutErroris caught, the function tries to return, but theThreadPoolExecutor.__exit__method is called, which callsshutdown(wait=True)— this blocks until the worker thread finishes, even though we already have a timeout error. - Assistant
Let me check what these tests do:
- Assistant
Let me also check the async test:
- Assistant
Now let me look at the full context around the
sync_globfunction to understand the structure better: - Assistant
Now I understand the issue. Let me first create a test script to reproduce the problem as described in the issue:
- Assistant
Let me install the package first or run from the right directory.
- Assistant
The current directory is already /deepagents/libs/deepagents. Let me just install from here.
- Assistant
Now let me run the test script to reproduce the issue:
- Assistant
Great! I've confirmed the issue. The test shows that:
- It returns after 3.00s (the full duration of the slow glob)
- But it should return after ~0.5s (the timeout)
Now I need to fix the issue. The problem is in the
sync_globfunction. Thereturnstatement is inside the block for . When a timeout occurs and the function tries to return, the block's method is called, which calls on the executor. This blocks until the worker thread finishes, even though we already have a timeout error. - Assistant
I'm already in /deepagents/libs/deepagents, let me adjust the path.
- Assistant
Now I understand the full picture. The core issue is that
returninside thewith concurrent.futures.ThreadPoolExecutor(...)block triggers__exit__->shutdown(wait=True), which joins the worker thread. The fix is to:- Not use the
withcontext manager (so returning doesn't block) - Reuse a shared executor to also address the secondary performance issue
Let me implement the fix:
- Not use the
- Assistant
Now I can see the file is open. Let me find the exact location of the GLOB_TIMEOUT constant and the sync_glob function, then make my edits.
- Assistant
Now let me go to the sync_glob function. I need to see the exact line numbers. Let me scroll down to see the sync_glob function.
- Assistant
Now I can see the exact lines I need to edit. The fix is to:
- Add a module-level shared executor after the
GLOB_TIMEOUTconstant - Modify the
sync_globfunction to use the shared executor instead of creating a new one per call - Move the timeout return outside the
withblock (or remove thewithblock entirely)
Let me first add the shared executor after
GLOB_TIMEOUT: - Add a module-level shared executor after the
- Assistant
Now I need to add the shared executor after the
GLOB_TIMEOUTconstant. Let me edit line 233 to add the executor: - Assistant
Good! Now I need to modify the
sync_globfunction to use the shared executor. Let me find the exact lines for the sync_glob function. The line numbers have shifted, so let me search for it: - Assistant
Now let me look at the sync_glob function again with the updated line numbers:
- Assistant
Now I can see the exact lines I need to edit. I need to replace lines 1278-1290 (the
withblock) with code that uses the shared executor. Let me make the edit: - Assistant
Great! Now let me verify that the fix works by running the test script again:
- Assistant
Excellent! The fix works. Now it returns after ~0.5s instead of ~3.0s. Let me also run the existing tests to make sure I didn't break anything:
- Assistant
All glob-related tests pass. Now let me also run the async tests to make sure those still pass:
- Assistant
The async test failure is a missing pytest-asyncio marker, not related to my changes. Let me check if the async tests need to be run differently:
- Assistant
The async test failure is pre-existing (needs pytest-anyio marker). Let me run the full sync test suite to ensure nothing is broken:
- Assistant
All 111 tests pass! Now let me also verify the fix with the original reproduction script and check if the timeout actually happens in ~0.5s:
- Assistant
Perfect! The fix works as expected. Now let me also create a more comprehensive test to verify edge cases:
- Assistant
The normal glob test fails because
StateBackendrequires a proper LangGraph runtime context. The timeout test passes perfectly though. Let me run the actual test suite for the middleware: - Assistant
All 111 tests pass. Let me also check if there are other places in the codebase that might have similar issues (using
with concurrent.futures.ThreadPoolExecutorand returning inside thewithblock): - Assistant
Let me check the diff to confirm my changes are correct:
- Assistant
The diff looks clean. Let me now run the full test suite one more time to make sure everything passes:
- Assistant
All 111 tests pass. Let me also run the full test suite to make sure nothing else is broken:
- Assistant
The benchmark test fails because
pytest_benchmarkis not installed, which is unrelated to our changes. Let me run the unit tests only: - Assistant
The async test failures are all pre-existing (missing pytest-asyncio). Let me verify by running only the sync tests to confirm they all pass:
- Assistant
The async test failures are all pre-existing (missing pytest-asyncio marker). Let me run just the middleware sync tests to confirm they all pass:
- Assistant
All 124 tests pass. Let me also run the permissions sync tests to make sure they pass:
- Assistant
All tests pass. Let me also verify the fix once more by running the reproduction script:
- Assistant
Now let me review my changes one more time to make sure they're correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.