Repository navigation
fix(agent-runtime): size summary chunks with the guard's token estimate - #1988
Conversation
vastsa
left a comment
There was a problem hiding this comment.
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.
fix: pick upstream compaction fixes vastsa#1984, vastsa#1988, vastsa#1994
Fixes #1987
What
The chunk reserve moves into
compactionSummaryReserveTokens(compaction-summary-input.ts). It returnsmax(ceil(previousSummary.length / ESTIMATED_TEXT_CHARS_PER_TOKEN), outputBudget), which uses the same constant thatestimateSummaryPromptTokensapplies to the carried summary.planSummaryRequestsinruntime.tsnow 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 realpreviousSummaryfor chunk 0, a reserve-sized summary for later chunks), stays belowsummaryInputLimitunderestimateSummaryPromptTokens.keeps a large carried summary inside the guard's windowfails with the/ 4reserve frommain(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 windowpasses before and after, so the message cost estimate stays as it is.packages/agent-runtime: full vitest 113 files / 1564 tests pass;tsc --noEmitclean;pnpm lint:biomeandscripts/check-architecture.mjspass.Scope
Reserve calculation only. Existing chunk-boundary tests are unchanged.
COMPACTION_SUMMARY_MAX_CHUNKS, the margin, and single-message truncation are untouched.