Skip to content

feat: make max_attempts a sliding window, not a lifetime cap#6

Merged
ShutovKS merged 1 commit into
devfrom
feat/reset-attempts
Jul 13, 2026
Merged

feat: make max_attempts a sliding window, not a lifetime cap#6
ShutovKS merged 1 commit into
devfrom
feat/reset-attempts

Conversation

@ShutovKS

Copy link
Copy Markdown
Owner

Проблема

state.attempts — пожизненный счётчик, сбрасывался только при ручном switch/reset. Несколько ранних блипов rate-limit → fallback отключён до конца длинной сессии.

Решение

Попытки fallback теперь метятся временем и считаются в скользящем окне attempts_window_ms (по умолчанию 10 минут). По прошествии окна старые попытки перестают учитываться в max_attempts.

  • Escape-hatch: attempts_window_ms: 0 возвращает прежний абсолютный лимит на всю сессию.
  • status дополнительно отдаёт windowAttempts и attemptsWindowMs.
  • Все места сброса (reset, ручной switch, recovery) чистят и таймстемпы через общий clearAttempts.

Тесты

  • Достигнут лимит в окне → заблокировано; после истечения окна → снова разрешён fallback.
  • attempts_window_ms: 0 → лимит остаётся абсолютным.

Юнит-тесты 49/49, typecheck чист.

🤖 Generated with Claude Code

state.attempts was a lifetime counter that only reset on manual switch or
reset, so a few early transient blips could disable fallback for the rest of
a long-running session.

Fallback attempts are now timestamped and counted within a sliding window
(`attempts_window_ms`, default 10 min). Once the window passes, older
attempts no longer count against `max_attempts`. Set `attempts_window_ms: 0`
to restore the previous absolute lifetime limit. status now also reports
`windowAttempts` and `attemptsWindowMs`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 13, 2026 23:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ShutovKS ShutovKS merged commit 3ad3e04 into dev Jul 13, 2026
1 check passed
@ShutovKS ShutovKS deleted the feat/reset-attempts branch July 13, 2026 23:48
@ShutovKS ShutovKS mentioned this pull request Jul 14, 2026
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.

2 participants