Commit Graph

3 Commits

Author SHA1 Message Date
陈少杰 e581adbeca refactor(factory): add pattern caching and type safety to validation
Improvements:
- Add ProviderMismatch TypedDict for type-safe return values
- Cache compiled regex patterns for better performance
- Update documentation to reflect optimizations

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 20:28:14 +08:00
陈少杰 78312851f9 refactor(orchestrator): centralize provider validation in factory
Move provider × base_url validation patterns from llm_runner.py to
factory.py's ProviderSpec, implementing the architecture improvement
suggested in docs/architecture/orchestrator-validation.md.

Changes:
- Add base_url_patterns field to ProviderSpec dataclass
- Split ollama and openrouter into separate ProviderSpec entries
  (previously shared openai's spec with dynamic provider selection)
- Add validate_provider_base_url() function in factory for reusable validation
- Simplify LLMRunner._detect_provider_mismatch() to delegate to factory
- Update architecture doc with change log and implementation notes

Benefits:
- Single source of truth for provider configuration
- Easier maintenance when adding/updating providers
- Reduced code duplication (llm_runner.py: -39 lines, factory.py: +84 lines)
- Factory validation can be tested independently

All 28 orchestrator validation tests pass, including 6 provider mismatch tests.
2026-04-16 20:06:30 +08:00
陈少杰 eda9980729 feat(orchestrator): add comprehensive provider and timeout validation
Add three layers of configuration validation to LLMRunner:

1. Provider × base_url matrix validation
   - Validates all 6 providers (anthropic, openai, google, xai, ollama, openrouter)
   - Uses precompiled regex patterns for efficiency
   - Detects mismatches before expensive graph initialization

2. Timeout configuration validation
   - Warns when analyst/research timeouts may be insufficient
   - Provides recommendations based on analyst count (1-4)
   - Non-blocking warnings logged at init time

3. Enhanced error classification
   - Distinguishes provider_mismatch from provider_auth_failed
   - Uses heuristic detection for auth failures
   - Simplified nested ternary expressions for readability

Improvements:
- Validation runs before cache check (prevents stale cache on config errors)
- EAFP pattern for cache reading (more robust than TOCTOU)
- Precompiled regex patterns (avoid recompilation overhead)
- All 21 unit tests passing

Documentation:
- docs/architecture/orchestrator-validation.md - complete validation guide
- orchestrator/examples/validation_examples.py - runnable examples

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 11:43:19 +08:00