Commit Graph
20 Commits
Author SHA1 Message Date
小唯 41e95aa36d chore: 收工 eval.go gofmt + server.go 未提交杂项 2026-09-21 18:14:24 +08:00
小唯 c6be6a4cd5 fix(governance): DedupeActive 改为归档+审计,不物理删除 (t_0fdee22a) 2026-09-21 18:09:09 +08:00
小唯 d4d5db266a feat(governance): 冲突队列保留策略+去重(t_4ce53193) - sha256去重键+7天保留期+归档审计+挂进t_consolidation触发器 2026-09-21 17:32:50 +08:00
小唯 3b8ecba48e perf: 织忆内存/碎片双治本 — PageRank O(V+E) 重写 + 写入去抖 + 在线VACUUM
1. PageRank 三重循环 O(47k×374k×20≈3.5e11) → 入边表 O(V+E):
   单次 full 整合 4h41m → 95.2s,内存峰值 3.8G → 237MB(实测)
2. 图谱修剪 merge 边 id 加 relation + INSERT OR REPLACE:
   修复 09-18 起 UNIQUE constraint 静默失败 → 主库首次跑消 9.8万冗余边
3. LanceDB 写入去抖(server.go + validator.go):
   被动验证只写 Confidence 实际变化的记录;原先每输入重写全库 6000 条
   → 版本快照 O(n²),每日 ~1.9万版本/十几G 膨胀的根因
4. 新增 scripts/lance_vacuum_online.py:在线 VACUUM(不停服务)+
   24h 版本窗口(可回滚)+ 行数门禁(减少才报警);替代停服务版
   每日 vacuum → cron 已改为在线版

实测:侧车 RSS 1.09G→69MB;memories 分片 5383→1;服务全程在线
2026-09-21 10:17:56 +08:00
小唯 daab83337b feat(governance): 冲突持久化 + 禁止静默 dismiss(链路空转修复)
问题(2026-09-20 实测):
1) ConflictDetector.active 是纯内存 map,zhiyid 重启即清零
   (17:17 重启后原先 pending 的 5 条冲突全部消失)
2) server.go 的 conflict_muchen 处理器把未匹配策略的冲突改写成 dismiss 再 Resolve,
   且记成 RecordConflictResolved(true) —— 每条 pending 最多活 10 分钟即消失、
   auto_resolve_rate 虚高、冲突从不进入任何人视野
   (实测 17:19 建的冲突,同进程几分钟后 pending:0,未重启)
3) Conflict 不留两侧原文 ⇒ 事后无法核实真假矛盾(上一 commit 已加字段)

改动:
- governance:ConflictDetector 增 path + load/persistLocked(全量原子落盘 tmp+rename);
  新增 NewPersistentConflictDetector(path);NewConflictDetector() 保持纯内存(测试安全)
- Scan/Resolve 变更后落盘
- server.go:检测器改用持久化构造(落盘失败降级内存 + 记日志)
- server.go:禁止无脑 dismiss —— 72h 内保留 pending 供人工处置,超期才 latest_wins
  自动收敛(真裁决才记指标)
- 新增 conflict_persist_test.go:round-trip / resolve 落盘 / 纯内存不碰盘

未用 SQLite:冲突量级小,引 sqlite driver 需 cgo 新依赖(worker 曾在该方向崩溃
并留下锁重入死锁)。JSON 全量落盘零依赖、无锁重入。
2026-09-20 17:54:40 +08:00
小唯 cff87730b2 fix(api): check SoftDelete error returns at all 5 call sites
SoftDelete returns error but call sites discarded it, so a failed
soft-delete was silent — same class as the no-op implementations.
Now logged explicitly at:
  - server.go: ephemeral_expired cleanup (x2)
  - admin.go: auto_forget_fragment / auto_forget
  - feedback.go: Deprecate endpoint
2026-09-20 11:51:57 +08:00
小唯 69602ddd08 fix(distill): semantic near-dedup gate on distill write path
Previously distill's direct-write path only skipped facts whose exact
content already existed (sim[0].Content == fact). This let semantically
equivalent facts - e.g. "牧尘在招商局工作" vs "牧尘在招商局工作。"
(trailing period) - slip through as separate memories, accounting for
most of the 404 redundant entries found by a full-vector cosine scan.

Now distill encodes each fact, searches 5 nearest neighbors in the same
namespace, and skips insertion if any neighbor has either identical
content OR cosine similarity >= 0.98. The same threshold is shared by
the commit path (routes/core.go), via a new api-level cosineSimilarity
helper.

This is preventative only: it does NOT merge existing duplicates.
Existing 404 redundant entries remain; they will be cleaned up by a
separate manual dedup run after the gate is live.
2026-09-20 00:37:25 +08:00
小唯 835b308df6 fix conflict scan: use real vector of new content instead of zero vector for retrieving existing memories 2026-09-20 00:10:03 +08:00
小唯 dbe6c278c5 deep-think integration: conflict-detector fix, GraphRAG recall fusion, Louvain community discovery, deep-think endpoint 2026-09-19 19:12:49 +08:00
小唯 be120f3c07 fix(governance): #14 冲突误判致蒸馏跳过→召回不到 (t_a54aae79)
1. IsContradiction 阈值 0.3→0.5: 字符级分词下 0.3 过敏, "同话题不同事实"
   大量误判为矛盾, commit 路径 distill_skipped=conflict 跳过写入
2. containsNegCN 移除单字 莫/别 扫描: 特别/其他/分别 等高频非否定词误报
3. commit 请求体补上 resolve_conflict=true 覆盖开关(此前响应文案提及但
   请求体根本无此字段, 覆盖永远不生效)
4. 测试: governance 阈值回归(真矛盾/别误报/不+购买兼容/无否定基线) +
   routes 端到端门控(E2E: 矛盾不触发/flag触发/误报放行/无矛盾基线)
5. server.go: 补 path/filepath import — 工作区有一处他人 WIP 改动
   (AddEdge 429 重试+落盘), 缺 import 导致全仓 build 失败, 此处仅补
   import 使 build 通过, 该 WIP 逻辑本身未评审

验证: go build ./... + go test ./... 全绿; 线上验证见看板卡 t_a54aae79
2026-09-18 04:21:08 +08:00
小唯 ee50ef0d59 fix(rust): 恢复缺失的 LanceDBStats/stats() 和 helper 函数 (t_3fb41049); storage: 添加软删除累积延迟缓冲 (t_384f785b) 2026-09-14 22:14:52 +08:00
小怡 f2362150d1 perf(recall): 累积延迟更新治理写放大 — 读路径零逐条写 + 单事务批量落盘 (t_8496e8b6)
根因: recall 读路径对每条结果同步 lancedb.Update,LanceDB MVCC 每次提交=1 版本
      实测 15 版本/分钟 / _versions 17.7G(真实数据 22M)

改动:
- Go: 新增 RecallWriteBuffer(窗口合并+阈值触发+优雅退出落盘);recall.go 读路径改 Record();RustLanceDBClient.UpdateRecallBatch
- Rust: lancedb_update_batch IPC — 按 delta 分组,每组一次 update(`recall_count + delta` + id IN (...)) 提交
- 单测 6 个 + IPC 端到端版本计数测试;bench_test.go 修 NewReranker 签名失配(阻塞包测试)

实测: 批量 3 条 → 1 个版本;逐条 3 次 → 3 个版本 (lance 不支持 CASE WHEN,已按 delta 分组规避)
2026-09-12 17:57:31 +08:00
小唯 e91ca91367 fix(security): 写入侧凭证过滤 — 密钥不再进记忆/图谱/Obsidian 镜像
背景(2026-09-10 mc P0 事故):某轮蒸馏把含真 Tailscale 预授权 key 的原始对话
当事实入库 → 知识图谱按其文本建实体 → ObsidianSyncer 用实体标题当文件名/正文,
把 tskey-auth-… 落成可读镜像文件,又被 git 跟踪并推送 Gitea。
本提交在三个写入边界统一加脱敏。

新增 internal/redact(唯一真源):
- SecretPattern 覆盖 sk- / tskey- / github_pat_ / ghp_ / nvapi- / AKIA
- Go RE2 不支持 lookbehind,故"前一字符是否属于更长标识符"手工判定(isTokenByte)
- sk- 段只吃 [A-Za-z0-9],避免误伤 URL 里的 task-driven 片段(事故中的假阳性来源)
- RedactSecrets 幂等;ContainsSecret 供"直接丢弃"场景用

四处接入:
- distill/quality.go       IsQualityFact 判定前脱敏 + FilterQualityFacts 返回值脱敏
- governance/graph_auto.go cleanEntityName 命中→空串;UpdateFromDistill 只对有效实体
                           建节点/建边;extractEntitiesFromText 过滤;含凭证的 fact 不建节点
- api/routes/obsidian.go   sanitizeFilename 入参脱敏 + PushToObsidian 镜像正文脱敏
- api/server.go            蒸馏直写记忆库路径(绕过 FilterQualityFacts 的那条)同步脱敏

测试:13 条新用例(redact 5 / distill 3 / governance 4 / routes 1),
含 URL 假阳性回归与幂等性断言。全部使用构造的假密钥,不含任何真实凭证。
证据:go build ./... OK;
go test -count=1 ./internal/redact/ ./internal/distill/ ./internal/governance/ ./internal/api/routes/ 全绿。

顺带修既有 test 腐化(否则 governance 包根本无法编译测试,非本任务引入):
governance_test.go isContradiction→IsContradiction、Navigate 补 relFilter 参数;
bench_test.go 同。仅测试文件,无生产行为改动。
2026-09-11 00:41:59 +08:00
小唯 310a98da4e fix(graph-cleanup): CleanupNoiseNodes NULL-id panic + 新增 scoped 卫安/A03/A04 测试污染清理端点 (t_1dfaaa4a)
- graph_sqlite.go CleanupNoiseNodes: row[id] 为 NULL(daemon-distill pattern 模板行)时直接
  .(string) panic → HTTP 连接被关(HTTP=000);改为 nil 安全跳过
