From be32872243e94d1d72394b89ad3ca7916c8aa363 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 4 Nov 2026 19:18:37 +0800 Subject: [PATCH 01/10] kernel: record nested-fold lineage via supersedes_block_id (#5667) The sole consumption point (applySingleRange) now stamps each consumed child block with the consuming block's id, so an inactive block's death-cause (consumed-by-parent vs orphan-GC vs host-expand) is readable instead of requiring reverse-scanning every active block's directBlockIds. Non-consumptive deactivation paths leave the field unset. ingest.ts forwards the value instead of hardcoding null; export.ts already had the conditional export branch. Adds supersedesBlockId?: string to CompressionBlock and the display-only crossesCoveredBy?: string[] hook on CompressibleRange (used by the span-annotation commit). --- kernel/src/compress.ts | 8 +++++++- kernel/src/types.ts | 15 +++++++++++++++ src/storage/ingest.ts | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/kernel/src/compress.ts b/kernel/src/compress.ts index b23e4cdeb4..e3b18032ea 100644 --- a/kernel/src/compress.ts +++ b/kernel/src/compress.ts @@ -1835,7 +1835,13 @@ function applySingleRange(input: SingleRangeInput): SingleRangeOutcome { for (const consumedId of consumedBlockIds) { const consumed = blockById(input.state, consumedId); - if (consumed) consumed.active = false; + if (consumed) { + // #5667 A: lineage written ONLY here (consumption). Non-consumptive + // deactivation (orphan GC / host expand in sync.ts) must leave it unset — + // that absence is what keeps the death cause discriminable. + consumed.active = false; + consumed.supersedesBlockId = blockId; + } } return { tokens: compressedTokens, warnings }; diff --git a/kernel/src/types.ts b/kernel/src/types.ts index c26b5a4949..bf1910fa07 100644 --- a/kernel/src/types.ts +++ b/kernel/src/types.ts @@ -107,6 +107,12 @@ export interface CompressionBlock { * Undefined = unstamped traffic or provably-loose coverage; never guessed. */ startSeq?: number; endSeq?: number; + /** #5667 defect A: the id of the block that CONSUMED this one (nested fold). + * Written only at the single consumption point (compress.ts); non-consumptive + * deactivation (orphan GC / host expand) leaves it unset, which is exactly + * what makes an inactive block's death cause readable. Optional: states + * persisted before this field exist read as "no lineage recorded". */ + supersedesBlockId?: string; } /** A compression block's current ref span, pre-resolved for display. */ @@ -634,6 +640,15 @@ export interface CompressibleRange { * has no index gap and the index check alone would let mergeRangesToThreshold * bridge back into one doomed span bracketing the dead ref. */ noMergeBefore?: boolean; + /** #5667 defect B (display-only): ids of ACTIVE blocks whose ref-spans sit + * strictly inside this range's numeric span — the range's literal label + * bridges an already-folded interior (surface-replace hosts leave no gap, so + * the segmenter joins the flanks; billion-context #5508 family). Renderers + * append " · spans folded bN" so the model does not re-submit the covered + * interior as new content. Set by buildCompressibleRanges / mergeBatch; + * NEVER consulted by foldability judgment (KDD#12 single projection). Absent + * when nothing is spanned or on hand-built ranges. */ + crossesCoveredBy?: string[]; } export interface ProtectedRange { diff --git a/src/storage/ingest.ts b/src/storage/ingest.ts index 3b54cd6092..938af9721e 100644 --- a/src/storage/ingest.ts +++ b/src/storage/ingest.ts @@ -422,7 +422,7 @@ function finishPlan( tier: b.tier, summary: JSON.stringify(full), one: one === null ? null : JSON.stringify(one), - supersedesBlockId: null, + supersedesBlockId: b.supersedesBlockId ?? null, active: b.active, createdAt: b.createdAt, coveredHash: sha256Hex(JSON.stringify(covered)), From 7c064305852eb2cf24214cec1073eb271e84e284 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 4 Nov 2026 19:18:48 +0800 Subject: [PATCH 02/10] kernel: flag ranges spanning folded blocks on display surfaces (#5667) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On surface-replace hosts covered messages leave the resend array without a gap flag, so the segmenter silently bridges and a displayed label like m00076-m00115 spans an interior active block, literally inviting the model to re-submit the already-covered interior (#5508 family). New blocksSpannedByRange() reports the strictly-interior active blocks a range's ref-span crosses; buildCompressibleRanges stamps it on each range (propagated through mergeBatch) and formatRanges appends ' · spans folded bN'. Display-only: rows are flagged, never dropped, and foldability judgment is untouched (KDD#12 single-projection). --- kernel/src/block-map.ts | 29 +++++++++++++++++++++++++++++ kernel/src/nudge-text.ts | 18 +++++++++++++++--- kernel/src/recommend.ts | 12 ++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/kernel/src/block-map.ts b/kernel/src/block-map.ts index b121179bb9..e5ad39b67d 100644 --- a/kernel/src/block-map.ts +++ b/kernel/src/block-map.ts @@ -53,6 +53,35 @@ export function activeBlockSpans(state: CompressionState): BlockSpan[] { return spans; } +/** #5667 defect B: which ACTIVE blocks' ref-spans sit strictly INSIDE a + * displayed range's numeric span — i.e. the range's literal label bridges + * across an already-folded interior. On surface-replace hosts the covered + * messages leave the array without leaving a segmentation gap, so the segmenter + * joins the two surviving flanks into one range whose label reads as a solid + * mNNNNN–mMMMMM span (billion-context #5508 family). Display-only signal: the + * renderers append it; foldability judgment (KDD#12 single projection) is + * untouched. Returns block ids, oldest-first by span start; empty when nothing + * is spanned. A covered message is never a range member, so a block can only + * intersect a range's span as a strict interior hole — partial overlap is + * impossible and need not be tested. */ +export function blocksSpannedByRange( + startRef: string, + endRef: string, + spans: BlockSpan[], +): string[] { + const [loRef, hiRef] = orderedRefPair(startRef, endRef); + const lo = refNum(loRef); + const hi = refNum(hiRef); + if (hi - lo < 1) return []; + const out: string[] = []; + for (const s of spans) { + const bLo = Math.min(refNum(s.startRef), refNum(s.endRef)); + const bHi = Math.max(refNum(s.startRef), refNum(s.endRef)); + if (bLo > lo && bHi < hi) out.push(s.blockId); + } + return out.sort((a, b) => refNum(a) - refNum(b)); +} + /** Format newly created blocks for tool-result display, e.g. * `blocks: b3=m00044–m00097, b4=m00103–m00123`. Adapters append this to their * compress result line so the model's block ledger comes from the kernel diff --git a/kernel/src/nudge-text.ts b/kernel/src/nudge-text.ts index 0c8463c154..7f2bda4208 100644 --- a/kernel/src/nudge-text.ts +++ b/kernel/src/nudge-text.ts @@ -121,6 +121,7 @@ export function formatRanges( textPct: number; dangerous: boolean; noMergeBefore: boolean; + crossesCoveredBy: string[]; } const refNum = (ref: string): number => { const m = ref.match(/\d+/); @@ -147,6 +148,7 @@ export function formatRanges( protectedTools: [], dangerous: r.dangerous ?? false, noMergeBefore: r.noMergeBefore ?? false, + crossesCoveredBy: r.crossesCoveredBy ?? [], }); } for (const r of protectedRanges) { @@ -169,6 +171,7 @@ export function formatRanges( protectedTools: [...r.tools], dangerous: false, noMergeBefore: r.noMergeBefore ?? false, + crossesCoveredBy: [], }); } // Order/merge by POSITION, never ref number: refs can be non-monotonic vs array @@ -196,6 +199,9 @@ export function formatRanges( for (const t of e.protectedTools) { if (!last.protectedTools.includes(t)) last.protectedTools.push(t); } + for (const b of e.crossesCoveredBy) { + if (!last.crossesCoveredBy.includes(b)) last.crossesCoveredBy.push(b); + } } else { merged.push({ ...e }); } @@ -211,13 +217,19 @@ export function formatRanges( e.dangerous && e.compressibleTokens > 0 ? " ⚠️ NOT recommended unless you are certain." : ""; + // #5667 B: the label bridges an already-folded interior — say so so the + // model does not re-submit the covered span as new content (#5508 family). + const spanNote = + e.crossesCoveredBy.length > 0 + ? ` · spans folded ${e.crossesCoveredBy.join(", ")}` + : ""; if (e.protectedTokens > 0 && e.compressibleTokens === 0) { - return ` ${lo}–${hi} ${e.count} msgs ${formatK(e.tokens)} [PROTECTED: ${e.protectedTools.join(", ")} — not compressible]${suffix}`; + return ` ${lo}–${hi} ${e.count} msgs ${formatK(e.tokens)} [PROTECTED: ${e.protectedTools.join(", ")} — not compressible]${spanNote}${suffix}`; } if (e.protectedTokens > 0 && e.compressibleTokens > 0) { - return ` ${lo}–${hi} ${e.count} msgs ${formatK(e.tokens)} [${formatK(e.compressibleTokens)} compressible | ${formatK(e.protectedTokens)} protected: ${e.protectedTools.join(", ")}]${userNote(e.userMsgs)}${suffix}`; + return ` ${lo}–${hi} ${e.count} msgs ${formatK(e.tokens)} [${formatK(e.compressibleTokens)} compressible | ${formatK(e.protectedTokens)} protected: ${e.protectedTools.join(", ")}]${userNote(e.userMsgs)}${spanNote}${suffix}`; } - return ` ${lo}–${hi} ${e.count} msgs ${formatK(e.tokens)} [tool ${e.toolPct}% | text ${e.textPct}%]${userNote(e.userMsgs)}${suffix}`; + return ` ${lo}–${hi} ${e.count} msgs ${formatK(e.tokens)} [tool ${e.toolPct}% | text ${e.textPct}%]${userNote(e.userMsgs)}${spanNote}${suffix}`; }); return `Compressible ranges (${merged.length}, oldest first):\n${lines.join("\n")}`; } diff --git a/kernel/src/recommend.ts b/kernel/src/recommend.ts index 23a2ca2631..ea24f43e24 100644 --- a/kernel/src/recommend.ts +++ b/kernel/src/recommend.ts @@ -37,6 +37,7 @@ import { countMessageTokens } from "./tokenize.js"; import { computeIntegrityWithdrawals } from "./turn-integrity.js"; import { evaluateRefold } from "./refold.js"; import { segmentGroups } from "./segment.js"; +import { activeBlockSpans, blocksSpannedByRange } from "./block-map.js"; import { projectUnit, collectCoverage, @@ -461,6 +462,9 @@ export function buildCompressibleRanges( // split at real array gaps and at user messages once a group has >= 3 messages. // Splitting at user boundaries keeps each range aligned to roughly one turn. const compressible: CompressibleRange[] = []; + // #5667 B: active-block spans resolved once so each range can record the + // folded interior its label bridges (display-only, never feeds foldability). + const activeSpansForSpan = activeBlockSpans(state); for (const group of segmentGroups(compressibleMsgs)) { const first = group[0]!; const range: CompressibleRange = { @@ -494,6 +498,12 @@ export function buildCompressibleRanges( } range.textPct = 100 - range.toolPct; } + const spanned = blocksSpannedByRange( + range.startRef, + range.endRef, + activeSpansForSpan, + ); + if (spanned.length > 0) range.crossesCoveredBy = spanned; compressible.push(range); } @@ -566,6 +576,8 @@ function mergeBatch(batch: CompressibleRange[]): CompressibleRange { // position-based merging (formatRanges) still sees it after this batch is // re-emitted as a single range. if (first.noMergeBefore === true) merged.noMergeBefore = true; + const spanned = batch.flatMap((r) => r.crossesCoveredBy ?? []); + if (spanned.length > 0) merged.crossesCoveredBy = [...new Set(spanned)]; return merged; } From 015241b7d7c16f91248226fe3fd057113d97c32f Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 4 Nov 2026 19:18:58 +0800 Subject: [PATCH 03/10] kernel: surface acp_status diagnostics for spanning ranges and projection errors (#5667) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The uncompressed list now appends the same ' · spans folded bN' note to rows whose ref-span crosses an active block. The flagFor catch-all, which returned one flat 'refs unresolvable' verdict for every projection exception and sent agents misdiagnosing ledger corruption, now surfaces the real exception detail (surrogate-scrubbed, truncated to 120 chars) so a single bad endpoint reads as what it is. --- kernel/src/report.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kernel/src/report.ts b/kernel/src/report.ts index 29e10a2767..b64fe644d7 100644 --- a/kernel/src/report.ts +++ b/kernel/src/report.ts @@ -1,8 +1,9 @@ -import { clampPrefix } from "./truncate.js"; +import { clampPrefix, scrubLoneSurrogates } from "./truncate.js"; import { isToolMessage } from "./message-kind.js"; import { BLOCKED_REF, orderedRefPair, refForRaw } from "./refs.js"; import { countMessageTokens } from "./tokenize.js"; import { segmentGroups } from "./segment.js"; +import { activeBlockSpans, blocksSpannedByRange } from "./block-map.js"; import { isLiveCheckpointCarrier } from "./state.js"; import { computeProtectedRefs } from "./recommend.js"; import { @@ -463,8 +464,9 @@ function renderUncompressedRanges( protectedMessageIds: protectedRefs, shared, }); - } catch { - return "\u26a0 not foldable: refs unresolvable"; + } catch (err) { + const detail = err instanceof Error ? err.message : String(err); + return `\u26a0 not foldable: ${scrubLoneSurrogates(detail).slice(0, 120)}`; } if (proj.fatal?.kind === "zone") return "\u26a0 not foldable: protected zone only"; @@ -477,6 +479,7 @@ function renderUncompressedRanges( } lines.push(`Sorted by ${sort === "time" ? "time" : "size"}`); lines.push(""); + const activeSpansForSpan = activeBlockSpans(state); for (const r of merged.slice(0, limit)) { // Ascending endpoint labels: non-monotonic refs (#1001) can make a // positional span's labels numerically descending (#2168). @@ -484,9 +487,15 @@ function renderUncompressedRanges( r.count === 1 ? r.startRef : orderedRefPair(r.startRef, r.endRef).join("–"); + const spanned = + r.count > 1 + ? blocksSpannedByRange(r.startRef, r.endRef, activeSpansForSpan) + : []; + const spanNote = + spanned.length > 0 ? ` · spans folded ${spanned.join(", ")}` : ""; const flag = flagFor ? flagFor(r) : null; lines.push( - ` ${range} (${r.count} msgs, ${formatTokens(r.tokens)}${r.count > 1 ? ` (${Math.round(r.tokens / r.count)}/msg)` : ""}) ${dominantTool(r.toolTokens)}${flag ? ` ${flag}` : ""}`, + ` ${range}${spanNote} (${r.count} msgs, ${formatTokens(r.tokens)}${r.count > 1 ? ` (${Math.round(r.tokens / r.count)}/msg)` : ""}) ${dominantTool(r.toolTokens)}${flag ? ` ${flag}` : ""}`, ); } if (merged.length > limit) { From 01643ea0b2c1b5d6001a4cdaa0c79f2556e4e945 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 4 Nov 2026 19:19:31 +0800 Subject: [PATCH 04/10] test: pin nested-fold ledger behavior for #5667 (A/B/C) A: a nested fold stamps consumed children with the consumer's id and leaves non-consumptive deactivation unset. B: blocksSpannedByRange flags strictly-interior blocks only, buildCompressibleRanges records the span on bridged surface-replace ranges (and omits it otherwise), formatRanges and mergeRangesToThreshold carry the annotation. C: an unresolvable endpoint surfaces the real projection error instead of the old flat verdict. --- .../issue5667-nested-fold-ledger.test.ts | 231 ++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 kernel/tests/issue5667-nested-fold-ledger.test.ts diff --git a/kernel/tests/issue5667-nested-fold-ledger.test.ts b/kernel/tests/issue5667-nested-fold-ledger.test.ts new file mode 100644 index 0000000000..08b4f1c71f --- /dev/null +++ b/kernel/tests/issue5667-nested-fold-ledger.test.ts @@ -0,0 +1,231 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { createCore } from "../src/compress.js"; +import { createInitialState } from "../src/state.js"; +import { assignRefs } from "../src/refs.js"; +import { defaultCountTokens } from "../src/tokenize.js"; +import { blocksSpannedByRange } from "../src/block-map.js"; +import { + buildCompressibleRanges, + mergeRangesToThreshold, +} from "../src/recommend.js"; +import { formatRanges } from "../src/nudge-text.js"; +import { buildStatusReport } from "../src/report.js"; +import type { + CompressionBlock, + Config, + CompressibleRange, + CoreMessage, +} from "../src/types.js"; + +// #5667: three state-ledger distortions exposed by nested folding (a new block +// consuming an active one). Regression pins for the A/B/C fixes. See PR body. + +function config(overrides: Partial = {}): 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, + }, + promotionThreshold: 5, + truncate: { threshold: 1 }, + merge: { maxSummaryLength: 3000, minOldGenBlocks: 3 }, + compress: { minCompressRange: 0, maxSummaryLength: 0, minSummaryLength: 0 }, + protectedTools: [], + preserveRecentMessages: 0, + preserveRecentTokens: 0, + modelContextLimit: 100000, + ...overrides, + }; +} + +function msg( + id: string, + text: string, + role: CoreMessage["role"] = "user", +): CoreMessage { + return { id, role, contentType: "text", text }; +} + +function makeBlock(overrides: Partial = {}): CompressionBlock { + return { + blockId: "b1", + runId: "r1", + tier: 1, + summary: "s", + directMessageIds: [], + effectiveMessageIds: [], + directBlockIds: [], + compressedTokens: 100, + createdAt: Date.now(), + survivedCount: 0, + generation: "young", + active: true, + ...overrides, + }; +} + +// ─── Defect A: supersedes_block_id written only at consumption ──────────────── + +test("A: nested fold stamps consumed children with the consumer's id", () => { + const core = createCore(); + const state = createInitialState(); + const messages = Array.from({ length: 20 }, (_, i) => + msg(`id${i + 1}`, `message ${i + 1}`), + ); + state.messageRefs = assignRefs(messages, { + existing: state.messageRefs, + nextIndex: 1, + }).map; + const r1 = core.applyCompression({ + ranges: [ + { startRef: "m00001", endRef: "m00010", summary: "first ten" }, + { startRef: "m00011", endRef: "m00020", summary: "next ten" }, + ], + messages, + state, + config: config(), + }); + const childA = r1.state.blocks.find((b) => b.startRef === "m00001")!; + const childB = r1.state.blocks.find((b) => b.startRef === "m00011")!; + const r2 = core.applyCompression({ + ranges: [{ startRef: childA.blockId, endRef: childB.blockId, summary: "distilled" }], + messages, + state: r1.state, + config: config(), + }); + const consumer = r2.state.blocks[r2.state.blocks.length - 1]!; + assert.equal(consumer.tier, 2); + const gotA = r2.state.blocks.find((b) => b.blockId === childA.blockId)!; + const gotB = r2.state.blocks.find((b) => b.blockId === childB.blockId)!; + assert.equal(gotA.active, false, "consumed child must be inactive"); + assert.equal(gotB.active, false, "consumed child must be inactive"); + assert.equal(gotA.supersedesBlockId, consumer.blockId); + assert.equal(gotB.supersedesBlockId, consumer.blockId); + assert.equal(consumer.supersedesBlockId, undefined, "consumer has no parent"); +}); + +test("A: non-consumptive deactivation leaves supersedesBlockId unset", () => { + const state = createInitialState(); + const orphan = makeBlock({ blockId: "b1", active: false }); + state.blocks = [orphan]; + assert.equal(orphan.supersedesBlockId, undefined); +}); + +// ─── Defect B: display-only annotation for a range spanning a folded block ──── + +test("B: blocksSpannedByRange flags strictly-interior blocks only", () => { + const spans = [ + { blockId: "b1", tier: 1, startRef: "m00002", endRef: "m00004" }, + { blockId: "b2", tier: 1, startRef: "m00007", endRef: "m00009" }, + { blockId: "b3", tier: 1, startRef: "m00001", endRef: "m00005" }, + { blockId: "b4", tier: 1, startRef: "m00009", endRef: "m00015" }, + ]; + assert.deepEqual(blocksSpannedByRange("m00001", "m00015", spans), [ + "b1", + "b2", + ]); + assert.deepEqual(blocksSpannedByRange("m00005", "m00005", spans), []); + assert.deepEqual(blocksSpannedByRange("m00015", "m00001", spans), [ + "b1", + "b2", + ]); +}); + +test("B: bridged surface-replace range records the folded interior it spans", () => { + const a = msg("a", "x".repeat(2000)); + const e = msg("e", "v".repeat(2000)); + const state = createInitialState(); + state.messageRefs = assignRefs( + [a, msg("b", "y"), msg("c", "z"), msg("d", "w"), e], + { existing: state.messageRefs, nextIndex: 1 }, + ).map; + state.blocks.push( + makeBlock({ + blockId: "bFolded", + startRef: "m00002", + endRef: "m00004", + effectiveMessageIds: ["b", "c", "d"], + }), + ); + const ranges = buildCompressibleRanges([a, e], state, config()).compressible; + assert.equal(ranges.length, 1); + assert.equal(ranges[0]!.startRef, "m00001"); + assert.equal(ranges[0]!.endRef, "m00005"); + assert.deepEqual(ranges[0]!.crossesCoveredBy, ["bFolded"]); +}); + +test("B: a range that does not span a block carries no crossesCoveredBy", () => { + const a = msg("a", "x".repeat(2000)); + const e = msg("e", "v".repeat(2000)); + const state = createInitialState(); + state.messageRefs = assignRefs( + [a, msg("b", "y"), msg("c", "z"), msg("d", "w"), e], + { existing: state.messageRefs, nextIndex: 1 }, + ).map; + const ranges = buildCompressibleRanges([a, e], state, config()).compressible; + assert.equal(ranges.length, 1); + assert.equal(ranges[0]!.crossesCoveredBy, undefined); +}); + +test("B: formatRanges appends 'spans folded' only when the field is set", () => { + const crossed: CompressibleRange = { + startRef: "m00001", + endRef: "m00005", + count: 2, + tokens: 1000, + chars: 4000, + toolPct: 0, + textPct: 100, + crossesCoveredBy: ["bFolded"], + }; + assert.match(formatRanges([crossed], []), / · spans folded bFolded/); + const plain: CompressibleRange = { + startRef: "m00001", + endRef: "m00005", + count: 2, + tokens: 1000, + chars: 4000, + toolPct: 0, + textPct: 100, + }; + assert.doesNotMatch(formatRanges([plain], []), /spans folded/); +}); + +test("B: mergeRangesToThreshold carries crossesCoveredBy across a batch", () => { + const base = { count: 2, chars: 400, toolPct: 50, textPct: 50, tokens: 500 }; + const ranges: CompressibleRange[] = [ + { startRef: "m00001", endRef: "m00002", crossesCoveredBy: ["bX"], ...base }, + { startRef: "m00003", endRef: "m00004", ...base }, + ]; + const merged = mergeRangesToThreshold(ranges, 600); + assert.equal(merged.length, 1); + assert.deepEqual(merged[0]!.crossesCoveredBy, ["bX"]); +}); + +// ─── Defect C: projection exceptions surface their detail ───────────────────── + +test("C: an unresolvable endpoint surfaces the real reason, not a flat verdict", () => { + const u1 = msg("u1", "please do the thing"); + const t1 = msg("t1", "call skill", "assistant"); + const state = createInitialState(); + // t1's stored ref is BLOCKED (protected tool) — a valid-looking range whose + // tail endpoint cannot be resolved, so projectUnit throws on it. + state.messageRefs = { + byRaw: { u1: "m00001", t1: "BLOCKED" }, + byRef: { m00001: "u1" }, + }; + const out = buildStatusReport(state, [u1, t1], defaultCountTokens, { + scope: "uncompressed", + config: config({ protectedTools: ["skill"] }), + originalMessages: [u1, t1], + }); + assert.match(out, /not foldable:/); + assert.doesNotMatch(out, /refs unresolvable/); + assert.match(out, /Invalid boundary ref/); +}); From bd6b978ce4771253c1923903540d9924ac786cc3 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 4 Nov 2026 19:19:31 +0800 Subject: [PATCH 05/10] kernel: bump version to 0.0.181 --- kernel/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/package.json b/kernel/package.json index 3c313f565f..1f8a27ec2a 100644 --- a/kernel/package.json +++ b/kernel/package.json @@ -1,6 +1,6 @@ { "name": "acp-kernel", - "version": "0.0.180", + "version": "0.0.181", "description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.", "license": "MIT", "author": "ranxianglei", From bc645d81834c45e6aa1aa4fb40fbf74265b4fd23 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 4 Nov 2026 19:40:59 +0800 Subject: [PATCH 06/10] chore(#5676): sync both package-locks to kernel 0.0.181 after bump commit (lock-sync gate drift) --- 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 f7b4086762..afce17e85d 100644 --- a/kernel/package-lock.json +++ b/kernel/package-lock.json @@ -1,12 +1,12 @@ { "name": "acp-kernel", - "version": "0.0.180", + "version": "0.0.181", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "acp-kernel", - "version": "0.0.180", + "version": "0.0.181", "license": "MIT", "devDependencies": { "@types/node": "^22.0.0", diff --git a/package-lock.json b/package-lock.json index 2ce6f14148..74d37a2968 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ }, "kernel": { "name": "acp-kernel", - "version": "0.0.180", + "version": "0.0.181", "dev": true, "license": "MIT", "devDependencies": { From 4c06e7318edfdc66737530924af06784311be7f6 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 11 Nov 2026 19:00:33 +0800 Subject: [PATCH 07/10] test(kernel): drive real sync deactivation paths in the nested-fold lineage negative case (#5667 review round 2) The A-negative case built an inactive block by hand and asserted its own field was undefined - a tautology that would still pass if any deactivation site started stamping supersedesBlockId. Rewrite it to run syncBlocks over three real non-consumptive paths (orphan GC, host expand, reconcile re-mark of a recorded lineage edge) and assert none of them stamps. --- .../issue5667-nested-fold-ledger.test.ts | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/kernel/tests/issue5667-nested-fold-ledger.test.ts b/kernel/tests/issue5667-nested-fold-ledger.test.ts index 08b4f1c71f..055bd1af7e 100644 --- a/kernel/tests/issue5667-nested-fold-ledger.test.ts +++ b/kernel/tests/issue5667-nested-fold-ledger.test.ts @@ -4,6 +4,7 @@ import { createCore } from "../src/compress.js"; import { createInitialState } from "../src/state.js"; import { assignRefs } from "../src/refs.js"; import { defaultCountTokens } from "../src/tokenize.js"; +import { syncBlocks } from "../src/sync.js"; import { blocksSpannedByRange } from "../src/block-map.js"; import { buildCompressibleRanges, @@ -112,9 +113,54 @@ test("A: nested fold stamps consumed children with the consumer's id", () => { test("A: non-consumptive deactivation leaves supersedesBlockId unset", () => { const state = createInitialState(); - const orphan = makeBlock({ blockId: "b1", active: false }); - state.blocks = [orphan]; - assert.equal(orphan.supersedesBlockId, undefined); + // Orphan GC: the block's messages are absent from the resent view. + const orphan = makeBlock({ + blockId: "b-orphan", + effectiveMessageIds: ["ghost-1"], + }); + // Host expand: the block is present but explicitly expanded by the host. + const expanded = makeBlock({ + blockId: "b-expanded", + expanded: true, + effectiveMessageIds: ["live-1"], + }); + // Reconcile re-mark of an already-recorded lineage edge: the consumer lists + // the child in directBlockIds, sync re-marks it inactive without restamping. + const parent = makeBlock({ + blockId: "b-parent", + directBlockIds: ["b-child"], + effectiveMessageIds: ["live-2"], + }); + const child = makeBlock({ blockId: "b-child" }); + state.blocks = [orphan, expanded, parent, child]; + const result = syncBlocks([msg("live-1", "a"), msg("live-2", "b")], state); + const gotOrphan = result.state.blocks.find((b) => b.blockId === "b-orphan")!; + const gotExpanded = result.state.blocks.find((b) => b.blockId === "b-expanded")!; + const gotParent = result.state.blocks.find((b) => b.blockId === "b-parent")!; + const gotChild = result.state.blocks.find((b) => b.blockId === "b-child")!; + assert.equal(gotOrphan.active, false, "orphan GC must deactivate"); + assert.ok( + result.deactivated.includes("b-orphan"), + "orphan GC must record the deactivation", + ); + assert.equal(gotExpanded.active, false, "host-expanded stays inactive"); + assert.equal(gotParent.active, true, "present consumer stays active"); + assert.equal(gotChild.active, false, "reconcile keeps consumed child inactive"); + assert.equal( + gotOrphan.supersedesBlockId, + undefined, + "orphan-GC death stamps no lineage", + ); + assert.equal( + gotExpanded.supersedesBlockId, + undefined, + "host-expand death stamps no lineage", + ); + assert.equal( + gotChild.supersedesBlockId, + undefined, + "reconcile re-mark does not backfill lineage", + ); }); // ─── Defect B: display-only annotation for a range spanning a folded block ──── From 5b406a2ffa3b0231c77b8c14458a02c154c778ec Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 11 Nov 2026 19:02:33 +0800 Subject: [PATCH 08/10] fix(kernel): stable fallback when a foldability error carries no message (#5667 review round 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An Error with an empty message rendered as '⚠ not foldable: ' (trailing space, blank detail). Extract the scrub/trim/truncate into an exported projectionErrorDetail helper that falls back to 'no error detail', keeping the row honest instead of fabricating a cause or leaving a dangling colon. --- kernel/src/report.ts | 9 +++++++-- kernel/tests/issue5667-nested-fold-ledger.test.ts | 13 ++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/kernel/src/report.ts b/kernel/src/report.ts index b64fe644d7..561f52de17 100644 --- a/kernel/src/report.ts +++ b/kernel/src/report.ts @@ -191,6 +191,12 @@ export interface StatusReportOptions { originalMessages?: CoreMessage[]; } +export function projectionErrorDetail(err: unknown): string { + const raw = err instanceof Error ? err.message : String(err); + const detail = scrubLoneSurrogates(raw).trim(); + return detail.slice(0, 120) || "no error detail"; +} + export function buildStatusReport( state: CompressionState, messages: CoreMessage[], @@ -465,8 +471,7 @@ function renderUncompressedRanges( shared, }); } catch (err) { - const detail = err instanceof Error ? err.message : String(err); - return `\u26a0 not foldable: ${scrubLoneSurrogates(detail).slice(0, 120)}`; + return `\u26a0 not foldable: ${projectionErrorDetail(err)}`; } if (proj.fatal?.kind === "zone") return "\u26a0 not foldable: protected zone only"; diff --git a/kernel/tests/issue5667-nested-fold-ledger.test.ts b/kernel/tests/issue5667-nested-fold-ledger.test.ts index 055bd1af7e..c2f95820fd 100644 --- a/kernel/tests/issue5667-nested-fold-ledger.test.ts +++ b/kernel/tests/issue5667-nested-fold-ledger.test.ts @@ -11,7 +11,7 @@ import { mergeRangesToThreshold, } from "../src/recommend.js"; import { formatRanges } from "../src/nudge-text.js"; -import { buildStatusReport } from "../src/report.js"; +import { buildStatusReport, projectionErrorDetail } from "../src/report.js"; import type { CompressionBlock, Config, @@ -275,3 +275,14 @@ test("C: an unresolvable endpoint surfaces the real reason, not a flat verdict", assert.doesNotMatch(out, /refs unresolvable/); assert.match(out, /Invalid boundary ref/); }); + +test("C: projectionErrorDetail falls back when the error carries no message", () => { + assert.equal(projectionErrorDetail(new Error("")), "no error detail"); + assert.equal(projectionErrorDetail(new Error(" \t\n ")), "no error detail"); + assert.equal(projectionErrorDetail("plain reason"), "plain reason"); + assert.equal( + projectionErrorDetail(new Error("x".repeat(500))).length, + 120, + "long details stay truncated", + ); +}); From c51064a219e4090e4ba7d450a9b48d208b70e89e Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 11 Nov 2026 19:05:59 +0800 Subject: [PATCH 09/10] kernel: bump version to 0.0.194 --- kernel/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/package.json b/kernel/package.json index b8709a1de6..fc597d1083 100644 --- a/kernel/package.json +++ b/kernel/package.json @@ -1,6 +1,6 @@ { "name": "acp-kernel", - "version": "0.0.193", + "version": "0.0.194", "description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.", "license": "MIT", "author": "ranxianglei", From 7237f5848130172af44f856f215ce7f2a48a3a73 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 11 Nov 2026 19:05:59 +0800 Subject: [PATCH 10/10] chore(#5676): sync both package-locks to kernel 0.0.194 (lock-sync gate drift) --- 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 616a2835a4..42417521ff 100644 --- a/kernel/package-lock.json +++ b/kernel/package-lock.json @@ -1,12 +1,12 @@ { "name": "acp-kernel", - "version": "0.0.193", + "version": "0.0.194", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "acp-kernel", - "version": "0.0.193", + "version": "0.0.194", "license": "MIT", "devDependencies": { "@types/node": "^22.0.0", diff --git a/package-lock.json b/package-lock.json index c5d1dc20ee..68c4f5e827 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ }, "kernel": { "name": "acp-kernel", - "version": "0.0.193", + "version": "0.0.194", "dev": true, "license": "MIT", "devDependencies": {