Skip to content

Harden OpenRouter completion handling - #283

Merged
astrovm merged 3 commits into
mainfrom
codex/fix-openrouter-finish-reason
Jul 28, 2026
Merged

Harden OpenRouter completion handling#283
astrovm merged 3 commits into
mainfrom
codex/fix-openrouter-finish-reason

Conversation

@astrovm

@astrovm astrovm commented Jul 28, 2026

Copy link
Copy Markdown
Owner

What changed

  • Retry empty finish_reason=None responses and transient in-band OpenRouter errors with bounded exponential backoff.
  • Avoid retrying permanent errors or responses that already contain content, tool calls, token usage, web-search usage, or provider cost.
  • Count every provider request made during retries.
  • Add response/request/provider diagnostics to exhausted-retry admin reports.
  • Use an 8,192-token output budget for DeepSeek V4 Flash reasoning requests while keeping the shared default at 1,024 tokens.
  • Translate operational admin-report labels to English.

Why

OpenRouter occasionally returned an empty completion with finish_reason=None during web-search/tool flows. The bot treated it as terminal, emitted an admin alert, and fell back without retrying. Separately, DeepSeek reasoning could consume the previous 1,024-token output budget before producing a useful visible answer.

Impact

Transient empty provider responses now recover automatically without retrying permanent or billable failures. DeepSeek gets enough room for reasoning, other models retain the existing output ceiling, retry accounting is accurate, and VPS admin reports are consistently in English.

Validation

  • uv run --locked ruff check api/ tests/
  • uv run --locked python -m pytest -q — 866 passed

@astrovm
astrovm marked this pull request as ready for review July 28, 2026 04:06
@astrovm
astrovm merged commit 20fca71 into main Jul 28, 2026
5 checks passed
@astrovm
astrovm deleted the codex/fix-openrouter-finish-reason branch July 28, 2026 04:09
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