Skip to content

Commit 4faba02

Browse files
fix: sigint during tool execution (#724)
1 parent e992ab0 commit 4faba02

File tree

1 file changed

+19
-6
lines changed
  • crates/q_cli/src/cli/chat

1 file changed

+19
-6
lines changed

crates/q_cli/src/cli/chat/mod.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use eyre::{
3737
use fig_api_client::StreamingClient;
3838
use fig_api_client::clients::SendMessageOutput;
3939
use fig_api_client::model::{
40+
AssistantResponseMessage,
4041
ChatResponseStream,
4142
ToolResult,
4243
ToolResultContentBlock,
@@ -379,13 +380,25 @@ Hi, I'm <g>Amazon Q</g>, your AI Developer Assistant.
379380
cursor::MoveToColumn(0),
380381
)?;
381382
}
382-
let mut tool_uses = None;
383-
let mut tools_were_interrupted = false;
384383
match e {
385384
ChatError::Interrupted { tool_uses: inter } => {
386385
execute!(self.output, style::Print("\n\n"))?;
387-
tool_uses = inter;
388-
tools_were_interrupted = true;
386+
// If there was an interrupt during tool execution, then we add fake
387+
// messages to "reset" the chat state.
388+
if let Some(ref tool_uses) = inter {
389+
self.conversation_state.abandon_tool_use(
390+
tool_uses.clone(),
391+
"The user interrupted the tool execution.".to_string(),
392+
);
393+
let _ = self.conversation_state.as_sendable_conversation_state();
394+
self.conversation_state
395+
.push_assistant_message(AssistantResponseMessage {
396+
message_id: None,
397+
content: "Tool uses were interrupted, waiting for the next user prompt"
398+
.to_string(),
399+
tool_uses: None,
400+
});
401+
}
389402
},
390403
ChatError::Client(err) => {
391404
if let fig_api_client::Error::QuotaBreach(msg) = err {
@@ -408,8 +421,8 @@ Hi, I'm <g>Amazon Q</g>, your AI Developer Assistant.
408421
}
409422
self.conversation_state.fix_history();
410423
next_state = Some(ChatState::PromptUser {
411-
tool_uses,
412-
tools_were_interrupted,
424+
tool_uses: None,
425+
tools_were_interrupted: false,
413426
});
414427
},
415428
}

0 commit comments

Comments
 (0)