Skip to content
Merged
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
22 changes: 20 additions & 2 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export function compressibleSpanHint(state: Pick<CompressionState, "messageRefs"
const span = actives.length >= 2 ? ` (e.g. startId ${actives[0]}, endId ${actives[actives.length - 1]})` : "";
return ` No raw refs are directly compressible right now — compress a run of ACTIVE blocks instead${span}: fold their summaries into one higher-tier block. acp_status lists the current active blocks.`;
}
const covered = boundary > 0 ? ` (everything up to ${fmt(boundary)} is already inside active blocks)` : "";
// #1366: blocks need not be contiguous — a gap below the highest block end
// (e.g. m05027–m05052 between two blocks) is still compressible raw space, so
// claiming "everything up to N is inside blocks" misleads models into skipping it.
const covered = boundary > 0 ? ` (refs up to ${fmt(boundary)} are largely inside active blocks; isolated free gaps may still exist below it)` : "";
return ` Live compressible refs: ${fmt(boundary + 1)}–${fmt(highest)}${covered}. Retry NOW in this same turn with startId/endId inside that span.`;
}

Expand Down Expand Up @@ -208,11 +211,26 @@ export function applyRanges(parsed: ReturnType<typeof parseCompressInput>, ctx:
// list stays logged above).
const reasons = rawReasons.slice(0, 3).map((r) => (r.length > 160 ? r.slice(0, 160) + "..." : r));
const why = reasons.length > 0 ? ` Rejected entries: ${reasons.join(" | ")}.` : "";
// #1366: a call with NO content at all ({} / "" args — an "empty companion"
// compress() emitted alongside the real one) must never be told to
// "re-issue": a structurally empty call fails identically every time, so
// that advice loops until the #847 guard trips. The #362 shape-drift case
// ({ranges: …} instead of {content: …}) stays on the format lecture below:
// there, fixing the key CAN succeed, so re-issue IS the right advice.
const isEmptyCall =
rawReasons.length === 0 &&
(diagnostics.kind === "empty-input" ||
(diagnostics.kind === "missing-content" && !(diagnostics.keys ?? []).includes("ranges")));
const guard = recordCompressFailure(
ctx.session,
`parse:${diagnostics.kind}:${diagnostics.invalidItems}:${rawReasons.slice(0, 3).join("|")}`,
"Fix the argument shape against the format below instead of re-issuing the same malformed call.",
isEmptyCall
? "An empty call fails identically on every retry — drop it instead of re-issuing."
: "Fix the argument shape against the format below instead of re-issuing the same malformed call.",
);
if (isEmptyCall) {
return `[Compression FAILED: the call carried no content at all (kind=${diagnostics.kind}) — an empty compress() compresses nothing and can never succeed. Do NOT re-issue an empty call; if you meant to compress, put the non-empty 'content' array (elements {startId, endId, summary}) in that SAME single call.${guard}]`;
}
return `[Compression FAILED: no valid ranges parsed (kind=${diagnostics.kind}, dropped=${diagnostics.invalidItems}).${why} compress requires a non-empty 'content' array where each element is EITHER an object {startId, endId, summary} OR one line-form string whose first line is 'mNNNNN–mNNNNN optional topic' with the summary markdown on the following lines (a separate summary-only element right after a bare header line is also accepted). startId/endId are mNNNNN message refs from the conversation (call acp_status to see current refs).${compressibleSpanHint(ctx.session.state)} Re-issue the compress call with a valid content array.${guard}]`;
}
// #847: detect reversed refs as SUBMITTED, before #1001 normalization
Expand Down
35 changes: 35 additions & 0 deletions tests/compress-observability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,41 @@ test("#349: empty compress args → actionable no-valid-ranges message (missing-
assert.ok(!out.includes("Check your startId/endId parameters"), "old misleading hint removed");
});

test("#1366: truly-empty call gets the targeted no-re-issue receipt (no loop bait)", () => {
const ctx = makeCompressibleCtx();
const out = runApply(ctx, {});
assert.ok(out.startsWith("[Compression FAILED"), `expected failure, got: ${out}`);
assert.ok(out.includes("carried no content at all"), out);
assert.ok(out.includes("kind=missing-content"), out);
assert.ok(out.includes("Do NOT re-issue an empty call"), out);
assert.ok(!out.includes("Re-issue the compress call with a valid content array"), "old loop-bait tail gone: " + out);
assert.ok(out.includes("non-empty 'content' array") && out.includes("{startId, endId, summary}"), "#349 steering kept");
});

test("#1366: empty-string arguments get the same targeted receipt (kind=empty-input)", () => {
const ctx = makeCompressibleCtx();
const out = runApply(ctx, "");
assert.ok(out.includes("carried no content at all"), out);
assert.ok(out.includes("kind=empty-input"), out);
assert.ok(!out.includes("Re-issue the compress call with a valid content array"), out);
});

test("#1366: empty calls are still recorded by the #847 repeat-failure guard", () => {
const ctx = makeCompressibleCtx();
runApply(ctx, {});
const keys = ctx.session.metadata["compressFailKeys"] as unknown[];
assert.equal(keys.length, 1, "failure recorded");
assert.match(String(keys[0]), /^parse:missing-content:0:/, String(keys));
});

test("#1366/#362: shape drift ({ranges: …}) keeps the format lecture — re-issue IS right there", () => {
const ctx = makeCompressibleCtx();
const out = runApply(ctx, { ranges: [{ startId: "m00001", endId: "m00002", summary: "s" }] });
assert.ok(out.includes("kind=missing-content"), out);
assert.ok(out.includes("Re-issue the compress call with a valid content array"), "lecture retained: " + out);
assert.ok(!out.includes("carried no content at all"), "not mislabeled as empty: " + out);
});

test("#189: staged-compress steering note appended when shrink exceeds the configured max", () => {
const prev = process.env.BILI_MAX_SHRINK_PER_COMPRESS;
process.env.BILI_MAX_SHRINK_PER_COMPRESS = "0.05";
Expand Down
3 changes: 3 additions & 0 deletions tests/compress-span-hint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ test("#1026: hint names the raw span past the highest ACTIVE block boundary", ()
const hint = compressibleSpanHint(ctx.session.state);
assert.ok(hint.includes("m00021–m00080"), `span past boundary: ${hint}`);
assert.ok(hint.includes("inside active blocks"), `explains the covered prefix: ${hint}`);
// #1366: the covered-prefix claim must stay hedged — blocks need not be contiguous,
// and a flat "everything up to N" misled a model into skipping a live gap.
assert.ok(hint.includes("isolated free gaps may still exist"), `gap hedge present: ${hint}`);
});

test("#1026: INACTIVE blocks (decompressed) do not hold the boundary", () => {
Expand Down
Loading