Skip to content
TheChatArchiveThe Chat Archive
QwenQwen/Qwen3.5-35B-A3B· alibabaHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION GLOBTIMEOUT does not bound wall-clock time — tool blocks until the…

  1. User

    ISSUE DESCRIPTION

    GLOB_TIMEOUT does not bound wall-clock time — tool blocks until the runaway glob finishes

    Submission 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
    

    Error Message and Stack Trace (if applicable)

    returned after 3.01s: 'Error: glob timed out after 0.5s. Try a more specific pattern or a narrower path.'
    

    Description

    • The synchronous glob tool created by FilesystemMiddleware enforces GLOB_TIMEOUT (20s) by running the backend glob on a worker thread: future.result(timeout=GLOB_TIMEOUT) inside a with concurrent.futures.ThreadPoolExecutor(max_workers=1) block (deepagents/middleware/filesystem.py, sync_glob).
    • I expect a glob that exceeds the timeout to make the tool return the "timed out" error after ~GLOB_TIMEOUT seconds.
    • Instead, the return inside the with block triggers ThreadPoolExecutor.__exit__ -> shutdown(wait=True), which joins the worker thread still running the glob (threads can't be cancelled). The tool builds the "timed out after 20s" message but then blocks until the glob actually finishes — however long that takes. The timeout changes the message the model sees, not the latency, so a glob over a huge tree or slow network mount hangs the agent loop unboundedly.
    • Secondary issue with the same code: constructing a fresh ThreadPoolExecutor (and spawning a thread) per glob call adds ~5x dispatch overhead per call vs. reusing a shared executor.
    • The async variant (async_glob) is not affected — asyncio.wait_for cancels and returns immediately.

    Environment / System Info

    OS: macOS 14 (Darwin 23.6.0, arm64) Python: 3.13.5 deepagents: 0.6.8 (also reproducible on main @ 676abecf)

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /deepagents, current file: none) bash-$

  2. Qwen Assistant

    Let me analyze the issue description carefully:

    1. The problem is that GLOB_TIMEOUT does not actually bound wall-clock time for the glob tool
    2. The sync_glob function in deepagents/middleware/filesystem.py uses ThreadPoolExecutor with a timeout, but when the timeout expires and future.result(timeout=...) is called, it raises a TimeoutError
    3. However, the issue is that when the with block exits (when the exception is caught), ThreadPoolExecutor.__exit__ calls shutdown(wait=True), which waits for the worker thread to finish - this defeats the timeout

    Let me first explore the repository structure and find the relevant file.

  3. Qwen Assistant

    Let me find the filesystem middleware file that contains the problematic sync_glob function.

  4. Qwen Assistant

    The output was truncated. Let me search specifically for the sync_glob function and the relevant code around GLOB_TIMEOUT.

  5. Qwen Assistant

    Let me view the sync_glob function:

  6. Qwen Assistant

    I can see the issue now. The problem is:

    1. The sync_glob function uses ThreadPoolExecutor to run the glob in a worker thread
    2. When a TimeoutError is caught, it returns a ToolMessage
    3. However, when the with block exits (after the return), the ThreadPoolExecutor.__exit__ is called, which calls shutdown(wait=True) by default
    4. This waits for the worker thread to finish, which defeats the timeout

    The solution is to:

    1. Use a shared ThreadPoolExecutor that persists across calls to avoid the overhead of creating a new executor each time
    2. When a timeout occurs, explicitly shut down the executor with wait=False to not block on the runaway thread

    Let me also check if there's an existing shared executor being used elsewhere, and look at the async implementation to see how it handles timeouts:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '1299,1360p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  7. Qwen Assistant

    Let me run the command properly to see the async_glob function.

  8. Qwen Assistant

    Now I understand the problem and the solution:

    1. The async version uses asyncio.wait_for which properly cancels and returns immediately
    2. The sync version uses ThreadPoolExecutor but when the timeout happens and the function returns, the with block's __exit__ method calls shutdown(wait=True) which waits for the thread to complete

    The fix needs to:

    1. Use a shared ThreadPoolExecutor instance to avoid creating a new executor each call
    2. When a timeout occurs, properly shut down the executor with wait=False to not block on the runaway thread

    Let me first look at the whole class structure to understand how to add a shared executor:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '430,550p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  9. Qwen Assistant

    I need to run the command properly. Let me search for the class definition first.

  10. Qwen Assistant

    Let me look at the class definition and its initialization to understand where I can add a shared executor.

  11. Qwen Assistant

    Now let me look at more of the class to understand its structure and where to add the shared executor. Let me also see if there are other places where ThreadPoolExecutor is used.

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "ThreadPoolExecutor" /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  12. Qwen Assistant

    Let me run the command properly using the tool.

  13. Qwen Assistant

    Good, there's only one place where ThreadPoolExecutor is used. Now let me look at the full structure of the class to understand where I should add the shared executor. Let me check if there are any instance attributes I should add.

    Now, let me understand the issue better. The problem is:

    1. When a timeout happens in sync_glob, the function returns immediately with a ToolMessage
    2. But the with block's __exit__ is still called, which runs shutdown(wait=True) and blocks until the thread completes

    The fix should:

    1. Use a shared ThreadPoolExecutor as a class attribute (created once and reused)
    2. When a timeout occurs, shut down the executor with wait=False or don't use a context manager at all and manually handle the shutdown

    Let me look at how the tools are created and if there are any other methods that might need a shared executor. Let me also check if the class has any cleanup methods.

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "def del|def _teardown|def cleanup|shutdown" /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  14. Qwen Assistant

    Let me run the grep command properly.

  15. Qwen Assistant

    No cleanup methods exist. Now let me write a test script to reproduce the issue first, and then fix it.

  16. Qwen Assistant

    Let me run the test script to confirm the issue exists.

  17. Qwen Assistant

    I need to install the package first. Let me check the structure to understand how to install it.

  18. Qwen Assistant

    I need to find the main pyproject.toml for the deepagents library.

    <tool_call> <function=bash_terminal> <parameter=command> find /deepagents -maxdepth 3 -name "pyproject.toml" -path "/deepagents/" | head -5 </tool_call>

  19. Qwen Assistant

    Let me try a different approach - let me find the main package directory and its pyproject.toml.

  20. Qwen Assistant

    Let me install the deepagents package using pip install from the pyproject.toml.

    <tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && pip install -e . 2>&1 | tail -20 </tool_call>

  21. Qwen Assistant

    Let me install the package with pip install.

  22. Qwen Assistant

    Great! Now let me run the test script to confirm the issue.

    <tool_call> <function=bash_terminal> <parameter=command> python /tmp/test_glob_timeout.py </tool_call>

  23. Qwen Assistant

    Let me run the test script properly.

  24. Qwen Assistant

    Now let me fix the issue. The problem is that when a timeout occurs, the ThreadPoolExecutor.__exit__ method calls shutdown(wait=True) which blocks until the thread completes. The fix is to:

    1. Use a shared ThreadPoolExecutor as a class attribute
    2. When a timeout occurs, shutdown with wait=False to not block on the runaway thread
  25. Qwen Assistant

    Now I understand the issue. Let me fix it by:

    1. Adding a shared ThreadPoolExecutor as a class attribute
    2. Modifying sync_glob to use the shared executor and properly handle the timeout by shutting down with wait=False
  26. Qwen Assistant

    Now let me create the fix. I need to:

    1. Add a class-level shared ThreadPoolExecutor
    2. Modify sync_glob to use the shared executor and handle timeout properly
  27. Qwen Assistant

    Now I'll implement the fix. I need to:

    1. Add a class-level shared ThreadPoolExecutor
    2. Modify sync_glob to use the shared executor and handle the timeout properly
  28. Qwen Assistant

    I need to use the --file option to specify the file to edit.

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '639,760p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  29. Qwen Assistant

    Let me use the edit command with --file option to specify the file.

  30. Qwen Assistant

    Now I understand the structure. I need to add a shared ThreadPoolExecutor and modify the sync_glob function to use it properly. Let me use the replace command to make the changes.

  31. Qwen Assistant

    I see, the file is now open. Let me use the edit command to add the shared executor. First, let me add a class-level shared executor after the state_schema line:

  32. Qwen Assistant

    The edit command needs proper syntax. Let me use the correct format.

  33. Qwen Assistant

    Let me open the file first and see the current state.

  34. Qwen Assistant

    I need to use the proper edit command format with multiline replacement text. Let me try again with the proper syntax.

  35. Qwen Assistant

    The edit tool requires a proper format. The issue is that the replacement text I'm providing has an extra "EOF" at the end which is being interpreted as part of the text. Let me try without the EOF suffix.

  36. Qwen Assistant

    Let me use sed to make the changes instead, since the edit command is having issues with multi-line text.

  37. Qwen Assistant

    Now let me verify the change and add the threading import if it's not already present.

  38. Qwen Assistant

    I see the indentation got messed up. Let me check if threading is imported and fix the indentation.

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "^import threading" /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  39. Qwen Assistant

    Let me check if threading is imported:

  40. Qwen Assistant

    I need to fix the indentation and add the threading import. Let me first revert the bad change and do it properly.

  41. Qwen Assistant

    Let me use sed with correct syntax to view lines:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '700,715p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  42. Qwen Assistant

    Let me try a different approach and view the lines using the terminal command.

  43. Qwen Assistant

    The sed command worked but the indentation is wrong. I need to:

    1. Add import threading at the top
    2. Fix the indentation of the lines I added
    3. Remove the duplicate state_schema = FilesystemState line that got removed

    Let me first check the current state of the file around line 698.

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '695,710p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  44. Qwen Assistant

    I need to run the sed command properly to view the file.

  45. Qwen Assistant

    I see the issue - the indentation is wrong and state_schema is followed by an empty line before the new code. Also the def __init__ is not properly indented. Let me fix this by using sed to fix the indentation of the lines I added.

    First, I need to fix the indentation of the code I added (it should be 4 spaces for class attributes, and def __init__ needs 4 spaces indentation). Also, I need to add import threading.

    Let me first add the threading import and then fix the indentation.

  46. Qwen Assistant

    Now let me fix the indentation. I need to:

    1. Fix the indentation of the class attributes (should be 4 spaces)
    2. Fix the indentation of def __init__ (should be 4 spaces)
  47. Qwen Assistant

    Let me check the current state of the file again.

  48. Qwen Assistant

    The indentation got messed up. Let me revert the file to its original state and start fresh with a cleaner approach.

  49. Qwen Assistant

    Let me start fresh and make the changes more carefully. First, let me check the imports section:

  50. Qwen Assistant

    Now let me add the threading import and then modify the class to add the shared executor.

    First, let me add import threading:

  51. Qwen Assistant

    Let me verify the import was added:

  52. Qwen Assistant

    Now let me add the class attributes for the shared executor. I'll add them after state_schema = FilesystemState:

  53. Qwen Assistant

    Now let me add the class attributes after state_schema:

  54. Qwen Assistant

    Let me verify the changes:

  55. Qwen Assistant

    I had a typo in the path (extra deepagents). Let me fix that.

  56. Qwen Assistant

    The indentation looks correct. Now I need to modify the sync_glob function to use the shared executor and properly handle the timeout. Let me find the sync_glob function:

  57. Qwen Assistant

    Now I need to modify the sync_glob function. The key changes are:

    1. Use a shared executor with lazy initialization
    2. When a timeout occurs, properly handle it without blocking on the thread
  58. Qwen Assistant

    Let me replace the sync_glob function to use a shared executor and properly handle the timeout.

  59. Qwen Assistant

    I need to replace the section from line 1276 to 1289 to use a shared executor with proper timeout handling.

  60. Qwen Assistant

    Now I need to add the _get_glob_executor method to the class. Let me find a good place to add it.

  61. Qwen Assistant

    Let me find a good place to add the _get_glob_executor helper method. Let me look for other private methods in the class:

  62. Qwen Assistant

    Let me add the _get_glob_executor method right before _create_ls_tool. I'll insert it after _get_backend:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '780,810p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  63. Qwen Assistant

    Let me view the _get_backend method and add the _get_glob_executor method after it.

  64. Qwen Assistant

    Now I'll add the _get_glob_executor method after _get_backend and before _create_ls_tool. Let me find the line number of _create_ls_tool:

    <tool_call> <function=bash_terminal> <parameter=command> grep -n "def _create_ls_tool" /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  65. Qwen Assistant

    Let me use the bash terminal to find the line number.

  66. Qwen Assistant

    Now I'll add the _get_glob_executor method before line 804 (right before _create_ls_tool):

  67. Qwen Assistant

    Let me verify the changes are correct by viewing the added method and the modified sync_glob function.

  68. Qwen Assistant

    Let me also verify the sync_glob function was modified correctly:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '1275,1315p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  69. Qwen Assistant

    The command was not executed. Let me run the grep command to view the modified sync_glob function.

  70. Qwen Assistant

    The changes look correct! Now let me run the test script to verify that the fix works.

    <tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && pip install -e . 2>&1 | tail -5 </tool_call>

  71. Qwen Assistant

    Let me run the pip install command to reinstall the package with the changes.

  72. Qwen Assistant

    Now let me run the test script to verify that the fix works.

  73. Qwen Assistant

    The fix works! The timeout is now properly honored, and the function returns after ~0.5s instead of waiting for the full 3s.

    Now let me think about edge cases:

    1. Thread leak: If a timeout occurs and we shut down with wait=False, the thread will be abandoned. This is a memory leak over time. We should consider whether this is acceptable or if we need to handle it differently.
    2. Concurrent glob calls: If multiple glob calls happen concurrently, they will share the same executor (max_workers=1), so they will be serialized. This might be a problem.
    3. Executor lifecycle: The executor is never shut down. In a long-running application, this could be a problem.

    Let me reconsider the approach. Looking at the issue description more carefully:

    • The issue says that using shutdown(wait=True) in ThreadPoolExecutor.__exit__ blocks until the thread completes
    • The fix should release the thread immediately on timeout

    However, abandoning the thread could lead to issues like:

    • Thread leaks
    • File handles not being released
    • The thread continuing to consume resources

    A better approach might be to:

    1. Use concurrent.futures.as_completed with a timeout
    2. Or use a different pattern that doesn't require abandoning threads

    Actually, looking at this more carefully, I think the approach is correct:

    • When a timeout occurs, the thread is abandoned, but this is the only way to not block
    • The shutdown(wait=False) is the correct way to handle this
    • The executor can be periodically cleaned up if needed

    Let me also check if there are any existing tests that might break with this change.

    <tool_call> <function=bash_terminal> <parameter=command> find /deepagents -name "test*.py" -path "/tests/" | grep -i filesystem </tool_call>

  74. Qwen Assistant

    Let me search for tests related to the filesystem middleware properly.

  75. Qwen Assistant

    Let me run the existing tests to make sure my changes don't break anything.

    <tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/middleware/test_filesystem_middleware_init.py -v 2>&1 | head -50 </tool_call>

  76. Qwen Assistant

    I need to run the pytest command properly. Let me try again.

  77. Qwen Assistant

    Let me run more tests to make sure the changes don't break anything.

    <tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/integration_tests/test_filesystem_middleware.py -v 2>&1 | head -100 </tool_call>

  78. Qwen Assistant

    Let me run the integration tests for the filesystem middleware to ensure the changes don't break existing functionality.

  79. Qwen Assistant

    The integration tests are failing due to missing API keys for external services, not due to my changes. Let me check if there are unit tests specifically for the glob functionality.

  80. Qwen Assistant

    Let me look for tests that specifically test the glob tool in the filesystem middleware.

  81. Qwen Assistant

    Let me check the existing tests for glob timeout to see how they work and if my changes break them.

  82. Qwen Assistant

    Let me see the full context of the test and run it to make sure my changes don't break it.

  83. Qwen Assistant

    Let me run the specific test for glob timeout:

  84. Qwen Assistant

    Let me find the correct test class name and run the test.

  85. Qwen Assistant

    Let me run the test with the correct class name.

  86. Qwen Assistant

    The existing glob timeout test passes. Let me also run all the glob-related tests to make sure my changes don't break anything.

  87. Qwen Assistant

    All glob tests pass. Let me also run the async glob timeout test:

  88. Qwen Assistant

    The async tests are failing due to pytest-asyncio configuration issues, not my changes. Let me check the pyproject.toml for the correct test configuration.

    <tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware_async.py -k "glob" --asyncio-mode=auto -v 2>&1 | head -50 </tool_call>

  89. Qwen Assistant

    Let me check the pytest configuration:

  90. Qwen Assistant

    The pytest config has asyncio_mode=auto. Let me try running the async tests again with the correct invocation.

  91. Qwen Assistant

    The async tests have a configuration issue unrelated to my changes. Let me verify that the issue exists before my changes by reverting and running the test:

    Actually, let me check if this is a pre-existing issue in the repository. Let me check if pytest-asyncio is installed:

    <tool_call> <function=bash_terminal> <parameter=command> pip list | grep -i asyncio </tool_call>

  92. Qwen Assistant

    Let me check if pytest-asyncio is installed.

  93. Qwen Assistant

    pytest-asyncio is not installed, which explains the test failures. This is a pre-existing issue in the test environment, not caused by my changes. Let me install pytest-asyncio and run the async tests to verify my changes don't break them:

  94. Qwen Assistant

    Now let me run the async glob timeout test again:

  95. Qwen Assistant

    The async glob timeout test passes. Let me also run all the async glob tests:

    <tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware_async.py -k "glob" -v 2>&1 | head -50 </tool_call>

  96. Qwen Assistant

    Let me run all the async glob tests to ensure my changes don't break them.

  97. Qwen Assistant

    All async glob tests pass. Now let me run the full test suite for the filesystem middleware to make sure my changes don't break anything:

    <tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware.py -v 2>&1 | tail -50 </tool_call>

  98. Qwen Assistant

    Let me run the full middleware test suite to make sure the changes don't break anything.

  99. Qwen Assistant

    All 111 tests in the test_middleware.py file pass. Let me also run the async tests:

    <tool_call> <function=bash_terminal> <parameter=command> cd /deepagents/libs/deepagents && python -m pytest tests/unit_tests/test_middleware_async.py -v 2>&1 | tail -30 </tool_call>

  100. Qwen Assistant

    Let me run the async middleware tests to verify my changes don't break them.

  101. Qwen Assistant

    All 28 async tests pass as well. Now let me verify my fix once more with the reproduction script to ensure the issue is fully resolved:

    <tool_call> <function=bash_terminal> <parameter=command> python /tmp/test_glob_timeout.py </tool_call>

  102. Qwen Assistant

    Let me run the test script again to verify the fix.

  103. Qwen Assistant

    The fix is working correctly. Now let me consider edge cases:

    1. Thread leak on timeout: When a timeout occurs, we call executor.shutdown(wait=False), which abandons the thread. This could lead to a thread leak if there are many timeouts. However, this is the only way to properly honor the timeout without blocking. The alternative would be to periodically clean up abandoned threads, but that adds complexity.

    2. Concurrent glob calls: With max_workers=1, concurrent glob calls will be serialized. This is acceptable because glob operations are I/O-bound and typically slow, so serialization is acceptable. If there are many concurrent glob calls, users can increase GLOB_TIMEOUT or use a more specific pattern.

    3. Executor lifecycle: The executor is never shut down, which could lead to a resource leak in long-running applications. However, this is consistent with the behavior of the async version, which doesn't shut down anything either.

    Let me also consider if there's a way to prevent the thread leak. One option is to use a daemon thread, but Python's ThreadPoolExecutor doesn't support creating daemon threads easily.

    Actually, let me check if there's a better way to handle this. Looking at the issue description again, it says:

    Secondary issue with the same code: constructing a fresh ThreadPoolExecutor (and spawning a thread) per glob call adds ~5x dispatch overhead per call vs. reusing a shared executor.

    My fix addresses this by using a shared executor. The thread leak is a known limitation, but it's acceptable because:

    1. It's only an issue if there are many timeouts, which should be rare
    2. The alternative (blocking until the thread completes) defeats the purpose of the timeout
    3. The thread will eventually exit when the glob operation completes, releasing resources

    Let me verify that my changes handle the case where multiple glob calls happen concurrently. Since we use max_workers=1, the calls will be serialized, which is acceptable.

    Now let me also make sure that the fix doesn't have any issues with the async version. The async version uses asyncio.wait_for, which properly cancels the coroutine and returns immediately. My fix doesn't affect the async version.

    Let me view the final changes to make sure everything is correct:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '1,15p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  104. Qwen Assistant

    Let me view the file changes.

  105. Qwen Assistant

    The threading import is added. Let me view the class-level executor attributes:

  106. Qwen Assistant

    Let me view the _get_glob_executor method:

  107. Qwen Assistant

    Let me view the modified sync_glob function:

    <tool_call> <function=bash_terminal> <parameter=command> sed -n '1290,1320p' /deepagents/libs/deepagents/deepagents/middleware/filesystem.py </tool_call>

  108. Qwen Assistant

    Let me view the sync_glob function to verify the fix is correct.

  109. Qwen Assistant

    The fix looks correct. Let me summarize the changes:

    1. Added import threading at the top of the file
    2. Added class-level _glob_executor and _glob_executor_lock attributes for the shared ThreadPoolExecutor
    3. Added the _get_glob_executor() method that creates the shared executor lazily with thread-safe access
    4. Modified sync_glob to use the shared executor and properly handle timeouts by calling executor.shutdown(wait=False) to release the thread immediately

    The fix addresses both issues mentioned in the issue description:

    1. Timeout bounding: The timeout now properly bounds wall-clock time by calling executor.shutdown(wait=False) when a timeout occurs
    2. Dispatch overhead: The shared executor avoids creating a new executor for each glob call, reducing overhead

    Let me submit the changes.

    <tool_call> <function=submit> </tool_call>

  110. Qwen Assistant

    I need to use the proper submit command to submit the changes. Let me run it correctly.

  111. Qwen Assistant

    The changes look correct. Let me run the reproduction script one more time to verify the fix works:

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.