#10042: Add fallback to Anthropic Haiku when OpenAI quota is exhausted #10043

Merged
HAL9000 merged 2 commits from feature/10042-openai-quota-fallback into master 2026-04-17 04:11:42 +00:00

2 Commits

Author SHA1 Message Date
HAL9000 51472c0b37 debug: upgrade logging levels for fallback diagnostics
CI / push-validation (pull_request) Successful in 20s
CI / helm (pull_request) Successful in 24s
CI / lint (pull_request) Successful in 27s
CI / security (pull_request) Successful in 1m0s
CI / build (pull_request) Successful in 3m21s
CI / typecheck (pull_request) Successful in 3m59s
CI / quality (pull_request) Successful in 4m5s
CI / e2e_tests (pull_request) Successful in 4m52s
CI / integration_tests (pull_request) Successful in 9m51s
CI / unit_tests (pull_request) Successful in 10m57s
CI / docker (pull_request) Successful in 1m31s
CI / coverage (pull_request) Successful in 10m57s
CI / status-check (pull_request) Successful in 2s
CI / benchmark-regression (push) Failing after 0s
CI / benchmark-publish (push) Failing after 0s
CI / build (push) Successful in 17s
CI / push-validation (push) Successful in 17s
CI / quality (push) Successful in 32s
CI / helm (push) Successful in 35s
CI / security (push) Successful in 58s
CI / unit_tests (push) Successful in 3m13s
CI / lint (push) Successful in 3m17s
CI / typecheck (push) Successful in 3m56s
CI / integration_tests (push) Successful in 4m15s
CI / docker (push) Successful in 1m41s
CI / e2e_tests (push) Successful in 7m30s
CI / coverage (push) Successful in 14m4s
CI / status-check (push) Successful in 2s
Change fallback LLM creation and invocation logs from DEBUG to WARNING level
so they appear in Robot Framework test output. Also enhance error message to
clearly show which provider failed and why.

This change makes it possible to diagnose why the fallback is not working
by seeing the actual logs in test output instead of having them filtered
as DEBUG level messages.

Logs now include:
- 'Creating fallback LLM instance: anthropic/claude-sonnet-4-20250514'
- 'Fallback LLM created, attempting invocation'
- 'Using cached fallback LLM, attempting invocation'
- 'FALLBACK PROVIDER FAILED: anthropic/claude-sonnet-4-20250514 returned error: [error details]'

This will help diagnose why E2E tests fail with 'both providers exhausted'
when Anthropic should have available credits.
2026-04-17 03:56:35 +00:00
CoreRasurae f5712787e0 feat: add fallback to Anthropic Sonnet when OpenAI quota is exhausted
Implements graceful degradation for E2E robot integration tests that hit OpenAI 429 quota limit errors.

Changes:
- Add _is_quota_error() helper to detect quota-specific API errors (429, insufficient_quota, rate_limit)
- Modify _execute_with_llm() in StrategyActor to catch quota errors and attempt fallback to Anthropic Haiku
- Configure fallback provider as 'anthropic/claude-sonnet-4-20250514'
- Add comprehensive logging for quota error detection and provider fallback
- Add E2E test scenarios for quota fallback verification

When quota errors occur on both OpenAI and Anthropic fallback, tests
now fail with a clear message explaining that the test outcome cannot
be verified when no LLM provider is available.
 This ensures CI/CD pipelines properly track which tests could not be
executed due to quota constraints, rather than silently skipping them
and creating false confidence in test coverage.

This ensures CI/CD pipelines can complete E2E tests even when the primary provider (OpenAI) hits quota limits,
improving pipeline reliability and reducing false negatives caused by provider-specific issues.

1. **Cache fallback_llm instance** - Instead of recreating the fallback LLM
   every time a quota error occurs, cache it as an instance variable
   (self._fallback_llm). This avoids unnecessary re-initialization overhead.

2. **Implement quota recovery logic** - Add intelligent recovery behavior:
   - Track last quota error timestamp (self._last_quota_error_time)
   - Track fallback mode state (self._using_fallback)
   - Once quota error detected, switch to fallback provider
   - Only attempt to recover primary provider every 5 minutes (_QUOTA_RECOVERY_INTERVAL)
   - This avoids hammering primary provider with repeated quota errors

3. **Add detailed recovery logging** - Log quota fallback transitions and
   recovery attempts to improve observability and debugging.

Benefits:
- Reduced latency: No redundant primary provider calls after quota error
- Reduced overhead: Cached fallback LLM instance, no per-call recreation
- Better observability: Clear logging of fallback mode entry/exit
- Intelligent recovery: Automatic recovery attempt after 5-minute interval

Updated tests:
- M6 E2E Event Queue Via Plan Lifecycle Transitions
- M6 E2E Hierarchical Decomposition Via Plan Tree
- M6 E2E Full Autonomy Acceptance Flow

Fixes: #10042
2026-04-17 03:56:35 +00:00