fix(quota): veto 5xx errors + tighten patterns to stop false-positive swaps

v0.2.2's 2-poll confirmation was insufficient because Anthropic 500/503
errors are printed into Claude Code's conversation transcript and stay
visible in every tmux capture until the user scrolls. A persistent
server error would confirm on the second poll and still trigger a swap.

Root cause: the pattern "rate limit" (bare substring) matched any 500
payload that happened to mention rate limits in its error text. Real
HTTP 429s from Anthropic are typed as "rate_limit_error" in the error
payload — and that's the signature we should actually key on.

- Remove "rate limit" from quotaPatterns (too generic — matches transcripts).
- Add "rate_limit_error" (Anthropic's typed 429 error) and "5-hour limit".
- Add serverErrorPatterns veto: "api_error", "overloaded_error",
  "internal server error", "api error: 5". When any is present in the
  pane, isQuotaExhausted returns false even if a quota pattern matched.
- 4 new subtests covering the veto paths + sanity that real 429s pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ubuntu 2026-04-15 19:26:00 +00:00
parent 7c5f8384fa
commit 62e98cb9e7
3 changed files with 102 additions and 23 deletions

View file

@ -1,4 +1,39 @@
# Version actuelle : 0.2.2
# Version actuelle : 0.2.3
## [0.2.3] - 2026-04-15
**Type:** Patch — Veto 5xx pour écarter les faux positifs persistants
### Corrigé
- **Les 500/503 d'Anthropic restent visibles dans l'historique de conversation
Claude Code** (pas juste en flash). Donc `tmux capture-pane -S -3` les voyait
à chaque poll, et la confirmation 2-polls v0.2.2 finissait par les confirmer
→ swap sur faux positif persistant.
- **Racine du faux positif** : le pattern `"rate limit"` (substring lâche)
matchait dans le contenu textuel d'un 500 rendu par Claude TUI.
### Modifié
- `quotaPatterns` retravaillés pour privilégier les signatures spécifiques :
- Retiré : `"rate limit"` (trop générique, matche les transcripts)
- Ajouté : `"rate_limit_error"` (type d'erreur Anthropic pour les vrais 429)
- Ajouté : `"5-hour limit"` (phrasing Claude Code)
- **Veto 5xx** : `serverErrorPatterns` = [`"api_error"`, `"overloaded_error"`,
`"internal server error"`, `"api error: 5"`]. Si l'un est présent, même si un
`quotaPattern` matche, `isQuotaExhausted` retourne `false`. Un 500/503
n'est pas un quota.
### Ajouté
- `hasServerError()` helper + tests exhaustifs :
- `api_error_500_veto`, `overloaded_error_veto`, `internal_server_error_veto`
- `real_rate_limit_error_wins` (sanity : vrai 429 passe toujours)
### Tests effectués
- ✅ 14 sous-tests `TestIsQuotaExhausted` passent
- ✅ `go test ./...` complet OK
- ✅ Service redémarré
### Fichiers modifiés
- `internal/quota/monitor.go`
- `internal/quota/monitor_test.go`
## [0.2.2] - 2026-04-15
**Type:** Patch — Confirmation requise pour les faux positifs (root cause)