Repository navigation
feat: model-decided nudge timing (compress.nudgeModelDecided) - #2243
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2579-pr.2243.4425341This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2243.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…mpress.yaml Review fix for #2243: the PR hand-edited CONFIGURATION.md/.zh-CN.md but the config docs are generated from the YAML seeds (#2107 single source of truth), so the docs-sync CI job failed — regeneration dropped the two rows. Add the seed entries (descriptions taken from the hand-written rows; backticks in desc_* are generator-forbidden, so the nudgeDecisionMaxTokens row loses its inline key backticks) and regenerate all four doc artifacts.
The module header said 'the emergency/over-limit path bypasses the decision outright', but the implemented gate (and the owner-approved #2228 policy) routes OVER-LIMIT tier-1 arms through the decision; only the EMERGENCY arm bypasses it. Comment-only fix.
PR #2243 审查完成。代码本身审查通过(两种压缩模式都推演过、内核零改动、测试有牙),审查中发现 2 处缺陷已直接在分支上修掉并推送( 1. 是什么问题:#2228——现有 nudge 节奏是纯增长驱动(每 50K 增长必注入),经常在不值得压缩的时机打扰模型;本 PR 让 tier-1 nudge 先问模型一句「现在压不压」,模型说压才注入指令。 2. 什么原因导致的:机制层原因是 nudge 的触发决策权完全在宿主(growth 计数器),模型对「此刻上下文是否真的需要压缩」没有发言渠道;PR 用一次带缓存前缀的决策 side-call 补上这个渠道,而不是改触发阈值(改阈值会动 #379/#380 定下的 flat-50K 契约,方向不对)。 3. 怎么修复的:纯宿主侧新增 4. 是否有回归问题(逐项核过的既有行为):默认关闭时零变更——else 分支逐行复刻改前代码,e2e 对照组断言 side-call 数为 0 且 advisory 字节级一致;EMERGENCY/tier-2/3 旁路保持;plugin/proxy 双模式下指令走同一 wrapper 链( 5. 是否破坏缓存:side-call 复用与主请求完全相同的稳定前缀(同路由—— 6. 是否改了设计方向:没有。内核边界完整(kernel-guard 绿, 7. 是否引入了新的配置:是,两个字段挂在既有三级
审查中发现并已直接修复的 2 处缺陷(additive commits,见上):
验证:本地定向 65/65 通过(9 单测 + 4 e2e + plugin-nudge 回归对照 + compress-settings/knobs 级联),typecheck 干净,全量交给 CI;CI 在 f019ef2 上 25/25 全绿(含此前红的 docs-sync)。测试有效性:mock upstream 用 ≤200 token 预算精确区分 side-call,解析器有完整的接受/拒绝矩阵,e2e 有 OFF 对照组钉住字节级兼容——是真测试,bug 回归时抓得住。 收工判定:可合并(feat + 配置面新增,按 §7.4 不走自动合并,请人工合并):#2243 |
9eec3fa to
92c8f5b
Compare
|
又冲突 |
When enabled, an armed tier-1 (gentle growth or over-limit) compression
nudge first asks the model - over the session's already-cached prefix, in a
short side call with a tiny output budget and no extra tools - whether
compressing NOW is net-beneficial for the current task. The answer must be
strict JSON ({"compress": true|false, "range"?, "topic"?}); a valid yes
injects an explicit directive with a program-finalized span (the proposed
range is honored only when fully contained in a live range, else the largest
live range), while no/malformed/timeout injects nothing that round. After 3
consecutive hard failures the next arm falls back to the legacy advisory once
and resets (self-healing ladder). EMERGENCY arms and tier>=2 distillation
always keep the legacy advisory byte-for-byte. Default off; host-only (not
passed to the kernel); no new env vars (#2030).
…mpress.yaml Review fix for #2243: the PR hand-edited CONFIGURATION.md/.zh-CN.md but the config docs are generated from the YAML seeds (#2107 single source of truth), so the docs-sync CI job failed — regeneration dropped the two rows. Add the seed entries (descriptions taken from the hand-written rows; backticks in desc_* are generator-forbidden, so the nudgeDecisionMaxTokens row loses its inline key backticks) and regenerate all four doc artifacts.
The module header said 'the emergency/over-limit path bypasses the decision outright', but the implemented gate (and the owner-approved #2228 policy) routes OVER-LIMIT tier-1 arms through the decision; only the EMERGENCY arm bypasses it. Comment-only fix.
92c8f5b to
c053d26
Compare
[bot] 🏷 冲突已解决,rebase 到最新 master 并推送完成。 结构化八问
判定:冲突解除(PR |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.137-master.89da0a8 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2228
What
Model-decided compression timing (
compress.nudgeModelDecided, default off). When enabled, an armed gentle-growth tier-1 nudge no longer injects the advisory text immediately. It first sends a short decision side call to the model over the session's already-cached prefix — same system/tools/messages prefix, tiny output budget (default 200 tokens), 15 s idle timeout, no extra tools — asking whether compressing NOW is net-beneficial for the current task. The answer must be strict JSON:{"compress": true|false, "range": "mNNNNN-mNNNNN", "topic": "<short>"}yes→ injects an explicit directive with a program-finalized span: the model-proposed range is honored only when fully contained in a live compressible range, otherwise the largest live range is used (the model never dictates range boundaries outright);no, malformed answer, timeout or HTTP error → nothing is injected that round; the session simply continues;emergencyNudge) does the same.Host-only: new module
src/nudge-decide.ts(pure logic) + injection-site wiring insrc/server.ts. No kernel changes. The decision call mirrors the forward path exactly (same route/proxy/header copy/APIG re-signing, non-stream response parsed per protocol with SSE fallback).config surface
Two new fields under the existing three-level
compresscascade (global → provider → model):compress.nudgeModelDecidedcompress.nudgeDecisionMaxTokensWhy the existing surface cannot express this: everything currently in
compressshapes when the proxy arms the legacy advisory (growth step, thresholds, tiers, preserve rules) or switches the whole advisory on/off (injectNudge). None of them can express "ask the model before injecting" — there is no consultation channel at all in the current schema, and bolting it ontoinjectNudgewould conflate a boolean switch with a behavioral mode. Considered and rejected: theproviderstable (this is compression behavior, not provider routing); newBILI_*env vars (forbidden by the #2030 env-var discipline — a behavior knob belongs in the config file behind the existing cascade). Compat/migration: purely additive; unset = previous behavior byte-for-byte (verified by the off-path integration test below).Behavior flags (past-behavior audit)
Tests
tests/nudge-decide.test.ts— 9 unit tests: prompt shape, strict parser accept/reject matrix (garbage never degrades to yes-without-range), span finalization rules (contained proposal honored, straddling/out-of-view/garbage/reversed fall back to largest live range), 3-strike fallback ladder, per-protocol answer extraction.tests/nudge-model-decided.test.ts— 5 end-to-end scenarios through the real pipeline (mock upstream discriminates the side call by its ≤200-token budget): gentle-growth yes → directive with program-finalized span injected; no → nothing; garbage prose → nothing; feature off → forwarded body identical to legacy advisory and zero side calls; over-limit (pressure band) → immediate legacy advisory, model never consulted (owner ruling). The gentle-growth fixture needs three turns because reported usage lags one turn (settleUsageReportruns per response): turn 1 seeds the baseline, turn 2's report carries turn 3's prepare past the growth floor at 62.5% usage — under the 75% over-limit line.tests/plugin-nudge-injection.test.tsstill green.npm run typecheckclean,npm run buildgreen; targeted runs green — 9/9 unit (nudge-decide), 5/5 e2e (nudge-model-decided), 2/2 legacy-nudge regression control (plugin-nudge-injection). (One full-suite failure observed on the OLD base intests/pi-subagent-registry.test.tswas reproduced on a clean tree without my diff — pre-existing, and already fixed upstream by master red: pi-subagent-registry factory test broken by #2209 + #2186 semantic merge (fake pi Map shadows selfRegister handler) #2234; green on the rebased head.)Docs: CONFIGURATION.md (en) + CONFIGURATION.zh-CN.md quick-ref rows and detail sections added.