Skip to content

fix(rate-limit): patch Bottleneck doExpire capacity leak - #9151

Closed
HouMinXi wants to merge 2 commits into
cheaper-inference:release/v3.8.50from
HouMinXi:fix/bottleneck-doexpire-patch
Closed

HouMinXi wants to merge 2 commits into
cheaper-inference:release/v3.8.50from
HouMinXi:fix/bottleneck-doexpire-patch

Conversation

@HouMinXi

@HouMinXi HouMinXi commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Bottleneck v2.19.5's doExpire (Job.js:162) has a typo that compares the job ID to the string "RUNNING" instead of checking the job's actual status. When a job's execution time exceeds the expiration timeout, doExpire fires but fails to advance the job from RUNNING to EXECUTING. The resulting exception is swallowed by setTimeout, leaving the job permanently stuck in RUNNING state and Bottleneck's internal _running counter permanently incremented -- a capacity leak that eventually causes "all accounts inactive" even with available reservoir.

The bug is unfixed upstream (v2.19.5 is the latest release; master branch still has it).

Fix

  1. Monkey-patch Bottleneck.prototype._run to correct job.doExpire before the expiration timeout fires. The patch uses job.id (not job.options.id) for status lookup, includes a _doExpirePatched guard against recursive wrapping, and adds optional chaining on states.next.

  2. Diagnostic fallback in withRateLimit: when a queue timeout fires and the limiter shows running > 0, executing = 0, reservoir > 0 (the leak pattern) with no recent dispatch, evict the limiter and retry.

Files changed

  • open-sse/services/bottleneckPatch.ts -- new, 80 lines
  • open-sse/services/rateLimitManager.ts -- +20 lines (import, patch call, diagnostic)
  • tests/unit/bottleneck-doexpire-patch.test.ts -- new, 148 lines (5 tests)

Testing

5/5 unit tests pass. Forge review: 6 rounds, PASS (R6 0 new findings).

Bottleneck's doExpire has a typo that leaves expired jobs stuck in
RUNNING state, leaking _running capacity until the limiter reports
"all accounts inactive" despite available reservoir.

Patch job.doExpire before the timer fires, and add a diagnostic that
evicts limiters matching the leak pattern.

Signed-off-by: Minxi Hou <houminxi@gmail.com>
@HouMinXi
HouMinXi requested a review from diegosouzapw as a code owner August 1, 2026 16:38
@HouMinXi

HouMinXi commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #9328, which is the same fix re-cut onto the live release/v3.8.50 tip. This branch's merge-base sat 20 commits back and its file-size-baseline commit re-encoded the whole file, so the diff read +432/-184; #9328 is 4 files, +248/-0.

