优化: AI Chat全栈多批审查修复与架构清理(risk_level清理/路由解耦/工具渲染/测试补测/死代码)

This commit is contained in:
2026-06-18 22:57:19 +08:00
parent 0ca5d9805f
commit a2871a66e0
87 changed files with 5720 additions and 3012 deletions

View File

@@ -101,6 +101,8 @@ impl Dag {
for edge in &self.edges {
// 仅收录两端均为已注册节点的边,跳过野节点
if node_ids.contains(&edge.source) && node_ids.contains(&edge.target) {
// safe: edge.target 已在 node_ids 中(上一行 contains 守卫),而 in_degree
// 对每个 node_id 都插入了表项line 97-99 初始化),故 get_mut 必命中
*in_degree.get_mut(&edge.target).unwrap() += 1;
adjacency_out
.entry(edge.source.clone())
@@ -127,6 +129,9 @@ impl Dag {
// 出边已索引O(出度) 遍历而非 O(E) 全表扫描
if let Some(succs) = adjacency_out.get(&id) {
for succ in succs {
// safe: succ 来自 adjacency_out其元素均为通过 line 103 contains 守卫
// 的 edge.targetline 108 push而 in_degree 覆盖所有 node_idline 97-99
// 故 succ 必在 in_degree 表内get_mut 必命中
let deg = in_degree.get_mut(succ).unwrap();
*deg -= 1;
if *deg == 0 {

View File

@@ -135,13 +135,25 @@ impl DagExecutor {
// 与 Err 分支 is_cancelled 短路对称:已取消节点保持 Cancelled 终态
if !self.state_machine.is_cancelled(&node_id) {
self.state_machine.set_completed(node_id.clone())?;
// 未取消才 emit NodeCompleted,取消时 emit NodeCancelled(对齐 Err 分支语义):
// 避免 状态机=Cancelled 但事件=NodeCompleted 的矛盾信号
self.event_bus
.send(WorkflowEvent::NodeCompleted {
node_id: node_id.clone(),
duration_ms: duration,
})
.await;
} else {
// 对齐 Err 分支:取消节点 emit NodeCancelled(非 NodeCompleted),
// 前端按 type 归「取消」,与状态机 Cancelled 一致
self.event_bus
.send(WorkflowEvent::NodeCancelled {
node_id: node_id.clone(),
})
.await;
}
self.event_bus
.send(WorkflowEvent::NodeCompleted {
node_id: node_id.clone(),
duration_ms: duration,
})
.await;
// outputs.insert 保留现状不动:取消时仍写入 output 供下游消费,
// 当前测试锁定"取消不中止后续层",改 insert 会变行为致回归
outputs.insert(node_id, output);
}
Err(e) => {

View File

@@ -30,8 +30,6 @@ pub struct NodeContext {
pub struct NodeOutput {
/// 输出数据
pub data: serde_json::Value,
/// 输出元数据
pub metadata: std::collections::HashMap<String, String>,
}
impl NodeOutput {
@@ -39,16 +37,12 @@ impl NodeOutput {
pub fn empty() -> Self {
Self {
data: serde_json::Value::Null,
metadata: std::collections::HashMap::new(),
}
}
/// 从 JSON 值创建输出
pub fn from_value(data: serde_json::Value) -> Self {
Self {
data,
metadata: std::collections::HashMap::new(),
}
Self { data }
}
}