Repository navigation
Description
Priority
P1 · impact H · effort M · risk M; patch defects first, add runtime tests incrementally.
Real defects
- src/factory.ts:605 calls onRequestEnd inside the dispatch try before cost recording. A throwing hook enters provider fallback even after a successful vendor call. Verified synthetic probe: onRequestEnd throws; two providers are called and the logical request fails.
- src/utils/hooks.ts:236 composeHooks catches handler errors, but a raw hooks object is called directly. Image attempt hooks are guarded; ordinary lifecycle hooks are not.
- src/utils/hooks.ts:216 exports onRetry, onCircuitStateChange and onBudgetThreshold, but source search finds declarations/composition only, no producers for these events.
- src/providers/base.ts:176 clears timeout at headers; a stalled body/read can wait indefinitely.
- src/utils/retry.ts:89 sleeps without abort/deadline.
- src/errors.ts:241 discards Retry-After headers, and src/errors.ts:215 recognizes quota_exceeded only by one body type; verify vendor-specific insufficient-quota shapes.
- src/errors.ts:269 classifies network failure via message containing fetch; adapters often propagate native TypeError rather than normalized NetworkError.
- src/factory.ts:1688 quota settlement and src/factory.ts:676 cache writes float beyond request lifetime.
- src/factory.ts:886 tool abort is checked between calls only; src/types.ts:134 has no request signal.
Testing gaps / evidence
src/tests/circuit-breaker.test.ts:16 already has fake clocks, deterministic randomness, degradation and snapshot tests—keep them. src/tests/schema-drift.test.ts:1046 covers malformed SSE. src/tests/schema-canary.test.ts:118 compares fixture shapes against synthetic objects, not scheduled live contracts. vitest.config.ts:7 runs in Node; .github/workflows/ci.yml:24 has no workerd behavior test or coverage gate. Source inspection found no dedicated retry or OpenAI non-streaming test file; related schema/canonical suites do cover some of those paths, so do not equate absent filenames with zero coverage.
Implementation
Normalize hook invocation once (composeHooks already has safe behavior), outside provider-failure classification. Record successful billable usage even if telemetry fails. Wire documented events at real physical attempts/state transitions/thresholds or deprecate unsupported hooks; terminal/error attempt counts must be accurate.
Add signal + absolute request deadline to execution options. Honor remaining deadline across fallback/retries and body reads, distinguish AbortError from TimeoutError, parse Retry-After seconds and HTTP dates, use bounded jitter/concurrency. Clarify single owner for retries when AI Gateway/another SDK also retries. Do not retry/replay a completed tool side effect.
Provide a structural waitUntil callback or observable completion promise for optional writes. Required quota settlement must be awaited; an optional telemetry sink may use ctx.waitUntil.
Acceptance
- Throwing every hook leaves response/fallback/breaker/ledger outcome unchanged.
- Retry/breaker/budget events actually fire once with resolved provider/model and attempt.
- Aborted/stalled header/body/backoff/tool-loop requests stop without fallback.
- Retry-After, 429 insufficient quota, 401/403/400/404/5xx have provider-specific fixture contracts.
- Deterministic fault matrix: connection reset, malformed JSON, split UTF-8, first/mid-stream failure, cancellation, simultaneous failures/recovery.
- Workers runtime test for byte SSE and settlement lifetime.
- Fixtures record source endpoint/model/date/provenance; sanitize payloads. Live canaries are opt-in with bounded spend.
- Coverage gates target resilience branches after collecting a real baseline.
Verification: source typecheck passes; nine standalone synthetic assertions pass. Full Vitest run is blocked locally by missing @rollup/rollup-win32-x64-msvc, and Worker bundle smoke by Linux-only esbuild. Report this limitation; do not claim the suite passed.
Related: #77 owns the existing supply-chain workflow problem; do not duplicate it.
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.Related streaming/quota slices now have regression coverage:
Still a priority defect: raw non-streaming lifecycle hooks can replay a successful vendor call. Central safe-hook normalization is not done. Non-streaming body deadlines, abortable retry sleeps/tool calls, Retry-After and vendor-specific quota/error fixtures, unproduced hook events, non-streaming floating cache/quota writes, workerd fault tests and measured coverage gates also remain.
The old missing-Windows-binary limitation no longer applies to the current local working tree: binaries were repaired without manifest/lockfile changes. No workerd/coverage/live-fixture claim is made.
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.
fix: isolate lifecycle hooks so telemetry cannot replay requests (#120)