(fix) hybrid scoring: compute the score max in a loop — the Math.max(...) spread crashed at 130K+ docs - #228
Open
ranxianglei wants to merge 1 commit into
Open
(fix) hybrid scoring: compute the score max in a loop — the Math.max(...) spread crashed at 130K+ docs#228ranxianglei wants to merge 1 commit into
ranxianglei wants to merge 1 commit into
Conversation
…...) spread crashed at 130K+ docs
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)In your adapter project: npm install acp-kernel@pr-228Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf acp-kernel-pr228.tgz
npm install ./packageThis comment is automatically updated on each push. |
This was referenced Sep 9, 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.
Problem
hybridAlgorithm.score— the default search algorithm — crashes withRangeError: Maximum call stack size exceededwhen the doc count gets large. Reproduced with 160,170 docs (46MB corpus, the scale of a long compressed session): the call throws before returning any result, so search breaks entirely instead of degrading. Found while analyzing Tyan66666/billion-context-dsh#133 (search latency in long sessions); reported as #227.Cause
src/search/algorithms/hybrid.tsnormalizes the two channel scores with an argument spread:Math.max(...array)passes the whole array as call arguments, and V8 caps call arguments at ~125K–130K (Node 22: 125,000 works, 130,000 throws). Any corpus above that limit — ~30K+ compressed messages in a long session — crashes the search.Fix
Compute the max with a loop (
maxScorehelper) — same semantics (max(floor, ...scores)), no argument limit, O(n) either way. Two call sites changed; scoring behavior is byte-identical below the limit.Verification
tests/hybrid-large-corpus.test.ts: 130,000 docs (just above the Node 22 limit) — the old code fails it withRangeError(verified by stashing the fix), the fixed code passes in ~1.1s and still ranks the distinctive doc first (normalization intact).tsc --noEmitclean.