修复: 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

@@ -109,6 +109,7 @@ pub(crate) async fn stream_llm(
request: CompletionRequest,
app_handle: &AppHandle,
stop_flag: &AtomicBool,
notify: &tokio::sync::Notify,
conv_id: &str,
) -> Option<(String, HashMap<u32, ToolCallDraft>, df_ai::provider::TokenUsage)> {
/// 流式读取空闲超时:超过此时长无任何 chunk 即判定连接已断
@@ -239,6 +240,16 @@ pub(crate) async fn stream_llm(
conversation_id: Some(conv_id.to_string()),
});
}
// 3) 即时停止唤醒(B-260615-14):用户点 stop → ai_chat_stop 置 stop_flag 后 notify_one()。
// stream.next() 正阻塞等 chunk 时立即被唤醒,不再等 30s 心跳 tick 或 120s idle timeout。
// 唤醒后判 stop_flag:真值仍由 AtomicBool 决定,Notify 仅承载「即时唤醒」职责
// (防误唤醒继续跑——若非 stop 触发的 notify,flag 仍 false 则照常进下一轮循环)。
_ = notify.notified() => {
if stop_flag.load(std::sync::atomic::Ordering::SeqCst) {
stopped = true;
break;
}
}
}
}