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
I'll start by exploring the repository structure and finding the relevant file mentioned in the issue.
Assistant
I'll start by exploring the repository structure and finding the relevant file mentioned in the issue.
Assistant
Let me find the actual filesystem.py file mentioned in the issue.
Assistant
Now I understand the issue. Let me look at the broader context — the imports and the class structure to understand how to best fix this.
Assistant
I need to make only one tool call at a time. Let me look at the imports and class structure.
Assistant
Now let me look at the
FilesystemMiddlewareclass definition and its__init__to understand the structure.Assistant
Now I understand the issue clearly. Let me look at existing tests for the glob timeout to understand expected behavior.
Assistant
The existing test patches
GLOB_TIMEOUTon the module, so my fix must keep referencing the module-levelGLOB_TIMEOUT. Let me first reproduce the bug to confirm it. Let me check the test setup and imports.Assistant
Now let me create a reproduction script based on the issue to confirm the bug.
Assistant
I need to install the package first. Let me check how to set up the environment.
Assistant
The package was installed but it's not finding the module. Let me check the python environment.
Assistant
The
uv pip installinstalled to a venv, but/usr/local/bin/pythondoesn't have langchain. Let me useuv runor check the venv.Assistant
uv runworks. Let me run the reproduction script.Assistant
The bug is confirmed — returns after 3.00s instead of ~0.5s. Now let me investigate an important subtlety: whether leaving a hung worker thread in a
ThreadPoolExecutorcould block interpreter exit (via theatexit_python_exitjoin). Let me test this empirically.Assistant
Interesting — it exited immediately. Let me time it precisely to confirm whether
_python_exitblocked ornot.Assistant
The program took 10.08s to exit — confirming that
ThreadPoolExecutor's atexit_python_exithandler joins the hung worker thread, blocking interpreter exit. This is an important consideration. Let me test whether a raw daemon thread (not via ThreadPoolExecutor) avoids this exit-blocking.Assistant
Confirmed — a raw daemon thread does NOT block exit (0.07s), while
ThreadPoolExecutorblocks for the full duration via its atexit handler. Let me benchmark the actual per-call overhead of creating a freshThreadPoolExecutorvs. reusing a shared one, to understand the magnitude of the secondary concern.Assistant
Let me look at the magnitude: shared executor is 37µs/call vs fresh 146µs/call — negligible for a glob tool doing I/O, but the issue mentions it. There's a real tension: a shared
ThreadPoolExecutorblocks interpreter exit if a glob is hung at exit (via the_python_exitatexit join). Let me check whether the codebase already uses any shared-executor or threading patterns elsewhere, and look at the broader context around the grep tool (which may have a similar timeout pattern).Assistant
Let me look at the
executetool and how it handles timeouts, to understand the codebase conventions for bounding time.Assistant
Let me check the pytest configuration to understand test timeouts and how tests are run.
Assistant
Tests run with
-n auto(parallel) and no global timeout for unit tests. Now let me make my decision. Let me first implement the shared-executor approach (which matches the issue's described secondary fix) and measure BOTH the printed invoke-time AND the total process-exit time, to see if the atexit exit-block is a practical problem.Assistant
Let me check the CHANGELOG for any hints about the intended fix direction.
Assistant
There's a "Timeout python grep fallback" fix (#1937). Let me examine how the grep tool handles its timeout — it likely establishes the codebase's pattern for this exact problem.
Assistant
Let me look at the grep tool's implementation, particularly the python fallback that was given a timeout.
Assistant
The glob tool is the only one using the
ThreadPoolExecutorpattern. Before deciding on the fix, I need to check whether the middleware/agent needs to remain picklable (a stored executor would break that) and whether there are serialization concerns.Assistant
No pickle/dill/cloudpickle references in the deepagents source or tests. So picklability isn't explicitly tested. But LangGraph runnables are often picklable for distributed execution. Let me not over-index on picklability since it's not tested. But still, storing a ThreadPoolExecutor on self is a smell.
Let me reconsider. Actually, let me check if there's any test that does something like pickling the agent or middleware.
Let me search more broadly.
Assistant
No picklability tests exist. Let me look at the exact import block and the surrounding code once more to plan the edit precisely.
Assistant
No picklability tests, so that's not a constraint tested. Let me check the ruff/lint configuration to write code that passes lint.
Assistant
Ruff uses
select = ["ALL"], so BLE001 (blind exception catch) applies tofilesystem.py. Let me see how the file handles broad exceptions andnoqaelsewhere.Assistant
I now have a clear understanding. Let me lay out my analysis and decision.
The bug: In
sync_glob, thereturninsidewith concurrent.futures.ThreadPoolExecutor(...) as executor:triggers__exit__→shutdown(wait=True), which joins the worker thread still running the glob. So the tool blocks until the glob actually finishes, makingGLOB_TIMEOUTonly change the message, not the latency.Key constraint I verified empirically: A
ThreadPoolExecutorworker that's still running a task is joined byconcurrent.futures'atexithook (_python_exit) at interpreter shutdown — so a shared/lingeringThreadPoolExecutorwith a stuck glob would block process exit (I measured 10s for a 10s glob). A raw daemon thread is not registered there and is abandoned cleanly at exit (0.07s). So using a raw daemon thread (instead of aThreadPoolExecutor) fixes the blocking and avoids introducing an exit-hang regression.My fix: run the backend glob on a daemon thread with a standalone , call , and on timeout return immediately without joining (the daemon worker is abandoned at exit). This also removes the per-call construction overhead.
Assistant
Now let me make the edits. First, add the
import threadingto the imports.Assistant
Now let me open the file and replace the
with ThreadPoolExecutorblock with the daemon-thread approach.Assistant
The edit looks correct. Now let me run the reproduction script to verify the fix — checking both the printed invoke-time AND the total process-exit time.
Assistant
The fix works:
- Invoke time: 0.50s (the timeout) instead of 3.0s — the primary bug is fixed.
- Process exits in 1.51s (mostly uv startup + 0.5s invoke) — the daemon thread running the 3s glob is abandoned at exit with no exit-hang.
Now let me run the existing tests. First the glob timeout tests (sync and async), then the full middleware test suite.
Assistant
All glob tests pass. Let me also run the async glob timeout test and verify the sync timeout test now completes quickly (it patches
GLOB_TIMEOUT=0.5with a 2s slow glob, so it should return near-instantly now rather than ~2s).Assistant
All tests pass. Now let me verify edge cases with a temporary script: (1) a glob that raises an exception should still propagate (matching prior behavior), and (2) a normal glob returns correct results through the new thread path.
Assistant
Edge case 1 (exception propagation) works correctly. Edge case 2 failed only because
StateBackendrequires a LangGraph config to read files (test-setup issue, not a fix bug). Let me use aStoreBackend(like the existing tests) to verify the normal success path returns correct matches.Assistant
All edge cases pass:
- Exception propagation — a glob that raises propagates the exception (matching prior behavior, not masked as a timeout).
- Normal glob — returns correct matches through the new thread path.
- Timeout — returns at exactly 0.40s (the timeout), not the full 2s.
Now let me run the linter (ruff) on the modified file to ensure no lint errors were introduced.
Assistant
Lint passes. Let me also run the formatter check and the type checker (ty) on the file to be thorough.
Assistant
Lint, format, and type checks all pass. Now let me run the broader middleware/filesystem test suite to ensure nothing is broken.
Assistant
All 139 middleware tests pass. Let me run the full unit test suite (mirroring the CI command) to ensure nothing else is affected.
Assistant
All 1748 unit tests pass (98 skipped, 4 xfailed). Let me review the final diff of my changes.
Assistant
The diff is clean and correct. Let me clean up the temporary test scripts and do a final verification run of the exact issue repro plus the timeout test.
Assistant
Both timeout tests pass quickly. Let me run the exact repro from the issue one final time to confirm the fix resolves the reported behavior.
Assistant
The fix is confirmed: the glob now returns after 0.50s (the timeout) instead of 3.00s (the full duration of the runaway glob).
Let me do a final review of the complete modified
sync_globfunction.Assistant
The fix is complete and correct. Let me do a final confirmation of the git status to ensure only the intended file is changed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.