refactor(dispatch): split provider_loop 808 LoC into resolver + retry + orchestration (T-SP-3 #9)#239
Merged
Destynova2 merged 2 commits intomainfrom Apr 21, 2026
Merged
Conversation
… + orchestration (T-SP-3 #9) provider_loop.rs was hosting three distinct concerns in a single file: 1. Provider selection (registry + CB + HC + RE-1a endpoint health) 2. Retry + error classification + single-provider dispatch 3. Outer fallback loop orchestration Split into: - src/server/dispatch/resolver.rs (~128 LoC) — resolve_provider, try_direct_provider_lookup (backward-compat path). - src/server/dispatch/retry.rs (~482 LoC) — ProviderLoopAction, ProviderAttempt, classify_and_handle_error, emit_provider_error_metrics, handle_provider_error, try_rotate_and_retry, dispatch_streaming, dispatch_non_streaming, wrap_stream_with_middleware, build_encrypted_content. - src/server/dispatch/provider_loop.rs (~275 LoC down from 808) — dispatch_provider_loop (outer loop), log_dispatch_attempt, prepare_provider_request, emit_fallback. No behavior change: public entry point src/server/dispatch/mod.rs:349 (provider_loop::dispatch_provider_loop) keeps the same signature and callers are unaffected. Validation: - cargo build --all-targets green - cargo test --lib : 949 passed, 0 failed - cargo clippy --all-targets -- -D warnings clean - RUSTFLAGS="-D warnings" cargo check --no-default-features clean Addresses Phoenix audit 2026-04-20 item #9.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phoenix audit 2026-04-20 item #9 — provider_loop.rs was a 808 LoC god-file with 3 concerns.
Split
resolver.rstry_direct_provider_lookupretry.rsProviderLoopAction+ retry classification + pool rotation + stream middleware layers + encrypted log exportprovider_loop.rsdispatch_provider_loop) + pre-flight helpers (log_dispatch_attempt,prepare_provider_request,emit_fallback)Gates
cargo build --all-targetscargo test --lib— 949 passed, 0 failedcargo clippy --all-targets -- -D warningsRUSTFLAGS="-D warnings" cargo check --no-default-featuresdispatch/mod.rs:349unchanged