Skip to content

docs: explain compaction timing — growth-gated first compaction & the ~200k landing zone - #2226

Merged
ranxianglei merged 4 commits into
masterfrom
2026-10-06_docs-large-window-compaction
Oct 6, 2026
Merged

ranxianglei merged 4 commits into
masterfrom
2026-10-06_docs-large-window-compaction

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Supersedes #2225 (same content, plus the pass-by fix from ework-agent; ework's branch became the surviving PR — reframe commit ported on top).

Why

Community feedback (awesome-dsh-plugin discussion #5795) shows users mis-model compaction timing on large-window + heavy-boot + local-model setups. The key fact the docs lacked:

Compaction does not trigger on absolute window position — it triggers on growth intervals. By default the first soft compaction fires 50k tokens past the boot content (nudgeGrowthTokens, flat and window-independent; kernel nudge.growthFloor == nudge.growthCap == 50000, golden-pinned — #379/#380). So the absolute position of the first compaction ≈ boot + 50k:

  • boot 30k–50k (dsh default) → first compaction ~80k–100k;
  • boot 100k–150k (heavy tool/skill stack) → first compaction likely waits until ~200k;
  • growth step raised to 100k → boot + 100k.

The 75% maxContextLimit forced line is only a backstop, applied over the effective window (output reserve min(max_tokens, outputHeadroomMaxPct × window), 25% cap by default, subtracted first): typically small reserve → forced line ≈190k on a 262k window; a request carrying max_tokens = 131072 → reserve 65,536 → forced line ≈147k.

After the first compaction the cadence stays growth-based (+50k per incremental compaction); on local models each is a full re-prefill — the "kept compacting, task took 2–3×" experience.

What this adds

  • CONFIGURATION.md / CONFIGURATION.zh-CN.md: ### Why the first compaction waits until 200k / ### 为什么第一次压缩要到 200k 才触发? — growth-gate mechanics, boot+50k arithmetic, backstop math, then remedy angles: earlier token saving (lower nudgeGrowthTokens / maxContextLimit), fewer compactions (raise the step), leaner boot (promptPack: "lean"), measure first via /acp or the web UI.
  • README.md / README.zh-CN.md: one FAQ entry each cross-linking the worked example.
  • Keeps ework-agent's pass-by fix f09edc1 (stale adaptive clamp(window×5%) growth-step formula in the Soft-target section → flat golden-pinned 50k).

Docs-only — no code or config changes.

ework-agent added 2 commits October 6, 2026 11:41
Add the large-window compacting narrative (worked example: 262,144 window +
max_tokens 131,072 -> reserve 65,536 -> effective 196,608 -> default 75% band
fires at ~147k ~= 56% of the full window; flat 50k growth step) with remedies
(measure with /acp or web UI, raise compress.nudgeGrowthTokens to 100k+,
slim the boot with promptPack lean) to CONFIGURATION.md/.zh-CN.md before the
soft-target section, plus one cross-linking FAQ entry in each README.

Docs only: no code or config changes. Closes #2225
…ix from #2225)

The Soft-target section still described the pre-#379/#380 shape: adaptive
step clamp(round(window*5%), 20k, 50k) with a window-dependent growth floor.
Current kernel constants (golden-pinned in tests/golden/wire-contract/kernel.json):
nudge.growthFloor == nudge.growthCap == 50000, so the step is flat 50k at every
window size and the growth gate is max(20k, 0.45*step) ~= 22.5k with the T1
path additionally requiring >= one step of compressible mass. The old text
contradicted the new large-window section added alongside #2225.
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-06_docs-large-window-compaction (742acbc)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2316-pr.2226.e0cd54f

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2226.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成 — 判定:可合。

重复判定(先于 Triage):发现 #2225(同标题,早 10 分钟开、单 commit、+54 行)。判定功能重复/被取代:同一需求(同样两个社区症状的叙事文档)、同样四个文件、同样插入位置;#2226 以改写形式包含 #2225 全部内容 + pass-by 修正 + Validation 节,且其正文显式声明 Closes #2225。若先合 #2225,#2226 会 stale 并在其扩展的段落上冲突。已关闭 #2225(附说明评论);其内容全部存活于 #2226,无丢失。

结构化七问:

  1. 是什么问题:大窗口 + 本地模型场景两个高频社区抱怨("262k 窗口不到 200k 就开始压缩"、"一直在压缩、任务时长 ×2–3")缺少叙事文档——两者都不是 bug,但不做算术就看不到两个默认值的交互。
  2. 什么原因导致的:两个默认值交互:①强制阈值作用在扣除输出预留(min(max_tokens, 0.25×window))后的有效窗口上,262k + max_tokens 131k → 有效 196,608 → 75% 阈值在 ≈147k(全窗口的 56%)触发;②增长 nudge 步长按设计恒定 50k(与窗口无关),重 boot(100k–150k prefill)在长任务里撞 2–4 次增量压缩,本地模型每次都是整窗重预填充。另有文档漂移:Soft-target 段残留 pre-fix: merge all system/developer messages into one leading message (SGLang #377) #379/探索是否可以集成进sglang,以做到透明管理 #380 的窗口比例公式(旧文档 vs 现行为,非行为漂移)。
  3. 怎么修复的:CONFIGURATION en/zh 各加一节叙事(算例表 + 按顺序的对策:先测量 → 调高 nudgeGrowthTokens → promptPack: "lean" 精简 boot);README en/zh 各加一条 FAQ 交叉链接;相邻段的公式订正独立成带标注 commit(2 文件 × 1 行),符合「有标注顺手小修」纪律。
  4. 是否有回归问题:无——纯 docs,零代码/零 config schema/零默认值变更。逐条对源码核验了所有引用常量:DEFAULT_OUTPUT_HEADROOM_MAX_PCT = 0.25(src/util.ts:333)、maxContextLimitPct = 0.75(kernel/src/config.ts:10)、growthFloor == growthCap == 50000(kernel/src/config.ts:16-17;golden 钉死于 tests/golden/wire-contract/kernel.json)、resolveAdaptiveGrowth clamp 到 [floor,cap] → 恒为 50k(kernel/src/compress.ts:1622)、增长门 max(20k, 0.45×step) = 22.5k(minGrowthFloor/minGrowthRatio,config.ts:18-19)+ T1 路径另需 t1Eff >= nudgeGrowthTokens(decideNudge,compress.ts:~1817)。算例复算:262144−65536=196608,0.75×196608=147456≈147k,147456/262144=56.25% ✓。分支头实跑 node tools/gen-config-docs.mjs generate:零 diff(新内容在 <!-- bili:gen --> 标记块之外,seeds 未动)✓。锚点链接(backtick 标题去反引号、CJK 锚点原样保留)全部可解析 ✓。promptPack "lean" 描述与 i18n 实测措辞一致("roughly half of default",kernel lean pack 定义于 kernel/src/packs.ts)✓。Pass-by fix 属 doc→reality 订正(旧文档称 20k–50k 窗口比例步长;实际自 fix: merge all system/developer messages into one leading message (SGLang #377) #379/探索是否可以集成进sglang,以做到透明管理 #380 起恒为 50k),已按 Deliverables 第 4 条在 PR 正文披露 ✓。
  5. 是否破坏缓存:不涉及(未触碰任何代码路径)。
  6. 是否改了设计方向:不涉及。
  7. 是否引入了新的配置:无——仅引用既有 key(compress.nudgeGrowthTokens、outputHeadroomMaxPct、compress.promptPack)。

diff 整洁度:4 文件、2 个线性 commit,pass-by 修正独立标注,无跑题文件/空白噪音/生成物连带变更。CI:head f09edc1 全部 job 绿(ubuntu/windows 双平台 test、全套 real-client e2e lanes、docs-sync、docs-coverage、kernel-guard、version-guard、lane-guard、build-artifact)。无需 rebase(mergeable=True,docs-only 与 master 无语义冲突)。

判定:可合。我无法合并 PR(系统规则禁止),请手动合并:#2226

The earlier framing ("starts earlier than expected") got the emphasis
backwards: the first compaction is growth-gated (boot + nudgeGrowthTokens,
flat 50k by default), not absolute-window-gated — with a heavy boot
(100k-150k) the first compaction naturally waits until ~200k, and the 75%
forced line is only a backstop over the effective window. Rewrites the
section and FAQ entries around "why the first compaction waits until 200k"
plus remedy angles (earlier saving vs fewer compactions vs leaner boot).
@ranxianglei ranxianglei changed the title docs: explain why compaction fires earlier/more often on large windows docs: explain compaction timing — growth-gated first compaction & the ~200k landing zone Oct 6, 2026
- boot ~100k OR a growth step set to ~100k is what pushes the first
  compaction out to ~200k (drop the boot-100k-150k phrasing)
- remedies now the three-step optimization order: trim prompt/tools/skills,
  lower nudgeGrowthTokens to ~50k, enable lean
- drop the forced-threshold aside from the FAQ entry (kept in the worked
  example); unify token units to k (was mixed 万/50k)
@ranxianglei
ranxianglei merged commit 46fb5a7 into master Oct 6, 2026
21 checks passed
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.70-master.46fb5a7 (rolling master tag).

npm install -g billion-context@0.0.70-master.46fb5a7  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant