Repository navigation
fix: eliminate 0.1.193 long-session CPU regression — unused SimHash sketches + duplicate history conversions (#2824) - #2828
Conversation
The #2791/#2807 wire-neutral rewrite made chainFingerprint run the fused hash+sketch pass, but its product carries no sketches and identified note() stores none — every request of a long session recomputed ~22K SimHashes (SKETCH_MEMO_CAP=8192 cannot warm across a sequential scan longer than itself): 0.1.193's ~2.2s/request identified-path cost. neutralFingerprints now takes a sketchCap (first N positions, default 0 = none): resolve() passes SKETCH_MAX_DEPTH (alignment can never read beyond the stored side's cap and note() slices to it anyway — provably byte-identical products); chainFingerprint/findResumeParent/findResumeParentWithin/chainContinues pass 0. All return values unchanged; only CPU drops. Also removes the dead v1 itemFingerprints (zero references since #2791) and adds simhashComputeCountForTest for regression observability.
…2824) Every regular request ran buildIncomingImageIndex in prepare AND refreshIncomingImageIndex after it — each build re-converts the FULL history wire→core before discovering there are no images (~351ms of extra conversion per turn on the 32MiB fixture; old 0.1.192 built at most once behind the stripImages condition). bodyMightCarryImages(bodyText, protocol) is one cheap raw-text pass over the already-parsed body string, computed once after JSON.parse while the protocol is stable. It OVER-APPROXIMATES by design — markers mirror every shape messageImageBytes indexes (data-URLs for openai/responses/anthropic source.url, anthropic source.type base64, google inlineData top-level and nested), so false positives cost one wasted conversion and a false negative cannot drop image recovery. When the predicate is false both sites yield exactly what today's builds return for an image-free body: an empty index (entry) / the unchanged previous index (refresh). Image-bearing sessions run both builds unchanged, preserving the #1995/#2607 ref-refresh + recovery contract.
Pins both regression facets on an 8300-message deep history (> SKETCH_MEMO_CAP 8192 and > SKETCH_MAX_DEPTH 2048): chainFingerprint/findResumeParent/findResumeParentWithin/chainContinues compute ZERO SimHashes; anonymous cold resolve computes exactly 2048 and a warm resend recomputes zero (memo stays warm); similarity adoption still works beyond the sketch cap (via 'simhash', coverage >= 0.9). Image-index guard: bodyMightCarryImages flags every indexable shape non-vacuously (each fixture also builds >= 1 entry), stays false for text-only/remote-URL bodies, and the guarded path deep-equals the unconditional build across the corpus.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3133-pr.2828.9cc867eThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2828.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2828 独立审查结论(修 #2824):可合并(仅剩 2 条 Windows CI leg 在跑)。 所有声明都在 PR head( 结构化八问:
测试有效性:有牙。8300 消息深历史(> memo cap 8192、> sketch cap 2048)钉住「hashes-only 零计算」「冷 resolve 恰好 2048、热 resend 零重算」「超 cap adoption 仍工作」;图片侧 fixture 非空断言(每个 fixture 同时断言索引出 ≥1 条目,防谓词断言空真)+ guarded≡unconditional 语料等价 + 故意 over-approx 用例(pdf inlineData 触发但 ∅)。本地复跑:9 个文件 86/86 绿(issue2824-regression + prefix-affinity×3 + affinity-neutral/crosswire-fold/persist + image-restore + fold-images-archive),typecheck 干净,build 干净(4c084af)。 CI:27/29 绿(ubuntu test×2、e2e、kernel-guard、各 lane 套件、registry e2e、image billing 等),剩 2 条 windows-latest test leg in_progress——与 ubuntu 同一套全量单测,ubuntu 已绿;若红我再定向追。 diff 整洁度:5 文件 +305/−35,每行都与本 issue 相关,无 lockfile/空白噪声。 判定:可合并。 auto-merge 门(§7.4):单机制性能修复 + 回归测试 + rebased-head 绿 + 不触碰 config schema/wire/kernel/update.ts → 满足;是否自动合并留给人/CI。 |
[bot] 🏷 CI 收尾:最后两条 windows-latest test leg(22/24)也已通过—— |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.300-master.1e8e1aa # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2824
What this fixes
Two independent CPU costs introduced at the request entry point between 0.1.192 and 0.1.193, which together took long-session local time from ~1.3s to ~3.2s per turn.
RC1 — identified-session fingerprint computed SimHash sketches it never used
After #2791/#2807 moved
chainFingerprintto the wire-neutral domain, EVERY request of an identified session ran the fused hash+sketch pass (neutralFingerprints) — but its product contains NO sketches, and identifiednote()stores none. On a 24K-turn session that was ~22K SimHash evaluations per request;SKETCH_MEMO_CAP=8192cannot warm across a sequential scan longer than itself, so even repeated resends recomputed ~22K.Fix:
neutralFingerprints(turns, sketchCap = 0)— sketches opt-in per caller:resolve()passesSKETCH_MAX_DEPTH(2048) — the only caller whose consumer reads sketches (simhash adoption). Provably equivalent: alignment'salignLenis bounded by the stored side's cap andnote()slices to it anyway, so positions ≥ 2048 were never read from incoming sketches.chainFingerprint/findResumeParent/findResumeParentWithin/chainContinuespass0(hashes-only products).All return values are byte-identical to before; only CPU drops. Also removes the dead v1
itemFingerprints(zero references since #2791) and addssimhashComputeCountForTest()for regression observability.RC2 — no-image requests converted the full history wire→core twice extra
Every regular request ran
buildIncomingImageIndexin prepare ANDrefreshIncomingImageIndexafter prepare — each build re-converts the ENTIRE history before discovering there are no images.Fix:
bodyMightCarryImages(bodyText, protocol)— one cheap raw-text pass over the already-parsed body string, computed once after JSON.parse while the protocol is stable. It OVER-APPROXIMATES BY DESIGN: markers mirror every shapemessageImageBytesindexes (data-URL for openai/responses/anthropic source.url; anthropicsource.type:"base64"; googleinlineDatatop-level + nested in functionResponse), so a false positive costs one wasted conversion and a false negative cannot drop image recovery. When false, both sites yield exactly what today's builds return for an image-free body (empty / unchanged index). Image-bearing sessions run BOTH builds unchanged — the #1995/#2607 ref-refresh + recovery contract is preserved.Behavior changes (CPU-only; all wire/persistence products byte-identical)
chainFingerprintSKETCH_MAX_DEPTH;note()sliced to this anyway, adoption never reads past the stored cap)Audited-safe edge: openai single-object
content: {type:"image_url"}fires the predicate but the kernel never sidecars an image from non-array content — guarded and unconditional builds both return ∅ (pre-existing kernel behavior, out of scope).Config surface
N/A — no new config field, env var, or CLI flag. Pure internal optimization; no wire, persistence, or API change.
Verification
tests/issue2824-regression.test.ts(7 tests, green): 8300-message deep history (> memo cap 8192, > sketch cap 2048) — hashes-only paths compute ZERO sketches; cold resolve computes exactly 2048 and a warm resend recomputes zero (memo stays warm); similarity adoption still works beyond the sketch cap (viasimhash, coverage ≥ 0.9); predicate flags every indexable shape non-vacuously (each fixture also builds ≥ 1 entry); negatives stay false; guarded path ≡ unconditional build across the corpus.