Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
6ef17e8
fix(#2929): fold claim window covers the post-fold cold tail
Oct 12, 2026
993ac45
fix(#2934): sync root package-lock with kernel 0.0.120 bump (lock-syn…
Oct 12, 2026
30eecd7
fix(#2934): sync kernel/package-lock with 0.0.120 bump (pre-existing …
Oct 12, 2026
d255f23
fix(#2934): web gap-cause heuristic — arm fold tail on opener line on…
Oct 12, 2026
1dbe9fc
fix(#2929): unify cache-bucket terminology across the web UI
Oct 12, 2026
0ae986b
fix(#2929): rename the comp bucket to 折叠后重读重建 / post-fold re-read per…
Oct 12, 2026
aba017f
fix(#2929): split provider-side misses by idle gap — normal TTL vs ab…
Oct 12, 2026
311dc49
chore(#2929): refresh storage-render goldens — ledger metadata now ca…
Oct 12, 2026
41eeefa
web(#2929): fold the attribution minis into the unattributed bucket a…
Oct 12, 2026
b896a09
web(#2929): clean attribution presentation — one composition strip, n…
Oct 12, 2026
6f4cd23
web(#2929): trajectory bands follow the ledger's authoritative attrib…
Oct 12, 2026
9b8a6fa
web(#2929): the unattributed KPI tile lost its box — route it through…
Oct 12, 2026
7521208
chore(#2929): refresh storage-render goldens — per-line prov attribut…
Oct 12, 2026
c20078d
web(#2929): composition moves INSIDE the unattributed tile; chart ban…
Oct 12, 2026
7710825
fix(#2929): let dense charts thin ticks — remove the backwards barW f…
Oct 12, 2026
f17471a
web(#2929): mitigation tip under the post-fold rebuild stat
Oct 12, 2026
e76b35f
web(#2929): de-conflict unattributed-bucket chip colors
Oct 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 2 additions & 44 deletions kernel/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kernel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acp-kernel",
"version": "0.0.119",
"version": "0.0.120",
"description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.",
"license": "MIT",
"author": "ranxianglei",
Expand Down
44 changes: 40 additions & 4 deletions kernel/src/cache-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ export interface PriceProfile {
q?: number;
}

/** #2929: a fold claims not only its first following sample but the whole
* post-fold COLD TAIL — until a warm line proves the provider re-cached or
* this many samples have elapsed (#1847 switch discipline, mirrored for
* folds). Rationale: the first post-fold request (the proxy's re-request)
* is attributed today, but the client-echo re-bill 25–66s later carried no
* fold stamp and fell into the unattributed TTL residual, tripping the
* cache-seam detector with "no fold attribution". Warm hit that retires
* the window (same threshold as the host's WARM_HIT_PCT). */
export const FOLD_CLAIM_WARM_HIT_PCT = 85;
export const FOLD_CLAIM_COLD_ROUNDS = 4;

export interface SampleDecomposition {
missed: number;
newContent: number;
Expand Down Expand Up @@ -331,24 +342,49 @@ export function buildCacheReport(

type Dec = SampleDecomposition & { foldSeq: number | null };
const decs: Dec[] = [];
// #2929: per-fold cold-tail claim state. A fold claims its FIRST following
// sample unconditionally (the materialization re-bill), then keeps claiming
// subsequent cold samples until a warm line (>= FOLD_CLAIM_WARM_HIT_PCT)
// proves re-cache or it has claimed FOLD_CLAIM_COLD_ROUNDS samples. A warm
// sample is never claimed as a continuation (it proves the damage is over).
const foldClaims: number[] = folds.map(() => 0);
const foldRetired: boolean[] = folds.map(() => false);
for (let i = 0; i < samples.length; i++) {
const s = samples[i]!;
const prev = i > 0 ? samples[i - 1]! : null;
const prevAt = prev ? prev.at : Number.NEGATIVE_INFINITY;
const warm = s.input > 0 && hitPct(s.input, s.cached) >= FOLD_CLAIM_WARM_HIT_PCT;
const pending: FoldEvent[] = [];
const pendingIdx: number[] = [];
let pendingBase = 0;
for (let j = 0; j < folds.length; j++) {
const fj = folds[j]!;
if (fj.at <= prevAt) continue;
if (fj.at > s.at) break;
if (pending.length === 0) pendingBase = j;
pending.push(fj);
if (foldRetired[j]) continue;
// First claim is unconditional; a warm continuation proves re-cache and
// is not the fold's damage anymore.
if (foldClaims[j] === 0 || !warm) {
if (pending.length === 0) pendingBase = j;
pending.push(fj);
pendingIdx.push(j);
}
}
const d = decomposeSample(prev, s, pending);
decs.push({
...d,
foldSeq: d.foldIndex !== null ? pendingBase + d.foldIndex + 1 : null,
});
for (const j of pendingIdx) {
foldClaims[j] = foldClaims[j]! + 1;
if (foldClaims[j]! >= FOLD_CLAIM_COLD_ROUNDS) foldRetired[j] = true;
}
// A warm line retires EVERY open window — claimed or not this sample
// (#1847 discipline: it proves the provider re-cached, so a later cold
// blip is a new, unrelated event and must not be swallowed).
if (warm) {
for (let j = 0; j < folds.length; j++) {
if (folds[j]!.at <= s.at) foldRetired[j] = true;
}
}
}

const totals: CacheTotals = {
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export {
buildCacheReport,
computeFoldEconomics,
decomposeSample,
FOLD_CLAIM_COLD_ROUNDS,
FOLD_CLAIM_WARM_HIT_PCT,
formatCacheReport,
summarizeFoldEconomics,
} from "./cache-report.js";
Expand Down
69 changes: 69 additions & 0 deletions kernel/tests/cache-report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
buildCacheReport,
computeFoldEconomics,
decomposeSample,
FOLD_CLAIM_COLD_ROUNDS,
formatCacheReport,
type CacheSample,
type FoldEvent,
Expand Down Expand Up @@ -541,3 +542,71 @@ test("formatCacheReport summary lists every fold when few, with TTL spike idle g
assert.match(text, /#1 .*S=20\.0K.* → (NOT PAID BACK|PAID BACK|\?)/);
assert.ok(!text.includes("more folds omitted"));
});

test("#2929 fold cold-tail claim: the client-echo re-bill is fold-owned until a warm line retires", () => {
// Degenerate head fold (X=3K): proxy re-request (s2) is claimed today, the
// client echo (s3) and the cold recovery tail (s4) must ALSO carry foldSeq —
// before #2929 s3/s4 fell into the unattributed ttlRepay residual and tripped
// the cache-seam detector. A warm line (s5) retires the window; a later cold
// blip (s6, real provider eviction) is NOT swallowed by the old fold.
const samples = [
sample(0, 100_000, 99_000), // warm baseline
sample(1, 51_000, 5_000), // proxy re-request after fold: 9.8%
sample(2, 55_000, 5_100), // client echo re-bill: 9.3%
sample(3, 60_000, 42_000), // recovery: 70% (still < 85 warm line)
sample(4, 65_000, 60_000), // warm: 92% — retires the claim window
sample(5, 66_000, 30_000), // unrelated later cold blip: 45%
];
const folds: FoldEvent[] = [
{ at: T0 + 0.5 * min, tokensCompressed: 50_000, firstFoldStartTokens: 3_000, viewBefore: 100_000, viewAfter: 50_500 },
];
const r = buildCacheReport(samples, folds);
const [, s2, s3, s4, s5, s6] = r.lines;
assert.equal(s2!.foldSeq, 1, "re-request claimed (first claim, unconditional)");
assert.equal(s2!.compRepay, 46_000);
assert.equal(s3!.foldSeq, 1, "client-echo re-bill claimed (#2929)");
assert.equal(s3!.compRepay, 45_900);
assert.equal(s3!.ttlRepay, 0, "echo residual no longer lands in the unattributed bucket");
assert.equal(s4!.foldSeq, 1, "cold recovery tail claimed");
assert.equal(s4!.compRepay, 13_000);
assert.equal(s5!.foldSeq, null, "warm line is never claimed as a continuation");
assert.equal(s5!.compRepay, 0);
assert.equal(s6!.foldSeq, null, "window closed — later cold blip is NOT the fold's");
assert.equal(s6!.ttlRepay, 35_000, "blip falls to the unattributed residual");
assert.equal(r.totals.ttlRepay, 36_000, "1K baseline residual + the 35K post-window blip");
assert.equal(r.folds[0]!.T, 46_000 + 45_900 + 13_000, "fold economics absorb the full cold tail");
});

test("#2929 fold cold-tail claim: FOLD_CLAIM_COLD_ROUNDS bounds the window without a warm line", () => {
const samples = [
sample(0, 100_000, 99_000),
sample(1, 51_000, 5_000),
sample(2, 52_000, 5_100),
sample(3, 53_000, 5_200),
sample(4, 54_000, 5_300),
sample(5, 55_000, 5_400), // 5th post-fold sample: window exhausted
];
const folds: FoldEvent[] = [
{ at: T0 + 0.5 * min, tokensCompressed: 50_000, firstFoldStartTokens: 3_000, viewBefore: 100_000, viewAfter: 50_500 },
];
const r = buildCacheReport(samples, folds);
const claimCount = r.lines.filter((l) => l.foldSeq === 1).length;
assert.equal(claimCount, FOLD_CLAIM_COLD_ROUNDS, "exactly the bound — never an open-ended claim");
assert.equal(r.lines[5]!.foldSeq, null);
assert.ok(r.lines[5]!.ttlRepay > 0, "post-window residual is unattributed again");
});

test("#2929 fold cold-tail claim: a warm FIRST post-fold sample claims once and retires", () => {
const samples = [
sample(0, 100_000, 99_000),
sample(1, 51_000, 50_000), // 98% warm immediately after a tiny fold
sample(2, 52_000, 20_000), // later cold blip must not be swallowed
];
const folds: FoldEvent[] = [
{ at: T0 + 0.5 * min, tokensCompressed: 5_000, firstFoldStartTokens: 3_000, viewBefore: 100_000, viewAfter: 95_500 },
];
const r = buildCacheReport(samples, folds);
assert.equal(r.lines[1]!.foldSeq, 1, "first claim is unconditional even on a warm line");
assert.equal(r.lines[2]!.foldSeq, null, "retired by the warm first sample");
assert.ok(r.lines[2]!.ttlRepay > 0);
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading