Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/infinity-slack-bot/src/daemon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ impl DaemonClient {
Ok(())
}

/// Interrupt in-flight generation on the given agent thread (and its
/// descendant subtree) without queuing any input.
pub async fn interrupt(
&self,
thread_id: &infinity_protocol::ThreadRef,
) -> Result<(), BoxError> {
self.tx
.send(ClientMessage::Interrupt {
thread_id: thread_id.clone(),
})
.await?;
Ok(())
}

pub async fn connect_session(
&self,
session_id: &infinity_protocol::ThreadRef,
Expand Down
38 changes: 38 additions & 0 deletions crates/infinity-slack-bot/src/daemon_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,44 @@ pub fn spawn() -> DaemonIo {
tracing::warn!("AnswerChoice: no connection for thread {thread_ts}");
}
}
DaemonCommand::Interrupt {
thread_ts,
session_id,
target_thread,
} => {
// The agent thread to interrupt: a subagent thread when
// the user stopped a dedicated subagent Slack thread, the
// session root (whole session) otherwise.
let interrupt_thread = target_thread.as_ref().unwrap_or(&session_id);
if !connections.contains_key(&thread_ts) {
// Reconnect after restart so the stop still lands.
match DaemonClient::connect().await {
Ok(daemon) => {
if let Err(e) = daemon.connect_session(&session_id, None).await {
tracing::error!(
"reconnect to session failed for {thread_ts}: {e}"
);
continue;
}
spawn_receiver(
thread_ts.clone(),
&mut connections,
daemon,
&to_df_tx,
);
}
Err(e) => {
tracing::error!("daemon connect failed for {thread_ts}: {e}");
continue;
}
}
}
if let Some(daemon) = connections.get(&thread_ts) {
if let Err(e) = daemon.interrupt(interrupt_thread).await {
tracing::error!("Interrupt failed for {thread_ts}: {e}");
}
}
}
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions crates/infinity-slack-bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ mod tests {
response_url: None,
trigger_id: None,
is_app_home_opened: false,
is_session_stopped: false,
streaming_message_ts: Vec::new(),
})
.await
.expect("send should succeed");
Expand Down
Loading
Loading