Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 17, 2025

Summary

This PR fixes issue #8093 by making the initial prompt preservation in context condensing conditional on the experimental power-steering feature being enabled.

Problem

Previously, context condensing always preserved the initial prompt/first message, which caused tasks to be restarted unnecessarily when the preserved initial prompt was reintroduced after condensing.

Solution

  • Added a powerSteeringEnabled parameter to the summarizeConversation function
  • The function now only preserves the first message when power steering is enabled
  • Updated all callers to check the power steering experiment flag and pass the appropriate value
  • Updated tests to handle the new parameter

Changes

  • src/core/condense/index.ts: Added conditional logic for first message preservation
  • src/core/task/Task.ts: Checks power steering flag before condensing
  • src/core/sliding-window/index.ts: Propagates the flag through truncation logic
  • Test files: Updated to explicitly pass the powerSteeringEnabled parameter

Testing

  • All existing tests pass
  • Tests verify both enabled and disabled states of the feature
  • No breaking changes for existing functionality

Fixes #8093


Important

Make initial prompt preservation in context condensing conditional on the power-steering feature being enabled.

  • Behavior:
    • summarizeConversation function now includes a powerSteeringEnabled parameter to conditionally preserve the first message.
    • Updates in Task.ts and sliding-window/index.ts to check the power steering flag before condensing.
  • Tests:
    • Test cases in condense.spec.ts, index.spec.ts, and sliding-window.spec.ts updated to handle the powerSteeringEnabled parameter.
  • Misc:
    • Propagates the power steering flag through truncation logic in sliding-window/index.ts.
    • Checks for power steering feature in Task.ts using experiments.isEnabled.

This description was created by Ellipsis for 334d310. You can customize this summary. It will automatically update as commits are pushed.

…eature

- Add powerSteeringEnabled parameter to summarizeConversation function
- Check power steering experiment flag before preserving first message
- Update all callers to pass power steering state
- Update tests to handle new parameter

This prevents tasks from being restarted unnecessarily after context
condensing when power steering is disabled.

Fixes #8093
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 17, 2025 22:23
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Sep 17, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Reviewing my own code because apparently I trust no one, not even myself.

isAutomaticTrigger?: boolean,
customCondensingPrompt?: string,
condensingApiHandler?: ApiHandler,
powerSteeringEnabled?: boolean,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this intentional? The parameter defaults to undefined but is used as a boolean. Consider explicitly defaulting to false for clarity:

Suggested change
powerSteeringEnabled?: boolean,
export async function summarizeConversation(
messages: ApiMessage[],
apiHandler: ApiHandler,
systemPrompt: string,
taskId: string,
prevContextTokens: number,
isAutomaticTrigger?: boolean,
customCondensingPrompt?: string,
condensingApiHandler?: ApiHandler,
powerSteeringEnabled: boolean = false,
): Promise<SummarizeResponse> {

// Conditionally preserve the first message based on power steering setting
// When power steering is enabled, preserve the initial prompt to maintain task context
// When disabled, don't preserve it to prevent task restarts after condensing
const firstMessage = powerSteeringEnabled ? messages[0] : undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could we simplify this logic for better readability?

Suggested change
const firstMessage = powerSteeringEnabled ? messages[0] : undefined
// Conditionally preserve the first message based on power steering setting
// When power steering is enabled, preserve the initial prompt to maintain task context
// When disabled, don't preserve it to prevent task restarts after condensing
const preserveFirstMessage = powerSteeringEnabled ?? false
const firstMessage = preserveFirstMessage ? messages[0] : undefined
const messagesToKeepFrom = preserveFirstMessage ? 1 : 0

This makes the boolean logic more explicit and easier to follow.

* @param {boolean} isAutomaticTrigger - Whether the summarization is triggered automatically
* @param {string} customCondensingPrompt - Optional custom prompt to use for condensing
* @param {ApiHandler} condensingApiHandler - Optional specific API handler to use for condensing
* @param {boolean} powerSteeringEnabled - Whether power steering is enabled (controls initial prompt preservation)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The JSDoc could be more explicit about the behavioral difference. Consider adding:

Suggested change
* @param {boolean} powerSteeringEnabled - Whether power steering is enabled (controls initial prompt preservation)
* @param {boolean} powerSteeringEnabled - Whether power steering is enabled (controls initial prompt preservation).
* When true: preserves the first message to maintain task context.
* When false: excludes first message to prevent task restarts after condensing.

defaultSystemPrompt,
taskId,
DEFAULT_PREV_CONTEXT_TOKENS,
false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider adding edge case tests:

  1. Test behavior when powerSteeringEnabled is explicitly undefined
  2. Test with empty message arrays to ensure no index errors
  3. Test with single message to verify boundary conditions

These would help ensure robustness of the first message preservation logic.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 17, 2025
@daniel-lxs
Copy link
Member

#8093 (comment)

@daniel-lxs daniel-lxs closed this Sep 22, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 22, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] Context Condensing Initial Prompt Preservation Should Be Optional

4 participants