feat: create checkpoints before context compression

- Add checkpoint save before manual context compression in condenseContext method
- Add checkpoint save before automatic context compression in attemptApiRequest method
- Use force=true to ensure checkpoint even without file changes
- Use suppressMessage=true for cleaner UI experience

Fixes #9334
This commit is contained in:
Roo Code 2025-11-18 05:07:50 +00:00
parent dbaaef756e
commit bd7175a11e

View file

@ -1074,6 +1074,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
}
public async condenseContext(): Promise<void> {
// Create a checkpoint before context compression to allow reverting if needed
// Use force=true to ensure checkpoint even if no file changes, and suppress message for cleaner UI
if (this.enableCheckpoints) {
await this.checkpointSave(true, true)
}
const systemPrompt = await this.getSystemPrompt()
// Get condensing configuration
@ -2952,6 +2958,18 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
// Get the current profile ID using the helper method
const currentProfileId = this.getCurrentProfileId(state)
// Create a checkpoint before automatic context compression to allow reverting if needed
// Only create checkpoint if compression might actually happen
const contextPercent = (100 * contextTokens) / contextWindow
if (
autoCondenseContext &&
(contextPercent >= autoCondenseContextPercent || contextTokens > contextWindow * 0.9 - (maxTokens || 0))
) {
if (this.enableCheckpoints) {
await this.checkpointSave(true, true)
}
}
const truncateResult = await manageContext({
messages: this.apiConversationHistory,
totalTokens: contextTokens,