Skip to content

Commit bae1073

Browse files
fix: don't retry compaction if it fails (#1363)
1 parent d1794d9 commit bae1073

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

crates/q_chat/src/lib.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,37 @@ impl ChatContext {
10151015
execute!(self.output, cursor::Hide, style::Print("\n"))?;
10161016
self.spinner = Some(Spinner::new(Spinners::Dots, "Creating summary...".to_string()));
10171017
}
1018-
let response = self.client.send_message(summary_state).await?;
1018+
let response = self.client.send_message(summary_state).await;
1019+
1020+
// TODO(brandonskiser): This is a temporary hotfix for failing compaction. We should instead
1021+
// retry except with less context included.
1022+
let response = match response {
1023+
Ok(res) => res,
1024+
Err(e) => match e {
1025+
fig_api_client::Error::ContextWindowOverflow => {
1026+
self.conversation_state.clear(true);
1027+
if self.interactive {
1028+
self.spinner.take();
1029+
execute!(
1030+
self.output,
1031+
terminal::Clear(terminal::ClearType::CurrentLine),
1032+
cursor::MoveToColumn(0),
1033+
style::SetForegroundColor(Color::Yellow),
1034+
style::Print(
1035+
"The context window usage has overflowed. Clearing the conversation history.\n\n"
1036+
),
1037+
style::SetAttribute(Attribute::Reset)
1038+
)?;
1039+
}
1040+
return Ok(ChatState::PromptUser {
1041+
tool_uses,
1042+
pending_tool_index,
1043+
skip_printing_tools: true,
1044+
});
1045+
},
1046+
e => return Err(e.into()),
1047+
},
1048+
};
10191049

10201050
let summary = {
10211051
let mut parser = ResponseParser::new(response);

0 commit comments

Comments
 (0)