diff --git a/docs/configuration.md b/docs/configuration.md index 45bea523e4..39c4858027 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -283,7 +283,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed | `compress.maxEstimateHoldRounds` | number | 2 | — | Backstop for the phantom-pressure guard (#5865 ruling): how many CONSECUTIVE estimate-grade rounds the pressure band may wait before firing on the estimate anyway. Capped so an upstream that never reports usage (anonymous zero-baseline forks, silent backends — where the local estimate is the only pressure signal) still gets automatic compression. 0 = no waiting at all. Only consulted while requireUsageSampleForPressure is on. | | `compress.nudgeModelDecided` | boolean | off (unset) | — | Model-decided nudge timing (#2228): an armed tier-1 nudge first asks the model — via a short side call over the session's cached prefix — whether compressing NOW helps the current task. A strict-JSON "yes" injects an explicit directive with a program-finalized span; "no", a malformed answer, or a timeout injects nothing this round. EMERGENCY arms and tier≥2 distillation always keep the legacy advisory. Off unless explicitly enabled. | | `compress.nudgeDecisionMaxTokens` | number | 200 | — | Output budget (tokens) of the model-decision side call used by nudgeModelDecided. Must be > 0. | -| `compress.requireNudge` | boolean | off (unset) | — | Forbid UNPROMPTED model-initiated compression (#5683): a compress call is refused unless a compression nudge actually reached the model in the current turn (advisory, decide-directive and emergency injections all arm; loop rounds of the same turn keep the arm, the next un-nudged turn disarms). Refusal sends the model an error receipt instead of folding; bili's own overflow backstop folds are exempt. For models that fold on their own (e.g. qwen 27b); can be scoped per provider/model. Off unless explicitly enabled. | +| `compress.requireNudge` | boolean | off (unset) | — | Forbid UNPROMPTED model-initiated compression (#5683/#5943): a compress call is refused unless a NUDGE CREDIT is live — a window of 20 MODEL rounds minted by the last compression nudge that actually reached the model (advisory, decide-directive and emergency injections all mint; "gated"/"vetoed"/"skipped" never do), refreshed by each new injection and decayed one per un-nudged model round (non-model request shapes hold it open). Successful folds do NOT consume the credit, so finishing a nudge's recommended cleanup over several rounds stays legal. Refusal sends the model an error receipt instead of folding; bili's own overflow backstop folds are exempt. For models that fold on their own (e.g. qwen 27b); can be scoped per provider/model. Off unless explicitly enabled. | | `compress.requireRecommendation` | boolean | off (unset) | — | Forbid OUT-OF-BOUNDS model-initiated compression (#5683): every submitted range must stay within what bili currently recommends folding — the same live compressible set the nudge text and acp_status show (this request's prepare-time offer when present, else a live recompute). Judgment is by COVERAGE: subdividing a recommended span passes, and messages already folded into active blocks (refolds updating an existing summary) are exempt. A range carrying any other live message is refused whole with an error receipt naming the offending span(s). Off unless explicitly enabled. | | `compress.streamSummary` | boolean | false (unset) | — | Force preflight summarization to run as a streaming (SSE) call from the first attempt. The error-driven self-learn handles stream-mandating upstreams on its own (any 400 on a non-streaming summary triggers a one-shot SSE probe, #2494) but NEVER arms on gateway timeouts (e.g. Cloudflare HTTP 524): set this where such a gateway sits between bili and the origin, or simply to skip the one probe round-trip. | | `compress.preserveRecentMessages` | number | 3 | — | The most recent messages stay soft-protected from folds. | @@ -1439,7 +1439,7 @@ For each request, the proxy resolves the settings by longest-URL-prefix match (t - **Default:** *(off unless set)* - **Status:** ACTIVE (#5683) - **Description:** Policy gates for models that compress on their own initiative (field case: qwen 27b calling compress without any prompt). Both are host-only fields — not passed to the kernel — merged PER FIELD across global → provider → model like every other compress field, editable in the web panel's quick-config card or any config level, hot-applied from the next request onward. - - `requireNudge` (timing gate): a model-initiated compress call is refused unless a compression nudge actually reached the model in the CURRENT TURN — the post-gate delivery fact (`nudgeOutcome === "injected"`), so advisory nudges, model-decided directives and emergency nudges all arm it, while "gated"/"vetoed"/"skipped" rounds never did. The arm persists across loop re-requests within the same turn (one turn may fold several times in response to one nudge) and dies with the next un-nudged turn. The refusal is an error receipt telling the model that unprompted compression is disabled here and to wait for a nudge. + - `requireNudge` (timing gate): a model-initiated compress call is refused unless a NUDGE CREDIT is live (#5943) — a window of 20 MODEL ROUNDS minted by the last compression nudge that actually reached the model (the post-gate delivery fact `nudgeOutcome === "injected"`: advisory nudges, model-decided directives and emergency nudges all mint it, while "gated"/"vetoed"/"skipped" rounds never do). Each new injection refreshes the window; every un-nudged MODEL round decays it by one; non-model request shapes (countTokens / responsesCompact / local forges) hold it open without refreshing, and loop re-requests within one turn do not re-stamp, so they burn nothing either. Successful folds do NOT consume the credit — finishing a nudge's recommended cleanup over several rounds (the multi-round-cleanup refusal storm #5943 reports) is exactly what the nudge asked for; long-term strictness survives because nudges are growth-driven, so quiet sessions lapse back to strict refusal after 20 un-nudged model rounds while growing ones keep refreshing the window. The refusal is an error receipt telling the model that unprompted compression is disabled here until a nudge appears. - `requireRecommendation` (scope gate): every submitted range must stay within what bili currently RECOMMENDS folding — the same live compressible set the nudge text and `acp_status` show (this request's prepare-time offer when present, else a live recompute, with the usual viable + dead-ref + `minCompressRangeChars` filters). Judgment is by COVERAGE, not equality: subdividing a recommended span into smaller chunks passes (bili's own first-sight guidance encourages splitting), and messages already folded into active blocks are exempt so refolds updating an existing block's summary stay legal. A range carrying any other still-live message is refused whole, naming the offending span(s) and pointing at `acp_status`. - Exemptions & interactions: bili's OWN overflow backstop folds (preflight / auto-fold — no model call involved) are exempt from both gates, so a gated session never dies of context overflow; availability is unaffected even while the nudge channel itself is suppressed (self-heal D1). Hosts that drive compression through their own mechanisms (e.g. codex's compaction trigger, which is not a bili nudge) fall outside the timing gate's notion of "prompted" — scope these settings to the affected provider/model rather than globally if such lanes share the route. No new environment variables; no behavior change unless a level explicitly enables a flag. diff --git a/docs/configuration.zh-CN.md b/docs/configuration.zh-CN.md index c6d3c537c9..e48758173b 100644 --- a/docs/configuration.zh-CN.md +++ b/docs/configuration.zh-CN.md @@ -283,7 +283,7 @@ | `compress.maxEstimateHoldRounds` | number | 2 | — | 幻影压力守卫的兜底(#5865 裁定):压力带最多连等多少轮估算读数就必须照估算动手。兜底保证从不回传计费的会话(匿名零基线 fork、静默后端——本地估算是它们唯一的压力信号)也能拿到自动压缩。0=完全不等待。仅在 requireUsageSampleForPressure 开启时生效。 | | `compress.nudgeModelDecided` | boolean | off (unset) | — | 模型自决的压缩时机(#2228):tier-1 提醒触发时,先通过一次走会话缓存前缀的短 side call 问模型——以当前任务为前提,现在压缩是否划算。严格 JSON 的 "yes" 会注入带程序最终确定范围的明确压缩指令;"no"、格式错误或超时则本轮不注入任何内容。EMERGENCY 档与 tier≥2 蒸馏始终保留原有 advisory。默认关闭,需显式开启。 | | `compress.nudgeDecisionMaxTokens` | number | 200 | — | nudgeModelDecided 所用模型决策 side call 的输出预算(token)。必须 > 0。 | -| `compress.requireNudge` | boolean | off (unset) | — | 禁止未提示的模型主动压缩(#5683):只有当前轮次压缩提醒真正送达模型时(advisory、模型自决指令、紧急提醒都算;"gated"/"vetoed"/"skipped" 不算)才允许 compress,否则拒绝并回错误回执;同一轮内的多次 loop 请求保持武装,下一个未提示轮次自动解除。bili 自己的溢出兜底折叠不受影响。针对会自行乱压的模型(如 qwen 27b),可按 provider/model 单独开启。默认关闭。 | +| `compress.requireNudge` | boolean | off (unset) | — | 禁止未提示的模型主动压缩(#5683/#5943):只有 nudge 信用存活时才允许 compress——即距最近一次真正送达模型的压缩提醒不超过 20 个 MODEL 轮的窗口(advisory、模型自决指令、紧急提醒都算铸券;"gated"/"vetoed"/"skipped" 不算);每次新注入刷新窗口,每个未提示的模型轮衰减 1(非模型请求形态既不刷新也不衰减)。成功折叠**不消耗**信用,分几轮压完 nudge 推荐的剩余范围仍然合法。否则拒绝并回错误回执;bili 自己的溢出兜底折叠不受影响。针对会自行乱压的模型(如 qwen 27b),可按 provider/model 单独开启。默认关闭。 | | `compress.requireRecommendation` | boolean | off (unset) | — | 禁止越界的模型主动压缩(#5683):提交的每个范围必须落在 bili 当前推荐折叠的集合内——即 nudge 文案与 acp_status 展示的同一份实时可压缩列表(有本轮 prepare 快照用快照,否则实时重算)。按「覆盖」判定而非精确相等:把推荐跨度拆小段通过;已折进活跃块的消息豁免(重折已有块更新摘要合法)。范围里含任何其他仍存活的消息则整体拒绝,回执点名越界跨度并指向 acp_status。默认关闭。 | | `compress.streamSummary` | boolean | false (unset) | — | 强制 preflight 摘要从首次尝试起就走流式(SSE)请求。要求流式的上游现在由错误驱动自学习自动处理(非流式摘要的任何 400 都会触发一次性 SSE 探测,#2494),但网关超时(如 Cloudflare HTTP 524)永远无法触发自学习:在此类网关位于 bili 与源站之间时设置此项,或用于省去一次探测往返。 | | `compress.preserveRecentMessages` | number | 3 | — | 最近的消息软保护、免于折叠。 | @@ -1436,7 +1436,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 - **默认值:** *(关闭,除非显式设置)* - **状态:** ACTIVE (#5683) - **说明:** 针对会自行主动压缩的模型的策略门禁(现场案例:qwen 27b 没有任何提示就调用 compress)。两者都是宿主侧字段——不传入内核——与其他 compress 字段一样按字段在 global → provider → model 三级合并,可在 web 面板快速配置卡片或任意配置层级编辑,从下一个请求起热生效。 - - `requireNudge`(时序门禁):只有**当前轮次**压缩提醒真正送达过模型(post-gate 投递事实 `nudgeOutcome === "injected"`——advisory 提醒、模型自决指令、紧急提醒都算;"gated"/"vetoed"/"skipped" 不算)才允许模型发起 compress,否则拒绝并回一条错误回执,告知未提示压缩在本线路被禁用、等提醒出现再压。武装在同一轮内的 loop 重请求间保持(一轮响应一个提醒可连续折几次),到下一个未提示轮次自动解除。 + - `requireNudge`(时序门禁):只有 **nudge 信用**存活(#5943)才允许模型发起 compress——即距最近一次真正送达模型的压缩提醒(post-gate 投递事实 `nudgeOutcome === "injected"`——advisory 提醒、模型自决指令、紧急提醒都算铸券;"gated"/"vetoed"/"skipped" 不算)不超过 20 个 MODEL 轮的窗口。每次新注入刷新窗口;每个未提示的 MODEL 轮衰减 1;非模型请求形态(countTokens / responsesCompact / 本地 forge)既不刷新也不衰减;同一轮内的 loop 重请求不重新盖章、同样不烧轮次。成功折叠**不消耗**信用——分几轮压完 nudge 推荐的剩余范围正是提醒所要求的(#5943 报告的「隔轮清理被连拒」病理即由此修复);长期严格性由增长驱动的提醒保证:安静会话连续 20 个未提示模型轮后回到严格拒绝,增长中的会话则持续刷新窗口。拒绝时回一条错误回执,告知未提示压缩在本线路被禁用、等提醒出现再压。 - `requireRecommendation`(范围门禁):提交的每个范围必须落在 bili 当前**推荐**折叠的集合内——与 nudge 文案、`acp_status` 展示的同一份实时可压缩列表(有本轮 prepare 快照用快照,否则实时重算,带常规的 viable + dead-ref + `minCompressRangeChars` 过滤)。按「覆盖」判定而非精确相等:把推荐跨度拆成小段通过(bili 自己的首见消化指南就鼓励拆分);已折进活跃块的消息豁免,重折已有块更新摘要保持合法。范围里含任何其他仍存活消息则整体拒绝,回执点名越界跨度并指向 `acp_status`。 - 豁免与交互:bili **自己**的溢出兜底折叠(preflight / auto-fold——不涉及模型调用)两个门禁都豁免,被门禁的会话不会因上下文溢出而死掉;即使 nudge 通道本身被自愈机制抑制(D1),可用性也不受影响。通过宿主自身机制驱动压缩的车道(如 codex 的 compaction trigger——它不是 bili 的提醒)不在时序门禁「已提示」的定义内——若这类车道与目标共用路由,请把这些设置限定到受影响的 provider/model 而不是全局开启。无新增环境变量;未显式开启任何一级时行为不变。 diff --git a/src/server/handle.ts b/src/server/handle.ts index 875cd8bbfd..552d2c87fc 100644 --- a/src/server/handle.ts +++ b/src/server/handle.ts @@ -2947,19 +2947,28 @@ async function handleRequest( degradeAvailable: opts.compress.injectTool && !knobNoInjectTool(), }, log); } - // #5683: stamp this round's compression-prompt facts for the - // unprompted/out-of-bounds gates (applyRanges). armed tracks the - // SAME post-gate delivery fact as the self-heal credit above — - // only an actually delivered nudge ("injected") arms; "gated" - // rounds held by the emergency backoff never did reach the model. - // Stamped on EVERY round (not just nudge-carrying ones) so an - // un-nudged round disarms a stale arm; loop re-requests within - // the same turn do not re-run prepare, so the arm persists across - // rounds of one turn and dies with the next un-nudged turn. + // #5683/#5943: stamp this round's compression-prompt facts for + // the unprompted/out-of-bounds gates (applyRanges). nudgeInjected + // tracks the SAME post-gate delivery fact as the self-heal credit + // above — only an actually delivered nudge ("injected") mints; + // "gated" rounds held by the emergency backoff never did reach + // the model. #5943: the gate consumes a CREDIT, not this-round + // arm — an injected round re-mints NUDGE_CREDIT_ROUNDS model + // rounds of eligibility and every un-nudged model round decays + // one, so a model that comes back one or several rounds later to + // finish a nudge's recommended cleanup is still inside its window + // instead of refused (the single-round arm refused all of them). + // Stamped on EVERY round (not just nudge-carrying ones) so + // un-nudged rounds keep decaying; loop re-requests within the + // same turn do not re-run prepare, so the window persists across + // them. Non-model shapes pass modelRound:false — they hold the + // window open without refreshing it, mirroring the preflight + // exclusion predicate below. storeUnpromptedGate(session, { - armed: prepared.nudgeOutcome === "injected", + nudgeInjected: prepared.nudgeOutcome === "injected", requireNudge: preparedCs?.requireNudge === true, requireRecommendation: preparedCs?.requireRecommendation === true, + modelRound: !countTokens && !responsesCompact && !prepared.codexForge && !prepared.threadsLane, }); // A locally-served codex compaction forge never reaches an // upstream: preflight would burn summarization rounds for a diff --git a/src/session.ts b/src/session.ts index 33d3e6ea6c..3748e3c3d9 100644 --- a/src/session.ts +++ b/src/session.ts @@ -12,7 +12,7 @@ import type { WireProtocol } from "./util.js"; import type { InboundSlot, SeamSlot } from "./cache-ledger.js"; import { isResponsesTurnSeparatorId } from "./turn-separator.js"; import type { FoldReconcileResult } from "./fold-reconcile.js"; -import type { UnpromptedGate } from "./unprompted-gate.js"; +import type { UnpromptedGateState } from "./unprompted-gate.js"; export type BlockView = { text: string; count: number }; @@ -337,12 +337,14 @@ export type Session = { * In-memory only: the abort→resume causality spans one process * lifetime, and a restart replants nothing. */ abortReanchor?: { anchor: number; at: number }; - /** #5683: the conversation's latest model-round compression-prompt facts - * for the unprompted/out-of-bounds gates (src/unprompted-gate.ts). - * Re-stamped on every prepare; in-memory only — a restart reads the - * all-off default until the first round re-stamps, which is safe: no - * tool call can reach applyRanges before its own round's prepare. */ - unpromptedGate?: UnpromptedGate; + /** #5683/#5943: the conversation's live nudge CREDIT plus the policy + * flags, for the unprompted/out-of-bounds gates (src/unprompted-gate.ts). + * Re-stamped on every prepare (injected rounds re-mint the window, + * un-nudged model rounds decay it); in-memory only — a restart lapses + * any live credit to the all-off default until the first round + * re-stamps, which is safe: no tool call can reach applyRanges before + * its own round's prepare. */ + unpromptedGate?: UnpromptedGateState; /** #5981: the last model stream on this conversation was CUT before its * terminal event (src/plugin.ts emitUpstreamTruncation sites). A tool * call dispatched out of such a stream can carry EMPTY arguments — diff --git a/src/stream.ts b/src/stream.ts index 49b482de28..4f24c3d639 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -20,7 +20,7 @@ import { attachSubagentSessions, subagentSessionNote, subagentSessionsOf, syncSu import { METADATA_DRIFT_ESCALATED } from "./fold-reconcile.js"; import { safePrefix, safeSuffix, scrubLoneSurrogates } from "./text-safe.js"; import { applyConfiguredCompression } from "./external-summary-compress.js"; -import { unpromptedGateOf } from "./unprompted-gate.js"; +import { NUDGE_CREDIT_ROUNDS, unpromptedGateOf } from "./unprompted-gate.js"; import { describeUncoveredRuns, shortTokenCount, uncoveredHistoryRuns } from "./uncovered.js"; export type RewriteCtx = { @@ -1057,14 +1057,18 @@ export function applyRanges(parsed: ReturnType, ctx: // failures have separate reporting (noteSkip) and must not arm the // model-facing circuit breaker on attempts the model never made. const trackLoop = opts?.loopTracking !== false; - // #5683: unprompted-compression policy gate (timing). Model-initiated calls - // only — bili's own overflow backstop folds ride loopTracking:false above - // and never reach this check, so availability is unaffected even when the - // nudge channel itself is suppressed. + // #5683/#5943: unprompted-compression policy gate (timing). Model-initiated + // calls only — bili's own overflow backstop folds ride loopTracking:false + // above and never reach this check, so availability is unaffected even when + // the nudge channel itself is suppressed. "armed" here reads as LIVE NUDGE + // CREDIT (#5943): a window of NUDGE_CREDIT_ROUNDS model rounds minted by the + // last actually-injected nudge, refreshed by each new one and decayed by + // every un-nudged model round (see src/unprompted-gate.ts) — NOT this-round + // arm, which refused every multi-round cleanup continuation. const gate = trackLoop ? unpromptedGateOf(ctx.session) : undefined; if (gate?.requireNudge && !gate.armed) { - ctx.log("[acp-proxy: refused unprompted compress — no nudge was injected this turn (compress.requireNudge)]"); - return compressResult("[Compression REFUSED: unprompted compression is disabled on this route (compress.requireNudge) — you may only call compress in a round where a compression nudge was actually injected, and no nudge accompanied this round. Continue the task without folding; when a nudge appears, follow its ranges.]", "refused", 0, "unprompted"); + ctx.log("[acp-proxy: refused unprompted compress — no live nudge credit (window expired or never minted) (compress.requireNudge)]"); + return compressResult(`[Compression REFUSED: unprompted compression is disabled on this route (compress.requireNudge) — you may only call compress while a nudge credit is live, i.e. within ${NUDGE_CREDIT_ROUNDS} model rounds of a compression nudge that was actually injected. No live credit right now: the last injected nudge's window has expired, or no nudge was ever injected. Continue the task without folding; when a nudge appears, follow its ranges.]`, "refused", 0, "unprompted"); } let { ranges, diagnostics } = parsed; if (ranges.length === 0) { diff --git a/src/unprompted-gate.ts b/src/unprompted-gate.ts index e38f900e38..cd88ebc104 100644 --- a/src/unprompted-gate.ts +++ b/src/unprompted-gate.ts @@ -5,32 +5,81 @@ // in-memory only, re-stamped every model round — and read here by applyRanges // (src/stream.ts), the single execution point for every model-initiated compress // across all lanes (proxy loop + POST /__bili/plugin/tool). +// #5943: the requireNudge fact is a CREDIT, not a single-round boolean. An +// actually injected nudge mints NUDGE_CREDIT_ROUNDS model rounds of eligibility; +// each new injection refreshes it, every un-nudged MODEL round decays it by one, +// and non-model shapes (countTokens/responsesCompact/local forges) hold it open — +// they are not model rounds, so they neither refresh nor decay. A successful fold +// does NOT consume it: finishing a nudge's recommended cleanup over several rounds +// is exactly what the nudge asked for (the single-round arm that preceded this +// refused every such continuation — the defect #5943 reports). Long-term strictness +// survives because nudges are growth-driven: quiet sessions lapse back to strict +// refusal after K un-nudged rounds; growing ones keep refreshing a window where +// folding is wanted. import type { Session } from "./session.js"; -export interface UnpromptedGate { - /** A compression nudge actually reached the model in the latest round - * (post-gate delivery fact: nudgeOutcome === "injected" — advisory, - * decide-directive and emergency injections all count; "gated"/"vetoed"/ - * "skipped" never arm). */ +/** Credit window in MODEL ROUNDS (#5943). A constant on purpose — no config + * surface for it: the knob pair already exists, only the window length is fixed. */ +export const NUDGE_CREDIT_ROUNDS = 20; + +/** Read-side view of the gate: what applyRanges judges on. */ +interface UnpromptedGate { + /** A nudge credit is LIVE right now: some compression nudge actually reached + * the model within the last NUDGE_CREDIT_ROUNDS model rounds (post-gate + * delivery fact: nudgeOutcome === "injected" — advisory, decide-directive + * and emergency injections all mint it; "gated"/"vetoed"/"skipped" never do). */ armed: boolean; requireNudge: boolean; requireRecommendation: boolean; } +/** Stamp-side facts, one per prepare. `nudgeInjected` is THIS ROUND'S delivery + * fact (true = a nudge reached the model in this very round); the module turns + * it into the credit transition below. `modelRound` (default true) marks genuine + * model rounds that decay the window; bypass shapes pass false to hold it. */ +interface UnpromptedGateStamp { + nudgeInjected: boolean; + requireNudge: boolean; + requireRecommendation: boolean; + modelRound?: boolean; +} + +/** Stored state (session.transient.unpromptedGate): the live credit counter plus + * the policy flags. In-memory only — a restart lapses any live credit back to + * the all-off default until the first round re-stamps. */ +export interface UnpromptedGateState { + credit: number; + requireNudge: boolean; + requireRecommendation: boolean; +} + const OFF: UnpromptedGate = { armed: false, requireNudge: false, requireRecommendation: false }; -export function storeUnpromptedGate(session: Session, gate: UnpromptedGate): void { +export function storeUnpromptedGate(session: Session, stamp: UnpromptedGateStamp): void { const t = session.transient ?? (session.transient = {}); - t.unpromptedGate = { ...gate }; + const prev = t.unpromptedGate as UnpromptedGateState | undefined; + const prevCredit = + prev && typeof prev === "object" && Number.isFinite(prev.credit) ? Math.max(0, Math.floor(prev.credit)) : 0; + const isModelRound = stamp.modelRound !== false; + // Credit transition: an injected round re-mints the full window; an un-nudged + // model round decays it by one; non-model stamps hold it (lenient freeze — the + // same persistence property loop re-requests within one turn always had, since + // they do not re-run prepare either). + const credit = stamp.nudgeInjected ? NUDGE_CREDIT_ROUNDS : isModelRound ? prevCredit - 1 : prevCredit; + t.unpromptedGate = { + credit: Math.max(0, credit), + requireNudge: stamp.requireNudge === true, + requireRecommendation: stamp.requireRecommendation === true, + }; } /** All-off when nothing was stamped yet (fresh process, unit-test ctxs, lanes * without a prepare) — the default configuration changes no behavior. */ export function unpromptedGateOf(session: Session): UnpromptedGate { - const g = session.transient?.unpromptedGate; + const g = session.transient?.unpromptedGate as UnpromptedGateState | undefined; if (!g || typeof g !== "object") return OFF; return { - armed: g.armed === true, + armed: Number.isFinite(g.credit) && g.credit > 0, requireNudge: g.requireNudge === true, requireRecommendation: g.requireRecommendation === true, }; diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 95ad37ed4d..f04f9072ab 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -582,7 +582,7 @@ export const MESSAGES: Record> = { "cfg.q_absorb_hint": "默认只吸含图结果(#3422);mediaOnly: false 可恢复吸全文。子项(minToolTokens、contextThresholdPct、excludeTools)请在下方 JSON 编辑框写", "cfg.q_cafp": "压缩摘要前置到折叠点(compressAtFoldPoint,默认关)——把每次压缩产生的摘要文本以纯文本形式放到它描述的折叠点处,原 compress 调用对留在原时间位置、参数替换成指针,不再是可执行的完整压缩命令", "cfg.q_cafp_hint": "针对 qwen3-27b 这类注意力机制有问题的小模型很有用:避免历史中部一整墙“完整形状”的 compress 交互被误读成继续压缩的示范/新命令;取消勾选 = 回到旧版布局(字节级一致)。可选的“清未签名思考”开关(clearThinking)只能走 env / JSON", - "cfg.q_require_nudge": "禁止未提示压缩(compress.requireNudge)——只在 bili 实际注入压缩提醒的同一轮允许模型调用 compress,其余一律拒绝并回错误回执(默认关)", + "cfg.q_require_nudge": "禁止未提示压缩(compress.requireNudge)——只在 nudge 信用存活时(最近一次真正注入的提醒起 20 个模型轮内,新提醒刷新、未提示轮衰减、成功折叠不消耗)允许模型调用 compress,其余拒绝并回错误回执(默认关)", "cfg.q_require_nudge_hint": "针对会自行乱压的模型(如 qwen 27b)。bili 自己的溢出兜底折叠不受影响;也可只对特定 provider/model 开启(JSON 编辑框)", "cfg.q_require_rec": "禁止越界压缩(compress.requireRecommendation)——只允许压缩 bili 当前推荐的范围,越界即拒(默认关)", "cfg.q_require_rec_hint": "推荐范围 = nudge / acp_status 展示的可压缩列表;把推荐跨度拆小段、重折已有块更新摘要都算合规", @@ -1330,7 +1330,7 @@ export const MESSAGES: Record> = { "cfg.q_absorb_hint": "by default only image-bearing results are absorbed (#3422); set mediaOnly: false to absorb full text. Sub-fields (minToolTokens, contextThresholdPct, excludeTools) go in the JSON editor below", "cfg.q_cafp": "Summary text relocated to the fold point (compressAtFoldPoint, default off) — each fold's summary text is re-emitted as plain text at the fold point it describes, while the compress call/result pair keeps its chronological slot with its args replaced by a pointer (no longer a fully-shaped compress command)", "cfg.q_cafp_hint": "very useful for small models with attention issues such as qwen3-27b: stops a mid-history wall of fully-shaped compress interactions from reading as an invitation to keep compressing; uncheck = byte-identical legacy layout. The optional clear-thinking companion (clearThinking) stays env/JSON-only", - "cfg.q_require_nudge": "Forbid unprompted compression (compress.requireNudge) — compress may only be called in a round where a nudge was actually injected; anything else is refused with an error receipt (default off)", + "cfg.q_require_nudge": "Forbid unprompted compression (compress.requireNudge) — compress may only be called while a nudge credit is live (within 20 model rounds of the last actually-injected nudge: refreshed by new nudges, decayed per un-nudged round, NOT consumed by successful folds); anything else is refused with an error receipt (default off)", "cfg.q_require_nudge_hint": "for models that fold on their own (e.g. qwen 27b). bili's own overflow backstop folds are unaffected; can also be scoped per provider/model in the JSON editor", "cfg.q_require_rec": "Forbid out-of-bounds compression (compress.requireRecommendation) — only ranges bili currently recommends may be folded; anything else is refused (default off)", "cfg.q_require_rec_hint": "recommended = the compressible list shown by nudge / acp_status; subdividing a listed span or re-folding an existing block to update its summary stays legal", diff --git a/tests/issue5683-forbid-unprompted-compress.test.ts b/tests/issue5683-forbid-unprompted-compress.test.ts index d87f7544d5..6c27bb38ac 100644 --- a/tests/issue5683-forbid-unprompted-compress.test.ts +++ b/tests/issue5683-forbid-unprompted-compress.test.ts @@ -3,16 +3,20 @@ // enforced in applyRanges — the single execution point for every model-initiated // compress across lanes. Gate discipline (#3617): BOTH directions asserted per // gate — fires when it should, stays silent when it should not. +// #5943: requireNudge judges a NUDGE CREDIT (a K-round window minted by each +// actually-injected nudge, decayed per un-nudged model round), not this-round +// arm — the multi-round cleanup continuation cases below pin both directions of +// the window transition. import { test } from "node:test"; import assert from "node:assert/strict"; import type { CoreMessage, CompressibleRange, NudgeDecision } from "acp-kernel"; import { createCore, createInitialState, assignRefs, emptyRefMap, defaultConfig } from "acp-kernel"; import { parseCompressInput } from "../src/compress-tool.ts"; import { parseCompressSettings } from "../src/config.ts"; -import { mergeCompress } from "../src/compress-settings.ts"; +import { mergeCompress } from "../src/compress-settings.js"; import { liveCompressionRanges } from "../src/acp-status.js"; import { applyRanges, type RewriteCtx } from "../src/stream.ts"; -import { storeUnpromptedGate } from "../src/unprompted-gate.ts"; +import { NUDGE_CREDIT_ROUNDS, storeUnpromptedGate } from "../src/unprompted-gate.ts"; const SUM = "SUMMARY-PAYLOAD-LONG-ENOUGH-FOR-THE-KERNEL-MIN-LENGTH-CHECK-XYZ"; @@ -107,7 +111,7 @@ test("#5683: default (nothing stamped) — unprompted compress SUCCEEDS (behavio test("#5683: requireNudge ON + unarmed round — refused with policy receipt, nothing folded", () => { const ctx = freshCtx(); - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: true, requireRecommendation: false }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: true, requireRecommendation: false }); const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); assert.ok(out.startsWith("[Compression REFUSED"), `expected refusal, got: ${out.slice(0, 160)}`); assert.ok(out.includes("requireNudge"), "receipt names the knob:\n" + out); @@ -117,14 +121,14 @@ test("#5683: requireNudge ON + unarmed round — refused with policy receipt, no test("#5683: requireNudge ON + armed round (nudge injected) — allowed", () => { const ctx = freshCtx(); - storeUnpromptedGate(ctx.session, { armed: true, requireNudge: true, requireRecommendation: false }); + storeUnpromptedGate(ctx.session, { nudgeInjected: true, requireNudge: true, requireRecommendation: false }); const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); assert.ok(out.startsWith("[Compressed"), `expected success, got: ${out.slice(0, 160)}`); }); test("#5683: requireNudge ON + unarmed + preflight lane (loopTracking:false) — exempt, succeeds", () => { const ctx = freshCtx(); - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: true, requireRecommendation: false }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: true, requireRecommendation: false }); const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }, { loopTracking: false }); assert.ok(out.startsWith("[Compressed"), `preflight self-save must stay available, got: ${out.slice(0, 160)}`); }); @@ -132,7 +136,7 @@ test("#5683: requireNudge ON + unarmed + preflight lane (loopTracking:false) — test("#5683: both gates ON + unarmed — the timing refusal wins (checked first)", () => { const ctx = freshCtx(); setOffer(ctx, [offerRange("m00001", "m00004", 4)]); - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: true, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: true, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); assert.ok(out.includes("requireNudge"), `timing gate reports first, got: ${out.slice(0, 160)}`); assert.ok(!out.includes("requireRecommendation"), "scope gate must not double-report"); @@ -145,7 +149,7 @@ test("#5683: both gates ON + unarmed — the timing refusal wins (checked first) test("#5683: requireRecommendation ON + range inside the prepare-time offer — allowed", () => { const ctx = freshCtx(); setOffer(ctx, [offerRange("m00001", "m00004", 4)]); - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); assert.ok(out.startsWith("[Compressed"), `expected success, got: ${out.slice(0, 160)}`); }); @@ -153,7 +157,7 @@ test("#5683: requireRecommendation ON + range inside the prepare-time offer — test("#5683: requireRecommendation ON + SUBDIVIDING a recommended span — allowed (coverage, not equality)", () => { const ctx = freshCtx(); setOffer(ctx, [offerRange("m00001", "m00004", 4)]); - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: "m00002", endId: "m00003", summary: SUM }] }); assert.ok(out.startsWith("[Compressed"), `subdivided span must pass, got: ${out.slice(0, 160)}`); }); @@ -161,7 +165,7 @@ test("#5683: requireRecommendation ON + SUBDIVIDING a recommended span — allow test("#5683: requireRecommendation ON + live range OUTSIDE the offer — refused naming the span, nothing folded", () => { const ctx = freshCtx(); setOffer(ctx, [offerRange("m00001", "m00004", 4)]); - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); // m5-m7 are live-compressible per the kernel but were NOT offered this round. const out = runApply(ctx, { content: [{ startId: "m00005", endId: "m00007", summary: SUM }] }); assert.ok(out.startsWith("[Compression REFUSED"), `expected refusal, got: ${out.slice(0, 160)}`); @@ -173,7 +177,7 @@ test("#5683: requireRecommendation ON + live range OUTSIDE the offer — refused test("#5683: requireRecommendation ON + mixed range (part offered, part not) — refused as a whole", () => { const ctx = freshCtx(); setOffer(ctx, [offerRange("m00001", "m00004", 4)]); - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: "m00003", endId: "m00006", summary: SUM }] }); assert.ok(out.startsWith("[Compression REFUSED"), `mixed span must be refused whole, got: ${out.slice(0, 160)}`); assert.ok(out.includes("m00003–m00006")); @@ -188,7 +192,7 @@ test("#5683: requireRecommendation ON + offered span BELOW the minCompressRange const ctx = freshCtx(); setOffer(ctx, [offerRange("m00001", "m00004", 4)]); ctx.config.compress.minCompressRange = 40000; - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); assert.ok(out.startsWith("[Compression REFUSED"), `sub-floor span must be out of bounds, got: ${out.slice(0, 160)}`); assert.ok(out.includes("out-of-bounds compression is disabled"), "must be OUR receipt, not a kernel one:\n" + out); @@ -205,7 +209,7 @@ test("#5683: requireRecommendation ON + pure refold of an active block — NOT r assert.ok(first.startsWith("[Compressed"), `setup fold failed: ${first.slice(0, 160)}`); assert.ok(ctx.session.state.blocks.length > 0, "block exists after setup fold"); setOffer(ctx, [offerRange("m00005", "m00007", 3)]); - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM + "-REFOLD-UPDATE" }] }); assert.ok(!out.includes("out-of-bounds compression is disabled"), "scope gate must not fire on a refold:\n" + out); assert.ok(!ctx.logs.some((l) => l.includes("refused out-of-recommendation")), "no scope-gate refusal logged"); @@ -218,7 +222,7 @@ test("#5683: requireRecommendation ON + no offer and EMPTY live plan (every cand // the plugin-lane positive test below.) const ctx = freshCtx(); ctx.session.state.deadRefs = ["m00001", "m00002", "m00003", "m00004", "m00005", "m00006", "m00007"]; - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); assert.ok(out.startsWith("[Compression REFUSED"), `nothing recommended ⇒ nothing foldable, got: ${out.slice(0, 160)}`); assert.ok(out.includes("requireRecommendation")); @@ -235,7 +239,7 @@ test("#5683: plugin-lane ctx (no lastNudge) — a live-recommended span passes t const live = liveCompressionRanges(ctx); assert.ok(live && live.ranges.length > 0, "fixture must yield a live recommendation set"); const r = live.ranges[0]; - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: r.startRef, endId: r.endRef, summary: SUM }] }); assert.ok(!out.includes("out-of-bounds compression is disabled"), "live-recommended span must pass:\n" + out); }); @@ -246,9 +250,79 @@ test("#5683: plugin-lane ctx (no lastNudge) — a span containing a DEAD ref is // so submitting across it is definitively out-of-bounds (our receipt wins // over any kernel-side rejection because the gate runs before apply). ctx.session.state.deadRefs = ["m00006"]; - storeUnpromptedGate(ctx.session, { armed: false, requireNudge: false, requireRecommendation: true }); + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: false, requireRecommendation: true }); const out = runApply(ctx, { content: [{ startId: "m00005", endId: "m00007", summary: SUM }] }); assert.ok(out.startsWith("[Compression REFUSED"), `expected refusal, got: ${out.slice(0, 160)}`); assert.ok(out.includes("out-of-bounds compression is disabled"), "must be OUR receipt, not a kernel one:\n" + out); assert.equal(ctx.session.state.blocks.length, 0, "nothing folded"); }); + +// --------------------------------------------------------------------------- +// #5943 — nudge CREDIT window (requireNudge judges K model rounds, not this round). +// --------------------------------------------------------------------------- + +/** Stamp `n` consecutive un-nudged MODEL rounds on top of whatever credit exists. */ +function decayRounds(ctx: Ctx, n: number): void { + for (let i = 0; i < n; i++) { + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: true, requireRecommendation: false }); + } +} + +test("#5943: delayed fulfillment — nudge injected N rounds ago, fold NOW succeeds (the reported defect)", () => { + const ctx = freshCtx(); + storeUnpromptedGate(ctx.session, { nudgeInjected: true, requireNudge: true, requireRecommendation: false }); + decayRounds(ctx, 3); // three un-nudged model rounds pass; credit 20 → 17 + const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); + assert.ok(out.startsWith("[Compressed"), `delayed fulfillment inside the window must succeed, got: ${out.slice(0, 160)}`); +}); + +test("#5943: window expiry — both directions around the K-th un-nudged round", () => { + const ctx = freshCtx(); + storeUnpromptedGate(ctx.session, { nudgeInjected: true, requireNudge: true, requireRecommendation: false }); + decayRounds(ctx, NUDGE_CREDIT_ROUNDS - 1); // credit 20 → 1: still live + const alive = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); + assert.ok(alive.startsWith("[Compressed"), `last live round of the window must succeed, got: ${alive.slice(0, 160)}`); + + const ctx2 = freshCtx(); + storeUnpromptedGate(ctx2.session, { nudgeInjected: true, requireNudge: true, requireRecommendation: false }); + decayRounds(ctx2, NUDGE_CREDIT_ROUNDS); // credit → 0: expired + const out = runApply(ctx2, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); + assert.ok(out.startsWith("[Compression REFUSED"), `expired window must refuse, got: ${out.slice(0, 160)}`); + assert.ok(out.includes("requireNudge"), "receipt names the knob:\n" + out); + assert.ok(out.includes(`within ${NUDGE_CREDIT_ROUNDS} model rounds`), "receipt names the window length:\n" + out); + assert.equal(ctx2.session.state.blocks.length, 0, "nothing folded"); +}); + +test("#5943: refresh mid-decay — a new injection re-mints the full window", () => { + const ctx = freshCtx(); + storeUnpromptedGate(ctx.session, { nudgeInjected: true, requireNudge: true, requireRecommendation: false }); + decayRounds(ctx, NUDGE_CREDIT_ROUNDS - 1); // down to credit 1 + storeUnpromptedGate(ctx.session, { nudgeInjected: true, requireNudge: true, requireRecommendation: false }); // refresh → 20 + decayRounds(ctx, NUDGE_CREDIT_ROUNDS - 1); // back down to credit 1 + const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); + assert.ok(out.startsWith("[Compressed"), `refreshed window must still cover the fold, got: ${out.slice(0, 160)}`); +}); + +test("#5943: successful folds do NOT consume the credit — multi-round cleanup continues (#5943 item 3 deviation)", () => { + // The issue's consumption variant would have refused this exact sequence: + // the 18:41 fold would have eaten the credit and every continuation round + // (the reported 18:42–18:46 four-in-a-row refusals) stayed refused. Window- + // only semantics keep the cleanup going until the window lapses. + const ctx = freshCtx(); + storeUnpromptedGate(ctx.session, { nudgeInjected: true, requireNudge: true, requireRecommendation: false }); + const first = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); + assert.ok(first.startsWith("[Compressed"), `first fold failed: ${first.slice(0, 160)}`); + decayRounds(ctx, 2); // two more rounds pass; no consumption happened + const second = runApply(ctx, { content: [{ startId: "m00005", endId: "m00007", summary: SUM + "-CONT" }] }); + assert.ok(second.startsWith("[Compressed"), `continuation fold under the same credit must succeed, got: ${second.slice(0, 160)}`); +}); + +test("#5943: non-model stamps hold the window open (neither refresh nor decay)", () => { + const ctx = freshCtx(); + storeUnpromptedGate(ctx.session, { nudgeInjected: true, requireNudge: true, requireRecommendation: false }); + for (let i = 0; i < NUDGE_CREDIT_ROUNDS; i++) { + storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: true, requireRecommendation: false, modelRound: false }); + } + const out = runApply(ctx, { content: [{ startId: "m00001", endId: "m00004", summary: SUM }] }); + assert.ok(out.startsWith("[Compressed"), `countTokens-style shapes must not burn the window, got: ${out.slice(0, 160)}`); +}); diff --git a/website/config-reference/compress.yaml b/website/config-reference/compress.yaml index 09a69fbab0..15cd697a13 100644 --- a/website/config-reference/compress.yaml +++ b/website/config-reference/compress.yaml @@ -120,10 +120,10 @@ entries: group: compress id: cw.rnug render: compress-row - desc_en: "Forbid UNPROMPTED model-initiated compression (#5683): a compress call is refused unless a compression nudge actually reached the model in the current turn (advisory, decide-directive and emergency injections all arm; loop rounds of the same turn keep the arm, the next un-nudged turn disarms). Refusal sends the model an error receipt instead of folding; bili's own overflow backstop folds are exempt. For models that fold on their own (e.g. qwen 27b); can be scoped per provider/model. Off unless explicitly enabled." - desc_zh: "禁止未提示的模型主动压缩(#5683):只有当前轮次压缩提醒真正送达模型时(advisory、模型自决指令、紧急提醒都算;\"gated\"/\"vetoed\"/\"skipped\" 不算)才允许 compress,否则拒绝并回错误回执;同一轮内的多次 loop 请求保持武装,下一个未提示轮次自动解除。bili 自己的溢出兜底折叠不受影响。针对会自行乱压的模型(如 qwen 27b),可按 provider/model 单独开启。默认关闭。" - site_en: "Forbid unprompted compression (off by default): a model compress call is refused unless a nudge actually reached the model this turn; the refusal returns an error receipt instead of folding." - site_zh: "禁止未提示压缩(默认关闭):只有本轮压缩提醒真正送达模型时才允许模型调用 compress,否则拒绝并回错误回执。" + desc_en: "Forbid UNPROMPTED model-initiated compression (#5683/#5943): a compress call is refused unless a NUDGE CREDIT is live — a window of 20 MODEL rounds minted by the last compression nudge that actually reached the model (advisory, decide-directive and emergency injections all mint; \"gated\"/\"vetoed\"/\"skipped\" never do), refreshed by each new injection and decayed one per un-nudged model round (non-model request shapes hold it open). Successful folds do NOT consume the credit, so finishing a nudge's recommended cleanup over several rounds stays legal. Refusal sends the model an error receipt instead of folding; bili's own overflow backstop folds are exempt. For models that fold on their own (e.g. qwen 27b); can be scoped per provider/model. Off unless explicitly enabled." + desc_zh: "禁止未提示的模型主动压缩(#5683/#5943):只有 nudge 信用存活时才允许 compress——即距最近一次真正送达模型的压缩提醒不超过 20 个 MODEL 轮的窗口(advisory、模型自决指令、紧急提醒都算铸券;\"gated\"/\"vetoed\"/\"skipped\" 不算);每次新注入刷新窗口,每个未提示的模型轮衰减 1(非模型请求形态既不刷新也不衰减)。成功折叠**不消耗**信用,分几轮压完 nudge 推荐的剩余范围仍然合法。否则拒绝并回错误回执;bili 自己的溢出兜底折叠不受影响。针对会自行乱压的模型(如 qwen 27b),可按 provider/model 单独开启。默认关闭。" + site_en: "Forbid unprompted compression (off by default): a model compress call is refused unless a nudge credit is live — a delivered nudge opens a 20-model-round window, refreshed by each new nudge; the refusal returns an error receipt instead of folding." + site_zh: "禁止未提示压缩(默认关闭):只有 nudge 信用存活(送达的提醒开启 20 个模型轮窗口,新提醒刷新窗口)才允许模型调用 compress,否则拒绝并回错误回执。" - key: compress.requireRecommendation type: boolean default: "off (unset)" diff --git a/website/docs/index.html b/website/docs/index.html index 29a4a03334..ee50b3b31f 100644 --- a/website/docs/index.html +++ b/website/docs/index.html @@ -192,7 +192,7 @@

compress — every knob

maxEstimateHoldRoundsnumberWhen the decision meter has no billing sample this round (aborted turn, short-TTL expiry), pressure-band nudges are deferred one round until a usage-grade reading decides; billed readings keep byte-identical behavior. Set false to restore estimate-driven pressure injection. nudgeModelDecidedbooleanModel-decided nudge timing (off by default): an armed tier-1 nudge first asks the model, over the session's cached prefix, whether compressing now helps the current task; a strict-JSON yes injects a directive with a program-finalized span, anything else injects nothing this round. nudgeDecisionMaxTokensnumberOutput budget (tokens) of the model-decision side call (default 200). Must be > 0. - requireNudgebooleanForbid unprompted compression (off by default): a model compress call is refused unless a nudge actually reached the model this turn; the refusal returns an error receipt instead of folding. + requireNudgebooleanForbid unprompted compression (off by default): a model compress call is refused unless a nudge credit is live — a delivered nudge opens a 20-model-round window, refreshed by each new nudge; the refusal returns an error receipt instead of folding. requireRecommendationbooleanForbid out-of-bounds compression (off by default): only ranges bili currently recommends may be folded; subdividing a listed span or refolding an existing block stays legal. streamSummarybooleanForce streaming (SSE) summarization from the first attempt — stream-mandating upstreams now self-heal via a one-shot SSE probe on any non-streaming 400 (#2494); kept as the escape hatch for gateways that time out long non-streaming calls (e.g. Cloudflare 524), which the self-learn cannot detect, or to skip the one probe round-trip. preserveRecentMessagesnumberKernel default 3 (tuned 5 → 3, #3058): the most recent messages stay soft-protected from folds. diff --git a/website/main.js b/website/main.js index 638ff41629..8e0780b4ea 100644 --- a/website/main.js +++ b/website/main.js @@ -72,7 +72,7 @@ "cw.mehr": "When the decision meter has no billing sample this round (aborted turn, short-TTL expiry), pressure-band nudges are deferred one round until a usage-grade reading decides; billed readings keep byte-identical behavior. Set false to restore estimate-driven pressure injection.", "cw.nmd": "Model-decided nudge timing (off by default): an armed tier-1 nudge first asks the model, over the session's cached prefix, whether compressing now helps the current task; a strict-JSON yes injects a directive with a program-finalized span, anything else injects nothing this round.", "cw.ndmt": "Output budget (tokens) of the model-decision side call (default 200). Must be > 0.", - "cw.rnug": "Forbid unprompted compression (off by default): a model compress call is refused unless a nudge actually reached the model this turn; the refusal returns an error receipt instead of folding.", + "cw.rnug": "Forbid unprompted compression (off by default): a model compress call is refused unless a nudge credit is live — a delivered nudge opens a 20-model-round window, refreshed by each new nudge; the refusal returns an error receipt instead of folding.", "cw.rrec": "Forbid out-of-bounds compression (off by default): only ranges bili currently recommends may be folded; subdividing a listed span or refolding an existing block stays legal.", "cw.ssm": "Force streaming (SSE) summarization from the first attempt — stream-mandating upstreams now self-heal via a one-shot SSE probe on any non-streaming 400 (#2494); kept as the escape hatch for gateways that time out long non-streaming calls (e.g. Cloudflare 524), which the self-learn cannot detect, or to skip the one probe round-trip.", "cw.prm": "Kernel default 3 (tuned 5 → 3, #3058): the most recent messages stay soft-protected from folds.", @@ -329,7 +329,7 @@ "cw.mehr": "本轮无计费样本(回合中断、短 TTL 丢 usage)时,压力带 nudge 延后一轮等实际 usage 级读数再决定;计费级读数行为逐字节不变。设 false 恢复旧的估算驱动行为。", "cw.nmd": "模型自决的压缩时机(默认关闭):tier-1 提醒触发时,先通过会话缓存前缀上的短 side call 问模型现在压缩是否划算;严格 JSON 的 yes 注入带程序最终确定范围的指令,其余情况本轮不注入。", "cw.ndmt": "模型决策 side call 的输出预算(token,默认 200)。必须 > 0。", - "cw.rnug": "禁止未提示压缩(默认关闭):只有本轮压缩提醒真正送达模型时才允许模型调用 compress,否则拒绝并回错误回执。", + "cw.rnug": "禁止未提示压缩(默认关闭):只有 nudge 信用存活(送达的提醒开启 20 个模型轮窗口,新提醒刷新窗口)才允许模型调用 compress,否则拒绝并回错误回执。", "cw.rrec": "禁止越界压缩(默认关闭):只允许折叠 bili 当前推荐的范围;拆分推荐跨度、重折已有块更新摘要仍合法。", "cw.ssm": "强制摘要从首次起走流式(SSE)——要求流式的上游现在通过任何非流式 400 上的一次性 SSE 探测自愈(#2494);保留作为会掐断长非流式调用的网关(如 Cloudflare 524)的逃生通道(自学习无法感知该场景),也可用于省去一次探测往返。", "cw.prm": "内核默认 3(5 → 3,#3058):最近消息软保护、免于折叠。",