@HouMinXi HouMinXi closed this Aug 4, 2026
diegosouzapw added a commit that referenced this pull request Aug 8, 2026
…tion (#9615)

* fix(docker): complete partially traced packages in standalone co-location

Publish-to-Docker-Hub has failed on every release/v3.8.50 push since #9151
enabled publishing from active release branches: the post-build guard dies
with "Cannot find module .../@atjsh/llmlingua-2/dist/index.js" while the
co-location step right above it reports 100 packages copied.

Root cause: Next's file tracing materializes @atjsh/llmlingua-2 PARTIALLY
in the standalone (package.json lands, the dist/ payload its main points at
does not). colocateOptionals' no-clobber checked existsSync on the package
DIRECTORY, so the partial shell counted as present and the one package that
mattered was skipped forever (#9185 added the closure walk but kept the
directory-level check).

Fix: presence is now judged by entrypoint integrity — the package resolves
from inside the target tree (same contract as the Dockerfile guard). Partial
directories are completed with a file-level no-clobber merge (cpSync
force:false), so files the trace did materialize are never overwritten and
pinned instances (dist transformers 3.5.2) keep their protection.

Validation (TDD): 2 new tests in docker-llmlingua-optionals-9166.test.ts
reproduce the CI failure (partial package skipped; closure-wide early-exit
firing while a member is partial) — red on the old code, 5/5 green after.

* fix: update colocate test mock packages to match isPackageIntact entrypoint resolution

The PR's isPackageIntact check uses require.resolve to validate that
co-located packages have a usable entrypoint inside the target tree.
The pre-existing test's mock packages lacked main fields and index
files, so require.resolve failed and the idempotency assertion broke.

Update buildRoot() to give every closure package a resolvable entry
(main + index.js), mirroring what real npm packages ship.

Refs #9615

* docs(changelog): fragment for #9615

* fix(yuanbao-web): accept content field in SSE text events (upstream format change) (#8739)

Closes #8739

* fix(errorClassifier): classify ChatGPT Web SENTINEL_BLOCKED 403 as FORBIDDEN, enabling combo fallback (#8813)

Closes #8813

* fix(vertex): route Claude models to native rawPredict and respect targetFormat overrides (#8994)

Closes #8994

* fix(cursor): preserve tool context across multi-turn conversations when client lacks conversation_id (#9029)

Closes #9029

* fix(sse): move Antigravity client system content to first user message to avoid upstream 429 (#9030)

Closes #9030

* fix(combo): distinguish pre-dispatch skips from genuine failures to prevent false 503 ALL_ACCOUNTS_INACTIVE (#9630)

Closes #9630

* fix: repair stray brace in combo.ts and fix no-explicit-any types in repro-9630 test

---------

Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
@HouMinXi
HouMinXi deleted the fix/bottleneck-doexpire-patch branch September 16, 2026 13:58
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…tion (cheaper-inference#9615)

* fix(docker): complete partially traced packages in standalone co-location

Publish-to-Docker-Hub has failed on every release/v3.8.50 push since cheaper-inference#9151
enabled publishing from active release branches: the post-build guard dies
with "Cannot find module .../@atjsh/llmlingua-2/dist/index.js" while the
co-location step right above it reports 100 packages copied.

Root cause: Next's file tracing materializes @atjsh/llmlingua-2 PARTIALLY
in the standalone (package.json lands, the dist/ payload its main points at
does not). colocateOptionals' no-clobber checked existsSync on the package
DIRECTORY, so the partial shell counted as present and the one package that
mattered was skipped forever (cheaper-inference#9185 added the closure walk but kept the
directory-level check).

Fix: presence is now judged by entrypoint integrity — the package resolves
from inside the target tree (same contract as the Dockerfile guard). Partial
directories are completed with a file-level no-clobber merge (cpSync
force:false), so files the trace did materialize are never overwritten and
pinned instances (dist transformers 3.5.2) keep their protection.

Validation (TDD): 2 new tests in docker-llmlingua-optionals-9166.test.ts
reproduce the CI failure (partial package skipped; closure-wide early-exit
firing while a member is partial) — red on the old code, 5/5 green after.

* fix: update colocate test mock packages to match isPackageIntact entrypoint resolution

The PR's isPackageIntact check uses require.resolve to validate that
co-located packages have a usable entrypoint inside the target tree.
The pre-existing test's mock packages lacked main fields and index
files, so require.resolve failed and the idempotency assertion broke.

Update buildRoot() to give every closure package a resolvable entry
(main + index.js), mirroring what real npm packages ship.

Refs cheaper-inference#9615

* docs(changelog): fragment for cheaper-inference#9615

* fix(yuanbao-web): accept content field in SSE text events (upstream format change) (cheaper-inference#8739)

Closes cheaper-inference#8739

* fix(errorClassifier): classify ChatGPT Web SENTINEL_BLOCKED 403 as FORBIDDEN, enabling combo fallback (cheaper-inference#8813)

Closes cheaper-inference#8813

* fix(vertex): route Claude models to native rawPredict and respect targetFormat overrides (cheaper-inference#8994)

Closes cheaper-inference#8994

* fix(cursor): preserve tool context across multi-turn conversations when client lacks conversation_id (cheaper-inference#9029)

Closes cheaper-inference#9029

* fix(sse): move Antigravity client system content to first user message to avoid upstream 429 (cheaper-inference#9030)

Closes cheaper-inference#9030

* fix(combo): distinguish pre-dispatch skips from genuine failures to prevent false 503 ALL_ACCOUNTS_INACTIVE (cheaper-inference#9630)

Closes cheaper-inference#9630

* fix: repair stray brace in combo.ts and fix no-explicit-any types in repro-9630 test

---------

Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
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