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
GLOB_TIMEOUTinFilesystemMiddlewaredoesn't actually bound wall-clock time becauseThreadPoolExecutor.__exit__callsshutdown(wait=True)which waits for the worker thread to finish. - The fix should prevent the shutdown from blocking - either by using
shutdown(wait=False)or by using a shared executor that isn't shut down after each call. - There's also a secondary issue about creating a new ThreadPoolExecutor per call adding overhead.
Let me start by exploring the repository structure and finding the relevant file.
- The
Assistant
I found the file. Let me read it to understand the current implementation.
Assistant
The user is pointing out that I need to use the correct tool format. Let me use the bash_terminal to open the file with the
opencommand.Assistant
Let me search for the
GLOB_TIMEOUTconstant and thesync_globfunction.Assistant
Now let me view the
sync_globfunction in detail to understand the exact code that needs to be fixed.Assistant
Now I understand the issue clearly. The problem is on lines 1272-1280:
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(...) # This return exits the `with` block # After the `with` block, executor.shutdown(wait=True) is called, blocking until the thread finishesWhen
TimeoutErroris caught and the function returns, thewithblock's__exit__triggersexecutor.shutdown(wait=True), which blocks until the worker thread finishes running the slow glob operation.The fix is to use
shutdown(wait=False)so the executor doesn't wait for the thread to complete. Let me first create a reproduction script to confirm the issue.Assistant
The module isn't installed. Let me check the project structure to see how to run Python with the correct path.
Assistant
Now let me run the reproduction script:
Assistant
I've confirmed the bug. The return happens after 3 seconds instead of 0.5 seconds. Now let me fix the issue.
The fix is to change the
withblock to useshutdown(wait=False)when a timeout occurs. This way, the executor won't block waiting for the thread to complete. I'll also consider the secondary issue about reusing a shared executor.The best approach is to:
- Not use a
withstatement, but instead create the executor explicitly and callshutdown(wait=False)when needed. - This way, when a timeout occurs, we return immediately without waiting for the thread.
Let me look at the exact lines more carefully:
- Not use a
Assistant
Now I understand the structure. The fix is to restructure the code so that when a timeout occurs, we don't wait for the executor to shutdown. I'll modify the code to use
shutdown(wait=False)explicitly in the timeout case:Assistant
I need to use the edit command with the correct syntax. Let me fix the
sync_globfunction to properly handle the timeout by not waiting for the executor to shut down when a timeout occurs.Assistant
I need to use the proper format for the edit command. Let me check the correct syntax.
Assistant
The edit looks correct. Now let me run the reproduction script again to verify the fix works:
Assistant
The fix didn't work. It seems the module wasn't reinstalled properly, or the issue is more subtle. Let me check if the changes are actually in the file:
Assistant
The changes are in the file. Let me check if the module is being reloaded properly and debug the issue further:
Assistant
The code is there. The issue might be that
finallyblock still callsshutdown(wait=True)even after thereturnstatement. But wait... in Python, when youreturnfrom within atryblock, thefinallyblock still executes before the actual return happens. So thereturnin line 1279 will first executefinally: executor.shutdown(wait=True)which will block!I need to set a flag so the
finallyblock knows not to wait:Assistant
Now let me reinstall and test:
Assistant
The fix works. Now the function returns after ~0.5s (the timeout) instead of waiting for the full 3s. Let me now run the existing tests to make sure I didn't break anything:
Assistant
The integration tests fail because they need authentication for external services (Anthropic). Let me check if there are unit tests specifically for the glob timeout:
Assistant
There are existing tests for glob timeout. Let me run them:
Assistant
The test passes. Let me also run the async version of the test:
Assistant
The async test failure is due to a missing pytest-asyncio plugin - not related to my changes. Let me also run more middleware unit tests to make sure I didn't break anything:
Assistant
All 7 glob-related tests pass. Let me run all the middleware unit tests to make sure nothing else is broken:
Assistant
All 111 tests pass. Let me also test a successful glob scenario (non-timeout) to ensure the normal path still works:
Assistant
That's a different issue with the test setup (StateBackend needs LangGraph config). The existing unit tests already cover normal glob scenarios. Let me look at how the existing test does it:
Assistant
Good, the existing test already covers the timeout scenario. Let me verify my changes one more time by looking at the full diff:
Assistant
The diff looks correct. Let me also run the reproduction script one more time to confirm the fix works:
Assistant
The fix is working. Let me clean up the temporary test file and verify the fix one more time by reviewing what the change does:
Summary of the fix:
The original code used a
withstatement to manage theThreadPoolExecutor:pythonwith concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit(...) try: glob_result = future.result(timeout=GLOB_TIMEOUT) except concurrent.futures.TimeoutError: return ToolMessage(...) # Timeout error messageThe problem was that when
TimeoutErrorwas caught and the function returned, thewithblock's__exit__calledexecutor.shutdown(wait=True), which blocked until the worker thread (still running the slow glob) finished.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.