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 and find the relevant file mentioned in the issue.
Assistant
Let me explore the repository structure.
Assistant
Let me look at the specific file mentioned in the issue.
Assistant
Let me find the
sync_globfunction and theGLOB_TIMEOUTconstant.Assistant
Now I understand the issue clearly. Let me look at the
GLOB_TIMEOUTdefinition and surrounding context.Assistant
Let me look at the
FilesystemMiddlewareclass structure to understand how to best implement a shared executor.Assistant
Let me check the Python version requirements and look for existing tests related to glob.
Assistant
Let me run these one at a time.
Assistant
Let me look at the existing test for glob timeout to understand the test structure.
Assistant
Let me reproduce the issue first. Let me check the Python version and the package structure.
Assistant
Now let me create a reproduction script based on the issue.
Assistant
Need to install the package or set PYTHONPATH. Let me check how the package is set up.
Assistant
I've confirmed the bug: returns after 3.00s instead of ~0.5s. Now let me look at the broader codebase to see if there's an existing shared-executor pattern, and understand the
concurrent.futuresimport.Assistant
I've confirmed the bug: returns after 3.00s instead of ~0.5s. Now let me implement the fix. My plan:
- Create a shared module-level executor near
GLOB_TIMEOUTto address the secondary concern (per-call executor/thread overhead). - In
sync_glob, replace thewith concurrent.futures.ThreadPoolExecutor(...)block with a direct submit to the shared executor. This way, on timeout thereturnis not inside awithblock, so noshutdown(wait=True)blocks the worker thread still running the glob.
Let me first add the shared executor definition:
- Create a shared module-level executor near
Assistant
Now let me add the shared executor definition after
GLOB_TIMEOUT:Assistant
Now let me find the
sync_globfunction'swithblock (line numbers shifted by 13):Assistant
Now let me replace the
withblock insync_globwith a direct submit to the shared executor:Assistant
The edit looks correct. Now let me run the reproduction script to confirm the fix:
Assistant
The fix works: the tool now returns after 0.50s (the timeout) instead of 3.00s, with the correct error message. Let me verify the normal (non-timeout) success path still works and run the existing glob tests:
Assistant
All glob tests pass. Let me also run the async middleware glob tests and the integration filesystem tests:
Assistant
Let me see the failure details to determine if it's related to my change:
Assistant
This failure is unrelated to my change — it's because
pytest-asyncioisn't installed (async tests aren't natively supported). Let me check the test config and install the needed plugin:Assistant
All async glob tests pass. Now let me run the full sync and async middleware test suites to make sure nothing is broken:
Assistant
All 139 tests pass. Now let me write a more thorough verification covering edge cases: (1) timing is bounded, (2) a subsequent normal glob still works promptly after a timed-out one (worker exhaustion concern), and (3) the success path returns correct results:
Assistant
Case 1 passed (0.50s). The Case 2 failure is a test-setup issue in my verification script (StateBackend requires LangGraph config). Let me check how the actual tests set up the backend:
Assistant
I see — the tests use
StoreBackendwith anInMemoryStoreand a properToolRuntime. Let me rewrite the verification script using that pattern so I can properly test the "subsequent glob works after a timed-out one" case:Assistant
ToolRuntimeis imported fromlangchain.toolsin the filesystem.py file (from langchain.tools import ToolRuntime). Let me fix the import.Assistant
All checks passed:
- Sync timeout returns in 0.50s (bounded by GLOB_TIMEOUT) — primary issue fixed.
- Subsequent normal glob returns in 0.00s — not blocked by the lingering runaway worker (the shared executor grows workers on demand, addressing worker-exhaustion concerns).
- Async timeout returns in 0.50s — already worked, still works.
- Success path returns correct results.
The deprecation warnings are pre-existing and unrelated. Now let me run the broader test suites (integration + middleware init) to ensure nothing else broke:
Assistant
There are integration test failures. Let me check whether these are pre-existing (unrelated to my change) by stashing my change and re-running:
Assistant
These failures are due to missing Anthropic API credentials (integration tests call a real model). They're unrelated to my change. Let me confirm by stashing my change and running the same test:
Assistant
Confirmed — the integration test fails identically without my change (missing API credentials). These are pre-existing failures unrelated to my fix. Let me run the full unit test suite to confirm nothing else broke:
Assistant
3 failures in
test_subagent_middleware_init.py— unrelated to filesystem. Let me verify they're pre-existing by checking against a clean checkout:Assistant
Confirmed — those 3 subagent failures are pre-existing (fail without my change). My fix introduces no new test failures. Let me review the final diff and clean up the temporary scripts:
Assistant
The diff is clean. Let me verify the module imports correctly and check how the test references the module attribute, then clean up temp scripts:
Assistant
Good — the test patches the module-level
GLOB_TIMEOUTattribute, which my code reads at call time (consistent with the original). Let me run the targeted timeout tests once more and also confirm they return promptly (the test usessleep(2)withGLOB_TIMEOUT=0.5):Assistant
Both timeout tests pass and run promptly. Now let me clean up the temporary scripts so they aren't submitted:
Assistant
The only change is to
filesystem.py. Let me do a final review of the complete modifiedsync_globfunction:Assistant
The fix is complete and correct. Let me run the full glob-related unit tests one final time to confirm everything is green after cleanup:
Assistant
All 31 glob/grep-related tests pass. The fix is complete. Let me do a final review of the diff before submitting:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.