Skip to content

Configurable retries; retry empty answers instead of ending the turn silently - #320

Merged
stippi merged 5 commits into
mainfrom
feature/retry-policy
Nov 17, 2026
Merged

stippi merged 5 commits into
mainfrom
feature/retry-policy

Conversation

@stippi

@stippi stippi commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Problem

Users came back to sessions that had stopped with the Resume button showing, but no error and no visible retries.

One cause: when the model answered with no content at all, the agent loop treated that as the end of the turn. Nothing was recorded, so the history still ended with the user's message or the tool results, and the session sat idle and resumable.

How rate limits are handled also couldn't be configured: there were always 3 retries, and the backoff had no upper bound.

Change

  • One retry policy (llm::RetryPolicy, <config_dir>/retry.json, Settings → General → Failed requests): retry until the request succeeds, or at most N times, plus the longest wait between retries. This cap also applies when the provider asks for a longer wait. Defaults: 5 retries, at most 300 s.
  • LLM clients (Anthropic, OpenAI, Responses, Vertex, and the wrappers such as AI Core) use the policy for rate limits and transient network or server errors. The factory hands it over through LLMProvider::set_retry_policy; the default for that method is a no-op, which Ollama and the WebSocket client keep.
  • Agent loop: an empty answer is now an error (agent_core::types::EmptyResponse). DefaultRecovery retries it under the policy, together with broken streams and, new, stalled streams. Once the retries run out, the session fails and shows the error.
  • While retrying, the session shows the reason and attempt/max, or only attempt when there is no limit (max_attempts: Option<u32>).
  • Eight core tests used an empty answer to mean "turn done". They now get a text answer.
  • docs/retry-policy.md and a section in AGENTS.md.

Not tried in the app

Not tried in the app yet. cargo test, clippy and fmt all pass.

…ing the turn

One RetryPolicy (llm::retry, retry.json, Settings → General) bounds the
retries of a failed LLM request — at most N or until it succeeds — and the
wait between them. The clients use it for rate limits and transient errors,
the agent loop for broken or stalled streams.

An answer without content ended the turn as if the model had answered:
nothing was recorded, the history still ended in the user's message, and the
session showed Resume without an error. The agent loop now treats it as a
failed request (EmptyResponse) and retries it under the same policy.
The agent loop recognised errors by their text and retried overloaded and
network errors the client had already given up on, so N retries became
(N+1)² − 1 requests. A client now marks such an error RetriesExhausted and
the agent loop leaves it alone. A maximum wait of 0 counts as one second, so
retrying forever cannot send requests back to back.
A model that answers a prompt empty may do so every time, so unlimited
retries could send paid requests until someone stops the session. The
policy is now just the number of retries and the longest wait.
None of the zip code paths is reached: nothing extracts to the file system,
reads archives as a stream, decrypts entries or builds legacy-zip. chrono has
no maintained release to move to. Also update the yanked async-executor.
@stippi
stippi merged commit e7995e5 into main Nov 17, 2026
9 checks passed
@stippi
stippi deleted the feature/retry-policy branch November 17, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant