Skip to content

fix: cache ledger narrates co-flipped identity dimensions as one cause (#2784) - #2795

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-11_subsumed-switch-events
Oct 11, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-11_subsumed-switch-events

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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 ×1 next 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-cache PROMPT 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. switchEvents likewise lists only lines where that dimension won the partition (lines persisted pre-#1847 without a cause field keep their historical display).

Behavior change (disclosed per owner policy)

  • Switch-event counters (model/key/prompt/wire/upstream): previously counted EVERY observed flip on a line; now count only the line's winning dimension. Affected ONLY when ≥2 identity dimensions flip on the SAME request line (e.g. dsh model switch + induced prompt-fingerprint flip): the shadowed dimensions' counts drop by k; their missedTokens were already 0 (tokens always went to the winner), so NO token number changes anywhere — hit rates, residual closure, invalidation buckets, fold economics are byte-identical. Single-dimension switches (the common case) are unchanged.
  • Event lists (*.events, web detail tables, /acp-cache sections): now omit shadowed co-flips; they remain visible on the ledger line itself (flag + value pair).
  • No config surface change, no persistence-format change (line schema unchanged; only which agg counters increment), no kernel change, purely diagnostic layer.

Tests

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_subsumed-switch-events (24a8679)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3069-pr.2795.3a986f7

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2795.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei merged commit d0cebb9 into master Oct 11, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.285-master.d0cebb9 (rolling master tag).

npm install -g billion-context@0.0.285-master.d0cebb9  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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.

切模型归因有问题✍️ 宿主改写提示词 0 ×1 ·

1 participant