Skip to content

refactor: internalize deterministic ramp sampling - #86

Merged
lan17 merged 2 commits into
mainfrom
agent/internal-ramp-sampling
Jul 25, 2026
Merged

lan17 merged 2 commits into
mainfrom
agent/internal-ramp-sampling

Conversation

@lan17

@lan17 lan17 commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • remove DialCacheConfig.rampSampler and the public CacheRampSample, CacheRampSampler, deterministicRampSampler, and randomRampSampler exports
  • keep the existing deterministic key-and-layer assignment algorithm behind an internal boundary
  • reject legacy JavaScript rampSampler configuration explicitly instead of silently ignoring it
  • replace sampler-injection tests with stable-cohort behavior tests and lock the existing hash outputs with regression vectors
  • update the README and packed-consumer contract checks for the simplified API

Why

The public sampler made a basic ramp percentage depend on arbitrary caller code on the cache hot path. Because the callback could be asynchronous, throw, reject, or return invalid values, it expanded DialCache's liveness and fail-open surface and allowed partial-ramp behavior to vary between instances. The only production implementation used by default was already deterministic.

DialCache now owns the meaning of a partial ramp. Applications that need externally coordinated cohorts can implement that policy in the existing cacheConfigProvider by returning sparse per-key ramp overrides of 0 or 100.

Breaking change

This removes published API from v0.9.0, so the conventional title deliberately marks the change as breaking. Consumers must remove rampSampler from new DialCache(...) and stop importing the removed sampler symbols. Existing partial ramps continue using the same deterministic key-and-layer cohorts.

Validation

  • Node v22.22.0: corepack pnpm check
    • 254 unit tests passed
    • 96.56% statement / 92.56% branch coverage
    • typecheck, ESM/CJS bundles, declarations, and packed consumers passed
  • focused ramp/metrics/liveness/internal suite: 96 tests passed
  • final ramp regression suite: 50 tests passed
  • corepack pnpm audit --prod --audit-level high: no known vulnerabilities
  • git diff --check: passed
  • git merge-tree --write-tree origin/main HEAD: clean

corepack pnpm test:integration was attempted, but the local Docker daemon is not running. Testcontainers stopped before executing code with Could not find a working container runtime strategy; all 69 integration tests were skipped. CI remains responsible for the real Redis/Valkey/cluster matrix.

@lan17
lan17 marked this pull request as ready for review July 25, 2026 19:01
@lan17 lan17 changed the title refactor!: internalize deterministic ramp sampling refactor: internalize deterministic ramp sampling Jul 25, 2026
@lan17 lan17 changed the title refactor: internalize deterministic ramp sampling refactor!: internalize deterministic ramp sampling Jul 25, 2026
Comment thread src/dialcache.ts
if (Object.hasOwn(config, "urnPrefix")) {
throw new TypeError('DialCacheConfig.urnPrefix was renamed to "namespace"');
}
if (Object.hasOwn(config, "rampSampler")) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just remove these checks? Perhaps its better to check that whatever object is passed in only has fields defined in DialCacheConfig. is that possible in ts?

@lan17 lan17 changed the title refactor!: internalize deterministic ramp sampling refactor: internalize deterministic ramp sampling Jul 25, 2026
@lan17
lan17 merged commit efa02cc into main Jul 25, 2026
6 checks passed
@lan17
lan17 deleted the agent/internal-ramp-sampling branch July 25, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant