From 3676ee609500ee06ef0f326d91e5b1ace7a3d43e Mon Sep 17 00:00:00 2001 From: ci-check Date: Sat, 24 Oct 2026 06:02:59 +0800 Subject: [PATCH] feat(acp-status): surface host-native compaction landings as an explicit per-session marker (#4458) Add a HOST-NATIVE COMPACTION section to acp_status, shown per-session when a host-native compaction landing is recorded (session.metadata.nativeCompactionBoundary), in BOTH compression modes. It distinguishes "the host compacted this conversation" from "bili folded it", shows pending-rebase vs rebased state, and names the resolved client/lane. Proactive visibility ahead of the reactive DEAD REFS / breaker / conflict-watch surfaces, so an operator or agent can see a landing BEFORE a follow-up call burns a ref minted before the boundary. Additive display-only output: absent when no landing was recorded; no wire, config, cache, or identity impact. Regression test covers both gate directions (#3617). --- src/acp-status.ts | 21 +++++++++++++++++++++ tests/acp-status.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/acp-status.ts b/src/acp-status.ts index ba3b8f276d..d6e60baa31 100644 --- a/src/acp-status.ts +++ b/src/acp-status.ts @@ -284,6 +284,27 @@ export function handleAcpStatus(args: Record, ctx: AcpStatusCtx extra.push(""); extra.push(`DEAD REFS — ${deadRefs.length} ref(s) no longer back any visible or folded message (the client history no longer carries them — host-native compaction or a bulk rewrite). Ranges citing them can NEVER compress; target only the live refs listed above: ${formatDeadRefSpans(deadRefs)}`); } + // #4458: host-native compaction landed under this session — an explicit per-session + // marker so an operator/agent can tell "the host compacted this conversation" from + // "bili folded it" BEFORE a follow-up call burns a ref minted before the boundary. + // Display-only; the boundary record is set server-side by every prepare/relay path in + // BOTH compression modes, so the marker is lane-neutral (hermes/codex/omp/...). + const nativeBnd = ctx.session.metadata.nativeCompactionBoundary; + if (nativeBnd && typeof nativeBnd === "object") { + const bnd = nativeBnd as { at?: number; pendingRebase?: boolean; rebasedAt?: number }; + if (typeof bnd.at === "number") { + const lane = conflictClientOf(ctx.session); + const atIso = new Date(bnd.at).toISOString(); + if (bnd.pendingRebase === true) { + extra.push(""); + extra.push(`HOST-NATIVE COMPACTION — the client (${lane ?? "unknown lane"}) compacted this conversation natively at ${atIso}; bili has NOT yet rebased onto the compacted view (the rebase lands on the next turn). Refs minted before this boundary stop resolving once it completes — compress only live refs.`); + } else { + const rebasedIso = typeof bnd.rebasedAt === "number" ? new Date(bnd.rebasedAt).toISOString() : "?"; + extra.push(""); + extra.push(`HOST-NATIVE COMPACTION — the client (${lane ?? "unknown lane"}) compacted this conversation natively at ${atIso} and bili rebased onto it at ${rebasedIso}. Refs minted before that boundary no longer resolve — compress only the live refs listed above (DEAD REFS names which ones died).`); + } + } + } if (breaker) { extra.push(""); extra.push(`COMPRESS CIRCUIT BREAKER: ARMED — consecutiveFailures: ${breaker.n} / ${breaker.threshold}. Disarms on one successful compress or ${breaker.decayMinutes} min without further failures.`); diff --git a/tests/acp-status.test.ts b/tests/acp-status.test.ts index 01ccac12ac..e9460ed8c2 100644 --- a/tests/acp-status.test.ts +++ b/tests/acp-status.test.ts @@ -203,3 +203,25 @@ test("acp_status renders the ACTIVE SURFACE line from the session's pack stamp", assert.ok(line, "ACTIVE SURFACE line present once stamped"); assert.ok(line!.startsWith("ACTIVE SURFACE: pack=lean | host=billion-context "), `host identity rendered (got: ${line})`); }); + +test("acp_status marks host-native compaction landings per session (#4458)", () => { + const clean = handleAcpStatus({}, makeCtx12()).text; + assert.ok(!clean.includes("HOST-NATIVE COMPACTION"), "negative gate: no marker when no native-compaction landing was recorded"); + + const pending = makeCtx12(); + const t0 = Date.now() - 30_000; + pending.session.metadata.pluginAgent = "hermes"; + pending.session.metadata.nativeCompactionBoundary = { at: t0, pendingRebase: true }; + const outPending = handleAcpStatus({}, pending).text; + assert.ok(outPending.includes("HOST-NATIVE COMPACTION"), "marker present when a landing is recorded"); + assert.ok(outPending.includes("(hermes)"), "names the resolved client/lane"); + assert.ok(outPending.includes("NOT yet rebased"), "pending-rebase state surfaced"); + + const done = makeCtx12(); + const t1 = Date.now() - 90_000; + done.session.metadata.clientHint = "codex"; + done.session.metadata.nativeCompactionBoundary = { at: t1, pendingRebase: false, rebasedAt: Date.now() - 60_000 }; + const outDone = handleAcpStatus({}, done).text; + assert.ok(outDone.includes("rebased onto it at"), "rebased state surfaced"); + assert.ok(outDone.includes("(codex)"), "codex lane resolved from clientHint"); +});