Skip to content

Commit 8fbc6d7

Browse files
committed
fix: respect autoCondenseContext setting on context window overflow
- Update Task.handleContextWindowExceededError() to read user settings from state - No longer force autoCondenseContext=true when context window is exceeded - Use user's configured autoCondenseContextPercent instead of FORCED_CONTEXT_REDUCTION_PERCENT - Add comprehensive tests for the new behavior Fixes #7953
1 parent c4c4780 commit 8fbc6d7

File tree

2 files changed

+394
-5
lines changed

2 files changed

+394
-5
lines changed

src/core/task/Task.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
24382438

24392439
private async handleContextWindowExceededError(): Promise<void> {
24402440
const state = await this.providerRef.deref()?.getState()
2441-
const { profileThresholds = {} } = state ?? {}
2441+
const { profileThresholds = {}, autoCondenseContext = true, autoCondenseContextPercent = 100 } = state ?? {}
24422442

24432443
const { contextTokens } = this.getTokenUsage()
24442444
const modelInfo = this.api.getModel().info
@@ -2458,18 +2458,18 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
24582458
console.warn(
24592459
`[Task#${this.taskId}] Context window exceeded for model ${this.api.getModel().id}. ` +
24602460
`Current tokens: ${contextTokens}, Context window: ${contextWindow}. ` +
2461-
`Forcing truncation to ${FORCED_CONTEXT_REDUCTION_PERCENT}% of current context.`,
2461+
`Auto-condense: ${autoCondenseContext}, Threshold: ${autoCondenseContextPercent}%.`,
24622462
)
24632463

2464-
// Force aggressive truncation by keeping only 75% of the conversation history
2464+
// Respect user's settings for condensation
24652465
const truncateResult = await truncateConversationIfNeeded({
24662466
messages: this.apiConversationHistory,
24672467
totalTokens: contextTokens || 0,
24682468
maxTokens,
24692469
contextWindow,
24702470
apiHandler: this.api,
2471-
autoCondenseContext: true,
2472-
autoCondenseContextPercent: FORCED_CONTEXT_REDUCTION_PERCENT,
2471+
autoCondenseContext,
2472+
autoCondenseContextPercent,
24732473
systemPrompt: await this.getSystemPrompt(),
24742474
taskId: this.taskId,
24752475
profileThresholds,

0 commit comments

Comments
 (0)