修复: 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() 透传 ¬ify;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:
@@ -139,6 +139,17 @@ pub struct AiSession {
|
||||
pub agent_language: Option<String>,
|
||||
/// 停止信号:ai_chat_stop 置位,agentic loop / stream_llm 检测后尽快退出
|
||||
pub stop_flag: Arc<AtomicBool>,
|
||||
/// 即时停止唤醒(B-260615-14):stream_llm 阻塞在 `stream.next()` 等 chunk 时,
|
||||
/// `notify_one()` 立即唤醒跳出 select!,不再等 30s 心跳 tick 轮询。
|
||||
///
|
||||
/// 语义边界:Notify 仅承载「即时唤醒」这一职责——停止的真值仍由 `stop_flag`
|
||||
/// (AtomicBool)决定。`ai_chat_stop` 置 `stop_flag=true` 后调 `notify_one()`;
|
||||
/// 被唤醒的 select! 分支再判 `stop_flag` 决定退出或继续,避免 Notify 的通知
|
||||
/// 与「真的该停」耦合(防误唤醒继续跑)。
|
||||
///
|
||||
/// `Arc<Notify>` 可 Clone(Notify 内部用 Atomic 计数,Clone 等价于 Arc 引用 +1),
|
||||
/// 不影响 AiSession 其他字段语义。
|
||||
pub notify: Arc<tokio::sync::Notify>,
|
||||
}
|
||||
|
||||
impl AiSession {
|
||||
@@ -152,9 +163,19 @@ impl AiSession {
|
||||
generating: false,
|
||||
agent_language: None,
|
||||
stop_flag: Arc::new(AtomicBool::new(false)),
|
||||
notify: Arc::new(tokio::sync::Notify::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// 取即时停止唤醒器引用(B-260615-14)。
|
||||
///
|
||||
/// 供 `stream_llm`(接 `&Notify` 进 select! 监听 `notified()`)与 `ai_chat_stop`
|
||||
/// (置 `stop_flag` 后调 `notify_one()`)等外部持有方获取同一 Notify 实例。
|
||||
/// 返回 `&Notify` 而非 clone,避免不必要的 Arc 引用计数调整。
|
||||
pub fn stop_notify(&self) -> &tokio::sync::Notify {
|
||||
&self.notify
|
||||
}
|
||||
|
||||
/// 推导会话读侧状态视图(只读,不写任何字段)。
|
||||
///
|
||||
/// 优先级:`pending_approvals` 非空 → [`SessionState::AwaitingApproval`];
|
||||
|
||||
Reference in New Issue
Block a user