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 then find the relevant file mentioned in the issue.
Assistant
Let me explore the repository structure first.
Assistant
Now let me look at the imports and surrounding context of this file.
Assistant
Let me look at the FilesystemMiddleware class structure and its
__init__method.Assistant
Let me reproduce the issue first with the script from the issue. Let me check the package structure and whether the modules import correctly.
Assistant
I need to install the package and its dependencies. Let me check the project setup.
Assistant
The test extras aren't declared in the project, but in the dependency-groups. Let me install the test deps from the dependency groups.
Assistant
Now let me create and run the reproduction script from the issue.
Assistant
I've reproduced the issue (returns after 3.00s instead of ~0.5s). Now let me look at existing tests for the glob tool to understand expected behavior and conventions.
Assistant
There's an existing test for the glob timeout. Let me examine it.
Assistant
The existing test only checks the message, not timing. Let me verify the behavior of ThreadPoolExecutor threads (daemon vs non-daemon) in this Python version, since that affects whether lingering runaway threads block process exit.
Assistant
Let me check the CPython source for
ThreadPoolExecutorto understand thread creation and whether daemon threads are feasible.Assistant
The existing test only checks the message. Now I understand the issue thoroughly:
- The
with ThreadPoolExecutorblock's__exit__callsshutdown(wait=True), which joins the still-running worker thread, blocking until the glob actually finishes. - Also, a fresh executor/thread is created per call (overhead).
Let me check the area around
GLOB_TIMEOUTto decide where to place a shared executor helper.- The
Assistant
I'm in
/deepagents/libs/deepagents. Let me use the right relative path.Assistant
Now I understand the issue and the fix needed. Let me check the ruff/lint config to make sure my fix conforms to the project's style (the project uses
select = ["ALL"]).Assistant
Now I have a full picture.
SLF001is ignored globally, andBLE001needs a noqa for non-test code. Let me look at the area right before theFilesystemMiddlewareclass to find a clean insertion point for a shared executor helper.Assistant
Now let me make my edits. First, add the
queueandthreadingimports.Assistant
Now let me find the current line number for
class FilesystemMiddlewareto insert the executor helper before it.Assistant
The imports are added. Now let me insert the reusable daemon executor helper and singleton before the
FilesystemMiddlewareclass.Assistant
Now let me update the
sync_globfunction to use the shared executor and not block on timeout. Let me find the current lines.Assistant
I see the edit introduced a duplicated
backend_pathline and a stray). Let me fix both. First, remove the duplicatebackend_path.Assistant
Now remove the stray
)at line 1404.Assistant
The
sync_globnow looks correct. Let me verify the module imports and run the reproduction script.Assistant
The fix works — returns in 0.50s and the script exited promptly (no atexit hang). Let me write a comprehensive verification script to test edge cases: normal globs, thread reuse, concurrent globs, exception propagation, and clean process exit.
Assistant
The first test passed. My verify script used wrong field names for
write_file. Let me look at the existing test helpers to use the correct approach.Assistant
Let me rewrite the verify script to mirror the existing test patterns (
StoreBackend+ToolRuntime).Assistant
All 5 verification tests pass. Now let me explicitly verify the key daemon-thread benefit: a still-running runaway glob (never released) must NOT hang process exit.
Assistant
The process exited in 1.6s despite a 30s runaway glob that was never released — confirming daemon threads prevent atexit hangs. Now let me run the existing test suite to ensure nothing is broken.
Assistant
The glob tests pass (including the existing timeout test). Let me run the full middleware test files (sync and async) plus permissions tests.
Assistant
All 262 tests pass. Let me run the full deepagents unit test suite to be thorough (and confirm the session exits promptly with no lingering-thread hangs).
Assistant
3 tests failed in
test_subagent_middleware_init.py. Let me check if these are related to my change or pre-existing (e.g., a missing dependency).Assistant
These 3 failures are due to a missing optional dependency (
langchain-openai), unrelated to my change. Let me install it and confirm they pass.Assistant
Those failures were purely environmental (missing
langchain-openai). Now they pass. Let me run ruff lint on the modified file to ensure conformance with the project'sselect = ["ALL"]style.Assistant
Three lint issues (FBT001/FBT002 on the
shutdownbool args, and PLW0603 onglobal). Let me check how the codebase handles these patterns elsewhere.Assistant
The codebase convention is
# noqa: FBT001, FBT002for boolean positional args and# noqa: PLW0603forglobal. Let me apply the same.Assistant
The replace command needs the file to be scrolled to show the line. Let me use
goto 723then replace, or use the--fileoption with replace. Let me use the file option.Assistant
I also notice there are missing blank lines before
class FilesystemMiddleware(lines 754→755). Let me fix the noqa onshutdownfirst.Assistant
Now fix the
globalnoqa and add the missing two blank lines before the class.Assistant
Now let me re-run ruff to confirm all lint issues are resolved.
Assistant
All lint checks pass. Let me also verify the formatter is happy and run ruff format check.
Assistant
The formatter wants two small changes in my added code. Let me apply
ruff formatand then verify the diff is limited to my changes.Assistant
Let me view the full diff to confirm only my intended changes are present.
Assistant
The diff is clean — only my intended changes. Let me confirm both ruff check and format pass, and re-run the verification scripts.
Assistant
Excellent! Everything works. Let me run the relevant existing tests once more to confirm nothing broke after the formatting changes.
Assistant
All 265 tests pass. Let me also check the
tytype-checker (configured in pyproject) on the modified file, since the project uses it.Assistant
tyisn't installed. Let me check how the codebase handles method overrides / type: ignore for compatibility, to make sure my# type: ignore[override]and types conform.Assistant
Let me try installing
tyto run the project's type checker on the file.Assistant
The
tydiagnostic is at line 288 in_file_data_reducer— a function I did not touch. Let me confirm it's pre-existing by stashing my changes.Assistant
The
tydiagnostic is pre-existing (in_file_data_reducer, which I didn't touch) — my change introduces no new type errors. Let me run the complete deepagents unit test suite one final time to confirm everything is green.Assistant
All 1748 tests pass with no failures (and the session exited cleanly — no atexit hang). Let me clean up the temporary scripts and do a final review of the changed code.
Assistant
Let me view the final
sync_globchange once more.Assistant
The change is complete and clean. Let me do a final confirmation of the git status and the complete diff.
Assistant
Only one file is modified, with a clean, focused diff. Let me run a final lint + format + a quick smoke of the repro one more time 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.