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
28 changes: 27 additions & 1 deletion src/acp-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ interface AcpStatusCtx {
session: Session;
}

// #3192: the submit gate rejects any range that still cites a ref recorded DEAD
// (the client rewrote/dropped those messages), but the eligibility view
// (buildCompressibleRanges) never reads state.deadRefs — so without this filter
// the hint/acp_status advertise exactly the doomed ranges the gate then refuses,
// contradicting the "recorded as DEAD" receipt in the same message. Drop any
// advertised range whose [startRef..endRef] span contains a dead ref. No-op when
// deadRefs is empty; conservative — drops the whole span rather than splitting
// around the dead cell (the kernel-level split is the more fundamental home).
export function excludeDeadRefRanges<T extends { startRef: string; endRef: string }>(ranges: T[], deadRefs?: string[]): T[] {
if (!deadRefs || deadRefs.length === 0) return ranges;
const deadNumbers: number[] = [];
for (const ref of deadRefs) {
const m = /^m(\d+)$/i.exec(ref);
if (m) deadNumbers.push(Number(m[1]));
}
if (deadNumbers.length === 0) return ranges;
return ranges.filter((range) => {
const s = /^m(\d+)$/i.exec(range.startRef);
const e = /^m(\d+)$/i.exec(range.endRef);
if (!s || !e) return true;
const start = Number(s[1]);
const end = Number(e[1]);
return !deadNumbers.some((n) => n >= start && n <= end);
});
}

