Repository navigation
Description
Priority
P1 · impact H · effort M · risk M (default isolation belongs in major; offer opt-in now).
Problem and evidence
Independent clients with different provider credentials share health, exhaustion and analytics by the provider name:
- src/providers/base.ts:306 always binds to defaultCircuitBreakerManager.getBreaker(this.name).
- src/factory.ts:354 uses defaultCostTracker unless a ledger is attached.
- src/factory.ts:473 uses global exhaustion.
- src/factory.ts:1497 resets global exhaustion/histogram; a client reset can affect another client.
- src/providers/base.ts:196 executes the breaker unconditionally. Factory enableCircuitBreaker: false only removes a precheck.
- src/factory.ts:380 enableRetries: false does not override an explicit provider maxRetries.
- src/utils/circuit-breaker.ts:108 marks traffic before rejecting; src/utils/circuit-breaker.ts:421 resets the decay clock even on rejected calls.
- src/utils/circuit-breaker.ts:126 counts every operation error as provider health failure, including authentication/invalid requests thrown within the operation.
Verified: force-open the default OpenAI breaker; a separately constructed client with enableCircuitBreaker: false still fails without dispatching. This is not a lost JavaScript increment: synchronous mutations are safe within an isolate. The defects are state ownership, non-atomic admission across awaits, and completion-order semantics.
Proposed scope
Add an injectable ResilienceContext holding CircuitBreakerManager, ExhaustionRegistry, CostTracker and LatencyHistogram. Pass the same context to planning, adapters and telemetry; direct providers must support the same injection. Account/credential scopes should use consumer-supplied non-secret IDs, never log keys.
Add opt-in client-local context in a minor; make isolated context the next-major default, with explicit shared context for intentional sharing. Make breaker disable bypass execution as well as route precheck; document retry-option precedence and test it. Decide whether invalid/auth/content-policy errors count against health; default to infrastructure failures.
Fix breaker time decay so rejected traffic cannot postpone recovery indefinitely. Preserve graduated probabilistic recovery; do not call it a single-probe half-open lock that the implementation does not provide.
Fallback truth:
- src/factory.ts:1294 authentication/configuration always throw, before custom rules.
- src/factory.ts:1345 default generic error rule falls back for other errors, including invalid request/content filter.
- src/factory.ts:1359 latency rule is a no-op; cost rule is evaluated only in catch.
- README.md:554 promises 401 streaming fallback, contradicting code and src/tests/factory.test.ts:1031.
Document a precise error-policy table and safe defaults. Treat a policy change in content-filter/auth fallback as explicit configuration or a major, not a silent patch.
Acceptance
- Two clients/credentials never share failures, exhaustion, metrics or reset effects unless given shared context.
- Disabling breakers/retries has deterministic tested semantics.
- Rejected direct calls do not continually postpone recovery.
- User/input/policy errors do not degrade unrelated provider service health.
- Out-of-order concurrent success/failure behavior is specified and tested.
- Unsupported latency policy rejects configuration or is implemented; cost-trigger semantics are honest.
- README error classification matches implementation.
Related: closed #32 fixed one retry path; this covers remaining precedence and state scope. Atomic distributed budget admission is a separate quota issue.
Activity
stackbilt-admin commentedon Oct 13, 2026
Local implementation checkpoint — 2026-10-12
This work is uncommitted/unpushed on
main, based on8a9eda6c058d63f0ec08332f6a408aaf409232cf, and is not merged or released. Keep this issue open pending review/integration. The local handoff isdocs/maintenance/issue-sweep.md; it will travel with the code.Compatible state/policy phase implemented:
stateScope: 'client'creates independent breaker, exhaustion, factory cost and latency state; an explicitResilienceContextintentionally shares state. Factories and direct adapters use the injected context for health.fromEnvaccepts the options.enableCircuitBreaker: falsenow bypasses adapter admission and health recording, including streams.Evidence:
resilience-context.ts, base/factory/breaker changes and 12resilience-context.test.tscases. Existing schema-drift tests now reset breaker history because streaming failures genuinely record health outcomes.Remaining/compatibility decisions: isolated defaults need the next major; legacy retry precedence is preserved (explicit provider
maxRetrieswins overenableRetries: false, so set each provider to zero for guaranteed disablement); unsupported latency rules/cost-trigger semantics remain unchanged. README now documents these limits and stops promising streaming authentication fallback.Validation for the combined local sweep: 605 tests pass across 27 files, TypeScript typecheck passes, Worker-targeted bundle/import smoke passes. Packed entrypoint exports/client methods and all 33 JavaScript sourcemaps were checked on Windows with Node 24.19.0/npm 11.17.0. No live/billable providers or workerd execution; this does not prove minimum Node-version compatibility.
feat: streaming lifecycle, tenant-safe caching, client-scoped resilie…