Repository navigation
Closed
Description
Summary
FallbackRule.fallbackProvider is part of the public API and README examples, but the factory currently uses fallback rules only as a boolean "should continue?" decision. The configured fallbackProvider never affects the provider chain.
That means a user can configure { condition: 'error', fallbackProvider: 'anthropic' } and still route to whatever provider happens to be next in the default/cost-optimized chain.
Fractal Decomposition
Macro: Predictable failover policy
- Consumers use this package to centralize provider failover decisions across products.
- A fallback rule that reads as provider-directed policy but behaves as generic "try next" policy creates operational surprises during outages, rate limits, or cost controls.
Meso: Provider-chain construction vs fallback evaluation
- Provider ordering is built up front by
buildProviderChain(). shouldFallback()only decides whether the loop continues.evaluateFallbackRule()readsconditionandthreshold, but never returns or usesfallbackProvider/fallbackModel.
Micro: Concrete code paths
src/types.ts:204-208:FallbackRuleincludesfallbackProviderand optionalfallbackModel.src/factory.ts:370-400:shouldFallback()returns only a boolean.src/factory.ts:406-428:evaluateFallbackRule()ignores the provider/model specified by the rule.src/factory.ts:434-449: defaults document specific fallback providers that are not actually selected by this logic.README.md:163-176: examples imply callers can customize where fallback goes.
Impact
- Custom fallback rules do not provide deterministic routing.
- Cost-based fallback can be triggered only after a failure path and still does not guarantee routing to the configured cheap provider.
fallbackModelappears to be a public contract but has no effect.- Tests currently exercise "fallback happened", not "the rule's fallbackProvider was honored".
Suggested Fix
- Change fallback evaluation to return a routing decision, e.g.
{ shouldFallback, provider?, model? }. - When a rule matches, insert or prioritize the specified fallback provider/model as the next attempted target.
- Define precedence when multiple rules match.
- Add tests for custom rules such as
openaifailure -> configuredanthropicfirst, not cost/default priority first. - Either implement or remove the unimplemented
latencycondition so the type does not promise an inert policy.
Verification
npm run typecheckpasses.npm testpasses: 169 tests.
Metadata
Metadata
Assignees
Labels
No labels
Activity