Repository navigation
fix: cache ledger narrates co-flipped identity dimensions as one cause (#2784) - #2795
Merged
Merged
Conversation
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3069-pr.2795.3a986f7This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2795.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Contributor
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.285-master.d0cebb9 # this exact build
npm install -g billion-context@master # always the newest merged build
|
This was referenced Oct 11, 2026
Merged
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.
Closes #2784
Problem
In dsh (and any host that re-renders the active model into its system prompt), every model switch ALSO flips the ledger's system-prompt fingerprint on the same request line. The token partition correctly charged the residual to the model switch, but the event counters were deliberately independent (#2350 "counters stay independent"), so the shadowed prompt flip still booked its own event with 0 charged tokens — and the web panel rendered that as an independent cause chip:
✍️ 宿主改写提示词 0 ×1next to the model-switch row. One user action narrated twice, one of the narratives wrong.Verified on the dsh side (public repo deepseek-ai/deepseek-harness): the active model is registered as a system-prompt variable (
packages/core/agent-loop/src/index.ts:416-417) and persona text interpolates{{model}}, so switching models changes the rendered system text → fingerprint flip on the same line. That is why the reporter sees it on every switch ("可能所有的都是这样").Root cause
recordCacheSample(src/cache-ledger.ts) computes an EXCLUSIVE per-line cause partition (restart > model > key > prompt > wire > upstream) for TOKEN charging, but fired each dimension's EVENT counter independently of who won. A co-flipped lower-priority dimension therefore produced a zero-token event that every consumer (web chip,/acp-cachePROMPT SWITCHES section, sessions table row) renders as an independent cause.Fix
Event counters now follow the SAME rule as the token partition: one line, exactly ONE narrative cause — the highest-priority fresh flag wins; dimensions shadowed on that line are not counted as events. Raw observations are untouched: per-dimension flags + values + the winning cause still persist on the line itself, so forensics lose nothing.
switchEventslikewise lists only lines where that dimension won the partition (lines persisted pre-#1847 without acausefield keep their historical display).Behavior change (disclosed per owner policy)
*.events, web detail tables,/acp-cachesections): now omit shadowed co-flips; they remain visible on the ledger line itself (flag + value pair).Tests
tests/cache-ledger-prompt-switch.test.ts"a dsh-style model switch narrates ONE cause; a later genuine rewrite still fires (切模型归因有问题✍️ 宿主改写提示词 0 ×1 · #2784)": pins the exact reported shape (the chip gatecount>0 || tokens>0sees nothing after a pure model switch) AND that a later genuine host rewrite still fires (baseline advanced with it). Fails on the old code.tests/cache-ledger.test.ts(cache-ledger 归因账本:同一残差重复计入多个重叠桶、switch flag 只比紧邻上一条、未归因残差占绝对主导、unknown-cache 样本被画成 0% 平台 #1847 multi-flag partition),tests/cache-ledger-key-switch.test.ts(大量缓存接缝事件导致缓存命中率大幅度降低 #2131),tests/cache-ledger-prompt-switch.test.ts×2 ([cache-ledger] fold-reconcile 检测到宿主侧系统提示词改写但未接入归因:prompt 改写被误归入未归因 TTL 残差 #2350). All pure single-dimension tests untouched.