From 6860b8e92ed75c2493c0ce5a504c25234ea611d3 Mon Sep 17 00:00:00 2001 From: ci-check Date: Tue, 10 Nov 2026 22:15:48 +0800 Subject: [PATCH 1/5] kernel: bound the fold-gated orphan sweep window at the commit-time ref frontier (#6116) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #3769 fold-gated orphan sweep removed failed compress calls at/after the pending fold's earliest start ref with no upper bound, so a failure issued in the SAME assistant turn AFTER the successful compress call (mixed multi-tool turns) was wiped on the next pass too — destroying fresh error feedback the model needs to react correctly (the exact pathology #3769 exists to prevent). applyCompression now also records pendingOrphanSweepMaxRef = highestUsedIndex of the ref map at commit time: the successful call and any later same-turn calls only get refs strictly above that frontier on the next assignRefs pass, so they stay out of the sweep. Across folds committing before one consuming turn the markers accumulate (running MIN / running MAX). The hide node consumes both one-shot; sync-blocks, cloneState and hydration carry the new field. States written before this change lack the max bound and keep the pre-fix unbounded behavior (upgrade compat, pinned by test). kernel-change: issue #6116 requests exactly this behavior; owner filed the issue, in-thread decision B confirmed (mechanism fix only, no prompt change). --- kernel/package.json | 2 +- kernel/src/compress.ts | 17 + kernel/src/hide-consumed.ts | 24 +- kernel/src/sync.ts | 1 + kernel/src/types.ts | 13 + kernel/tests/issue6116-sweep-window.test.ts | 325 ++++++++++++++++++++ package-lock.json | 2 +- 7 files changed, 376 insertions(+), 8 deletions(-) create mode 100644 kernel/tests/issue6116-sweep-window.test.ts diff --git a/kernel/package.json b/kernel/package.json index d5c9064802..28b6e78c3b 100644 --- a/kernel/package.json +++ b/kernel/package.json @@ -1,6 +1,6 @@ { "name": "acp-kernel", - "version": "0.0.192", +"version": "0.0.193", "description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.", "license": "MIT", "author": "ranxianglei", diff --git a/kernel/src/compress.ts b/kernel/src/compress.ts index 2956d7b607..1b945d7e51 100644 --- a/kernel/src/compress.ts +++ b/kernel/src/compress.ts @@ -920,6 +920,20 @@ export function createCore(ports: Ports = {}): CompressionCore { state.pendingOrphanSweepMinRef === undefined ? foldStartRef : Math.min(state.pendingOrphanSweepMinRef, foldStartRef); + // #6116: upper bound of the same window. Every message in history at + // apply time carries a ref <= this frontier; the successful call and + // any later same-turn calls only get refs on the next assignRefs pass, + // so they land strictly above it and survive the sweep with their + // failure feedback intact (under-sweep is safe; over-sweep is not). + // Running MAX mirrors the min side's running MIN across folds that + // commit before one consuming turn. + const frontier = highestUsedIndex(state.messageRefs); + if (frontier > 0) { + state.pendingOrphanSweepMaxRef = + state.pendingOrphanSweepMaxRef === undefined + ? frontier + : Math.max(state.pendingOrphanSweepMaxRef, frontier); + } } // Compress succeeded: clear the growth baseline so the next turn // re-establishes it at the new (lower) token count. Without this the @@ -1446,6 +1460,8 @@ const hideCompressCallsNode: PipelineNode = { const patch: Partial = { hiddenOrphanRefs: hidden.hiddenOrphanRefs, pendingOrphanSweepMinRef: undefined, + // #6116: the window bound is one-shot with the marker it bounds. + pendingOrphanSweepMaxRef: undefined, }; if (hidden.newlySweptCallIds.length > 0) { patch.sweptOrphanCallIds = [ @@ -2633,6 +2649,7 @@ function cloneState(state: CompressionState): CompressionState { ? [...state.sweptOrphanCallIds] : undefined, pendingOrphanSweepMinRef: state.pendingOrphanSweepMinRef, + pendingOrphanSweepMaxRef: state.pendingOrphanSweepMaxRef, // #6116 (sweep window upper bound) deadRefs: state.deadRefs ? [...state.deadRefs] : undefined, lastPassIds: state.lastPassIds ? [...state.lastPassIds] : undefined, // #4797: the one-time ledger-alignment gate must survive the fold clone diff --git a/kernel/src/hide-consumed.ts b/kernel/src/hide-consumed.ts index fd62ef7585..f251212613 100644 --- a/kernel/src/hide-consumed.ts +++ b/kernel/src/hide-consumed.ts @@ -10,11 +10,14 @@ import type { CompressionState, CoreMessage } from "./types.js"; // (billion-context-pi #9: 3,849 identical calls over 5h13m under keep=0), AND a // quiet turn must never move the cached prefix breakpoint forward just to delete // a few hundred chars of old failure residue — the old keep-last-two rotation did -// exactly that (hid the oldest failure on EVERY turn, seam cost far exceeding the -// bytes removed). Now: between folds nothing is swept; on a fold the node sweeps -// orphans at/after the fold's earliest start ref onto the persistent -// sweptOrphanCallIds set (they stay hidden forever), leaving orphans before it -// visible. Residue is bounded by fold cadence, not a fixed pair count. + // exactly that (hid the oldest failure on EVERY turn, seam cost far exceeding the + // bytes removed). Now: between folds nothing is swept; on a fold the node sweeps + // orphans at/after the fold's earliest start ref — and at/before the highest ref + // allocated when that fold committed (#6116: the successful call and any later + // same-turn calls get refs above that frontier and keep their failure feedback + // visible) — onto the persistent sweptOrphanCallIds set (they stay hidden + // forever), leaving orphans outside the window visible. Residue is bounded by + // fold cadence, not a fixed pair count. export interface HideConsumedResult { messages: CoreMessage[]; @@ -319,8 +322,15 @@ export function hideConsumedCompressCalls( // fold pending nothing new is swept, so a quiet turn never breaks the prefix. // Orphans quoting an ACTIVE block's folded range are that block's summary // carrier (#1567) and are exempt from the sweep (quotesActiveBlock). + // #6116: the window is bounded above by pendingOrphanSweepMaxRef — the highest + // allocated ref when the pending fold committed. The successful call and any + // same-turn calls after it only get refs above that frontier, so their failure + // feedback must stay visible for the model to react to; sweeping them would be + // over-sweep (under-sweep is safe, over-sweep is not). States written before + // #6116 lack the max bound and keep the pre-fix unbounded behavior. const sweptSet = new Set(state.sweptOrphanCallIds ?? []); const foldMinRef = state.pendingOrphanSweepMinRef; + const foldMaxRef = state.pendingOrphanSweepMaxRef; const newlySweptCallIds: string[] = []; const keepCallIds = new Set(); @@ -346,7 +356,9 @@ export function hideConsumedCompressCalls( hide = true; } else if (foldMinRef !== undefined && !quotesActiveBlock(messages[i]!.text, activeRangeKeys)) { const num = refNum(ref); - if (num !== null && num >= foldMinRef) { + // #6116: window is [foldMinRef, foldMaxRef]; a missing max bound + // (pre-#6116 state) degrades to the pre-fix unbounded sweep. + if (num !== null && num >= foldMinRef && (foldMaxRef === undefined || num <= foldMaxRef)) { hide = true; newlySweptCallIds.push(callId); } diff --git a/kernel/src/sync.ts b/kernel/src/sync.ts index 5565d84cc9..a243baa474 100644 --- a/kernel/src/sync.ts +++ b/kernel/src/sync.ts @@ -84,6 +84,7 @@ export function syncBlocks( hiddenOrphanRefs: state.hiddenOrphanRefs ? [...state.hiddenOrphanRefs] : undefined, sweptOrphanCallIds: state.sweptOrphanCallIds ? [...state.sweptOrphanCallIds] : undefined, pendingOrphanSweepMinRef: state.pendingOrphanSweepMinRef, + pendingOrphanSweepMaxRef: state.pendingOrphanSweepMaxRef, // #6116 (sweep window upper bound) // #3939 ③: the truncation latch must survive the sync node — dropping it // here would re-expose clipped bytes mid-history after a sync carried the // rest of the state (#3691 oscillation via the sync path). diff --git a/kernel/src/types.ts b/kernel/src/types.ts index 7d4daaf365..6d83779263 100644 --- a/kernel/src/types.ts +++ b/kernel/src/types.ts @@ -340,6 +340,19 @@ export interface CompressionState { * Carries the position so the sweep is cache-neutral: it only removes records * the fold already invalidated. Optional: absent until the first post-fix fold. */ pendingOrphanSweepMinRef?: number; + /** UPPER bound of the same pending orphan-sweep window (#6116): the highest + * allocated m-ref at the moment the most recent pending fold committed + * (highestUsedIndex of messageRefs in applyCompression). Every message that + * was already in history then carries a ref <= this value; the successful + * compress call itself and anything issued after it (mixed multi-tool turns) + * only gets a ref on the NEXT assignRefs pass — strictly above it — so it + * stays out of the sweep and its failure feedback remains visible for the + * model to react to. Consumed together with pendingOrphanSweepMinRef (the + * sweep condition becomes min <= refNum <= max). Across several folds that + * commit before one consuming turn it keeps the running MAX, mirroring the + * min side's running MIN. Optional: states written before #6116 lack it, and + * a missing max degrades to the pre-fix unbounded sweep (upgrade compat). */ + pendingOrphanSweepMaxRef?: number; /** Emergency-truncation latch (#3939 ③/#3691): the clipped texts (post-clip * bytes, keyed by padded ref) of messages clipped by the emergency-truncate * node. The watermark decision is made ONCE — replaying these clips on every diff --git a/kernel/tests/issue6116-sweep-window.test.ts b/kernel/tests/issue6116-sweep-window.test.ts new file mode 100644 index 0000000000..6700c6b48d --- /dev/null +++ b/kernel/tests/issue6116-sweep-window.test.ts @@ -0,0 +1,325 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { createCore } from "../src/compress.js"; +import { assignRefs } from "../src/refs.js"; +import { hideConsumedCompressCalls } from "../src/hide-consumed.js"; +import { createInitialState } from "../src/state.js"; +import type { CompressionState, Config, CoreMessage } from "../src/types.js"; + +// #6116 regression: the fold-gated orphan sweep (#3769) is bounded by a WINDOW — +// [earliest covered ref of the pending fold, highest ref allocated when it committed]. +// The successful compress call and any same-turn calls issued after it only receive +// refs above that frontier, so their failure feedback must survive the sweep: wiping +// fresh error text would push the model straight back into re-issuing the same no-op +// compress (the pathology #3769 exists to prevent). Under-sweep is safe; over-sweep +// is not. States written before #6116 lack the max bound and keep the pre-fix +// unbounded behavior (upgrade compat). + +const isMcp = (n: string) => n === "compress" || n === "mcp__bili__compress"; + +function msg(id: string, text: string): CoreMessage { + return { id, role: "user", contentType: "text", text }; +} + +function failPair(callId: string): [CoreMessage, CoreMessage] { + return [ + { + id: `c-${callId}`, + role: "assistant", + contentType: "tool-call", + toolName: "mcp__bili__compress", + toolCallId: callId, + text: JSON.stringify({ content: [{ startId: "mA", endId: "mB", summary: "s" }] }), + }, + { + id: `r-${callId}`, + role: "tool", + contentType: "tool-result", + toolCallId: callId, + text: "nothing to compress", + }, + ]; +} + +function seqRefs(state: CompressionState, messages: CoreMessage[]): void { + messages.forEach((m, i) => { + state.messageRefs.byRaw[m.id] = `m${String(i + 1).padStart(5, "0")}`; + }); +} + +function config(): Config { + return { + tiers: { enabled: true, tier2Trigger: 5, tier3Trigger: 10 }, + nudge: { + maxContextLimitPct: 0.55, + minContextLimitPct: 0.45, + frequency: 5, + iterationThreshold: 15, + force: "soft", + growthRatio: 0.05, + growthFloor: 6000, + growthCap: 50000, + minGrowthFloor: 5000, + minGrowthRatio: 0.45, + emergencyThresholdPct: 0.98, + }, + promotionThreshold: 5, + truncate: { threshold: 1 }, + merge: { maxSummaryLength: 3000, minOldGenBlocks: 3 }, + compress: { minCompressRange: 0, maxSummaryLength: 0, minSummaryLength: 0 }, + protectedTools: [], + preserveRecentMessages: 0, + preserveRecentTokens: 0, + modelContextLimit: 100000, + }; +} + +// refs: p1=1 c-f1=2 r-f1=3 p2=4 c-f2=5 r-f2=6 p3=7 c-f3=8 r-f3=9 p4=10 c-f4=11 r-f4=12 +function windowLayout(): { state: CompressionState; messages: CoreMessage[] } { + const state = createInitialState(); + const messages: CoreMessage[] = []; + messages.push(msg("p1", "early")); + messages.push(...failPair("f1")); + messages.push(msg("p2", "mid")); + messages.push(...failPair("f2")); + messages.push(msg("p3", "late")); + messages.push(...failPair("f3")); + messages.push(msg("p4", "later")); + messages.push(...failPair("f4")); + seqRefs(state, messages); + return { state, messages }; +} + +test("the sweep window is inclusive on both ends: inside swept, outside visible (#6116)", () => { + const { state, messages } = windowLayout(); + state.pendingOrphanSweepMinRef = 5; + state.pendingOrphanSweepMaxRef = 9; + + const r = hideConsumedCompressCalls(state, messages, isMcp); + assert.deepEqual(r.newlySweptCallIds, ["f2", "f3"], "only orphans inside [min,max] swept"); + const ids = r.messages.map((m) => m.id); + assert.ok(ids.includes("c-f1"), "orphan below min stays visible (still-cached prefix)"); + assert.ok(!ids.includes("c-f2") && !ids.includes("c-f3"), "in-window orphans removed"); + assert.ok(ids.includes("c-f4"), "orphan above max stays visible (fresh failure feedback)"); + + // Endpoint inclusivity, one side each. + const lo = createInitialState(); + seqRefs(lo, messages); + lo.pendingOrphanSweepMinRef = 5; + lo.pendingOrphanSweepMaxRef = 5; + assert.deepEqual( + hideConsumedCompressCalls(lo, messages, isMcp).newlySweptCallIds, + ["f2"], + "lower endpoint inclusive", + ); + const hi = createInitialState(); + seqRefs(hi, messages); + hi.pendingOrphanSweepMinRef = 8; + hi.pendingOrphanSweepMaxRef = 8; + assert.deepEqual( + hideConsumedCompressCalls(hi, messages, isMcp).newlySweptCallIds, + ["f3"], + "upper endpoint inclusive", + ); +}); + +test("a legacy state without the max bound degrades to the pre-fix unbounded sweep (#6116 upgrade compat)", () => { + const { state, messages } = windowLayout(); + state.pendingOrphanSweepMinRef = 5; + // pendingOrphanSweepMaxRef absent: exactly the shape of states written before #6116. + + const r = hideConsumedCompressCalls(state, messages, isMcp); + assert.deepEqual( + r.newlySweptCallIds, + ["f2", "f3", "f4"], + "min-only marker keeps the #3769 unbounded-at/after behavior", + ); +}); + +test("a max bound without a min marker sweeps nothing (defensive invariant, #6116)", () => { + const { state, messages } = windowLayout(); + state.pendingOrphanSweepMaxRef = 12; + // Cannot arise in practice — applyCompression sets both markers together — but + // the guard order must make a stray max inert rather than an all-history sweep. + + const r = hideConsumedCompressCalls(state, messages, isMcp); + assert.equal(r.hidden, 0, "no min marker -> no sweep"); + assert.equal(r.newlySweptCallIds.length, 0, "stray max bound is inert"); +}); + +test("a real fold writes BOTH markers: min = earliest covered ref, max = commit-time frontier (#6116)", () => { + const core = createCore(); + const messages: CoreMessage[] = [ + msg("h1", "first detailed work item alpha content"), + msg("h2", "second detailed work item beta content"), + msg("h3", "third detailed work item gamma content"), + ...failPair("f1"), + msg("h4", "fourth detailed work item delta content"), + msg("last", "latest user intent theta"), + ]; + // refs: h1=1 h2=2 h3=3 c-f1=4 r-f1=5 h4=6 last=7 + const state = createInitialState(); + state.messageRefs = assignRefs(messages, { + existing: state.messageRefs, + nextIndex: 1, + }).map; + + const out = core.applyCompression({ + ranges: [{ startRef: "m00001", endRef: "m00003", summary: "fold the spent head", topic: "head" }], + messages, + state, + config: config(), + }); + assert.equal(out.result.errors.length, 0, `unexpected errors: ${out.result.errors.join("; ")}`); + assert.ok(out.result.blocksCreated >= 1, "the head genuinely folds"); + assert.equal(out.state.pendingOrphanSweepMinRef, 1, "min marker points at the fold's earliest start ref"); + assert.equal(out.state.pendingOrphanSweepMaxRef, 7, "max marker is the highest allocated ref at commit time"); +}); + +test("a failure issued after the successful call keeps its feedback visible (mixed multi-tool turn, #6116)", () => { + // THE issue scenario: the model fires several tools in one assistant turn. The + // request history the fold applies to ends BEFORE the response's calls land; the + // successful call and any later same-turn failures only get refs on the next + // assignRefs pass — strictly above the committed frontier — so they must stay + // out of the sweep while the pre-success residue inside the window goes away. + const core = createCore(); + const requestHistory: CoreMessage[] = [ + msg("h1", "first detailed work item alpha content"), + msg("h2", "second detailed work item beta content"), + msg("h3", "third detailed work item gamma content"), + ...failPair("f1"), + msg("h4", "fourth detailed work item delta content"), + msg("last", "latest user intent theta"), + ]; + const state = createInitialState(); + state.messageRefs = assignRefs(requestHistory, { + existing: state.messageRefs, + nextIndex: 1, + }).map; + + const out = core.applyCompression({ + ranges: [ + { startRef: "m00001", endRef: "m00003", summary: "fold the spent head", topic: "head", compressCallId: "s1" }, + ], + messages: requestHistory, + state, + config: config(), + }); + assert.equal(out.result.errors.length, 0, `unexpected errors: ${out.result.errors.join("; ")}`); + assert.equal(out.state.pendingOrphanSweepMaxRef, 7, "frontier frozen at apply time"); + + // The response then rides the history: success s1 (the block's carrier) plus a + // fresh failure fAfter issued in the same turn. + const extended: CoreMessage[] = [ + ...requestHistory, + { + id: "c-s1", + role: "assistant", + contentType: "tool-call", + toolName: "mcp__bili__compress", + toolCallId: "s1", + text: JSON.stringify({ content: [{ startId: "m00001", endId: "m00003", summary: "fold the spent head" }] }), + }, + { + id: "r-s1", + role: "tool", + contentType: "tool-result", + toolCallId: "s1", + text: "compressed the head", + }, + ...failPair("fAfter"), + ]; + out.state.messageRefs = assignRefs(extended, { + existing: out.state.messageRefs, + nextIndex: 8, + }).map; + // c-s1=8 r-s1=9 c-fAfter=10 r-fAfter=11 — all strictly above the frontier. + + const r = hideConsumedCompressCalls(out.state, extended, isMcp); + assert.deepEqual(r.newlySweptCallIds, ["f1"], "only the pre-success failure inside the window is swept"); + const ids = r.messages.map((m) => m.id); + assert.ok(ids.includes("c-fAfter") && ids.includes("r-fAfter"), "post-success failure stays visible for the model to react to"); + assert.ok(ids.includes("c-s1"), "the active success carrier is untouched"); +}); + +test("two folds before one consuming turn: running min + running max define the union window (#6116)", () => { + const core = createCore(); + const m1: CoreMessage[] = [ + msg("h1", "first detailed work item alpha content"), + msg("h2", "second detailed work item beta content"), + msg("h3", "third detailed work item gamma content"), + ...failPair("f1"), + msg("h4", "fourth detailed work item delta content"), + msg("last", "latest user intent theta"), + ]; + // refs: h1=1 h2=2 h3=3 c-f1=4 r-f1=5 h4=6 last=7 + const state = createInitialState(); + state.messageRefs = assignRefs(m1, { existing: state.messageRefs, nextIndex: 1 }).map; + + const first = core.applyCompression({ + ranges: [{ startRef: "m00001", endRef: "m00003", summary: "fold the head", topic: "head" }], + messages: m1, + state, + config: config(), + }); + assert.equal(first.result.errors.length, 0, `unexpected errors: ${first.result.errors.join("; ")}`); + assert.equal(first.state.pendingOrphanSweepMinRef, 1, "first fold: min=1"); + assert.equal(first.state.pendingOrphanSweepMaxRef, 7, "first fold: max=7"); + + // Next request appends two messages and folds the tail — no consuming turn in + // between, so the markers accumulate instead of resetting. + const m2: CoreMessage[] = [ + ...m1, + msg("p5", "fifth detailed work item epsilon content"), + msg("p6", "sixth detailed work item zeta content"), + ]; + first.state.messageRefs = assignRefs(m2, { existing: first.state.messageRefs, nextIndex: 8 }).map; + // p5=8 p6=9 + const second = core.applyCompression({ + ranges: [{ startRef: "m00006", endRef: "m00009", summary: "fold the tail", topic: "tail" }], + messages: m2, + state: first.state, + config: config(), + }); + assert.equal(second.result.errors.length, 0, `unexpected errors: ${second.result.errors.join("; ")}`); + assert.ok(second.result.blocksCreated >= 1, "the tail genuinely folds"); + assert.equal(second.state.pendingOrphanSweepMinRef, 1, "running MIN keeps the earliest fold start"); + assert.equal(second.state.pendingOrphanSweepMaxRef, 9, "running MAX tracks the newest frontier"); + + const r = hideConsumedCompressCalls(second.state, m2, isMcp); + assert.deepEqual(r.newlySweptCallIds, ["f1"], "union window [1,9] sweeps the pre-fold orphan once"); +}); + +test("the full pipeline carries the max bound and consumes BOTH markers one-shot (#6116)", () => { + const core = createCore(); + const messages: CoreMessage[] = [ + msg("p1", "early cached prefix alpha"), + ...failPair("f2"), + msg("p2", "mid detailed work item beta content"), + ...failPair("f3"), + ]; + const state = createInitialState(); + seqRefs(state, messages); + // refs: p1=1 c-f2=2 r-f2=3 p2=4 c-f3=5 r-f3=6 — a fold covering refs 2..3 + // committed last turn. Without the sync-blocks carry of the NEW field the max + // would die on the first pipeline node and degrade to the unbounded sweep, + // wrongly taking f3 (ref 5 > intended max 3). + state.pendingOrphanSweepMinRef = 2; + state.pendingOrphanSweepMaxRef = 3; + + const cfg = { ...config(), isCompressTool: isMcp }; + const turn = core.processTurn({ + messages, + state, + config: cfg, + tokenCount: 1000, + renderTags: "none", + }); + + const ids = turn.messages.map((m) => m.id); + assert.ok(!ids.includes("c-f2") && !ids.includes("r-f2"), "orphan inside the window swept inside the pipeline"); + assert.ok(ids.includes("c-f3") && ids.includes("r-f3"), "orphan above the carried max bound stays visible"); + assert.deepEqual(turn.state.sweptOrphanCallIds, ["f2"], "swept id folded into the persistent set"); + assert.equal(turn.state.pendingOrphanSweepMinRef, undefined, "min marker consumed one-shot"); + assert.equal(turn.state.pendingOrphanSweepMaxRef, undefined, "max marker consumed one-shot"); +}); diff --git a/package-lock.json b/package-lock.json index 206ead55ad..2371dc918f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ }, "kernel": { "name": "acp-kernel", - "version": "0.0.192", +"version": "0.0.193", "dev": true, "license": "MIT", "devDependencies": { From 687c400deae99bbe7601924b1ded248dd019be67 Mon Sep 17 00:00:00 2001 From: ci-check Date: Tue, 10 Nov 2026 22:15:48 +0800 Subject: [PATCH 2/5] fix: hydrate the orphan-sweep window upper bound across restarts (#6116) mergeState() is the single source of truth for persisted CompressionState fields (#4192); add pendingOrphanSweepMaxRef to its literal so the transient window bound survives the unified round-trip like its min counterpart, and pin the round-trip in the storage field test. --- src/state-hydration.ts | 3 +++ tests/storage-state-fields.test.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/state-hydration.ts b/src/state-hydration.ts index 8bd9b10b4d..7fee18a9c1 100644 --- a/src/state-hydration.ts +++ b/src/state-hydration.ts @@ -64,6 +64,9 @@ export function mergeState(parsed: CompressionState): CompressionState { // transient, losing it only defers the sweep to the next fold. sweptOrphanCallIds: parsed.sweptOrphanCallIds ?? fresh.sweptOrphanCallIds, pendingOrphanSweepMinRef: parsed.pendingOrphanSweepMinRef ?? fresh.pendingOrphanSweepMinRef, + // #6116: the window's upper bound is transient like the min marker; + // losing it only degrades to the pre-fix unbounded sweep (safe side). + pendingOrphanSweepMaxRef: parsed.pendingOrphanSweepMaxRef ?? fresh.pendingOrphanSweepMaxRef, // #3939 ③/#3691: the emergency-truncate latch must survive hydration — // dropping it re-exposes clipped bytes mid-history after a restart, // rewriting the still-cached prefix on the first post-restart turn. diff --git a/tests/storage-state-fields.test.ts b/tests/storage-state-fields.test.ts index 501daeab1a..beb74be4fc 100644 --- a/tests/storage-state-fields.test.ts +++ b/tests/storage-state-fields.test.ts @@ -25,6 +25,8 @@ test("#4192: sweptOrphanCallIds / pendingOrphanSweepMinRef survive the unified r ...createInitialState(), sweptOrphanCallIds: ["m00042", "m00043"], pendingOrphanSweepMinRef: 42, + // #6116: the window's upper bound rides the same derived field list. + pendingOrphanSweepMaxRef: 43, }; const legacy = { id: "sf-1", @@ -51,6 +53,7 @@ test("#4192: sweptOrphanCallIds / pendingOrphanSweepMinRef survive the unified r // The two fields the hand list dropped (#4192) must round-trip intact. assert.deepEqual((view.state as Record).sweptOrphanCallIds, ["m00042", "m00043"]); assert.equal((view.state as Record).pendingOrphanSweepMinRef, 42); + assert.equal((view.state as Record).pendingOrphanSweepMaxRef, 43); // #6116 store.close(); } finally { rmSync(dir, { recursive: true, force: true }); From 61b7663623d79a63e65d9b0315b926e8407c882c Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 11 Nov 2026 04:09:05 +0800 Subject: [PATCH 3/5] docs: clarify max-bound hydration degradation is upgrade compat, not safe-side --- src/state-hydration.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/state-hydration.ts b/src/state-hydration.ts index 7fee18a9c1..4fa735d2b1 100644 --- a/src/state-hydration.ts +++ b/src/state-hydration.ts @@ -65,7 +65,9 @@ export function mergeState(parsed: CompressionState): CompressionState { sweptOrphanCallIds: parsed.sweptOrphanCallIds ?? fresh.sweptOrphanCallIds, pendingOrphanSweepMinRef: parsed.pendingOrphanSweepMinRef ?? fresh.pendingOrphanSweepMinRef, // #6116: the window's upper bound is transient like the min marker; - // losing it only degrades to the pre-fix unbounded sweep (safe side). + // states written before #6116 lack it and keep the pre-fix unbounded + // sweep for that one pending window (upgrade compat, pinned by + // kernel/tests/issue6116-sweep-window.test.ts). pendingOrphanSweepMaxRef: parsed.pendingOrphanSweepMaxRef ?? fresh.pendingOrphanSweepMaxRef, // #3939 ③/#3691: the emergency-truncate latch must survive hydration — // dropping it re-exposes clipped bytes mid-history after a restart, From 2a2fd9ef34d74d8af5a99d33a582c1afa4fafd86 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 11 Nov 2026 23:57:05 +0800 Subject: [PATCH 4/5] fix(ci): sync lockfiles to the 0.0.193 kernel bump (lock-sync red) kernel/package.json was bumped 0.0.192 -> 0.0.193 but its own package-lock.json was left at 0.0.192, and the version line in both lockfiles lost its indentation. npm install --package-lock-only re-normalizes all of it, so git diff --exit-code went red. - kernel/package-lock.json: 0.0.192 -> 0.0.193 (top-level + packages.""), matching the already-declared kernel bump in this PR. - package-lock.json: restore canonical 6-space indent on the acp-kernel version line (content unchanged). --- kernel/package-lock.json | 4 ++-- package-lock.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/package-lock.json b/kernel/package-lock.json index faf2a36220..616a2835a4 100644 --- a/kernel/package-lock.json +++ b/kernel/package-lock.json @@ -1,12 +1,12 @@ { "name": "acp-kernel", - "version": "0.0.192", + "version": "0.0.193", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "acp-kernel", - "version": "0.0.192", + "version": "0.0.193", "license": "MIT", "devDependencies": { "@types/node": "^22.0.0", diff --git a/package-lock.json b/package-lock.json index 2371dc918f..c5d1dc20ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ }, "kernel": { "name": "acp-kernel", -"version": "0.0.193", + "version": "0.0.193", "dev": true, "license": "MIT", "devDependencies": { From 227d45eb8f93371e620b6d21969c0f033dc0d61f Mon Sep 17 00:00:00 2001 From: ci-check Date: Thu, 12 Nov 2026 10:40:50 +0800 Subject: [PATCH 5/5] test: regenerate storage-render goldens for the #6116 sweep-window bound key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #6116 adds pendingOrphanSweepMaxRef to the persisted CompressionState (kernel/src/compress.ts, sync.ts, types.ts; hydrated in src/state-hydration.ts). The four storage-render goldens pre-date that key, so the per-top-level-state-key digest pin (stateKeyDigests) now sees one new entry. In the scripted golden scenario the value is undefined (the one-shot window bound is consumed together with its fold marker), so the entry carries the shared "null" digest 74234e98afe7498f and no other field changes — stateDigest, section digests, per-turn wire digests and state shape are all byte-identical. Net diff: one added line per wire. Regen: node --import tsx scripts/update-storage-render-goldens.ts --- tests/golden/storage-render/anthropic.json | 1 + tests/golden/storage-render/chat.json | 1 + tests/golden/storage-render/google.json | 1 + tests/golden/storage-render/responses.json | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/golden/storage-render/anthropic.json b/tests/golden/storage-render/anthropic.json index 558829d15d..6b469d64b7 100644 --- a/tests/golden/storage-render/anthropic.json +++ b/tests/golden/storage-render/anthropic.json @@ -121,6 +121,7 @@ "rules": "4f53cda18c2baa0c", "sweptOrphanCallIds": "74234e98afe7498f", "pendingOrphanSweepMinRef": "74234e98afe7498f", + "pendingOrphanSweepMaxRef": "74234e98afe7498f", "emergencyTruncateLatch": "74234e98afe7498f", "renderDeferredRefs": "74234e98afe7498f", "viewLatches": "74234e98afe7498f", diff --git a/tests/golden/storage-render/chat.json b/tests/golden/storage-render/chat.json index e0f1b4aa96..802070673e 100644 --- a/tests/golden/storage-render/chat.json +++ b/tests/golden/storage-render/chat.json @@ -121,6 +121,7 @@ "rules": "4f53cda18c2baa0c", "sweptOrphanCallIds": "74234e98afe7498f", "pendingOrphanSweepMinRef": "74234e98afe7498f", + "pendingOrphanSweepMaxRef": "74234e98afe7498f", "emergencyTruncateLatch": "74234e98afe7498f", "renderDeferredRefs": "74234e98afe7498f", "viewLatches": "74234e98afe7498f", diff --git a/tests/golden/storage-render/google.json b/tests/golden/storage-render/google.json index 3dde0e8cdc..a6c4146379 100644 --- a/tests/golden/storage-render/google.json +++ b/tests/golden/storage-render/google.json @@ -121,6 +121,7 @@ "rules": "4f53cda18c2baa0c", "sweptOrphanCallIds": "74234e98afe7498f", "pendingOrphanSweepMinRef": "74234e98afe7498f", + "pendingOrphanSweepMaxRef": "74234e98afe7498f", "emergencyTruncateLatch": "74234e98afe7498f", "renderDeferredRefs": "74234e98afe7498f", "viewLatches": "74234e98afe7498f", diff --git a/tests/golden/storage-render/responses.json b/tests/golden/storage-render/responses.json index c9aa385f1a..2d8f5bc830 100644 --- a/tests/golden/storage-render/responses.json +++ b/tests/golden/storage-render/responses.json @@ -121,6 +121,7 @@ "rules": "4f53cda18c2baa0c", "sweptOrphanCallIds": "74234e98afe7498f", "pendingOrphanSweepMinRef": "74234e98afe7498f", + "pendingOrphanSweepMaxRef": "74234e98afe7498f", "emergencyTruncateLatch": "74234e98afe7498f", "renderDeferredRefs": "74234e98afe7498f", "viewLatches": "74234e98afe7498f",