fix(cli): defer threshold compaction during tool loops - #12792
Merged
Conversation
marius-kilocode
enabled auto-merge (squash)
August 3, 2026 09:11
chrarnoldus
approved these changes
Aug 3, 2026
This was referenced Aug 5, 2026
LudwigSolutionsAI
pushed a commit
to LudwigSolutionsAI/kilocode
that referenced
this pull request
Aug 6, 2026
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
* fix(cli): preserve Kilo prompt cache keys * fix(cli): defer threshold compaction during tool loops
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Configured compaction thresholds can currently fire after a provider step while a tool sequence is still active. That lets an economic threshold interrupt a plan such as
grep -> read -> apply_patch -> bash, replacing the active prompt with a compaction summary before the remaining validation tool runs.The preflight path already measures the complete outgoing request and skips the configured economic threshold during tool continuations. The post-step path was inconsistent: it reused the threshold-aware
isOverflow()cap after every provider step. This change makes that post-step check safety-only, comparing usage against the usable context limit. Configuredthreshold_percentbehavior remains in preflight for normal request boundaries, and hard context-limit recovery is unchanged.The regression was reproduced in the isolated harness with
threshold_percent: 10: afterapply_patch, Kilo compacted, issued summary/continuation requests, and omitted the expectedbashtest. The matching baseline completed the full tool sequence. The reproduction intentionally used 10%, not the current global 100% configuration.The branch also removes the previously investigated Kilo prompt-cache-key change. Cloud already derives the production
prompt_cache_keyfromX-KILOCODE-TASKID, so that client-side change is not part of this fix.Changed paths are limited to the post-step overflow behavior, its focused tests, and the CLI changeset.
Validation:
bun test test/provider/transform.test.ts test/kilocode/session-overflow.test.ts: 342 passedbun run typecheck: passedbun run script/check-opencode-annotations.ts --worktree: passedgit diff --check: passed