From be309ca52f5f137c23c3f921123dc1bdbd5d87b1 Mon Sep 17 00:00:00 2001 From: ci-check Date: Mon, 2 Nov 2026 22:38:29 +0800 Subject: [PATCH 1/4] kernel: reject overlapping compress ranges atomically instead of skipping (#5541) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit applyCompression previously warn+skipped later overlapping ranges (earliest wins, legacy ISSUE-42 / dog/billion-context-pi#21), partially applying the batch. The model had already written both summaries, so the skipped range's summary was silently discarded and cross-references in the surviving block dangled; the event was also invisible in bili.log on the external-summary probe path. Overlapping (incl. nested) ranges now reject the WHOLE batch before any fold — zero commits, no prefix rewrite — naming each conflicting pair, consistent with the all-or-nothing contract #3003/#3939 established for every other failure class. The dead skipSpecs plumbing is removed. Consumed-range skips and unknown-ref per-range errors keep their existing semantics. kernel-change: owner-requested behavior change in issue #5541 — the overlap decision lives inside kernel applyCompression (resolved boundary indices), so the host side cannot express atomic validation without duplicating boundary resolution. --- kernel/package.json | 2 +- kernel/src/compress.ts | 60 ++++++--- kernel/tests/protect-recent.test.ts | 44 ++++--- kernel/tests/regression-bugfixes.test.ts | 159 +++++++++++++++++++---- package-lock.json | 2 +- 5 files changed, 205 insertions(+), 62 deletions(-) diff --git a/kernel/package.json b/kernel/package.json index bb32450b06..2c27ffc242 100644 --- a/kernel/package.json +++ b/kernel/package.json @@ -1,6 +1,6 @@ { "name": "acp-kernel", - "version": "0.0.178", + "version": "0.0.179", "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 906c7a8cdd..5e863cbab9 100644 --- a/kernel/src/compress.ts +++ b/kernel/src/compress.ts @@ -345,8 +345,8 @@ export function createCore(ports: Ports = {}): CompressionCore { const preExistingCoverage = collectCoverage(state); - // Classify every requested range ONCE. The result feeds overlap - // skipSpecs, the minCompressRange pre-check, and the per-range loop — + // Classify every requested range ONCE. The result feeds the overlap + // gate, the minCompressRange pre-check, and the per-range loop — // previously each re-resolved and silently swallowed failures, so // consumed/unknown ranges produced misleading "too small" errors. const classifications = new Map< @@ -481,27 +481,53 @@ export function createCore(ports: Ports = {}): CompressionCore { }); } const sortedRanges = [...rangeSpans].sort((a, b) => a.start - b.start); - // Overlapping ranges warn+skip (earliest wins) rather than aborting the - // whole batch — see ISSUE-42 / dog/billion-context-pi#21. - const skipSpecs = new Set<(typeof input.ranges)[number]>(); + // Overlapping ranges REJECT THE WHOLE BATCH atomically (#5541): a partial + // fold silently discarded the model's summary for the skipped range(s) and + // left cross-references inside the surviving block's summary dangling. The + // all-or-nothing contract #3003/#3939 established for every other failure + // class applies here too; the earlier ISSUE-42 warn+skip (earliest wins) + // predates that contract and is retired. Nesting counts as overlap. + type RangeSpec = (typeof input.ranges)[number]; + const overlapConflicts: { spec: RangeSpec; against: RangeSpec }[] = []; let acceptedMaxIndex = -1; + let acceptedAtMax: RangeSpec | null = null; for (const entry of sortedRanges) { - if (entry.start <= acceptedMaxIndex) { - skipSpecs.add(entry.spec); - warnings.push( - `Skipped range (${entry.spec.startRef}..${entry.spec.endRef}) — overlaps an earlier range in the batch; the earlier range takes precedence. Keep ranges disjoint.`, - ); + if (entry.start <= acceptedMaxIndex && acceptedAtMax !== null) { + overlapConflicts.push({ spec: entry.spec, against: acceptedAtMax }); continue; } - if (entry.end > acceptedMaxIndex) acceptedMaxIndex = entry.end; + if (entry.end > acceptedMaxIndex) { + acceptedMaxIndex = entry.end; + acceptedAtMax = entry.spec; + } + } + if (overlapConflicts.length > 0) { + const detail = overlapConflicts + .map( + (c) => + `(${c.spec.startRef}..${c.spec.endRef}) overlaps (${c.against.startRef}..${c.against.endRef})`, + ) + .join("; "); + return { + state, + result: { + blocksCreated: 0, + tokensCompressed: 0, + errors: [ + `Batch rejected before folding any range — ${overlapConflicts.length} of ${input.ranges.length} requested range(s) overlap another range in the same batch: ${detail}. Nothing was folded, so no prefix was rewritten. Re-issue the batch with disjoint ranges (no message may belong to two ranges; nesting counts as overlap).`, + ...classificationErrors, + ], + warnings: [], + }, + }; } if (input.config.compress.minCompressRange > 0 && input.ranges.length > 0) { let totalRangeChars = 0; let hasBlockBoundaryRange = false; let countedRanges = 0; - for (const [spec, resolution] of classifications) { - if (resolution.status !== "ok" || skipSpecs.has(spec)) continue; + for (const [, resolution] of classifications) { + if (resolution.status !== "ok") continue; if (resolution.resolved.boundaryKind === "block") { hasBlockBoundaryRange = true; continue; @@ -552,7 +578,7 @@ export function createCore(ports: Ports = {}): CompressionCore { const okBlockedReasons = [ ...new Set( [...classifications.entries()].flatMap(([spec, resolution]) => { - if (skipSpecs.has(spec) || resolution.status !== "ok") return []; + if (resolution.status !== "ok") return []; const decision = refoldDecisions.get(spec); return decision?.kind === "blocked" ? decision.reasons : []; }), @@ -600,8 +626,8 @@ export function createCore(ports: Ports = {}): CompressionCore { }; } const reversalNotes: string[] = []; - for (const [spec, resolution] of classifications) { - if (resolution.status === "ok" && !skipSpecs.has(spec)) { + for (const [, resolution] of classifications) { + if (resolution.status === "ok") { const note = resolution.resolved.reversedNote; if (note) reversalNotes.push(note); } @@ -666,7 +692,6 @@ export function createCore(ports: Ports = {}): CompressionCore { { const lengthFailures: string[] = []; for (const spec of input.ranges) { - if (skipSpecs.has(spec)) continue; const resolution = classifications.get(spec); if (resolution === undefined) continue; const foldsFresh = resolution.status === "ok"; @@ -723,7 +748,6 @@ export function createCore(ports: Ports = {}): CompressionCore { for (const spec of input.ranges) { - if (skipSpecs.has(spec)) continue; const resolution = classifications.get(spec); if (resolution === undefined) continue; if (resolution.status === "consumed") { diff --git a/kernel/tests/protect-recent.test.ts b/kernel/tests/protect-recent.test.ts index 91ee13e42e..42d3e08bb0 100644 --- a/kernel/tests/protect-recent.test.ts +++ b/kernel/tests/protect-recent.test.ts @@ -354,35 +354,49 @@ test("warnings accumulate across multiple ranges in one batch", () => { const state = seededState(messages); const cfg = config({ preserveRecentMessages: 3 }); - // Two ranges: the second now ends inside the recent zone, which under the - // #3939 all-or-nothing contract would reject the whole batch (a fully- - // protected range is a fatal apply error, pinned in issue3939-fold-boundary- - // pins.test.ts), so it instead OVERLAPS the first range's span — overlap - // warn+skip keeps the batch valid while still exercising multi-range - // warning accumulation. + // Pre-fold the head so one batch range is already consumed (skip-with- + // warning) while the other stays live and gets clipped by the recent zone + // (exclusion warning): two distinct per-range warnings in one valid batch. + // Overlapping ranges can no longer play this role — since #5541 an overlap + // rejects the whole batch atomically (pinned in regression-bugfixes.test.ts). + const setup = core.applyCompression({ + ranges: [ + { + startRef: "m00001", + endRef: "m00003", + summary: "head fold", + topic: "h", + }, + ], + messages, + state, + config: cfg, + }); + assert.equal(setup.result.blocksCreated, 1, "setup fold lands"); + const result = core.applyCompression({ ranges: [ + { + startRef: "m00001", + endRef: "m00003", + summary: "already folded head", + topic: "h2", + }, { startRef: "m00004", endRef: "m00009", - summary: "first partial range summary", + summary: "live range clipped by the recent zone", topic: "a", }, - { - startRef: "m00008", - endRef: "m00010", - summary: "second range overlaps the first", - topic: "b", - }, ], messages, - state, + state: setup.state, config: cfg, }); assert.ok( result.result.blocksCreated >= 1, - "at least the unprotected head compresses", + "the live range still compresses", ); assert.ok(result.result.warnings.length >= 2, "warnings surfaced"); }); diff --git a/kernel/tests/regression-bugfixes.test.ts b/kernel/tests/regression-bugfixes.test.ts index 7a6d011f3c..d02773c8ef 100644 --- a/kernel/tests/regression-bugfixes.test.ts +++ b/kernel/tests/regression-bugfixes.test.ts @@ -371,7 +371,7 @@ test("render-refs is idempotent across repeated renders", () => { ); }); -test("batch: overlapping ranges warn and skip (earliest wins) instead of failing", () => { +test("batch: overlapping ranges reject the whole batch atomically (#5541)", () => { const core = createCore(); const messages = [ msg("a", "x".repeat(2000)), @@ -394,20 +394,20 @@ test("batch: overlapping ranges warn and skip (earliest wins) instead of failing config: config(), }); - assert.equal( - result.result.errors.length, - 0, - "overlap is non-fatal — no errors", - ); - assert.equal( - result.result.blocksCreated, - 1, - "the earlier range is still compressed", + assert.equal(result.result.blocksCreated, 0, "nothing is folded"); + assert.equal(result.result.tokensCompressed, 0); + assert.equal(result.result.warnings.length, 0, "no partial-apply warning"); + assert.equal(result.result.errors.length, 1); + assert.match( + result.result.errors[0]!, + /Batch rejected before folding any range/, ); - assert.ok( - result.result.warnings.some((w) => /overlaps an earlier range/i.test(w)), - "a warning is recorded for the skipped range", + assert.match( + result.result.errors[0]!, + /\(m00002\.\.m00003\) overlaps \(m00001\.\.m00002\)/, + "the conflicting pair is named", ); + assert.equal(result.state.blocks.length, 0, "zero-commit purity"); }); test("batch: non-overlapping ranges all succeed", () => { @@ -438,7 +438,7 @@ test("batch: non-overlapping ranges all succeed", () => { assert.equal(result.result.errors.length, 0); }); -test("batch: disjoint range still compresses when two others overlap", () => { +test("batch: one overlapping pair rejects the whole batch, including the disjoint sibling (#5541)", () => { const core = createCore(); const messages = [ msg("a", "x".repeat(2000)), @@ -472,15 +472,30 @@ test("batch: disjoint range still compresses when two others overlap", () => { config: config(), }); - assert.equal(result.result.errors.length, 0); - assert.equal(result.result.blocksCreated, 2); - assert.ok( - result.result.warnings.some((w) => /overlaps an earlier range/i.test(w)), - "an overlap warning is recorded", + assert.equal( + result.result.blocksCreated, + 0, + "the disjoint sibling does not land either", + ); + assert.equal(result.result.warnings.length, 0); + assert.equal(result.result.errors.length, 1); + assert.match( + result.result.errors[0]!, + /1 of 3 requested range\(s\) overlap another range/, ); + assert.match( + result.result.errors[0]!, + /\(m00002\.\.m00003\) overlaps \(m00001\.\.m00002\)/, + ); + assert.doesNotMatch( + result.result.errors[0]!, + /m00004\.\.m00005/, + "the disjoint range is not blamed", + ); + assert.equal(result.state.blocks.length, 0, "zero-commit purity"); }); -test("batch: overlap resolved deterministically regardless of input order", () => { +test("batch: overlap rejection is deterministic regardless of input order (#5541)", () => { const core = createCore(); const messages = [ msg("a", "x".repeat(2000)), @@ -538,17 +553,107 @@ test("batch: overlap resolved deterministically regardless of input order", () = ["sorted", sorted], ["shuffled", shuffled], ] as const) { - assert.equal(result.result.errors.length, 0, `${label}: no errors`); + assert.equal(result.result.blocksCreated, 0, `${label}: nothing folded`); + assert.equal(result.result.warnings.length, 0, `${label}: no warnings`); assert.equal( - result.result.blocksCreated, - 2, - `${label}: earliest range + disjoint range compressed`, + result.result.errors.length, + 1, + `${label}: one atomic-rejection error`, ); - assert.ok( - result.result.warnings.some((w) => /overlaps an earlier range/i.test(w)), - `${label}: overlap warning present`, + assert.match( + result.result.errors[0]!, + /Batch rejected before folding any range/, ); } + assert.deepEqual( + shuffled.result.errors, + sorted.result.errors, + "the conflict list is identical regardless of input order", + ); +}); + +test("batch: a nested range rejects the whole batch as overlap (#5541)", () => { + const core = createCore(); + const messages = [ + msg("a", "x".repeat(2000)), + msg("b", "x".repeat(2000)), + msg("c", "x".repeat(2000)), + msg("d", "x".repeat(2000)), + msg("e", "x".repeat(2000)), + ]; + const state = createInitialState(); + state.messageRefs = assignRefs(messages, { + existing: state.messageRefs, + nextIndex: 1, + }).map; + + const result = core.applyCompression({ + ranges: [ + { startRef: "m00001", endRef: "m00005", summary: "outer summary" }, + { startRef: "m00003", endRef: "m00004", summary: "inner summary" }, + ], + messages, + state, + config: config(), + }); + + assert.equal(result.result.blocksCreated, 0); + assert.equal(result.result.errors.length, 1); + assert.match( + result.result.errors[0]!, + /\(m00003\.\.m00004\) overlaps \(m00001\.\.m00005\)/, + "the inner range is named against its containing outer range", + ); + assert.match( + result.result.errors[0]!, + /nesting counts as overlap/, + ); + assert.equal(result.state.blocks.length, 0, "zero-commit purity"); +}); + +test("batch: adjacent block-boundary distillation is not overlap (#5541 guard)", () => { + // Tier distillation over two sequential T1 blocks must still fold: block-ref + // spans are strictly sequential in message space and must not trip the gate. + const core = createCore(); + const messages = [ + msg("a", "x".repeat(2000)), + msg("b", "x".repeat(2000)), + msg("c", "x".repeat(2000)), + msg("d", "x".repeat(2000)), + ]; + const state = createInitialState(); + state.messageRefs = assignRefs(messages, { + existing: state.messageRefs, + nextIndex: 1, + }).map; + + const t1 = core.applyCompression({ + ranges: [ + { startRef: "m00001", endRef: "m00002", summary: "ab summary" }, + { startRef: "m00003", endRef: "m00004", summary: "cd summary" }, + ], + messages, + state, + config: config(), + }); + assert.equal(t1.result.blocksCreated, 2); + + const t2 = core.applyCompression({ + ranges: [ + { startRef: "b1", endRef: "b1", summary: "distilled ab" }, + { startRef: "b2", endRef: "b2", summary: "distilled cd" }, + ], + messages, + state: t1.state, + config: config(), + }); + + assert.equal( + t2.result.blocksCreated, + 2, + "adjacent block spans are not an overlap", + ); + assert.equal(t2.result.errors.length, 0); }); test("block-boundary distillation counts consumed block tokens", () => { diff --git a/package-lock.json b/package-lock.json index 73e28ff4ca..b03e0a7dc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,7 @@ }, "kernel": { "name": "acp-kernel", - "version": "0.0.178", + "version": "0.0.179", "dev": true, "license": "MIT", "devDependencies": { From f4bf2e435241c1bf99dd1fac1f741f1c3d0c8495 Mon Sep 17 00:00:00 2001 From: ci-check Date: Mon, 2 Nov 2026 22:38:29 +0800 Subject: [PATCH 2/4] fix: surface atomic overlap rejection on host lanes (#5541) stream.ts gate classification gains gate:overlap for the new kernel rejection (previously it would have been mislabeled gate:summary-length). The external-summary probe path now carries the kernel's own conflict text into its refusal receipt instead of the generic 'no selected range passed' message, so the event is greppable in bili.log on every lane. --- src/external-summary-compress.ts | 7 ++++++- src/stream.ts | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/external-summary-compress.ts b/src/external-summary-compress.ts index 6df0e557b6..3551c2a3c9 100644 --- a/src/external-summary-compress.ts +++ b/src/external-summary-compress.ts @@ -95,7 +95,12 @@ export async function applyConfiguredCompression(input: unknown, ctx: RewriteCtx instructions: `${ctx.session.meta.summaryInstructions ?? buildCompressSystemPrompt(undefined, messageTimestampSections(undefined))}\nWrite a faithful summary of the selected range ${range.startRef}-${range.endRef}. Preserve task status, constraints, decisions, exact code identifiers, paths and errors, and unfinished objectives with their source message refs. Submitted summary hints are non-authoritative. Never summarize or change the read-only reference.` + summaryLengthBudgetClause(maxSummaryChars, ctx.config.compress.minSummaryLength) }); } - if (work.length === 0) return compressResult("[Compression FAILED: no selected range passed the existing kernel protection checks. Nothing compressed.]", "refused", 0); + // #5541: when the whole batch was rejected atomically (overlapping ranges), + // surface the kernel's named conflict instead of the generic protection text. + const overlapError = preview.result.errors.find((error) => /overlap another range/i.test(error)); + if (work.length === 0) return compressResult(overlapError + ? `[Compression FAILED: ${overlapError} Nothing compressed.]` + : "[Compression FAILED: no selected range passed the existing kernel protection checks. Nothing compressed.]", "refused", 0); const batch = await plan.summarize(work, signal); if (signal?.aborted || ctx.session.state !== state || ctx.session.revisionEpoch !== revision) return compressResult("[Compression FAILED: cancelled or session changed while generating external summaries. Nothing compressed.]", "refused", 0); const successful: ParsedRange[] = []; diff --git a/src/stream.ts b/src/stream.ts index 2979f8401d..b6c8541265 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -1247,7 +1247,8 @@ export function applyRanges(parsed: ReturnType, ctx: const errs = r.errors.join("; ") || "no blocks created"; // #2362: machine-readable failure class for the [plugin] execution // line — outcome=refused alone never says why in the logs. - const gateReason = /cannot be anchored/.test(errs) ? "gate:cannot-anchor" + const gateReason = /overlap another range/i.test(errs) ? "gate:overlap" + : /cannot be anchored/.test(errs) ? "gate:cannot-anchor" : /already compressed/.test(errs) ? "gate:already-compressed" : /requested range\(s\) resolved/.test(errs) ? "gate:none-resolved" : /too small/.test(errs) ? "gate:too-small" From b5b2c86c7c66c68d8011190ae3c8caf60d4782e7 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 11 Nov 2026 11:15:27 +0800 Subject: [PATCH 3/4] chore: bump acp-kernel 0.0.193 -> 0.0.194 after syncing master (#6132/#6150 fold-point removal) Master independently bumped the kernel to 0.0.193 for the compressAtFoldPoint removal; this PR's overlap atomic-reject changes now sit on top of that, so the version must move again (max+1, same precedent as #5609 sync). Both lockfiles regenerated; diff vs master is only the kernel version lines. --- kernel/package-lock.json | 4 ++-- kernel/package.json | 2 +- package-lock.json | 2 +- 3 files changed, 4 insertions(+), 4 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/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", 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": { From 5cd7b7b2cac51ddbdd86225c08856b21f32e164d Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sun, 15 Nov 2026 12:23:47 +0800 Subject: [PATCH 4/4] fix(ci): regen kernel lockfile after merge (lock-sync drift: root version indent) --- kernel/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/package-lock.json b/kernel/package-lock.json index ccd3913c9d..9437e48cf1 100644 --- a/kernel/package-lock.json +++ b/kernel/package-lock.json @@ -1,6 +1,6 @@ { "name": "acp-kernel", - "version": "0.0.198", + "version": "0.0.198", "lockfileVersion": 3, "requires": true, "packages": {