export function liveCompressionRanges(ctx: AcpStatusCtx): { nudge: NudgeDecision; ranges: CompressibleRange[] } | undefined {
const turn = ctx.core.processTurn({
messages: ctx.messages,
Expand All @@ -44,7 +70,7 @@ export function liveCompressionRanges(ctx: AcpStatusCtx): { nudge: NudgeDecision
const minChars = ctx.config.compress.minCompressRange;
return {
nudge: turn.nudge,
ranges: viableRanges(turn.nudge.compressibleRanges).filter((r) => minChars <= 0 || (r.chars ?? r.tokens * 4) >= minChars),
ranges: excludeDeadRefRanges(viableRanges(turn.nudge.compressibleRanges).filter((r) => minChars <= 0 || (r.chars ?? r.tokens * 4) >= minChars), ctx.session.state.deadRefs),
};
}

Expand Down
8 changes: 8 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function tailLooksTerminal(tail: string, protocol: WireProtocol | "responses"):
}
import { degenerateTurnWarning, endsWithDraftClose, requestExpectsProseSummary } from "./degenerate-turn.js";
import { PANEL_BOX_FOOTER } from "./acp-panel.js";
import { excludeDeadRefRanges } from "./acp-status.js";
import { describeAdvisory, getAdvisoryState } from "./advisory.js";
import { describeUpdateReady, getUpdateVisibility } from "./update-notes.js";
import { warnCacheCollapse } from "./cache-warn.js";
Expand Down Expand Up @@ -1464,6 +1465,13 @@ export function handlePluginStatus(conversationId: string, res: import("node:htt
} catch {
nudge = undefined;
}
// #3204: the submit gate rejects any span that brackets a ref recorded DEAD
// (the client rewrote/dropped those messages) — the same self-contradiction
// as the #3192 receipt/acp_status surfaces. Filter at the source so the
// panel text and the compressibleRanges field below cannot drift apart.
if (nudge) {
nudge = { ...nudge, compressibleRanges: excludeDeadRefRanges(nudge.compressibleRanges ?? [], session.state.deadRefs) };
}
let panel: string | undefined;
try {
// #532: the kernel breakdown classifies messages only; bili measured
Expand Down
7 changes: 6 additions & 1 deletion src/server/prepare-anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { CompressReasoningConfig } from "../reasoning-drop.js";
import type { ProxyOptions } from "../config.js";
import { diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, reapOrphansLogged, runNudgeDecision, stripKernelSummaries, warnAnthropicThinkingPairs, withReasoningDrop, type Prepared } from "../server.js";
import { buildDecisionPrompt, buildDirectiveText, consumeFallback, ladderMode, resolveDecisionRange, stripDecisionReasoningFields, type DecideConfig } from "../nudge-decide.js";
import { excludeDeadRefRanges } from "../acp-status.js";
import { reconcileFoldCoverage, noteSystemPromptFingerprint, resolveFoldReconcileMode } from "../fold-reconcile.js";
import { nudgeSuppressed } from "../session-self-heal.js";
import { compressBreakerArmed } from "../stream.js";
Expand Down Expand Up @@ -232,7 +233,11 @@ export async function prepareAnthropic(
// Drop sub-viability fragments before any consumer sees them: a tiny
// range in the list makes batched compress attempts fail atomically
// (kernel validates the whole batch). Mirrors billion-context-pi.
if (turn.nudge) turn.nudge.compressibleRanges = viableRanges(turn.nudge.compressibleRanges);
// #3204: also drop DEAD-ref-bracketing spans at this single point so
// every downstream consumer (decision prompt + directive, prose nudge,
// emergency override, preflight length gates) sees only spans the
// submit gate can accept — no surface advertises a doomed span.
if (turn.nudge) turn.nudge.compressibleRanges = excludeDeadRefRanges(viableRanges(turn.nudge.compressibleRanges), session.state.deadRefs);
nudge = turn.nudge;
session.stats.contextTokens = tokenCount;
session.stats.contextTokensSource = tokenCountSource;
Expand Down
7 changes: 6 additions & 1 deletion src/server/prepare-google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ProxyOptions } from "../config.js";
import { currentCalibrationFactor } from "../util.js";
import { diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, reapOrphansLogged, runNudgeDecision, stripKernelSummaries, usageGradeInputBaseline, type Prepared } from "../server.js";
import { buildDecisionPrompt, buildDirectiveText, consumeFallback, ladderMode, resolveDecisionRange, stripDecisionReasoningFields, type DecideConfig } from "../nudge-decide.js";
import { excludeDeadRefRanges } from "../acp-status.js";
import { reconcileFoldCoverage, noteSystemPromptFingerprint, resolveFoldReconcileMode } from "../fold-reconcile.js";
import { nudgeSuppressed } from "../session-self-heal.js";
import { compressBreakerArmed } from "../stream.js";
Expand Down Expand Up @@ -172,7 +173,11 @@ export async function prepareGoogle(
// Drop sub-viability fragments before any consumer sees them: a tiny
// range in the list makes batched compress attempts fail atomically
// (kernel validates the whole batch). Mirrors billion-context-pi.
if (turn.nudge) turn.nudge.compressibleRanges = viableRanges(turn.nudge.compressibleRanges);
// #3204: also drop DEAD-ref-bracketing spans at this single point so
// every downstream consumer (decision prompt + directive, prose nudge,
// emergency override, preflight length gates) sees only spans the
// submit gate can accept — no surface advertises a doomed span.
if (turn.nudge) turn.nudge.compressibleRanges = excludeDeadRefRanges(viableRanges(turn.nudge.compressibleRanges), session.state.deadRefs);
nudge = turn.nudge;
session.stats.contextTokens = tokenCount;
session.stats.contextTokensSource = tokenCountSource;
Expand Down
7 changes: 6 additions & 1 deletion src/server/prepare-openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { currentCalibrationFactor, hardenOpenaiAssistantContent, systemToUser }
import { conversationHeaderSource, shouldStampRelayAffinityPck } from "../session-id.js";
import { diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, reapOrphansLogged, runNudgeDecision, stripKernelSummaries, warnDroppedOpenaiParts, warnReasoningPairs, withReasoningDrop, type Prepared } from "../server.js";
import { buildDecisionPrompt, buildDirectiveText, consumeFallback, ladderMode, resolveDecisionRange, stripDecisionReasoningFields, type DecideConfig } from "../nudge-decide.js";
import { excludeDeadRefRanges } from "../acp-status.js";
import { reconcileFoldCoverage, noteSystemPromptFingerprint, resolveFoldReconcileMode } from "../fold-reconcile.js";
import { nudgeSuppressed } from "../session-self-heal.js";
import { compressBreakerArmed } from "../stream.js";
Expand Down Expand Up @@ -177,7 +178,11 @@ export async function prepareOpenai(
// Drop sub-viability fragments before any consumer sees them: a tiny
// range in the list makes batched compress attempts fail atomically
// (kernel validates the whole batch). Mirrors billion-context-pi.
if (turn.nudge) turn.nudge.compressibleRanges = viableRanges(turn.nudge.compressibleRanges);
// #3204: also drop DEAD-ref-bracketing spans at this single point so
// every downstream consumer (decision prompt + directive, prose nudge,
// emergency override, preflight length gates) sees only spans the
// submit gate can accept — no surface advertises a doomed span.
if (turn.nudge) turn.nudge.compressibleRanges = excludeDeadRefRanges(viableRanges(turn.nudge.compressibleRanges), session.state.deadRefs);
nudge = turn.nudge;
session.stats.contextTokens = tokenCount;
session.stats.contextTokensSource = tokenCountSource;
Expand Down
7 changes: 6 additions & 1 deletion src/server/prepare-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { resolveCompressProtocol, type CompressSettings, type ProxyOptions } fro
import { currentCalibrationFactor, strippedResponseIdWarning } from "../util.js";
import { diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, repairResponsesAssistantOrdering, reapOrphansLogged, runNudgeDecision, stripKernelSummaries, usageGradeInputBaseline, warnResponsesReasoningPairs, withReasoningDrop, type Prepared } from "../server.js";
import { buildDecisionPrompt, buildDirectiveText, consumeFallback, ladderMode, resolveDecisionRange, stripDecisionReasoningFields, type DecideConfig } from "../nudge-decide.js";
import { excludeDeadRefRanges } from "../acp-status.js";
import { mergeAdjacentConfigurationUpdates, patchResponsesInputWithToolImages as patchResponsesInput, responsesToCoreWithToolImages as responsesToCore } from "../responses-tool-output.js";
import { dropWhitespaceResponsesMessages, normalizeResponsesMessageItems, sanitizeResponsesInputIds } from "../loop/adapter-responses.js";
import { METADATA_LAST_RESPONSES_MODE, noteCanonicalSystemFingerprint, reconcileFoldCoverage, noteSystemPromptFingerprint, resolveFoldReconcileMode } from "../fold-reconcile.js";
Expand Down Expand Up @@ -282,7 +283,11 @@ export async function prepareResponses(
// Drop sub-viability fragments before any consumer sees them: a tiny
// range in the list makes batched compress attempts fail atomically
// (kernel validates the whole batch). Mirrors billion-context-pi.
if (turn.nudge) turn.nudge.compressibleRanges = viableRanges(turn.nudge.compressibleRanges);
// #3204: also drop DEAD-ref-bracketing spans at this single point so
// every downstream consumer (decision prompt + directive, prose nudge,
// emergency override, preflight length gates) sees only spans the
// submit gate can accept — no surface advertises a doomed span.
if (turn.nudge) turn.nudge.compressibleRanges = excludeDeadRefRanges(viableRanges(turn.nudge.compressibleRanges), session.state.deadRefs);
nudge = turn.nudge;
session.stats.contextTokens = tokenCount;
session.stats.contextTokensSource = tokenCountSource;
Expand Down
Loading
Loading