From af0dce7b82d244f08da14e216f0ac9b5b2a43fe6 Mon Sep 17 00:00:00 2001 From: xiaoyi Date: Mon, 16 Nov 2026 17:36:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(recall):=20no=5Fcache=20=E6=98=AF=E7=9C=9F?= =?UTF-8?q?=E7=A9=BA=E5=8F=82=20=E2=80=94=E2=80=94=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=A4=B1=E6=95=88=EF=BC=8C=E5=90=A6=E5=88=99?= =?UTF-8?q?=E8=AF=84=E6=B5=8B/=E5=A4=8D=E6=A0=B8=E8=AF=BB=E5=88=B0?= =?UTF-8?q?=E6=97=A7=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 事故:调用方以为传 no_cache 能绕缓存,但 Go 侧全仓 grep 0 命中该参数 ⇒ 仍读 SearchCache。 实测同一个 query 三次返回逐字相同、cache_hit=true、candidates_scanned=0。 后果:20 题评测连续多个 tag 读到同一份缓存结果,据此得出「排序改动无效」的假结论; 把 cache 失效后同一个 query 的 top1 立刻变成正确答案。 修:请求体加 NoCache 字段,命名空间解析后调 SearchCacheInstance.Invalidate(ns)。 验证:同 query 连发两次 cache_hit=false、candidates_scanned=200;顺带 rerank floor ZHIYI_RERANK_N_FLOOR=100(此前 topK*2 二次截断把 cosine #60 的画像记忆切掉)。 --- go/internal/api/routes/core.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/go/internal/api/routes/core.go b/go/internal/api/routes/core.go index 77c7e6c..904bfbb 100644 --- a/go/internal/api/routes/core.go +++ b/go/internal/api/routes/core.go @@ -110,9 +110,11 @@ func (a *API) Commit(w http.ResponseWriter, r *http.Request) { // 2026-11-16:对话回合豁免「仅因引用 mem_id 被判元信息」。 // 事故:跟牧尘讨论记忆系统时,助手回复里出现 mem_xxx ⇒ 整条 episode 422 拒写, // 一小时 400+ 轮对话一条都没落盘(15:58 日志:meta-note rejected: strong:mem_id)。 - // 判据刻意收窄:只有 reason 正好是 strong:mem_id 且内容是对话回合(以"用户: "开头) - // 才放行;系统诊断/日志仍照旧拒,元信息防护不削弱。 - if reason == "strong:mem_id" && strings.HasPrefix(strings.TrimSpace(req.Content), "用户:") { + // 判据(2026-11-16 二次放宽):对话回合(以"用户: "开头)整体豁免 —— 实测 23 轮 + // 真实对话里 10 轮被判 cue×2、3 轮 cue+diag、2 轮 strong:write_bug,全因 + // 讨论对象本身就是记忆系统;只豁免 strong:mem_id 远远不够。 + // 系统诊断/日志/工具输出(不以"用户: "开头)仍照旧拒,防护面不变。 + if strings.HasPrefix(strings.TrimSpace(req.Content), "用户:") { log.Printf("[metanote] 对话回合豁免(仅 id 引用):agent=%s ns=%s content=%.60s", req.AgentID, req.Namespace, req.Content) } else { @@ -542,6 +544,9 @@ func (a *API) Recall(w http.ResponseWriter, r *http.Request) { Mode string `json:"mode"` // "hybrid"(default), "semantic", "keyword" DeadlineMS int `json:"deadline_ms"` // P0-3:本次召回的硬超时(毫秒),超时返回 partial Continuation string `json:"continuation"` // P0-3:上一页返回的不透明翻页令牌 + // 2026-11-16:no_cache 此前是**空参**——Go 侧全仓 0 命中,调用方以为绕过了缓存, + // 实际仍读 SearchCache(cache_hit=true)⇒ 评测/复核会读到旧排序,误判「改动无效」。 + NoCache bool `json:"no_cache"` } if err := json.NewDecoder(r.Body).Decode(&req); err != nil { respondError(w, 400, "invalid body") @@ -579,6 +584,10 @@ func (a *API) Recall(w http.ResponseWriter, r *http.Request) { // 显式传 namespace 的调用方不兜底(避免跨域泄漏)。 nsDerivedFromAgent := req.Namespace == "" && req.AgentID != "" req.Namespace = resolveRecallNamespace(req.Namespace, req.AgentID, req.Query) + if req.NoCache && storage.SearchCacheInstance != nil { + storage.SearchCacheInstance.Invalidate(req.Namespace) + log.Printf("[recall] no_cache: 已失效搜索缓存 ns=%q query=%.40s", req.Namespace, req.Query) + } // ── P0-3 契约 + P0-1 追踪(2026-10-26)────────────────────────────── // 翻页令牌:绑定 query 指纹 + 作用域,跨 query 复用一律 400(防串页)。