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
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
name: CI

# Same-branch pushes supersede: cancel the branch's in-progress/queued CI run
# so a 12-leg matrix never piles up behind itself (the 8 e2e workflows have
# had this since their split; the main CI was the gap — see the 447-run queue
# incident on 2026-10-23).
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
# Release branches also run CI on push: ref updates made with a real
Expand Down
14 changes: 13 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BLOCKED_REF, COMPRESS_TOOL_NAME, type CompressionCore, type Config, type CoreMessage, type NudgeDecision, type RetrievalExport, applyRetrieve, countMessageTokens, parseStoredPlaceholder, prune } from "acp-kernel";
import { imageRescaleEnabled, publicSnapshotCapBytes } from "./knobs.js";
import { buildStatusPanel } from "acp-kernel/panel";
import { buildStatusPanel, formatCompactTokens } from "acp-kernel/panel";
import { fileURLToPath } from "node:url";
import type { ServerResponse } from "node:http";
import fs from "node:fs";
Expand Down Expand Up @@ -1712,6 +1712,14 @@ export function handlePluginStatus(conversationId: string, res: import("node:htt
if (obd !== undefined && obd.model !== undefined && obd.value !== undefined && obd.model === lastModel) {
preFooter.push(`⚠️ OUTPUT BUDGET: model "${obd.model}" has NO known output ceiling — outgoing max_tokens restored to ${obd.value} tokens from the client's own estimate (no ceiling to back it); longer replies may cut off at the output limit. Declare an output limit in bili config or set maxTokens on the host model item (#2904).`);
}
// #4130: the denominator above is the EFFECTIVE window (post output-headroom
// reservation) — tie it back to the declared one so a 200K model judging at
// 150K doesn't read as a misidentified window. Display-only note; the
// reservation itself is unchanged (#896 design).
const headroomBase = session.metadata.outputHeadroomBase;
if (typeof headroomBase === "number" && Number.isFinite(headroomBase) && headroomBase > modelContextLimit && modelContextLimit > 0) {
preFooter.push(`Window: judging against ${formatCompactTokens(modelContextLimit)} effective (${formatCompactTokens(headroomBase)} declared − ${formatCompactTokens(headroomBase - modelContextLimit)} output reserve)`);
}
const upd = getUpdateVisibility(VERSION);
if (upd.visible) {
// #1870 visibility for the silent courier, #1977 display policy:
Expand Down Expand Up @@ -1753,6 +1761,10 @@ export function handlePluginStatus(conversationId: string, res: import("node:htt
?? pluginRuntimeInfoForConversation(conversationIdForSession(session.id), typeof session.metadata.lastModel === "string" ? session.metadata.lastModel : undefined)
?? null,
contextLimit: typeof limit === "number" ? limit : null,
// #4130: declared (pre-output-headroom) window while a reservation shrinks
// the effective denominator — additive field, machine-readable twin of the
// Window: note above; null when no reservation is active.
contextWindowBase: typeof headroomBase === "number" && Number.isFinite(headroomBase) ? headroomBase : null,
contextTokens,
contextTokensSource,
contextTokensAt: observation?.at ?? null,
Expand Down
14 changes: 12 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2291,11 +2291,14 @@ export function diagTagSummary(messages: CoreMessage[], sessionId: string, strat
return `[${sessionId}] processTurn: ${messages.length} msgs, renderTags=${strategy}, ${textTagged} text tagged, ${toolTagged} tool tagged (should be 0 with text-only)`;
}

export function diagNudge(turn: { nudge?: { shouldInject: boolean; reason: string; contextUsage: number; tier: number | null; breakdown?: Record<string, number> } | null }, sessionId: string, tokenCount: number, limit: number, model: string | undefined, willInject: boolean, decidePending = false, surfaceOff?: string): string {
export function diagNudge(turn: { nudge?: { shouldInject: boolean; reason: string; contextUsage: number; tier: number | null; breakdown?: Record<string, number> } | null }, sessionId: string, tokenCount: number, limit: number, model: string | undefined, willInject: boolean, decidePending = false, surfaceOff?: string, windowBase?: number): string {
const n = turn.nudge;
if (!n) return `[${sessionId}] nudge: unavailable`;
const b = n.breakdown ?? {};
const pct = limit > 0 ? `${Math.round((tokenCount / limit) * 100)}%` : "?";
// #4130: when the denominator is the post-output-headroom effective window,
// say so inline — a bare "65256/150000" reads as a misidentified 150K model.
const winNote = typeof windowBase === "number" && Number.isFinite(windowBase) && windowBase > limit ? `, window ${windowBase} − output reserve ${windowBase - limit}` : "";
const growth = b["growth"] ?? 0;
const floor = b["growthFloor"] ?? 0;
const interval = b["nudgeGrowthTokens"] ?? 0;
Expand All @@ -2315,7 +2318,14 @@ export function diagNudge(turn: { nudge?: { shouldInject: boolean; reason: strin
// the observed top-level tools so the next omnibus rename is greppable here
// (`surface=off(top-level=[...])`) instead of arriving as a user incident.
const offTag = surfaceOff ? `, ${surfaceOff}` : "";
return `[${sessionId}] nudge ${inject}: usage=${pct} (${tokenCount}/${limit}), growth=${growth}/${floor} (ref=${ref}, interval=${interval}), pendingT1=${pendingT1}/${interval}${modelTag}${offTag}, reason="${n.reason.slice(0, 120)}"`;
return `[${sessionId}] nudge ${inject}: usage=${pct} (${tokenCount}/${limit}${winNote}), growth=${growth}/${floor} (ref=${ref}, interval=${interval}), pendingT1=${pendingT1}/${interval}${modelTag}${offTag}, reason="${n.reason.slice(0, 120)}"`;
}

// #4130: the declared (pre-output-headroom) window handle() records while a
// reservation shrinks the effective denominator — display annotations only.
export function outputHeadroomBase(session: Session): number | undefined {
const v = session.metadata?.outputHeadroomBase;
return typeof v === "number" && Number.isFinite(v) ? v : undefined;
}

// Zero-baseline sessions are judged conservatively ONLY when they arrived
Expand Down
2 changes: 2 additions & 0 deletions src/server/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,8 @@ function sendStats(res: http.ServerResponse): void {
// largest input recent successful turns actually got through. A wide gap
// means the provider overstates its window.
contextWindow: typeof s.metadata.effectiveContextLimit === "number" ? s.metadata.effectiveContextLimit : undefined,
// #4130: declared pre-output-headroom window — pairs with contextWindow (the effective denominator).
contextWindowBase: typeof s.metadata.outputHeadroomBase === "number" ? s.metadata.outputHeadroomBase : undefined,
lastSeen: new Date(s.lastSeen).toISOString(),
restored: s.restored === true,
};
Expand Down
11 changes: 11 additions & 0 deletions src/server/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,17 @@ async function handleRequest(
// pre-self-heal and only for plugin sessions, so wire-mode panels fell
// back to a hardcoded 200K.
session.metadata.effectiveContextLimit = reqConfig.modelContextLimit;
// #4130: tie the effective denominator back to the DECLARED window for
// display surfaces (/acp panel, nudge log line, Web UI bar) — a 200K
// model judging at 150K must not read as a misidentified window.
// Written only while a reservation actually shrank the window; cleared
// otherwise so a model/protocol switch never shows a stale annotation.
// Display-only: the kernel keeps judging against the value above.
if (reqConfig.modelContextLimit < nativeWindow) {
session.metadata.outputHeadroomBase = nativeWindow;
} else {
delete session.metadata.outputHeadroomBase;
}
// #955 runtime-info: record the model id + window source for this
// session so /__bili/plugin/status can show them pre-first-request and
// post-hoc forensics can tell which source sized the window.
Expand Down
4 changes: 2 additions & 2 deletions src/server/prepare-anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { rewriteInboundThreadContinue } from "./thread-tracking.js";
import { captureThreadsTurn, estimateThreadsTokens, isThreadsBody, threadsReforgeEnabled } from "./threads-lane.js";
import type { CompressReasoningConfig } from "../reasoning-drop.js";
import type { ProxyOptions } from "../config.js";
import { applyReasoningDrop, diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, planReasoningDrop, reapOrphansLogged, runNudgeDecision, stripKernelSummaries, warnAnthropicThinkingPairs, type Prepared } from "../server.js";
import { applyReasoningDrop, diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, outputHeadroomBase, planReasoningDrop, reapOrphansLogged, runNudgeDecision, stripKernelSummaries, warnAnthropicThinkingPairs, 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";
Expand Down Expand Up @@ -363,7 +363,7 @@ export async function prepareAnthropic(
growthFoldingArmed: growthFoldingArmed(loopConfig),
modelWantsIt: turn.nudge !== undefined && (turn.nudge.shouldInject || emergencyNudgeArmed(session, turn.nudge, loopConfig.compress.minCompressRange, tokenCount, loopConfig.nudge.growthFloor)),
});
log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, resolvedModel ?? parsed.model, willInjectNudge, decideTier1Arm && !decideFallbackOverride, surfaceOffDetail(laneDecisions, opts.compress.injectTool)));
log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, resolvedModel ?? parsed.model, willInjectNudge, decideTier1Arm && !decideFallbackOverride, surfaceOffDetail(laneDecisions, opts.compress.injectTool), outputHeadroomBase(session)));
processedMessages = applyReasoningDrop(stripKernelSummaries(turn.messages, turn.state), reasoningPlan, log, sessionId);
// #1001: a silent client history rewrite takes the same archive+prune path
// as an announced /compact boundary — syncBlocks above has already
Expand Down
4 changes: 2 additions & 2 deletions src/server/prepare-google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { renderNudgeText, viableRanges } from "acp-kernel";
import { coreToGoogle, googleToCore, normalizeGoogleUserPartOrder, type BiliMessage, type GoogleContent, type GoogleRequestBody, type GoogleSystemInstruction, type GoogleTool } from "acp-kernel/wire";
import type { ProxyOptions } from "../config.js";
import { currentCalibrationFactor } from "../util.js";
import { diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, reapOrphansLogged, resolveKnownOutputCeiling, runNudgeDecision, stripKernelSummaries, usageGradeInputBaseline, type Prepared } from "../server.js";
import { diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, outputHeadroomBase, reapOrphansLogged, resolveKnownOutputCeiling, 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";
Expand Down Expand Up @@ -241,7 +241,7 @@ export async function prepareGoogle(
growthFoldingArmed: growthFoldingArmed(loopConfig),
modelWantsIt: turn.nudge !== undefined && (turn.nudge.shouldInject || emergencyNudgeArmed(session, turn.nudge, loopConfig.compress.minCompressRange, tokenCount, loopConfig.nudge.growthFloor)),
});
log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, model, willInjectNudge, decideTier1Arm && !decideFallbackOverride, surfaceOffDetail(laneDecisions, opts.compress.injectTool)));
log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, model, willInjectNudge, decideTier1Arm && !decideFallbackOverride, surfaceOffDetail(laneDecisions, opts.compress.injectTool), outputHeadroomBase(session)));
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
Expand Down
4 changes: 2 additions & 2 deletions src/server/prepare-openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { CompressReasoningConfig } from "../reasoning-drop.js";
import type { ProxyOptions } from "../config.js";
import { currentCalibrationFactor, hardenOpenaiAssistantContent, systemToUser } from "../util.js";
import { conversationHeaderSource, resolveRelayAffinityPck } from "../session-id.js";
import { applyReasoningDrop, diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, planReasoningDrop, reapOrphansLogged, resolveKnownOutputCeiling, runNudgeDecision, stripKernelSummaries, warnDroppedOpenaiParts, warnReasoningPairs, type Prepared } from "../server.js";
import { applyReasoningDrop, diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, outputHeadroomBase, planReasoningDrop, reapOrphansLogged, resolveKnownOutputCeiling, runNudgeDecision, stripKernelSummaries, warnDroppedOpenaiParts, warnReasoningPairs, 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";
Expand Down Expand Up @@ -260,7 +260,7 @@ export async function prepareOpenai(
growthFoldingArmed: growthFoldingArmed(loopConfig),
modelWantsIt: turn.nudge !== undefined && (turn.nudge.shouldInject || emergencyNudgeArmed(session, turn.nudge, loopConfig.compress.minCompressRange, tokenCount, loopConfig.nudge.growthFloor)),
});
log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge, decideTier1Arm && !decideFallbackOverride, surfaceOffDetail(laneDecisions, opts.compress.injectTool)));
log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge, decideTier1Arm && !decideFallbackOverride, surfaceOffDetail(laneDecisions, opts.compress.injectTool), outputHeadroomBase(session)));
processedMessages = applyReasoningDrop(stripKernelSummaries(turn.messages, turn.state), reasoningPlan, log, sessionId);
// #1001: a silent client history rewrite takes the same archive+prune path
// as an announced /compact boundary — syncBlocks above has already
Expand Down
4 changes: 2 additions & 2 deletions src/server/prepare-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { CompressReasoningConfig } from "../reasoning-drop.js";
import { resolveAbsorbSettings } from "../compress-settings.js";
import { resolveCompressProtocol, type CompressSettings, type ProxyOptions } from "../config.js";
import { currentCalibrationFactor, strippedResponseIdWarning } from "../util.js";
import { applyReasoningDrop, diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, planReasoningDrop, repairResponsesAssistantOrdering, reapOrphansLogged, resolveKnownOutputCeiling, runNudgeDecision, stripKernelSummaries, usageGradeInputBaseline, warnResponsesReasoningPairs, type Prepared } from "../server.js";
import { applyReasoningDrop, diagNudge, diagTagSummary, deriveTitle, effectiveTokenCount, imageBillingFor, imageReserveFor, imageTokenCapFor, isAutoInjectedNotification, outputHeadroomBase, planReasoningDrop, repairResponsesAssistantOrdering, reapOrphansLogged, resolveKnownOutputCeiling, runNudgeDecision, stripKernelSummaries, usageGradeInputBaseline, warnResponsesReasoningPairs, 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";
Expand Down Expand Up @@ -361,7 +361,7 @@ export async function prepareResponses(
growthFoldingArmed: growthFoldingArmed(loopConfig, codexLane && codexCompactMode() === "intercept" ? loopConfig.modelContextLimit * CODEX_COMPACT_HEALTH_RATIO : undefined),
modelWantsIt: turn.nudge !== undefined && (turn.nudge.shouldInject || emergencyNudgeArmed(session, turn.nudge, loopConfig.compress.minCompressRange, tokenCount, loopConfig.nudge.growthFloor)),
});
log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge, decideTier1Arm && !decideFallbackOverride, surfaceOffDetail(laneDecisions, opts.compress.injectTool)));
log("info", diagNudge(turn, sessionId, tokenCount, config.modelContextLimit, parsed.model, willInjectNudge, decideTier1Arm && !decideFallbackOverride, surfaceOffDetail(laneDecisions, opts.compress.injectTool), outputHeadroomBase(session)));
processedMessages = repairResponsesAssistantOrdering(applyReasoningDrop(stripKernelSummaries(turn.messages, turn.state), reasoningPlan, log, sessionId), originalMessages);
// #3477: consume the announced native-compaction boundary (pi session_compact
// → /__bili/plugin/compact → markCompactionBoundary) exactly once, after the
Expand Down
5 changes: 5 additions & 0 deletions src/web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,11 @@ if (d.keepalive) kv(parts, t("det.keepalive"), d.keepalive.tierLabel + " · " +
const cls = pct >= 90 ? "bar-fill danger" : pct >= 70 ? "bar-fill warn" : "bar-fill";
parts.push('<div class="bar-row"><span class="dim small">' + t("common.context") + ctxMark + " / " + t("common.window") + '</span><div class="bar-track"><div class="' + cls + '" style="width:' + pct + '%"></div></div><span class="mono small">' + fmtW(ctxVal) + " / " + fmtW(d.contextWindow) + " (" + pct + "%)" + ctxMark + "</span></div>");
const ctxSubBits = [];
// #4130: denominator is the post-output-headroom effective window —
// say so, or a reserved 200K model reads as a misidentified 150K one.
if ((d.contextWindowBase || 0) > (d.contextWindow || 0)) {
ctxSubBits.push('<span title="' + escapeHtml(t("det.window_reserve_tip")) + '">' + escapeHtml(t("det.window_reserve", { base: fmtW(d.contextWindowBase), res: fmtW(d.contextWindowBase - d.contextWindow) })) + "</span>");
}
if ((d.contextUpperTokens || 0) > 0 && (!best || best.kind !== "upper") && d.contextUpperTokens !== ctxVal) {
ctxSubBits.push(t("det.upper_bound", { v: fmtW(d.contextUpperTokens) }));
}
Expand Down
Loading
Loading