Skip to content

Fix concurrent limiter accounting and bounded waiting - #103

Merged
jhurliman merged 2 commits into
mainfrom
fix/limiter-correctness
Sep 9, 2026
Merged

jhurliman merged 2 commits into
mainfrom
fix/limiter-correctness

Conversation

@jhurliman

@jhurliman jhurliman commented Sep 9, 2026 •

Copy link
Copy Markdown
Owner

Concurrent removeTokens() calls can exceed interval allowances, wait unexpectedly with fireImmediately, or debit a shared parent more than once. Reserve allowance synchronously, recheck after waking, and debit each hierarchy atomically. Waiting calls now use a FIFO queue with one active timer per instance.

Validate numeric inputs, detect cyclic parents, retain fractional monotonic time, and cap long platform timers. Handle extreme refill inputs without NaN balances or spurious multi-day waits. Clarify zero-value semantics, local state, synchronous queue bypass, non-rolling intervals, and floating-point limits; fix the byte-throttling example. CI now builds both distributions in addition to linting and testing.

Validation: 27 tests pass, including 10,000 seeded operations against an independent integer reference model, a 1,000-request FIFO backlog, mixed sync/async contention, hierarchy failures, and timer extremes. Lint, TypeScript builds, packed CommonJS/ESM imports, and a TypeScript NodeNext consumer pass locally. An Apple M2 Max / Node 26 microbenchmark measured median synchronous throughput of 13.3M removals/s versus 8.7M on the base commit (five measured rounds of one million calls after warmup); this is a local measurement, not a portable performance guarantee.

Compatibility: invalid numeric input now throws/rejects, async ordering is FIFO per instance, and fractional balances can differ from older whole-millisecond timing. Shared children do not gain global FIFO ordering. Public mutable bucket fields and normal JavaScript floating-point limits remain; this does not introduce distributed or rolling-window guarantees. No npm release is included.

Dependency audit: refreshed the existing semver-compatible development lockfile without adding runtime dependencies or changing declared ranges. yarn audit now reports zero advisories, and lint, all 27 tests, and both builds pass with the refreshed toolchain.

@jhurliman
jhurliman marked this pull request as ready for review September 9, 2026 01:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-09T01:40:04.818493Z 5afe6e5 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jhurliman
jhurliman merged commit b1cab7e into main Sep 9, 2026
3 checks passed
@jhurliman
jhurliman deleted the fix/limiter-correctness branch September 9, 2026 01:44
@jhurliman jhurliman mentioned this pull request Sep 9, 2026
jhurliman added a commit that referenced this pull request Sep 9, 2026
Release the merged concurrency and accounting fixes as `limiter@4.0.0`.
Use a major version because invalid numeric inputs now reject and
waiting requests use FIFO ordering, both observable behavior changes
that consumers should opt into.

Add a 3.x migration guide to the README, finalize the changelog, and
include it in the npm package. Exclude test files and TypeScript build
caches from the published archive. No runtime code changes beyond merged
PR #103.

Validation: lint, all 27 tests, both TypeScript builds, package-content
inspection, and CommonJS/ESM smoke checks against the packed package.
Publishing follows the merged release commit.
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