fix(core): 修复 v0.3.0 审查发现的 6 项警告问题

- InMemoryGraph 的 10 处 lock().unwrap() 改为错误传播,避免 Mutex poison 时 panic
- SubTaskResult 添加 Serialize/Deserialize,支持结果序列化
- dispatch_all 移除多余的 task.clone()
- truncate_total_chars 补充字节切片安全性注释
- SessionManager::children 添加 ponytail 注释标记 O(N) 扫描现状
- SessionMemoryEntry.created_at 添加 i64 类型说明注释
This commit is contained in:
徐涛
2026-07-17 15:59:02 +08:00
parent 9d73f525d0
commit 6676322666
5 changed files with 41 additions and 13 deletions
+2
View File
@@ -446,6 +446,8 @@ impl SessionManager {
/// 查询某 parent 的所有直接子 session 的 ID 列表。
///
/// 实现:prefix 查询所有 `session:*:meta`,过滤 `parent_id == parent_id`。
// ponytail: O(N) 全表扫描,当前规模(≤10K session)可接受。
// 如有性能需求,可维护 `parent:{parent_id}:children` 索引 key 替代扫描。
pub async fn children(&self, parent_id: &str) -> Result<Vec<String>, EngineError> {
let filter = MemoryFilter {
prefix: Some("session:".to_string()),
+3
View File
@@ -12,6 +12,9 @@ pub struct SessionMemoryEntry {
#[serde(default)]
pub metadata: serde_json::Value,
/// 创建时间(Unix 时间戳秒;`None` 兼容旧快照)。
///
/// 类型为 `i64` 而非 `u64``time` crate 的 `OffsetDateTime::from_unix_timestamp` 接收 `i64`
/// 这里保持与 `SessionMemory::set_with_meta` 签名一致,避免来回转换。
#[serde(default)]
pub created_at: Option<i64>,
}
+3 -2
View File
@@ -9,6 +9,8 @@
//! - 可增加 `cancel_all(parent_id)` 中止正在运行的子 session
//! - 可暴露 `child_session_tree` API 支持会话树查询
use serde::{Deserialize, Serialize};
use crate::llm::stream::StreamEvent;
use crate::llm::types::response_v2::MessageResponse;
use crate::llm::types::usage::CostTracker;
@@ -53,7 +55,7 @@ impl Default for DispatchConfig {
/// dispatch 成功后子 session **保留在 SessionManager 中**,调用方可
/// 通过 `sm.get(&result.child_id)` 获取子 session 引用,进而通过
/// `session_memory()` 读取子 SessionMemory(如 `"result_summary"`)。
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct SubTaskResult {
/// 子 session ID。可通过此 ID 在 SessionManager 中读取子 session。
pub child_id: String,
@@ -273,7 +275,6 @@ impl SessionManager {
let sm = self.clone();
let parent_id = parent_id_owned.clone();
let config = config.clone();
let task = task.clone();
handles.push(tokio::spawn(async move {
let _permit = sem.acquire_owned().await.expect("Semaphore closed");