Skip to content

fix: make enableRetries affect provider retry behavior or remove it #32

Closed

Description

@stackbilt-admin

Summary

enableRetries is exposed on ProviderFactoryConfig, FromEnvOverrides, and createCostOptimizedFactory(), but it is not wired to provider retry behavior. Providers always construct a RetryManager from provider-level maxRetries / retryDelay, defaulting to 3 retries.

As a result, enableRetries: false does not disable retries, and enableRetries: true is effectively decorative unless the provider config already has retry settings.

Fractal Decomposition

Macro: Control-plane knobs must match runtime behavior

  • Retry policy affects latency, cost, duplicate requests, and provider-side rate-limit pressure.
  • A no-op factory-level retry flag makes production behavior hard to reason about, especially when consumers expect one request attempt for non-idempotent tool or JSON-generation paths.

Meso: Factory config vs provider config

  • ProviderFactoryConfig includes enableRetries, but initializeProviders() forwards only provider config, logger, and hooks into provider constructors.
  • BaseProvider always creates a RetryManager.
  • There is no factory-level mapping from enableRetries to provider maxRetries.

Micro: Concrete code paths

  • src/factory.ts:53-57: enableRetries is part of the factory config.
  • src/index.ts:152-159 and src/index.ts:228-230: fromEnv() exposes and copies the override.
  • src/factory.ts:604-615: createCostOptimizedFactory() sets enableRetries: true.
  • src/providers/base.ts:37-50: every provider defaults maxRetries to 3 and constructs RetryManager regardless of enableRetries.

Impact

  • Consumers cannot disable retry from the high-level factory config.
  • Tests assert the override is accepted, but do not assert any runtime effect.
  • Package docs advertise "configurable delays, jitter, and per-error-class behavior"; the most visible high-level config knob for this behavior is currently misleading.

Suggested Fix

  • Decide the public contract:
    • If enableRetries is kept, map false to maxRetries: 0 unless provider config explicitly overrides it.
    • If retries should be provider-only, remove enableRetries from public factory/fromEnv config and update docs/tests.
  • Add tests that count provider request attempts for retryable errors with enableRetries: false and enableRetries: true.
  • Consider emitting retry hooks from RetryManager, since ObservabilityHooks defines onRetry but retry events are not currently wired through.

Verification

  • npm run typecheck passes.
  • npm test passes: 169 tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions