feat: add fallback deadlines and coalescing state#69
Merged
Conversation
lan17
marked this pull request as ready for review
July 20, 2026 00:03
lan17
added a commit
that referenced
this pull request
Jul 20, 2026
Combines runtime config overlays with the fallback deadline and coalescing state work from #69. Both cached() registration validations (defaultConfig snapshot and fallbackTimeoutMs) run before the use case name is registered. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 20, 2026
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.
Closes #41
Summary
This change gives enabled cache fallbacks a finite lifetime and makes process-scoped single-flight health exactly inspectable, without unsafe leader eviction or a registry-only global cap.
Enabled fallbacks use a 60-second monotonic deadline by default. A cached wrapper can select a positive
fallbackTimeoutMsor usenullto disable the guard. Followers share their leader's remaining budget. Timeout rejects the DialCache chain withFallbackTimeoutError, clears the flight through normal settlement, and prevents the late fallback result from reaching serializer, Redis, or local-cache publication. It does not cancel the underlying operation.API and semantics
fallbackTimeoutMsis validated whencached()creates the wrapper. It accepts positive safe integer milliseconds through 2,147,483,647, plus explicitnull. Invalid options do not reserve the use-case name.AbortSignalsupport remain preferred.Liveness boundary
fallbackTimeoutMsgoverns only fallback execution. DialCache does not claim to cancel or time-bound Redis, serializers, configuration providers, ramp samplers, or other injected async work. Public JSDoc and the README require every injected boundary to settle within an application-defined budget.Valkey GLIDE
requestTimeoutbounds client waiting, not server-side cancellation. node-redis 4.7 connection and queue settings do not bound a dispatched response; itsAbortSignalcan remove only work still waiting to be sent. Applications needing strict finite settlement must provide a semantic-client policy, including ambiguous-write handling.No Redis key, frame, Lua protocol, invalidation, serializer, or cached-value contract changes.
Coalescing observability
getCoalescingState()returns a detached snapshot for thisDialCacheinstance:Process flights are registered before synchronous leader work, carry a monotonic start time, and maintain exact follower counts. Joins, cleanup, and oldest-flight lookup remain O(1). Request-local flights remain lifecycle-owned by the outer
enable()scope and are intentionally excluded.There is no automatic leader replacement or global process-flight cap. Eviction can permit duplicate late writes, while a metadata cap does not bound backend work. Application admission control owns distinct-key concurrency; the snapshot shows whether finite resource budgets are working.
Compatibility and performance
The finite default deliberately changes enabled fallbacks that previously remained pending beyond 60 seconds.
fallbackTimeoutMs: nullis the explicit migration escape hatch.Cache hits allocate no fallback timer, and followers reuse the leader promise and timer. Tracking adds one monotonic clock read and one small record per process leader; pre-work registration adds no promise, timer, or microtask. A Node 22.22 base-versus-head probe over 200,000 calls measured about 0.29 microseconds per immediate enabled fallback and 0.10 microseconds per process-local hit. These timings are informational; benchmark correctness assertions are deterministic.
Validation
corepack pnpm check: typecheck, 211 unit tests with coverage gates, build/declarations, packed ESM/CJS consumers