Skip to content

(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
masterfrom
2026-09-09_hybrid-max-arg-limit
Open

(fix) hybrid scoring: compute the score max in a loop — the Math.max(...) spread crashed at 130K+ docs#228
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-09_hybrid-max-arg-limit

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem

hybridAlgorithm.score — the default search algorithm — crashes with RangeError: Maximum call stack size exceeded when 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.ts normalizes the two channel scores with an argument spread:

const maxBm = Math.max(...bm.map((r) => r.score), 1e-9)

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 (maxScore helper) — 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

  • New regression test tests/hybrid-large-corpus.test.ts: 130,000 docs (just above the Node 22 limit) — the old code fails it with RangeError (verified by stashing the fix), the fixed code passes in ~1.1s and still ranks the distinctive doc first (normalization intact).
  • Full suite: 625/625 pass; tsc --noEmit clean.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

📦 Built Package Artifact

Branch: 2026-09-09_hybrid-max-arg-limit (9b5f022)

Option A — Install from npm PR tag (recommended)

In your adapter project:

npm install acp-kernel@pr-228

Each push to this PR publishes a new version under the pr-228 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf acp-kernel-pr228.tgz
npm install ./package

This comment is automatically updated on each push.

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