fix: 3 项问题

1. 审批DB更新精确匹配 — code_hash 从 removed entry 提取
2. delete memo 提取 id — prompt 中数字 → id 参数
3. 清理未使用的 current_user_id 全局变量
This commit is contained in:
2026-06-02 15:44:28 +08:00
parent fe83687495
commit 6708fe33a0
3 changed files with 12 additions and 16 deletions
+9 -6
View File
@@ -89,7 +89,7 @@ impl ApprovalManager {
/// 处理用户回复(由消息循环调用)
/// 匹配成功时返回 Some(技能名),匹配失败返回 None
pub async fn handle_reply(&self, user_id: &str, reply: &str) -> Option<String> {
let (result, name) = {
let (result, name, code_hash) = {
let mut map = self.pending.lock().await;
let entries = map.get_mut(user_id)?;
if entries.is_empty() { return None; }
@@ -99,19 +99,22 @@ impl ApprovalManager {
if reply_trimmed == "0" || reply_trimmed == "取消" {
let entry = entries.remove(0);
let hash = entry.code_hash.clone();
let _ = entry.sender.send(ApprovalDecision::Rejected);
(ApprovalDecision::Rejected, entry.skill_name.clone())
(ApprovalDecision::Rejected, entry.skill_name.clone(), hash)
} else if let Some(idx) = entries.iter().position(|e| e.code_hash == reply_hash) {
let entry = entries.remove(idx);
let hash = entry.code_hash.clone();
let _ = entry.sender.send(ApprovalDecision::Approved);
(ApprovalDecision::Approved, entry.skill_name.clone())
(ApprovalDecision::Approved, entry.skill_name.clone(), hash)
} else if let Some(entry) = entries.first_mut() {
entry.attempts_left -= 1;
if entry.attempts_left <= 0 {
let entry = entries.remove(0);
let n = entry.skill_name.clone();
let hash = entry.code_hash.clone();
let _ = entry.sender.send(ApprovalDecision::Rejected);
(ApprovalDecision::Rejected, n)
(ApprovalDecision::Rejected, n, hash)
} else {
return None;
}
@@ -128,10 +131,10 @@ impl ApprovalManager {
};
// 按 user_id + 最近 pending 记录更新
let _ = sqlx::query(
"UPDATE pending_approvals SET status = $1, consumed_at = NOW() WHERE id = (SELECT id FROM pending_approvals WHERE user_id = $2 AND status = 'pending' ORDER BY created_at DESC LIMIT 1)",
"UPDATE pending_approvals SET status = $1, consumed_at = NOW() WHERE code_hash = $2 AND status = 'pending'",
)
.bind(status)
.bind(user_id)
.bind(&code_hash)
.execute(pool.as_ref())
.await;
}
+2 -1
View File
@@ -61,7 +61,8 @@ async fn handle_memos(args_json: &str) -> SkillResult {
"list"
};
let content = params.get("prompt").and_then(|v| v.as_str()).unwrap_or("");
params = serde_json::json!({"action": action, "content": content});
let memo_id: i32 = content.chars().filter(|c| c.is_ascii_digit()).collect::<String>().parse().unwrap_or(0);
params = serde_json::json!({"action": action, "content": content, "id": memo_id});
}
let action = params.get("action").and_then(|v| v.as_str()).unwrap_or("list");
let path = ".data/memos.json";