From 174ba409a01860b830b49b943178fffad9f5a2a0 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sun, 11 Oct 2026 20:02:42 +0800 Subject: [PATCH 1/2] fix: wire the #2621 novelty gate onto the anthropic and google dsh lanes (#2775) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #2658 shipped the dsh native-compaction detector on /v1/messages and generateContent but called carriesDshLocalCompactionSummary without the pre-turn ref map, although knownRefsBefore was already computed at both call sites — so only the carrier gate ran and any user-role plain-text message merely quoting the checkpoint framing (tag anywhere or preamble prefix), replayed byte-identical under ordinary fold drift, false-recorded a native-compaction conflict and wiped all live ACP state via resetSessionCompression (#2621's false-rebase profile, reborn on the two new wires). Pass knownRefsBefore at both call sites (same wiring + comment shape as the openai lane) so the framing match also demands novelty: a freshly-landed checkpoint is a NEW id, a quoted/replayed mention hits an OLD id. The contract comment in dsh-compaction-guard.ts ('every in-repo caller passes it') is true again. Tests: port the #2621 negative to both wires — a seeded user message quoting the framing, replayed byte-identical (old id) with a real fold gap (8/9 covered ids missing) must not rebase, must not record a native-compaction conflict, and the live fold must survive. Red without the wiring (6/8 pass, both negatives fail with a false rebase), green with it (8/8). --- src/server/prepare-anthropic.ts | 5 +- src/server/prepare-google.ts | 5 +- ...58-dsh-anthropic-google-compaction.test.ts | 75 +++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/server/prepare-anthropic.ts b/src/server/prepare-anthropic.ts index 545db594e2..1bf0482fc0 100644 --- a/src/server/prepare-anthropic.ts +++ b/src/server/prepare-anthropic.ts @@ -205,7 +205,10 @@ export async function prepareAnthropic( if (!anthropicTitleGen && session.metadata["pluginAgent"] === "dsh" && session.state.blocks.some((b) => b.active)) { const coveredBeforeDshCompact = coveredRealHistoryIds(session.state.blocks); // #2627: same real-history caliber const dshGap = foldCoverage(coveredBeforeDshCompact, msgs.map((m) => m.id)); - if (dshGap && carriesDshLocalCompactionSummary(msgs)) { + // #2621: pass the pre-turn ref map so the framing match also demands + // NOVELTY — a freshly-landed checkpoint is a NEW id, while every + // historical quote/replay of the marker string hits an old id. + if (dshGap && carriesDshLocalCompactionSummary(msgs, knownRefsBefore)) { const missing = dshGap.expected - dshGap.matched; if (missing >= DSH_LOCAL_COMPACTION_MIN_MISSING && missing * 2 >= dshGap.expected) { recordConflict(session, "native-compaction", `dsh native compaction: ${missing}/${dshGap.expected} covered id(s) replaced by the compacted history; ACP state rebased (#2432)`); diff --git a/src/server/prepare-google.ts b/src/server/prepare-google.ts index 414b900311..13e5c6bec1 100644 --- a/src/server/prepare-google.ts +++ b/src/server/prepare-google.ts @@ -134,7 +134,10 @@ export async function prepareGoogle( if (!isTitleGen && session.metadata["pluginAgent"] === "dsh" && session.state.blocks.some((b) => b.active)) { const coveredBeforeDshCompact = coveredRealHistoryIds(session.state.blocks); // #2627: same real-history caliber const dshGap = foldCoverage(coveredBeforeDshCompact, msgs.map((m) => m.id)); - if (dshGap && carriesDshLocalCompactionSummary(msgs)) { + // #2621: pass the pre-turn ref map so the framing match also demands + // NOVELTY — a freshly-landed checkpoint is a NEW id, while every + // historical quote/replay of the marker string hits an old id. + if (dshGap && carriesDshLocalCompactionSummary(msgs, knownRefsBefore)) { const missing = dshGap.expected - dshGap.matched; if (missing >= DSH_LOCAL_COMPACTION_MIN_MISSING && missing * 2 >= dshGap.expected) { recordConflict(session, "native-compaction", `dsh native compaction: ${missing}/${dshGap.expected} covered id(s) replaced by the compacted history; ACP state rebased (#2432)`); diff --git a/tests/issue2658-dsh-anthropic-google-compaction.test.ts b/tests/issue2658-dsh-anthropic-google-compaction.test.ts index da0d3ff61b..d814961256 100644 --- a/tests/issue2658-dsh-anthropic-google-compaction.test.ts +++ b/tests/issue2658-dsh-anthropic-google-compaction.test.ts @@ -15,6 +15,10 @@ // (pluginAgent === "dsh" + framing + decimated coverage) is shared across all // four lanes, so those shapes are re-pinned here per wire only where the lane // adds its own twist (the anthropic unannounced-rewrite double-record skip). +// #2775 adds the #2621 novelty-gate negative per wire: a SEEDED user message +// quoting the framing, replayed byte-identical (old id) under real fold drift, +// must not rebase — pre-#2775 neither lane passed knownRefsBefore, so the +// carrier gate alone fired on the quote. import assert from "node:assert/strict"; import http from "node:http"; @@ -384,3 +388,74 @@ test("negative #2658: google decimated history WITHOUT checkpoint framing stays await rig.close(); } }); + +test("negative #2775: anthropic seeded user quote replayed byte-identical + real fold gap does NOT rebase", async () => { + const rig = await startAnthropicRig(); + const conv = "dshc-ant-quoteold"; + try { + // The quote sits inside the folded span (m00005): the decimated replay + // below retains exactly 1 of the 9 covered ids → missing = 8 (≥ the 8-id + // floor, missing*2 ≥ expected) — signal ② fully armed by plain drift. + const quoteText = `${DSH_CHECKPOINT_PREAMBLE_PREFIX} that I pasted from another session's transcript for reference — not a compaction boundary here.`; + const seedMessages = Array.from({ length: 14 }, (_, i) => ({ + role: i % 2 === 0 ? "user" : "assistant", + content: i === 4 ? quoteText : seedText(i), + })); + await seedAndFold(rig, conv, { model: MODEL_ANTHROPIC, max_tokens: 8192, stream: true, messages: seedMessages }); + + const r = await fetch(rig.url, { + method: "POST", + headers: dshHeaders(conv), + body: JSON.stringify({ + model: MODEL_ANTHROPIC, max_tokens: 8192, stream: true, + messages: [ + { role: "user", content: quoteText }, + { role: "user", content: seedText(12) }, + { role: "assistant", content: seedText(13) }, + ], + }), + }); + assert.equal(r.status, 200); + await r.text(); + const s = getSession(conv)!; + assert.ok(s.metadata.nativeCompactionBoundary === undefined, "a byte-identical replay of an already-seen user quote must NOT trigger a native-compaction rebase (#2775/#2621)"); + assert.ok(!conflictEventsOf(s).some((e) => e.kind === "native-compaction"), "no misattributed native-compaction conflict recorded (#2775)"); + assert.ok((s.state.blocks ?? []).some((b) => b.active), "the live fold survives the drift — no rebase reset happened"); + } finally { + await rig.close(); + } +}); + +test("negative #2775: google seeded user quote replayed byte-identical + real fold gap does NOT rebase", async () => { + const rig = await startGoogleRig(); + const conv = "dshc-gem-quoteold"; + try { + const quoteText = `${DSH_CHECKPOINT_PREAMBLE_PREFIX} that I pasted from another session's transcript for reference — not a compaction boundary here.`; + const seedContents = Array.from({ length: 14 }, (_, i) => ({ + role: i % 2 === 0 ? "user" : "model", + parts: [{ text: i === 4 ? quoteText : seedText(i) }], + })); + await seedAndFold(rig, conv, { model: MODEL_GOOGLE, generationConfig: { maxOutputTokens: 8192 }, contents: seedContents }); + + const r = await fetch(rig.url, { + method: "POST", + headers: dshHeaders(conv), + body: JSON.stringify({ + model: MODEL_GOOGLE, generationConfig: { maxOutputTokens: 8192 }, + contents: [ + { role: "user", parts: [{ text: quoteText }] }, + { role: "user", parts: [{ text: seedText(12) }] }, + { role: "model", parts: [{ text: seedText(13) }] }, + ], + }), + }); + assert.equal(r.status, 200); + await r.text(); + const s = getSession(conv)!; + assert.ok(s.metadata.nativeCompactionBoundary === undefined, "a byte-identical replay of an already-seen user quote must NOT trigger a native-compaction rebase (#2775/#2621)"); + assert.ok(!conflictEventsOf(s).some((e) => e.kind === "native-compaction"), "no misattributed native-compaction conflict recorded (#2775)"); + assert.ok((s.state.blocks ?? []).some((b) => b.active), "the live fold survives the drift — no rebase reset happened"); + } finally { + await rig.close(); + } +}); From 6d5123be1872f18ea6ef281e13b528c31de47653 Mon Sep 17 00:00:00 2001 From: ework-agent Date: Sun, 11 Oct 2026 20:05:02 +0800 Subject: [PATCH 2/2] fix: stop the google lane double-recording unannounced-rewrite beside a dsh native-compaction rebase (#2775) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #2658 port to the google wire shipped the detector without the dshRebased skip that openai/anthropic/responses carry around detectUnannouncedHistoryRewrite: when a genuine native compaction lands and the rebase has already recorded the 'native-compaction' conflict, the rewrite path could also record a second 'unannounced-rewrite' entry — presenting the substrate destruction as 'another compressor fighting you', the exact double-attribution the sibling lanes' guards exist to prevent. Capture reconcileNativeCompactionBoundary's return and skip the rewrite record when dshRebased, matching the sibling lanes; pin the no-double-record assertion on the google e2e positive in parity with the anthropic one. --- src/server/prepare-google.ts | 11 ++++++++--- .../issue2658-dsh-anthropic-google-compaction.test.ts | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/server/prepare-google.ts b/src/server/prepare-google.ts index 13e5c6bec1..0ae700e838 100644 --- a/src/server/prepare-google.ts +++ b/src/server/prepare-google.ts @@ -131,6 +131,7 @@ export async function prepareGoogle( // checkpoint framing in resent history AND decimated fold coverage; // detection runs BEFORE reconcileFoldCoverage/processTurn. No known // dsh+google traffic yet — this closes the same hole on the fourth wire. + let dshRebased = false; if (!isTitleGen && session.metadata["pluginAgent"] === "dsh" && session.state.blocks.some((b) => b.active)) { const coveredBeforeDshCompact = coveredRealHistoryIds(session.state.blocks); // #2627: same real-history caliber const dshGap = foldCoverage(coveredBeforeDshCompact, msgs.map((m) => m.id)); @@ -143,7 +144,7 @@ export async function prepareGoogle( recordConflict(session, "native-compaction", `dsh native compaction: ${missing}/${dshGap.expected} covered id(s) replaced by the compacted history; ACP state rebased (#2432)`); log("warn", `[${sessionId}] dsh native compaction detected (${dshGap.matched}/${dshGap.expected} covered id(s) retained, checkpoint framing in resent history) — rebasing ACP state onto the compacted history (#2432)`); markNativeCompactionBoundary(session); - reconcileNativeCompactionBoundary(session); + dshRebased = reconcileNativeCompactionBoundary(session); } } } @@ -188,8 +189,12 @@ log("info", diagTagSummary(turn.messages, sessionId, renderStrategy)); processedMessages = stripKernelSummaries(turn.messages, turn.state); // #1001: a silent client history rewrite takes the same archive+prune path // as an announced /compact boundary — syncBlocks above has already - // deactivated the blocks whose sources left the context. - { + // deactivated the blocks whose sources left the context. Skipped when + // the rewrite was just classified as dsh native compaction above + // (#2432/#2658): it is already recorded as "native-compaction" and + // rebased — a second "unannounced-rewrite" entry beside it would present + // the substrate destruction as "another compressor fighting you". + if (!dshRebased) { const rewrite = detectUnannouncedHistoryRewrite(session, knownRefsBefore, msgs.map((m) => m.id)); if (rewrite.detected) { log("warn", `[${sessionId}] unannounced client history rewrite detected (${rewrite.knownIncoming}/${rewrite.incomingTotal} incoming message(s) carry pre-turn refs of ${rewrite.knownBefore} known) — marking compaction boundary (#1001)`); diff --git a/tests/issue2658-dsh-anthropic-google-compaction.test.ts b/tests/issue2658-dsh-anthropic-google-compaction.test.ts index d814961256..67d1325d84 100644 --- a/tests/issue2658-dsh-anthropic-google-compaction.test.ts +++ b/tests/issue2658-dsh-anthropic-google-compaction.test.ts @@ -324,6 +324,8 @@ test("e2e #2658: dsh replaying [checkpoint, retained tail] on generateContent re await r.text(); assertRebased(conv, rig); + const s = getSession(conv)!; + assert.ok(!conflictEventsOf(s).some((e) => e.kind === "unannounced-rewrite"), "no double-record as unannounced-rewrite beside the native-compaction entry (#2775)"); // The session keeps working afterwards (append + forward). const r2 = await fetch(rig.url, { method: "POST", headers: dshHeaders(conv), body: JSON.stringify({ ...replay(), contents: [...replay().contents as unknown[], { role: "user", parts: [{ text: "Post-compaction turn continues fine." }] }] }) });