Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.126",
"version": "0.0.127",
"description": "Framework-agnostic context-compression engine (model-driven, 3-tier LSM). Pure core: no host dependency.",
"license": "MIT",
"author": "ranxianglei",
Expand Down
27 changes: 19 additions & 8 deletions kernel/src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,31 @@ export function createCore(ports: Ports = {}): CompressionCore {
// retry (the self-amplifying failure loop). Tombstone-with-clear: refs
// are never removed from byRef (Kernel Contract), and a tombstone lifts
// once its message reappears in the view.
// #3137: an EMPTY view is not evidence of disappearance — it means this
// call carried no messages at all (proxy resident-pool eviction between
// model requests, process restarts, any consumer calling with []). Under
// [] every requested ref trivially "backs no visible message", so marking
// them DEAD would poison the intact refs table until the next model
// request restores the view, lying in every receipt in between ("can
// NEVER compress"). An empty view therefore creates NO new tombstones;
// existing ones are merely not lifted either ([] proves nothing in that
// direction) and clear on reappearance as usual.
const visibleIdsForDead = new Set(input.messages.map((m) => m.id));
let deadRefs: string[] = (state.deadRefs ?? []).filter((ref) => {
const rawId = state.messageRefs.byRef[ref];
return !(rawId !== undefined && visibleIdsForDead.has(rawId));
});
const danglingBySpec = new Map<(typeof input.ranges)[number], string[]>();
for (const spec of input.ranges) {
const resolution = classifications.get(spec);
if (resolution === undefined || resolution.status !== "consumed") continue;
const dangling = danglingMessageRefs(state, input.messages, spec);
if (dangling.length === 0) continue;
danglingBySpec.set(spec, dangling);
for (const ref of dangling) {
if (!deadRefs.includes(ref)) deadRefs.push(ref);
if (input.messages.length > 0) {
for (const spec of input.ranges) {
const resolution = classifications.get(spec);
if (resolution === undefined || resolution.status !== "consumed") continue;
const dangling = danglingMessageRefs(state, input.messages, spec);
if (dangling.length === 0) continue;
danglingBySpec.set(spec, dangling);
for (const ref of dangling) {
if (!deadRefs.includes(ref)) deadRefs.push(ref);
}
}
}
if (deadRefs.length > 0) {
Expand Down
77 changes: 77 additions & 0 deletions kernel/tests/dead-refs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,83 @@ test("mixed batch: live range compresses, dead range warns DEAD instead of 'alre
assert.deepEqual(result.state.deadRefs, ["m00005", "m00006"]);
});

// #3137: an empty view carries no visibility evidence — it must create no new
// tombstones and lift none; the refs table stays intact until the next model
// request restores the view (tombstone-with-clear).

test("empty view marks no refs DEAD even when every requested ref is uncovered (#3137)", () => {
const core = createCore();
const { state } = vanishedScenario();
const result = core.applyCompression({
ranges: [{ startRef: "m00005", endRef: "m00006", summary: "the vanished pair" }],
messages: [],
state,
config: config(),
});

assert.equal(result.result.blocksCreated, 0);
assert.deepEqual(result.state.deadRefs, undefined, "empty view creates no tombstones");
assert.doesNotMatch(result.result.errors.join("\n"), /DEAD/);
});

test("existing tombstones survive an empty-view call unlifted and unchanged (#3137)", () => {
const core = createCore();
const { state } = vanishedScenario();
state.deadRefs = ["m00005", "m00006"];
const result = core.applyCompression({
ranges: [{ startRef: "m00001", endRef: "m00004", summary: "live span recap" }],
messages: [],
state,
config: config(),
});

assert.deepEqual(
result.state.deadRefs,
["m00005", "m00006"],
"an empty view lifts nothing ([] proves nothing either way)",
);
});

test("mixed request under an empty view: the uncovered range adds no tombstone (#3137)", () => {
const core = createCore();
const state = createInitialState();
state.messageRefs = {
byRaw: { a1: "m00001", a2: "m00002", v3: "m00003", v4: "m00004" },
byRef: { m00001: "a1", m00002: "a2", m00003: "v3", m00004: "v4" },
};
state.blocks.push({
blockId: "b1",
runId: "r1",
tier: 1,
topic: "t",
summary: "s",
directMessageIds: ["a1", "a2"],
effectiveMessageIds: ["a1", "a2"],
directBlockIds: [],
createdAt: 0,
survivedCount: 0,
generation: "young",
active: true,
});

const result = core.applyCompression({
ranges: [
{ startRef: "m00001", endRef: "m00002", summary: "covered pair" },
{ startRef: "m00003", endRef: "m00004", summary: "uncovered pair" },
],
messages: [],
state,
config: config(),
});

assert.deepEqual(
result.state.deadRefs,
undefined,
"the uncovered part of a mixed request adds no tombstone under an empty view",
);
assert.doesNotMatch(result.result.errors.join("\n"), /DEAD/);
});

test("covered endpoints keep the 'already compressed' verdict; nothing is marked dead", () => {
const core = createCore();
const state = createInitialState();
Expand Down
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