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 inspect the repository structure and the filesystem middleware implementation, then identify relevant tests and reproduce the blocking behavior before changing it.
- Assistant
The middleware is under
libs/deepagents. I found the timeout constant; next I’ll locatesync_glob, inspect its lifecycle/context propagation requirements, and enumerate the package’s test layout to avoid introducing a shared-executor shutdown or contextvars regression. - Assistant
The defect is exactly the executor context manager’s implicit
shutdown(wait=True). A reusable module-level executor will both avoid that join and address per-call dispatch overhead. On timeout, the future should also be cancelled so queued (not-yet-started) work does not execute later; running threads cannot be stopped, but the caller can return at the deadline. I’ll first run a compact reproduction against the current code and inspect the existing sync timeout test’s assertions. - Assistant
The reproduction confirms a 0.1-second timeout returns only after ~0.6 seconds. I’ll add a lazily-thread-spawning shared executor at module scope, submit context-preserving work to it, and cancel the future on timeout. This bounds invocation latency, reuses workers for normal calls, and avoids accumulating queued timed-out work where cancellation is still possible.
- Assistant
The same reproduction now returns in ~0.10 seconds, while the backend thread continues independently as expected. Next I’ll run the focused synchronous and asynchronous middleware tests plus lint/type checks on the changed module. The async suite matters because the shared constant and module initialization are common even though its timeout mechanism is unchanged.
- Assistant
The package virtual environment has Python but no
pytestentry-point, so the combined command stopped before running checks. I’ll inspect available project tooling and use the repository’s configured package runner (or invoke installed modules directly) without altering dependencies or tests. - Assistant
uvis available and the local environment lacks only the test group. I’ll useuv run --group test, which follows the package configuration; first I’ll run the focused timeout test to get quick feedback, then the broader middleware files and static checks. - Assistant
The existing sync timeout test passes and now completes its assertion promptly. I’ll run both complete middleware test modules and static analysis. I’ll also explicitly verify a normal glob after a timed-out glob still succeeds, covering executor reuse while the first worker remains occupied.
- Assistant
All 139 relevant tests and both static tools pass. My additional reuse probe failed because it called
StateBackend.globoutside its required LangGraph runtime context—not because of the executor change. I’ll correct the probe to return the protocol’sGlobResultdirectly, then inspect the final diff and repository status for unintended generated changes. - Assistant
The corrected reuse probe passes: the timed-out call returns in ~0.102 seconds and a simultaneous subsequent glob succeeds on another shared worker. The diff is limited to production code, with no test modifications. I’ll run the filesystem middleware integration suite as the final behavioral check, then submit if it passes.
- Assistant
The integration suite is credential-dependent: 26 tests failed before exercising middleware behavior because no Anthropic API key is configured; its one offline test passed. This is unrelated to the change, while all 139 relevant unit tests passed.
Checklist:
- Reported error reproduced: Yes. Before the fix, a 0.1-second timeout around a 0.6-second glob returned after ~0.604 seconds.
- Fix confirmed: Yes. The same probe returned after ~0.102 seconds with the expected timeout message.
- Edge cases considered: Yes. Context variables remain copied per invocation; timed-out queued futures are cancelled; already-running thread work is not joined; a follow-up glob succeeds while a timed-out worker is still running; async behavior remains unchanged.
- Affected existing tests run: Yes. Both sync and async middleware unit modules passed (139 tests). Ruff lint/format and
typassed. Integration tests could not fully run without Anthropic credentials (26 credential failures, 1 offline pass), not due to this fix.
The final change replaces per-call context-managed executors with a shared executor, avoids blocking shutdown on timeout, and cancels timed-out futures where possible. I’ll now submit it.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.