Skip to content

Fit the model-switch checkpoint into the range it replaces - #1863

Merged
Fei2411 merged 2 commits into
devfrom
fix/1822-switch-smaller-window
Nov 20, 2026
Merged

Fei2411 merged 2 commits into
devfrom
fix/1822-switch-smaller-window

Conversation

@Fei2411

@Fei2411 Fei2411 commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Issue

Fixes #1822

Bug: switching a Bot to a model with a smaller context window (e.g. gpt sol 6.2 → codex/gpt-6.2-astra) failed with context compaction failed: summary is not smaller than the shadowed content (7210 … >= 6525), and the Bot stayed on the old model with no way out.

Agent: Devin (Cognition)

What changed / 改了什么

  • ds-bot/src/host/parts.js writeCheckpoint: for a range DSH condenses for a model switch, DS Bot's checkpoint (summary + kept recent messages) could be larger than the range it replaces, so DSH refused the switch. The switch checkpoint is now sized against the replaced range measured the way DSH checks it: the route-priced token counts of the selected nodes (measureOf(session).nodes), so images and files count at the route's price. It drops the oldest kept messages first, then clips the summary, and as a last resort uses a minimal [Checkpoint N] pointer to read_own_chat. Ordinary checkpoints are unchanged.
  • ds-bot/test/model-switch-compaction.test.js: regression tests (oversized carried messages, long/empty summaries, no summary model, small ranges, image/file ranges priced above and below the plain estimate). They fail before the fix, e.g. 194 framed tokens must be smaller than 158 and 647 framed tokens must be smaller than 180 route-priced tokens.

Limit: DSH adds ~90 framing tokens even to an empty summary, so a range smaller than that still can't be replaced without a DSH change.

Changelog

Switching a Bot to a model with a smaller context window no longer fails with "summary is not smaller than the shadowed content".

How I checked it / 怎么验证的

  • npm test (in ds-bot/) — 3095 pass, 4 skipped; two timing-sensitive tests unrelated to this change (archive cleanup, gateway subprocess) timed out once and pass on rerun
  • node scripts/build-client.mjs --check
  • npm run lint
  • Smoke test, for changes to index.js or src/host/ — 52/52 steps passed (DSH dsh-v0.2.2-rc.1)
  • Screenshot attached, for interface changes — no interface change

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. / 改了 src/client/ 就已重新 build 并提交 client.js。 (no client change)
  • No keys, tokens or personal data, also in screenshots. / 没有密钥、token 或个人信息,截图里也没有。
  • No AI tool as author or Co-authored-by. / 没有把 AI 工具写成作者或 Co-authored-by。

Product Engineer opened this PR for Lulu
Implemented in session Fix Chief switch to smaller-window model
Review with Devin · Open in Devin Desktop


Bound switch checkpoints by the replaced range with framing headroom, dropping carried messages before clipping the summary. Fall back to a short history pointer so oversized checkpoints do not prevent model switches.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T16:55:19.787246Z 5b71abc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@Fei2411 Fei2411 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Reaper review (comments only): needs two small fixes before lulu merges.

The fix addresses #1822 correctly for text-only ranges. The 13 tests in model-switch-compaction.test.js and lint pass locally on 5b71abc. CI is green apart from two package jobs still queued. The PR merges cleanly with dev.

1. The budget uses a different count than the one DSH checks (should fix).
In writeCheckpoint, rangeTokens adds up meter.estimateMessage(...) over input.messages. DSH (dsh-compaction-basic summarizeCompaction) does not compare against that. It refuses when framedSummaryTokenCount >= shadowedRouteTokenCount, and that number is the sum of measure(session).nodes[i].tokens over the shadowed seqs. Those are route-priced counts: images are charged the route's visual tokens and files their projected text (priceSurface in dsh-token-meter). They differ from estimateMessage in either direction whenever the range holds images or files, which is common for Bots that use the browser. In that case the switch can still fail with the same error, or the checkpoint gets trimmed more than it needs to be.
canMakeRoom in this file already does it the route-priced way through measured.nodes. The compactRegion wrapper knows start/end, so it could record them next to switchRanges, and writeCheckpoint could sum measureOf(session).nodes between those seqs. Please add a test case with an image block in the range.

2. The PR body has no Agent: line (AGENTS.md).
Add Agent: Devin (Cognition). The repo has no Devin agent/*/model/* labels, so no labels are needed.

Minor (no need to block on it).
The last-resort text 'Earlier context: read_own_chat.' drops the [Checkpoint N] mark. checkpointCount then misses it, and the next checkpoint's number starts again from the earlier count. [Checkpoint N] Earlier context: read_own_chat. would keep the mark and costs only a few tokens.

Overlaps.
Other open PRs that touch ds-bot/src/host/parts.js:

Nothing has to land before this one.

DSH compares replacement checkpoints against the selected surface nodes' route-priced tokens, not attachment reference estimates. Preserve the explicit boundaries and snapshot those node prices before summarizing so images and files neither permit oversized checkpoints nor discard summaries unnecessarily.

@Fei2411 Fei2411 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Reaper re-review (comments only): ready for lulu.

Both fixes from my last review are in c4b60817:

  • The switch checkpoint budget now sums the route-priced measureOf(session).nodes[].tokens over the start..end seqs that the compactRegion wrapper records. That is the same number dsh-compaction-basic checks against. It is taken before the summary request, like DSH's prepareCompaction, and it falls back to the heuristic estimate only when no measurement is available.
  • The Agent: Devin (Cognition) line is in the PR body.
  • The last-resort text keeps its [Checkpoint N] mark when there is room for it.

Checks: model-switch-compaction.test.js passes 17/17 locally, including the new image and file cases. All CI checks pass on c4b60817, and the PR merges cleanly with dev.

Overlaps are unchanged: #1841, #1771 and #733 also touch parts.js and merge cleanly with this PR. Nothing has to land first.

@Fei2411
Fei2411 merged commit 6b5d23b into dev Nov 20, 2026
16 checks passed
@Fei2411
Fei2411 deleted the fix/1822-switch-smaller-window branch November 20, 2026 12:39
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