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>
5.8 KiB
5.8 KiB
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 -3les 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é
quotaPatternsretravaillé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)
- Retiré :
- Veto 5xx :
serverErrorPatterns= ["api_error","overloaded_error","internal server error","api error: 5"]. Si l'un est présent, même si unquotaPatternmatche,isQuotaExhaustedretournefalse. Un 500/503 n'est pas un quota.
Ajouté
hasServerError()helper + tests exhaustifs :api_error_500_veto,overloaded_error_veto,internal_server_error_vetoreal_rate_limit_error_wins(sanity : vrai 429 passe toujours)
Tests effectués
- ✅ 14 sous-tests
TestIsQuotaExhaustedpassent - ✅
go test ./...complet OK - ✅ Service redémarré
Fichiers modifiés
internal/quota/monitor.gointernal/quota/monitor_test.go
[0.2.2] - 2026-04-15
Type: Patch — Confirmation requise pour les faux positifs (root cause)
Corrigé
- Cause racine du ping-pong : les erreurs HTTP 500 transitoires d'Anthropic
contiennent le texte "rate limit" dans leur payload (
{"type":"api_error",...}avec des traces mentionnant "rate limit"). Le monitor les confondait avec de vrais 429 quota hits. La v0.2.1 cassait la boucle via cooldown, mais un swap par salve de 500s pouvait encore tuer les sessions dédiées. - Le nouveau log forensique v0.2.1 a révélé exactement ça (snippet capturé :
API Error: 500 {"type":"error","error":{"type":"api_error",...}).
Ajouté
- Confirmation 2-polls pour les hits sans reset time : si
extractResetTimene trouve rien (= pas un vrai 429), le monitor marque l'étatsuspectedHitAtet attend le poll suivant. Le swap n'est émis que si la détection persiste. Un hit isolé (= erreur 500 transitoire) est absorbé sans swap. - Un vrai 429 (avec
resets in 45 minutesouresets at 8pm) continue à déclencher un swap instantané. Monitor.suspectedHitAt(not locked — only touched from poll goroutine).- 3 nouveaux tests :
TestPollTriggersSwitchOnTwoBlockedPoolWithReset,TestPollRequiresConfirmationWhenNoResetTime,TestPollSuspectedHitClearedOnRecovery.
Tests effectués
- ✅
go test ./...— full suite passe - ✅ Service redémarré, état consistant
Fichiers modifiés
internal/quota/monitor.gointernal/quota/monitor_test.go
[0.2.1] - 2026-04-15
Type: Patch — Fix boucle de swaps infinis (ping-pong)
Corrigé
- Boucle infinie de swaps : le monitor pouvait émettre des
SwapRequestedtoutes les 30s, créant un ping-pong entre comptes quand du texte de pane (anciens errors Anthropic 500 / TUI banners) matchaitquotaPatternsavecreset="". En prod, interval observé descendant jusqu'à 1 min. - Cause racine : aucun cooldown global entre swaps dans la boucle de
détection. La config
quota.reactivate_cooldown(5m) existait mais n'était utilisée que par le dispatcher, pas par le monitor.
Ajouté
state.QuotaState.LastSwapAt/LastSwapFrom/LastSwapTo+RecordSwap()+LastSwapInfo()pour tracker le dernier swap.monitor.poll()vérifiequota.reactivate_cooldownavant de déclencher un swap. Log explicite quand le cooldown bloque :[quota] swap cooldown active.- Log forensique détaillé lors d'un
SwapRequested: session déclencheuse, pattern matché, snippet du pane (120 chars). Ex :trigger_session="ccl-1-conformvault" pattern="rate limit" snippet="...". switcher.executeSwitchappellestate.RecordSwap()aprèsSetActiveAccount.
Tests effectués
- ✅
go build ./cmd/claude-failoverOK - ✅
go test ./internal/quota/... ./internal/state/... ./internal/switcher/...OK - ✅ Binaire installé dans
/usr/local/bin/claude-failover - ✅ Service redémarré — pas de swap intempestif depuis
Fichiers modifiés
internal/state/state.gointernal/quota/monitor.gointernal/switcher/account_switcher.go
[0.2.0] - 2026-04-14
Type: Minor — Implémentation des goroutines Phase 2
Ajouté
- Phase 2.1 :
internal/watcher— SessionWatcher (détection fin de tâche, timeout, signal file) - Phase 2.5 :
internal/notify— Notifier Telegram + Resend email - Phase 2.2 :
internal/dispatcher— Dispatcher fsnotify + launchAgent - Phase 2.3 :
internal/quota— QuotaMonitor (scraping pane tmux) - Phase 2.4 :
internal/switcher— AccountSwitcher (state machine flip symlink) - Phase 2.6 :
internal/janitor— Janitor (housekeeping agent-queue) - Phase 2.7 :
cmd/claude-failover/main.go— Intégration complète toutes goroutines - Nouveaux champs config :
watcher,dispatcher,janitor,notifications state: ForEachWorking, SetStalled, SetActiveAccount, ActiveAccountconfig.example.yaml: sections complètes pour tous les composantsscripts/claude-failover.service: unité systemd
Tests effectués
- ✅ go test ./... -race (toutes phases)
[0.1.0] - 2026-04-14
Type: Initial — Daemon skeleton
Ajouté
- Entry point, signal handling, config YAML loader
- tmux.Client interface + ExecClient
- State struct (JSON flush, sessions)
- HTTP /health + /status
- SessionLifecycleManager (reconcile 15s)