修复: B-14 stop 即时打断 Notify 跨文件接入(去 30s 心跳延迟)

AiSession 加 notify:Arc<Notify> 字段 + stop_notify() 取引用;stream_llm 加 notify 参数 + select! notify.notified() 分支(唤醒后 load stop_flag 判退出,防误唤醒继续跑——Notify 仅承载即时唤醒,停止真值仍由 stop_flag 决定);agentic.rs session.notify.clone() 透传 &notify;commands.rs ai_chat_stop 流式分支 stop_flag.store 后立即 notify_one() 唤醒阻塞的 stream.next()。批1 脚手架(本地无用实例)已 revert,本批完整接入。批3 wkitz0twz,cargo workspace 0 err
This commit is contained in:
2026-06-15 05:34:31 +08:00
parent af8f74e29e
commit 4665e910ee
4 changed files with 42 additions and 2 deletions

View File

@@ -140,7 +140,11 @@ pub(crate) async fn run_agentic_loop(
);
let tool_defs = tools_arc.tool_definitions();
// 停止信号副本stream_llm 与每轮迭代共享读取,避免重复加锁
let stop_flag = session_arc.lock().await.stop_flag.clone();
// notify 同取一份 Arc 引用B-260615-14stream_llm select! 监听 notified() 即时唤醒
let (stop_flag, notify) = {
let session = session_arc.lock().await;
(session.stop_flag.clone(), session.notify.clone())
};
// token 累加器:loop 生命周期内各轮叠加,退出时传 save_conversation(累加模式落库)
let mut tokens = TokenAccumulator::default();
@@ -221,7 +225,7 @@ pub(crate) async fn run_agentic_loop(
let _global_permit = llm_concurrency.acquire_global().await;
let _per_conv_permit = llm_concurrency.acquire_per_conv().await;
// 流式接收(内部处理 idle timeout / 断连检测 / 停止信号)
let (full_text, tool_calls_acc, round_usage) = match stream_llm(&*provider, request, &app_handle, &stop_flag, &conv_id).await {
let (full_text, tool_calls_acc, round_usage) = match stream_llm(&*provider, request, &app_handle, &stop_flag, &notify, &conv_id).await {
Some(result) => result,
None => {
// 错误已在 stream_llm 中 emit直接结束