{"record":{"id":"e347cfb1c044aa4c","repo":"langchain-ai/deepagents","slug":"agent-invocation-retry-loop-exited-unexpectedly","errorCode":null,"errorMessage":"agent invocation retry loop exited unexpectedly","messagePattern":"agent invocation retry loop exited unexpectedly","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/runtime.py","lineNumber":414,"sourceCode":"                return await invoke(payload, config=config)\n            except asyncio.CancelledError:\n                raise\n            except Exception as exc:\n                if not _is_retryable(exc) or attempt + 1 >= self.max_retries:\n                    raise\n                last_exc = exc\n                backoff = min(2**attempt, 10)\n                logger.warning(\n                    \"Retryable agent error in conversation %s; retrying in %ds: %s\",\n                    conversation_id,\n                    backoff,\n                    exc,\n                )\n                await asyncio.sleep(backoff)\n        if last_exc is not None:\n            raise last_exc\n        msg = \"agent invocation retry loop exited unexpectedly\"\n        raise RuntimeError(msg)\n\n    def _graph_invoke(self) -> Callable[..., Awaitable[object]]:\n        ainvoke = getattr(self._graph, \"ainvoke\", None)\n        if not callable(ainvoke):\n            msg = \"Deep Agents graph does not expose async invocation\"\n            raise TypeError(msg)\n        return cast(\"Callable[..., Awaitable[object]]\", ainvoke)\n\n    async def _invoke_until_unblocked(\n        self,\n        content: ModelContent,\n        request: AgentRequest,\n    ) -> object:\n        state = await self._invoke_with_retries(content, request.conversation_id)\n        for _ in range(DEFAULT_MAX_APPROVAL_ROUNDS):\n            interrupts = _interrupts_from_state(state)\n            if not interrupts:\n                return state","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/runtime.py#L396-L432","documentation":"_invoke_payload_with_retries loops retrying graph invocations and normally exits either by returning a result or by re-raising the last captured exception (last_exc). This RuntimeError is raised only if the loop ends with no result and no captured exception, which indicates an internal invariant violation (e.g. a break path that neither succeeded nor recorded an exception).","triggerScenarios":"An internal edge case in the retry loop: the loop terminates without a successful payload and without last_exc being set. Not reachable through normal configuration.","commonSituations":"Effectively a bug guard; encountered after a library upgrade or custom subclassing that overrides retry hooks, or a corrupted retry configuration that skips the attempt body.","solutions":["Report it to the library maintainers with a traceback and the runtime configuration","Check for subclasses/monkeypatches of _invoke_payload_with_retries or its retry hooks that break the loop invariant","Pin/upgrade to a version of the library where the retry loop is fixed"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    reply = await runtime.invoke(request)\nexcept RuntimeError as exc:\n    if \"retry loop exited unexpectedly\" in str(exc):\n        log.exception(\"runtime invariant violated; retrying once with fresh runtime\")\n        runtime = rebuild_runtime()\n        await runtime.start()\n        reply = await runtime.invoke(request)\n    else:\n        raise","preventionTips":["Treat this as a bug: capture full tracebacks and report to maintainers","Avoid monkeypatching or subclassing the retry internals","Pin library versions and re-verify after upgrades"],"tags":["runtime","retry","internal-invariant"],"backgroundTag":"retry-loop-exhausted","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}