-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGFIX] History overflow bug fix #920
Conversation
Implement user choice for handling conversation history overflow: - Compact: Summarize the history and continue - Reset: Clear the history and start fresh - Continue: Keep the history as is with a warning 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
- Add #[allow(dead_code)] to ctx field in HistoryOverflowHandler - Add #[allow(dead_code)] to unused methods in HistoryOverflowHandler - Fix test_conversation_state_history_handling_with_tool_results to avoid overflow errors - Mock shell execution in test_prompts to avoid dependency on shell binaries - Mark test_prompts as ignored to prevent failures in environments without shells 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Fix compiler warnings by adding #[allow(dead_code)] annotations to unused fields and methods, and properly handling Result types in tests. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Add proper error handling for HistoryOverflowError by adding it to the ChatError enum and using the ? operator to propagate the error. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Simplify error handling for history overflow by removing the unused history_overflow_handler.rs file and its associated test file. The code now uses Rust's built-in error propagation mechanism with the ? operator instead of a complex handler class. Also removed the unused extract_history method from ConversationState. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Remove the ignore annotation from test_prompts in init.rs to ensure tests are properly executed rather than being skipped. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Restore the original implementation of run_shell_stdout in init.rs that actually executes shell commands instead of using a mock implementation. Also fix imports by adding Command and Stdio and removing the redundant Write import in the tests module. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Move the Command and Stdio imports from the top-level module to the test module where they are actually used. This eliminates the unused import warning during compilation. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Remove the commented-out import for the HistoryOverflowHandler that is no longer needed since the module has been removed. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Update the import style in the test module to use multi-line format for better readability and consistency with the preferred style. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Enable unstable rustfmt features to allow for more control over code formatting, particularly for imports which will now use a multi-line style for better readability. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Revert imports back to multi-line format to maintain consistent code style throughout the codebase. This affects files in the q_cli crate including init.rs, chat/mod.rs, and test files. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Restore original configuration settings in .rustfmt.toml: - Set unstable_features back to false - Move use_field_init_shorthand to its original position 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
This reverts commit 16c998c.
Restore the original formatting in init.rs and init_tests.rs files to maintain consistent code style as they were at commit 853d86b. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Convert single-line imports to multi-line format in: - conversation_state.rs - mod.rs This maintains consistent code style across the codebase by using multi-line imports for better readability. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Keep the file locally for future reference but remove it from version control as it's not needed in the repository at this time. 🤖 Assisted by [Amazon Q Developer](https://aws.amazon.com/q/developer)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #920 +/- ##
==========================================
- Coverage 13.86% 13.85% -0.01%
==========================================
Files 2370 2370
Lines 205481 205528 +47
Branches 185845 185892 +47
==========================================
- Hits 28485 28479 -6
- Misses 175473 175524 +51
- Partials 1523 1525 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@@ -113,6 +117,70 @@ impl ConversationState { | |||
self.history.clear(); | |||
} | |||
|
|||
/// Forces the history to be valid without clearing it | |||
/// This is used when the user chooses to continue with a large history | |||
pub fn force_valid_history(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
force_valid_history
-> trim_history_until_valid
?
/// Forces the history to be valid without clearing it | ||
/// This is used when the user chooses to continue with a large history | ||
pub fn force_valid_history(&mut self) { | ||
// Find the first valid user message to keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could the definition of valid
change over time? Might be a good idea to extract this into a function
if let Some(i) = self | ||
.history | ||
.iter() | ||
.enumerate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to mark a user-message as valid while the conversation is ongoing, instead of having to scan it retroactively?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, we wanna make sure we don't consider this as a valid message -
https://github.com/aws/amazon-q-developer-cli/blob/main/crates/q_cli/src/cli/chat/mod.rs#L1130
matches!( | ||
m.user_input_message_context.as_ref(), | ||
Some(ctx) if ctx.tool_results.as_ref().is_none_or(|v| v.is_empty()) | ||
) && !m.content.is_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful to add a helper is_valid_user_message
fn here
After discussing with the team - it'll be easier for us to simply increase history length than trying to solve this way. We'll be closing the PR. |
Added History Overflow Error Handling:
• Created a new HistoryOverflowError struct to handle conversation history overflow
• Modified fix_history() to return a boolean indicating if overflow handling is needed
• Added a new force_valid_history() method to handle history without clearing it
Modified Return Types:
• Changed as_sendable_conversation_state() to return Result<FigConversationState, HistoryOverflowError>
• Updated all call sites to handle the new Result type with ? operator
Improved History Management:
• Added logic to find valid starting messages in conversation history
• Implemented smarter history truncation to preserve context
• Replaced automatic history clearing with controlled overflow handling
Test Improvements:
• Limited test iterations to avoid overflow errors
• Updated test assertions to handle Result return types
Files Modified
• crates/q_cli/src/cli/chat/conversation_state.rs
• crates/q_cli/src/cli/chat/mod.rs
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.