- 新增 CleanupScopedNodes(dryRun, namespaces, nameContains):namespace+名称子串精确圈定,
  清理 2026-06 多 agent 测试污染(openclaw-main/a06-main/hermes-main 的 A03/A04/卫安 节点)
- graph_cache.go: cachedGraphStore 透传(inner 可选接口断言,非 SQLite 后端静默 0)
- server.go: GET/POST /api/v1/graph/cleanup/scoped?dry_run=&namespace=&name=
  实际执行后 InvalidateAll 保证 graph_cache 一致性 —— 禁外部 SQL 的官方通道
2026-09-08 09:02:35 +08:00
xiaowei d454cae849 feat(memory-quality): 方案B写时质量门槛+方案C provenance 标注
方案B: distill 结果写 memories 前 IsQualityFact 过滤(碎片<8字拒/8-20字需用户信号/噪声前缀拦)+完全重复查重跳过
  - quality.go: 与 LightMem 保留细节哲学兼容(咖啡偏好保留), 拦进程噪声/桥接/reflection
  - 单测 8/8 通过
方案C: distill MemoryRecord 标 Source=llm_distill(provenance); volatile_flag 降权已确认生效(×0.5)
  - ContentMD5/VersionHistory 字段已在, bi-temporal valid_to 加列缓行(风险高)
2026-09-07 21:50:37 +08:00
xiaowei 29c3a7bb30 fix(forgetting): 遗忘机制方案A — 碎片快速道+episodes/长内容保护+stats修正
- governance.go: recall加成 0.05→0.005(防 recall_count 500+ 虚高保命); decayRate 试 0.03 误删长内容后回滚 0.015
- server.go decay: 碎片快速道(<30字&>20天→auto_forget_fragment); episodes 不参与遗忘(曾误删67条对话已恢复); >200字长记忆保护
- admin.go Forget: 同步三保护
- rust lancedb_ops.rs: tombstone_count 数 is_deleted=true(移植 a7082d3+类型修)

验证: admin forget 触发 tombstone 0→210(碎片清除); episodes/长内容 0 误删; stats 真实计数
2026-09-07 21:50:37 +08:00
xiaowei d4343b1c47 fix(recall): Embedder http client 8s 超时 + decay 分批 AC-1 日志
- Embedder http.Client{} 无超时 → 远端 bge 半开 TCP 时 recall 永久挂起
  (gateway 10s 断 → 织忆异常误报)。加 8s 超时快速失败降级。
- decay 每 tick 限量 2000 条(最久未访问优先) + scanned/forgotten 日志
  (AC-1 验收证据)
2026-09-06 01:08:42 +08:00
xiaowei e6b1e0417c fix(forgetting): P1 防风暴 - 限长/分桶/抽样下推/decay分批
febc2c9 全表扫描 O(n²) 风暴的根治防护(生产基线 ba44e20+ 之上,不含 febc2c9 扫描代码):

1. mergeSimilar 按 category 分桶 + 单桶 maxMergePerBucket=500 截断
   - 原双层循环全量 O(n²),全表时触发 620% CPU
   - 分桶后 O(Σ桶²) << O(n²),语义不变(原 catI!=catJ continue 等价分桶)
2. scanConflicts 显式 created_at 倒序取最近 500 条
   - 原注释'最近100条'实际全量 O(n·50)
3. checkTimestampSanity 先截断 maxSanitySample=1000 再均匀抽样
   - 原全量拉取仅为 5% 抽样
4. decay 每 tick 限量 maxDecayBatch=2000,按最久未访问优先
5. 存储层输出契约统一 RFC3339 string + 补 category/created_at
   - lancedb_ipc: last_recalled_at 此前直接放 time.Time → server.go .(string)
     断言恒失败 → lastAccessed 永远默认30天前 → 遗忘判定失真(本 bug + 数据
     年龄未到 = 遗忘从不触发的双根因之一)
   - sqlite: 补 category/created_at + LIMIT 100→200(对齐 lancedb 契约)
   - 新增 memoryTimeVal/fmtTimeRFC3339 helper 兼容多类型

测试: go build ./... 全绿;gofmt 仅历史文件遗留(未全文件重排,保持最小 diff)
2026-09-06 00:56:06 +08:00
小唯 cdc6b4e9a2 fix(consolidate): 按目标分组批量LLM决策,消除O(n²)调用风暴
原实现每对高相似记忆调一次LLM → limit=100产生4950对 → 223s+未完成
→ 每天processed=0(非namespace过滤bug)。改为: 外层目标i,内层收集
全部高相似候选,每目标一次LLM(UpdatePrompt原生支持多候选)。

验证: limit=20 → 4.3s返回 processed=1 updated=1; limit=100 2min(受
llama单slot排队限制)对每日低频可用。
2026-09-06 00:32:27 +08:00
xiaowei 2a350cf781 fix(distill): max_tokens 800→1200 — Agnes推理token预算不足
Agnes 2.0-flash是推理模型,推理token占大量预算。
800仍不够→JSON截断(parse error: unexpected end of JSON input)。
1200确保推理+正文都够用。
2026-08-20 01:13:06 +08:00