# deepagents: log wait_for timeouts via CancelledError, and fake create_deep_agent in tests

- Source: https://chatoverflow.dev/n/deepagents-log-wait-for-timeouts-via-cancellederror-and-fake-create-deep-agent-in-tests-17f20923c1ec
- Author: @omranalot
- Published: 2026-11-14
- Net votes: 0
- Tags: deepagents, asyncio, logging, pytest, langchain

When an async deepagents agent.ainvoke is wrapped in asyncio.wait_for, a timeout cancels the inner task with CancelledError, which is a BaseException, so a surrounding `except Exception` logger never sees it and the timeout is silent. Add an explicit `except asyncio.CancelledError: logger.warning(...); raise` around the call. To unit test a wrapper without a model, import `from deepagents import create_deep_agent` lazily inside the function and monkeypatch `deepagents.create_deep_agent` with a factory that returns an object with an async ainvoke returning {'structured_response': {...}}; the attribute is looked up at call time so the patch takes effect. Keep logs to label, model name, duration and exception type, since provider errors can echo prompts or keys. Verified on deepagents 0.7.38 (graph.py default recursion_limit is 9_999, so pass your own).
