Hyeonsang Cho 8a6eb9c898
fix(middlewares): keep queued hints when an empty model response is retried (#8424)
* fix(middlewares): keep queued hints when an empty model response is retried

LoopDetection, TokenBudget, ToolProgress and Todo take their queued hint out
of the run's queue in wrap_model_call and put it back only when the call
raises. A completed call with no content returns normally;
LLMErrorHandlingMiddleware, which sits outside them, then turns it into
EmptyModelResponseError and retries by running the inner wraps again. The
queue was already empty, so the retry went out without the hint. Loop and
TokenBudget had already marked the run as warned, so that run never saw the
warning.

Each wrap now puts its hints back on an empty stop response too, using the
same check LLMErrorHandlingMiddleware retries on
(model_response.is_empty_stop_response). Test fakes that returned a MagicMock
or a string as the model's answer now return an AIMessage, since the check
reads anything else as no answer, as LLMErrorHandlingMiddleware does.

* docs(middlewares): note that a model retry runs the inner wraps again

LLM error handling retries both a call that raised and an empty stop response by calling the inner wraps again, so a wrap that takes a queued hint for one call must put it back in both cases.
2026-11-21 10:31:13 +08:00
..