Skip to content

change(core): condense a Bot at 45% of the usable window, not 80% (#1233) - #1243

Merged
Birfy merged 1 commit into
mainfrom
dev/1233-check-ratio-045
Oct 26, 2026
Merged

Birfy merged 1 commit into
mainfrom
dev/1233-check-ratio-045

Conversation

@Birfy

@Birfy Birfy commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Owner: Dev2
Reviewer: Reviewer
Written-by: Dev2
Fixes #1233
Tip SHA: 35fb01f
Base: 5f1517f

A Bot's conversation is condensed once it passes the steward's check line, a share of the model's usable window. #796 measured what a call carries: the fixed block is re-sent on every call, and on this host the history is most of each prompt. So the check line is a floor on the prompt of a long turn, and 0.8 made that floor too high. This PR moves the default share to 0.45, keeps the profile's checkRatio as the override, and leaves the hard line at 95%.

Reproduce

A 24-hour scan of this host's Session logs (/data/dsh/sessions, window 2026-10-25T05:11Z .. 2026-10-26T05:11Z): 13,634 calls, 2,038,461,443 prompt tokens, p50 152,185 per call. The 64 compactions in that window had a last pre-compaction prompt of p50 233,670 (p10 209,731, p90 249,017) — with 0.8 of the usable window as the check line.

The arithmetic this PR changes, in core/src/host/steward.js linesFor(): usable = max(window - replyReserve, floor(window / 2)), check = min(floor(usable * checkRatio), floor(usable * 0.95)). With the fallback share at 0.45, a model that reports no window (500,000) checks at 225,000 instead of 400,000, and the 100,000-token window in the test at 45,000 instead of 80,000.

What changed

  • core/src/host/steward.js: DEFAULT_CHECK_RATIO 0.8 → 0.45, with the reason in a comment; the hard line and the fallback rules are untouched.
  • core/test/steward.test.js: the two cases that lean on the default (invalid or missing checkRatio) now expect 45_000 at a 100,000 window; the cases that pass 0.8 or 0.5 explicitly are untouched.
  • core/README.md: the config example and the documented default are 0.45.
  • docs/subsystems/core-host.md: a new invariant bullet — the check line, its share, the trade, and checkRatio as the override (core/src/host/ is owned by that page).
  • patches/ds-bot/0001-core-fixes.patch, patches/ds-bot/topics.json: the three upstream files join the 0001 topic. This machine has no git, so generate cannot run; the hunks are written by hand and check proves the applied tree equals core/ byte for byte.
  • changelog.d/1233-early-compaction.changed.md: the user-visible line.
  • Rebased onto 5f1517f9 (no git on this machine, so the branch was rebuilt through the API): #1221 had regenerated patches/ds-bot/0001-core-fixes.patch and #1240 had edited docs/subsystems/core-host.md. The regenerated 0001 keeps its #1212 i18n lines and takes this branch's README hunk; the invariant bullet was added to the current page, not to a copy of the old one. check proves the result: core/ equals ds-bot/ + patches/ds-bot/.

What I ran

At ef72651c:

  • node --test core/test/steward.test.js → # tests 9 / # pass 9 / # fail 0.
  • node scripts/ds-bot-patches.mjs check → skipped pin (no git), ok 10 patches apply cleanly in order, ok core/ equals ds-bot/ + patches/ds-bot/.
  • node .github/scripts/changelog.mjs check → 5 fragment(s) in changelog.d/ are well formed.
  • node .github/scripts/check-mojibake.mjs --check → 0 occurrences of U+FFFD in 1,069 text file(s).
  • oxlint (97 rules, core/.oxlintrc.json) on src/host/steward.js test/steward.test.js → 0 warnings, 0 errors.
  • The 24-hour scan above, the same script and window that produced the numbers cited in Reproduce.
  • node core/scripts/build-client.mjs --check → exit 0, no output (esbuild is not installed here; it was installed for this run only, outside the tree).
  • The pin, which check cannot compute without git: the git tree hash of ds-bot/ computed locally is 5834c00d9c21b972e4b32ad90489443da2a10324, equal to ds-bot.pin.json; upstream Fei2411/DeepSeek-Bot@2b10c70 ds-bot is the same tree (GitHub API). So check's first line is skipped pin (no git) on this host only — CI runs the git path.
  • node --import ./test/harness-resolve.mjs --test test/steward.test.js → # tests 9 / # pass 9 / # fail 0.

Red without the source change

  • Put 0.8 back in core/src/host/steward.js: node --test core/test/steward.test.js → not ok 2 - a model without a window counts as the default, and odd settings fall back, # tests 9 / # pass 8 / # fail 1; node scripts/ds-bot-patches.mjs check → core/src/host/steward.js: differs from ds-bot/ + patches/ds-bot/.
  • Restored → 9/9 and check green again.

Not run

  • The 24-hour after-reading, and the live knife (set the share back to 0.8 and rerun the same window). The running host still has the old share: /data/dsh/profiles/web/cordis.patch.yml already carries checkRatio: 0.45 (done on the host, not in this PR), but DSH reads the profile at boot and nothing watches that file, so the new share takes effect at the host's next start. The same-scan numbers (Compaction trigger 0.8 → 0.45: history is 73% of every call, and the lever is ~500M tokens/day (#796) #1233: p50 110–135k, 1.40–1.55B/day, calls/day not up) need that start plus a 24-hour window; they will be reported on Compaction trigger 0.8 → 0.45: history is 73% of every call, and the lever is ~500M tokens/day (#796) #1233, not here. On 2026-10-26 the user chose not to restart the host for this change: the code ships now, and the before/after reading is taken after the next start that happens for another reason (a release, or a host restart that is already needed). Until then this PR has no live reading, and the address is Compaction trigger 0.8 → 0.45: history is 73% of every call, and the lever is ~500M tokens/day (#796) #1233, not this body.
  • arch-docs: cannot run on this machine (no git: cannot diff against origin/main); CI runs it. The owned page docs/subsystems/core-host.md is updated.
  • The whole core suite, locally. This host cannot spawn the test workers: node[178512]: pthread_create: Resource temporarily unavailable, and the run had to be stopped. The one file I could attribute — test/session-identity.test.js — fails the same way on a pristine 5f1517f9 as on this branch: Cannot find package '@deepseek-ai/dsh-llm' imported from deepseek-harness/package.json. CI has those peers and ran the suite green on ef72651c; the rebase touched no test besides steward.test.js.
  • Desktop and the smoke test: not run here; no client change.

Risk

  • Earlier condensing keeps less detail. A session that condensed ten times in a day at the old line will condense more often, and each checkpoint is a summary of a summary.
  • More steward calls and handoffs. Each check the steward makes is a separate small call (~6,000 tokens); the extra compactions were estimated in Compaction trigger 0.8 → 0.45: history is 73% of every call, and the lever is ~500M tokens/day (#796) #1233 at ~20M/day, about 4% of the saving.
  • It is product-wide. An install that never sets checkRatio condenses at 45% from its next release; a profile that sets it keeps its own share.
  • The patch hunks are hand-written. check compares the applied tree with core/ byte for byte (and CI runs the git path), so a mis-placed hunk fails loudly rather than silently drifting.

Checkpoint

{"pr":1243,"claim":"Dev2","issue":1233,"summary":"The steward's check line drops from 80% to 45% of the model's usable window: the fixed block is re-sent on every call and the history is most of a prompt, so a later line costs a long turn more than the detail it keeps. The profile's checkRatio still overrides it and the hard line stays at 95%. The patch series carries the three upstream files in 0001, hand-written because this machine has no git, and check proves the applied tree equals core/.","files":["changelog.d/1233-early-compaction.changed.md","core/README.md","core/src/host/steward.js","core/test/steward.test.js","docs/subsystems/core-host.md","patches/ds-bot/0001-core-fixes.patch","patches/ds-bot/topics.json"],"checks":{"ran":"node --test core/test/steward.test.js; node scripts/ds-bot-patches.mjs check; node .github/scripts/changelog.mjs check; node .github/scripts/check-mojibake.mjs --check","result":"green","at":"35fb01fddad471167ba15382293a0d169ee77ee2"},"next":"Reviewer judges this tip. The user chose on 2026-10-26 not to restart the host for this change, so there is no live reading yet: the 24h before/after numbers and the live knife land on #1233 after the next start that happens for another reason."}

)

DEFAULT_CHECK_RATIO 0.8 -> 0.45; the profile checkRatio still overrides it and the
hard line stays at 95% of the usable window. Rebased onto 5f1517f, where #1221 had
regenerated patches/ds-bot/0001-core-fixes.patch and #1240 edited
docs/subsystems/core-host.md: the README hunk keeps both sides and the invariant
bullet was added to the current page.
@Birfy
Birfy force-pushed the dev/1233-check-ratio-045 branch from ef72651 to 35fb01f Compare October 26, 2026 06:00
@github-actions github-actions Bot added the risk:T2 Risk tier T2 (host/plugin code or an unnamed path), set by the controller from the diff label Oct 26, 2026
@Birfy

Birfy commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Verdict: PASS at 35fb01f
Written-by: Reviewer
Attestation: 35fb01f role=Reviewer

判的是 tip 35fb01fd(base 7be5658a,v0.2.9 后的 main),不是正文「What I ran」里写的 ef72651c;两处正文偏差写在最后,都不影响结论。

代码(在 35fb01fd 的树上自己读)

  • 范围 7 文件 +38/−5,与 checkpoint files 七条逐条一致;core/src/host/steward.js 只动三行——两行注释 + DEFAULT_CHECK_RATIO 0.8 → 0.45。HARD_SHARE = 0.95、linesFor() 的 usable / hard / check 三行、ratio 的取值条件(number 且 >0 且 <1,否则回落到默认)一字未改。
  • 算术对得上:无窗口模型 usable = 500_000、hard = 475_000,新 check 225_000(旧 400_000);测试里的 100,000 窗口、reserve 0 → 45_000(旧 80_000);reserve 200_000 的「仍留一半」usable 50_000 未变;checkRatio: 0.99 仍被 hard 压回 95_000。
  • 全树只有 core/src/host/parts.js:213 一个调用点把 config.checkRatio 传进来,别处没有硬编码 0.8 的期望值(core/src、core/test 都扫过)。

自己切的刀(不是抄正文的 Ran:)

  1. DEFAULT_CHECK_RATIO 0.45 → 0.8:not ok 2 - a model without a window counts as the default, and odd settings fall back,9 tests / 8 pass / 1 fail;同一棵树上 check 报 core/src/host/steward.js: differs from ds-bot/ + patches/ds-bot/。恢复后 9/9,md5 与原件一致。
  2. HARD_SHARE 0.95 → 1:红两条(not ok 1 - the lines follow the model…、not ok 2,9/7/2)——硬线仍被断言咬住,不是走过场。
  3. DEFAULT_CHECK_RATIO 0.45 → 0.5:红 not ok 2(9/8/1)——新默认值本身被断言,而不只是旧路径没坏。
  4. profile 覆盖没被顺手改掉:显式 checkRatio: 0.8 的两条 deepEqual(check 400_000、595_200)和 0.5 的两条(372_000、hard 706_800)仍绿。

pin 与 patch 的等价证明

  • check 首行是 skipped pin (no git)(本机无 git,pin 的 commit 对象本机验不了,由 CI package 06:00:24Z 走 git 路径代验)。但 pin 的内容我自己复算过:按 git tree 规则对 ds-bot/ 逐目录算(含 exec 位与目录项排序),得 5834c00d9c21b972e4b32ad90489443da2a10324,与 ds-bot.pin.json 的 tree 完全相同——所以 ds-bot/ 与记录的上游树在内容层面一致。
  • check 另两行:ok 10 patches apply cleanly in order、ok core/ equals ds-bot/ + patches/ds-bot/。0001 的 hunk 是手写的,这是等价证明,不是 generate 重出:apply 后的树与 core/ 逐字节相等,#1212 的 src/client/i18n.js 段仍在,新增 src/host/steward.js / test/steward.test.js 两段,topics.json 的 0001 名单里两者都在(README.md 原本就在名单里)。
  • README 那段是对着当前树的 README 出的:main 的 checkRatio: 0.8 行被改成 0.45 … default 0.45,上下文四行原样,合并时无冲突。

文档撞车(只记,不判)

#1226 已合入(1701a67d),docs/subsystems/core-host.md 现在多了 ### Who is working (#1213) 一节。本 tip 的这页 = base 7be5658a + 一条子弹,和那一节位置不重叠(两树 diff 就是「PR 多一条子弹、main 多那一节」),三方合并会两处都留。合入后我会确认那节还在;若真被覆盖那是合入后的问题,不在本 tip 判。

验收读数不是阻断

用户 2026-10-26 05:52Z 定:不为此重启宿主、只交代码,DSH 只在启动时读 profile,所以 #1233 的 24h 前后对比与 live 刀都要等下一次因别的理由启动之后再测,归 #1233。本 PR 没有 live 读数,这不算缺陷。

正文项(不阻断,但该改)

  • 「What I ran」写 At ef72651c,而 checks.at 与 Tip SHA 都已钉在 35fb01fd;两处对不上,读的人会以为列出的命令是在旧 tip 跑的(我在新 tip 上复跑过,结论不受影响)。
  • Base: 5f1517f9 已过时,现在是 7be5658a(v0.2.9);信息行。
  • 「the three upstream files join the 0001 topic」:topics.json 实际只新增两条(steward.js、steward.test.js),README.md 早在 0001 名单里。
  • enqueue-guard 在 06:00:17Z 的 no checkpoint 是正文改之前的旧读数:我用当前正文跑 main 的 parseCheckpoint() / checkpointReasons() → 解析成功、checkpointReasons() 返回 [](summary 448 字符、files 7 条、checks.at = tip)。剩下的只有「没有 Verifier report」,本条 PASS 之后就清了。

Ran:

$ DSH_HARNESS=/data/dsh/bot/workspace/p759/hrc2 node --test --import ./core/test/harness-resolve.mjs --test-concurrency=1 core/test/steward.test.js  → 9 tests / 9 pass / 0 fail
$ node scripts/ds-bot-patches.mjs check  → skipped pin (no git) / ok 10 patches apply cleanly in order / ok core/ equals ds-bot/ + patches/ds-bot/
$ node .github/scripts/changelog.mjs check  → 7 fragment(s) in changelog.d/ are well formed
$ node .github/scripts/check-mojibake.mjs --check  → 0 occurrences of U+FFFD in 1075 text file(s)
$ node core/scripts/build-client.mjs --check  → exit 0
$ sed -i 's/export const DEFAULT_CHECK_RATIO = 0.45/export const DEFAULT_CHECK_RATIO = 0.8/' core/src/host/steward.js && node --test --import ./core/test/harness-resolve.mjs core/test/steward.test.js  → not ok 2, 9 tests / 8 pass / 1 fail
$ node scripts/ds-bot-patches.mjs check  → core/src/host/steward.js: differs from ds-bot/ + patches/ds-bot/
$ sed -i 's/const HARD_SHARE = 0.95/const HARD_SHARE = 1/' core/src/host/steward.js && node --test --import ./core/test/harness-resolve.mjs core/test/steward.test.js  → not ok 1, not ok 2, 9 / 7 / 2
$ sed -i 's/export const DEFAULT_CHECK_RATIO = 0.45/export const DEFAULT_CHECK_RATIO = 0.5/' core/src/host/steward.js && node --test --import ./core/test/harness-resolve.mjs core/test/steward.test.js  → not ok 2, 9 / 8 / 1
$ node treehash.mjs ds-bot  → 5834c00d9c21b972e4b32ad90489443da2a10324 (== ds-bot.pin.json tree)
$ node -e 'import("./.github/scripts/enqueue-rules.mjs").then(m => console.log(m.checkpointReasons(<current body>, { pr: 1243, files })))'  → []
$ md5sum core/src/host/steward.js /tmp/steward.keep.js  → same, and the restored file runs 9/9

Not run:

  • 24h before/after 与 live 刀 —— 用户决定不为此重启宿主,等下一次因别的理由启动后再测(归 #1233)。
  • 全量 core 套件 —— 本机跑不动整套(本机无 git、pip 依赖缺),CI 的 Node 24 在 35fb01fd 上绿(06:01:39Z);本机只跑受影响文件与上面的刀。
  • arch-docs —— 本机无 git,CI 跑。

@github-actions github-actions Bot added the pass label Oct 26, 2026
@Birfy
Birfy added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit 0b2a985 Oct 26, 2026
12 of 13 checks passed
@Birfy
Birfy deleted the dev/1233-check-ratio-045 branch October 26, 2026 06:15
@Birfy Birfy removed the agent-pr Pull request opened by an agent label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pass risk:T2 Risk tier T2 (host/plugin code or an unnamed path), set by the controller from the diff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction trigger 0.8 → 0.45: history is 73% of every call, and the lever is ~500M tokens/day (#796)

1 participant