fix(channel): cancel and join scoped typing task safely
This commit is contained in:
parent
12c5473083
commit
5e800c38f1
1 changed files with 11 additions and 7 deletions
|
|
@ -320,13 +320,9 @@ async fn process_channel_message(ctx: Arc<ChannelRuntimeContext>, msg: traits::C
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let typing_cancellation = target_channel.as_ref().map(|_| {
|
let typing_cancellation = target_channel.as_ref().map(|_| CancellationToken::new());
|
||||||
let token = CancellationToken::new();
|
let typing_task = match (target_channel.as_ref(), typing_cancellation.as_ref()) {
|
||||||
let guard = token.clone().drop_guard();
|
(Some(channel), Some(token)) => Some(spawn_scoped_typing_task(
|
||||||
(token, guard)
|
|
||||||
});
|
|
||||||
let _typing_task = match (target_channel.as_ref(), typing_cancellation.as_ref()) {
|
|
||||||
(Some(channel), Some((token, _guard))) => Some(spawn_scoped_typing_task(
|
|
||||||
Arc::clone(channel),
|
Arc::clone(channel),
|
||||||
msg.reply_target.clone(),
|
msg.reply_target.clone(),
|
||||||
token.clone(),
|
token.clone(),
|
||||||
|
|
@ -358,6 +354,13 @@ async fn process_channel_message(ctx: Arc<ChannelRuntimeContext>, msg: traits::C
|
||||||
let _ = handle.await;
|
let _ = handle.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(token) = typing_cancellation.as_ref() {
|
||||||
|
token.cancel();
|
||||||
|
}
|
||||||
|
if let Some(handle) = typing_task {
|
||||||
|
log_worker_join_result(handle.await);
|
||||||
|
}
|
||||||
|
|
||||||
match llm_result {
|
match llm_result {
|
||||||
Ok(Ok(response)) => {
|
Ok(Ok(response)) => {
|
||||||
// Save user + assistant turn to per-sender history
|
// Save user + assistant turn to per-sender history
|
||||||
|
|
@ -1919,6 +1922,7 @@ mod tests {
|
||||||
auto_save_memory: false,
|
auto_save_memory: false,
|
||||||
max_tool_iterations: 10,
|
max_tool_iterations: 10,
|
||||||
min_relevance_score: 0.0,
|
min_relevance_score: 0.0,
|
||||||
|
conversation_histories: Arc::new(Mutex::new(HashMap::new())),
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue