Skip to content

fix(agent-runtime): size summary chunks with the guard's token estimate - #1988

Merged
vastsa merged 2 commits into
vastsa:mainfrom
xpeng5278-web:fix/summary-chunk-estimate
Oct 29, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
xpeng5278-web:fix/summary-chunk-estimate

Conversation

@xpeng5278-web

Copy link
Copy Markdown
Contributor

Fixes #1987

What

The chunk reserve moves into compactionSummaryReserveTokens (compaction-summary-input.ts). It returns max(ceil(previousSummary.length / ESTIMATED_TEXT_CHARS_PER_TOKEN), outputBudget), which uses the same constant that estimateSummaryPromptTokens applies to the carried summary. planSummaryRequests in runtime.ts now calls it instead of the inline / 4.

Why

The guard counts the previous summary at 3.5 chars/token, but the planner reserved it at 4. With a large carried summary, the first chunk plus that summary came out above summaryInputLimit. Example: 28k-char summary, limit 10k → 10,600 estimated tokens.

How tested

  • compaction-summary-input.test.ts: two property tests check that each planned chunk, together with the summary it carries (the real previousSummary for chunk 0, a reserve-sized summary for later chunks), stays below summaryInputLimit under estimateSummaryPromptTokens.
    • keeps a large carried summary inside the guard's window fails with the / 4 reserve from main (chunk 0: expected 10600 to be less than 10000) and passes with this change.
    • keeps plain-text chunks with no previous summary inside the guard's window passes before and after, so the message cost estimate stays as it is.
  • packages/agent-runtime: full vitest 113 files / 1564 tests pass; tsc --noEmit clean; pnpm lint:biome and scripts/check-architecture.mjs pass.

Scope

Reserve calculation only. Existing chunk-boundary tests are unchanged. COMPACTION_SUMMARY_MAX_CHUNKS, the margin, and single-message truncation are untouched.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Independently reproduced #1987: substituting the old /4 arithmetic into the new reserve helper makes the guard regression fail (10600 > 10000). Also exercised the compiled production DesktopAgentRuntime.planSummaryRequests with a 28000-character previous summary: old arithmetic yields first chunk 10600; restored candidate yields 9734 with 10 chunks. This confirms actual runtime wiring, beyond testing the helper alone. No provider requests were sent.

Non-destructively incorporated merged #1984/main: tested head 24539ed. Full runtime suite 115 files / 1586 tests passes, direct TypeScript build passes, diff check passes; integration tree 064f91709caa333ee8953de03548c632cd5155f9 equals tested head and latest main is ancestor. All six fresh remote checks now pass, including Windows Host/transcript and Electron E2E. Local interactive Electron/paid-provider tests not run; local evidence is production runtime budgeting plus complete runtime regressions. Scope correctly reuses the guard's character estimator for carried summary reserve without altering message costs, chunk margin, cap or truncation. Ready to merge.

@vastsa
vastsa merged commit e8f315d into vastsa:main Oct 29, 2026
6 checks passed
kylinmac added a commit to kylinmac/mc-agent that referenced this pull request Oct 30, 2026

This branch was previously deployed

1 inactive deployment
Preview — 24539edd Deployed Oct 29, 2026 by vercel[bot]
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.

[Bug] Chunked compaction reserves the previous summary at chars/4 while the guard counts chars/3.5, so the first chunk overflows summaryInputLimit

2 participants