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 understanding the issue.
Assistant
Let me find the
sync_globandasync_globfunctions:Assistant
Now I understand the issue. Let me look at the exact code and check for any existing patterns/tests:
Assistant
Let me look at the existing tests to understand expectations:
Assistant
Now let me reproduce the issue to confirm it:
Assistant
Confirmed: returns after 3.00s instead of ~0.5s. Now let me look at the module-level definitions and fix the code:
Assistant
Now let me add a shared module-level executor. First, let me view the imports section more carefully:
Assistant
Now let me add a shared module-level executor near the
GLOB_TIMEOUTconstant:Assistant
Let me check if there are any existing shared executor patterns in the codebase:
Assistant
I've confirmed the bug. Now let me implement the fix. First, I'll add a shared module-level executor near the
GLOB_TIMEOUTconstant:Assistant
I accidentally duplicated
LINE_NUMBER_WIDTH = 6. Let me fix that:Assistant
Now let me modify the
sync_globfunction to use the shared executor without awithblock:Assistant
Now let me verify the fix with the reproduction script:
Assistant
The fix works — now it returns after ~0.5s (the timeout) instead of 3.0s. Let me also verify the happy path (normal glob) still works and test edge cases. Let me check the existing tests first:
Assistant
Let me run the existing glob-related tests to make sure they pass:
Assistant
Now let me run the async glob tests too:
Assistant
Let me look at the failing async test:
Assistant
This failure is unrelated to my change — it requires an async test plugin. Let me check the test configuration to see how these are meant to be run:
Assistant
The async tests require
pytest-asyncio. Let me install it:Assistant
All glob tests pass (both sync and async). Let me also run the full middleware test files to ensure I didn't break anything:
Assistant
All 139 tests pass. Now let me write a more thorough test to verify edge cases — particularly that the happy path still works and that a subsequent glob call isn't blocked by a previous timed-out glob:
Assistant
The
StateBackendneeds a graph context. Let me useStoreBackendfor the happy-path test, similar to the test helpers:Assistant
All edge cases pass:
- Happy path — fast glob returns correct result in ~0.00s
- Timeout bounds wall-clock — returns in 0.50s instead of 3.0s (the primary fix)
- Retry not blocked — a subsequent fast glob isn't queued behind the orphaned worker (secondary fix benefits from a shared pool with spare capacity)
Let me verify the repro's process exit behavior is reasonable (orphaned worker for a slow-but-terminating glob) and run a broader test sweep:
Assistant
I need to make single tool calls. Let me run the repro first:
Assistant
The tool returns at 0.50s, but the process takes 4.1s total. This is because the orphaned worker thread is joined at interpreter shutdown (the primary agent-loop concern is fixed, but let me investigate the thread behavior at exit):
Assistant
The threads are non-daemon, so at interpreter exit
_python_exitjoins orphaned workers. Let me check the impact on the test suite timing (the timeout test creates an orphaned worker sleeping ~1.5s):Assistant
The test passes in 0.59s but the process takes 3.47s real time — the orphaned non-daemon worker (sleeping ~1.5s after timeout) is joined at interpreter shutdown via
_python_exit. This is a robustness edge case: a truly hanging glob (deadlocked mount) would block clean process shutdown. Let me investigate making the worker threads daemon cleanly:Assistant
Let me check the impact on the broader test suite timing with my change:
Assistant
The tests run in 1.66s (process exit 3.83s total due to orphaned-worker joins — this is stdlib
ThreadPoolExecutordefault behavior, and notably the net wall-clock improved vs. the old code where each timeout test blocked ~2s insideshutdown).Let me verify my final implementation is clean and correct:
Assistant
Let me run the original repro once more and run linting/formatting checks on the changed file:
Assistant
Ruff lint passes, but the formatter wants changes. Let me see what:
Assistant
Both lint and format pass. Now let me re-run the repro and edge-case tests, plus the full middleware test suite:
Assistant
All 265 tests pass. Let me also run a broader sweep of the unit tests to make sure nothing else is affected:
Assistant
There are 3 failures in
test_subagent_middleware_init.py. Let me check if these are pre-existing (unrelated to my change) by examining them and testing against the original code:Assistant
These 3 failures are due to a missing
langchain-openaipackage (ImportError: Initializing ChatOpenAI requires the langchain-openai package) — completely unrelated to my change. Let me confirm by stashing my changes and running the same tests against the original code:Assistant
Confirmed — those 3 failures are pre-existing (they fail on the original code too, due to the missing
langchain-openaipackage) and are unrelated to my change. My change introduces zero new failures.Let me clean up my temp files and review the final diff:
Assistant
The diff is clean and minimal. Let me do one final verification run of the exact reproduction from the issue to confirm the fix, and run the glob tests one final time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.