OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: v0.4.17.1 L0 directory abstracts not generated — Lock error wrapping + missing parent rollup

Open jlin53882 opened this issue 3 months ago • 8 comments

OpenViking v0.4.17.1 L0 Abstracts 問題完整報告

日期: 2026-09-02 環境: Windows, v0.4.17.1, local CPU vectordb 分支: fix/l0-abstracts-complete(隔離環境)


一、問題描述

所有 memory 目錄顯示 [Directory abstract is not ready],搜尋召回準確率 0/10。


二、發現的問題

🔴 Bug 1: Lock 錯誤被包裝成 RuntimeError

位置: semantic_processor.py line 773-774

問題: _write_memory_directory_semantics 把 LockAcquisitionError 包裝成 RuntimeError,導致外層 handler 無法識別。

流程:

write_abstract_overview → LockAcquisitionError
→ _write_memory_directory_semantics → RuntimeError
→ _process_memory_directory → isinstance(e, LockAcquisitionError) → False
→ ❌ 不 re-enqueue,不重試

影響: Lock 失敗時,abstract 不會被寫入,也不會重試。

🔴 Bug 2: Parent Rollup 沒有實作

位置: semantic_processor.py line 633-645

問題: 當目錄只有 subdirectories 沒有 .md 檔案時,直接 return,不生成 abstract。

影響: Parent 目錄永遠沒有 abstract。

注意: Line 85 的 docstring 說 "Collect .abstract.md from subdirectories" 但實際上沒有實作。

🟡 設定問題: Lock Timeout 1 秒

位置: semantic_processor.py line 280

問題: lock_timeout_secs=1.0 可能太短。

狀態: 需要先量測再決定是否調整。


三、確認的問題

1. SemanticLockScope lock 行為

結論: v0.4.17.1 的 SemanticLockScope 有 fallback 機制 — 當 EXACT lock 失敗時,嘗試用 TREE lock 重新獲取。這可能解決了 Issue #2797 的部分 lock self-contention 問題。

2. is_stale() 邏輯

結論: is_stale() 檢查 coalesce_version 是否小於當前版本。這是正確的行為 — 避免過時的資料覆蓋新資料。

3. v0.4.17.1 lock 機制

結論: v0.4.17.1 的 lock 機制已經重構(semantic_sidecar.py 不存在),但 Bug 1(Lock 錯誤包裝)仍然存在。


四、修復 Plan

Phase 1: 修復 Lock 錯誤包裝(Bug Fix)

檔案: semantic_processor.py line 773-774

修復: 直接 re-raise LockAcquisitionError,不要包裝成 RuntimeError。

Phase 2: Parent Rollup(重新設計)

檔案: semantic_processor.py line 633-645

修復: 當 not file_paths 時,從 child directory 的 .abstract.md 聚合生成 parent abstract。

Edge Cases: placeholder 檢查、error handling、lock error 處理。

Phase 3: Lock Timeout(暫不調整)

狀態: 需要先量測再決定。


五、關聯 Issue 和 PR

# 類型 編號 狀態 說明
1 Issue #2797 Open L0 abstracts 不生成(根本原因)
2 PR #3679 Open Recursion + L1 vectorization(不修復 lock/rollup)
3 PR #2957 Open Parent rollup(沒測試,2 個月沒動)
4 PR #4209 Open CLI 版本對齊(不修復 L0)
5 Issue #4208 Open CLI 版本不一致

六、測試結果

基準測試(修改前)

# 查詢 預期匹配 實際結果 命中
1 google calendar sync Google行事曆同步案例 profile.md (0.99) ❌
2 option list management option_list_management.md 0 結果 ❌
3 收尾紀錄 wrap up 收尾相關案例 0 結果 ❌
4 DeepSeek 模型設定 模型設定案例 profile.md (0.987) ❌
5 obsidian vault sync vault sync 案例 .overview.md (resource) ❌
6 hvac 庫存系統 稽核 hvac 稽核案例 timeout ❌
7 openviking server openviking entity timeout ❌
8 Sarah Wang 同事 sarah_wang entity timeout ❌
9 CSS flex 重疊 CSS 重疊案例 0 結果 ❌
10 cron job 故障 cron 診斷案例 0 結果 ❌

基準準確率: 0/10 (0%)

後測(修改後)

待執行


七、成功標準

  1. ✅ viking_browse 顯示非 placeholder 的 abstracts
  2. ✅ Search accuracy 從 0/10 提升到 ≥7/10
  3. ✅ Server log 沒有錯誤
  4. ✅ 現有功能不變

jlin53882 avatar Sep 02 '26 15:09 jlin53882

Related Issues and PRs

Root Cause Issue:

  • Closes #2797 (Semantic reindex leaves missing .abstract.md/.overview.md)

Related PRs:

  • #3679 (fix(memory): add reindex recursion and API write L1 vectorization) — Does NOT fix lock error wrapping or parent rollup
  • #2957 (fix(memory): roll up child abstracts during semantic reindex) — No tests, 2 months inactive
  • #4209 (fix(release): align bundled CLI version with wheels) — Does NOT fix L0 abstracts

Related Issues:

  • #4208 (Release wheels embed next-patch .dev0 in bundled Rust CLI) — May affect CLI reindex behavior
  • #2631 (Search index unbuildable on Windows) — Windows-specific vector DB issues

Environment:

  • OpenViking v0.4.17.1
  • Windows 11
  • local CPU vectordb
  • Python 3.11

jlin53882 avatar Sep 02 '26 15:09 jlin53882

Local Baseline Benchmark (v0.4.17.1, Windows, 2026-09-02)

Environment:

  • OpenViking v0.4.17.1
  • Windows 11
  • local CPU vectordb
  • 4,796 .md files indexed (99.4%)
  • 75,130 facts (1024-dim vectors, qwen3-embedding:0.6b)

Test Queries and Results:

# Query Expected Match Actual Result Score Hit
1 google calendar sync Google行事曆同步案例 profile.md 0.99 ❌
2 option list management option_list_management.md 0 results - ❌
3 收尾紀錄 wrap up 收尾相關案例 0 results - ❌
4 DeepSeek 模型設定 模型設定案例 profile.md 0.987 ❌
5 obsidian vault sync vault sync 案例 .overview.md (resource) 0.485 ❌
6 hvac 庫存系統 稽核 hvac 稽核案例 profile.md 0.967 ❌
7 openviking server openviking entity timeout - ❌
8 Sarah Wang 同事 sarah_wang entity 0 results - ❌
9 CSS flex 重疊 CSS 重疊案例 0 results - ❌
10 cron job 故障 cron 診斷案例 0 results - ❌

Baseline Accuracy: 0/10 (0%)

Root Cause:

  • All directory abstracts show [Directory abstract is not ready]
  • Searches return profile.md as top result (score ~0.99) instead of relevant case files
  • Target case files (e.g., Google行事曆同步全階段實作.md, option_list_management.md) are not returned

Note: This benchmark was run on the local environment with actual indexed data, not simulated.

jlin53882 avatar Sep 02 '26 15:09 jlin53882

🔴 Root Cause Identified (2026-09-03)

The real root cause: memory write path never enqueues semantic processing

After clean-baseline testing (restored pristine v0.4.17.1 + restart), I found that memory file writes never trigger semantic queue processing, so .abstract.md is never auto-generated for memory directories.

Evidence

  1. viking_remember (writes to viking://user/home/memories/events/) → GET /api/v1/observer/queue shows Semantic: Processed=0 (no semantic processing at all)
  2. events/.abstract.md unchanged for 63+ minutes after write (before fix)
  3. Code path analysis in content_write.py (L170-184):
# Memory write → _write_memory_with_refresh → NO semantic enqueue
if context_type == "memory" and not is_abstract_overview_uri(normalized_uri):
    return await self._write_memory_with_refresh(...)
    # only does: refresh_schema_overview (.overview.md template) + refresh_file_embedding

# Resource/skill write → _write_direct_with_refresh → HAS semantic enqueue
return await self._write_direct_with_refresh(...)
    # _enqueue_semantic_refresh → semantic queue → generates .abstract.md

_write_memory_with_refresh was missing the _enqueue_semantic_refresh_changes call that resource/skill writes have.

Fix (local branch)

Added _enqueue_semantic_refresh_changes call in _write_memory_with_refresh after refresh_file_embedding, matching the _write_direct_with_refresh pattern.

Verified after fix:

  • viking_remember → Semantic: Processed 0→1
  • events/.abstract.md auto-generated within ~1 second of write
  • viking_search quality normal (score 0.93-0.997)

Relationship to other PRs

  • PR #4615 (Lock error wrapping) — addresses retry-on-lock-contention, complementary but NOT the root cause
  • PR #2957 / #3679 (parent rollup / recursion) — different approach, not the root cause
  • This fix addresses the actual missing link: memory writes → semantic processing → L0 abstracts

jlin53882 avatar Sep 03 '26 11:09 jlin53882

Migration Note: Existing memory directories need manual reindex

This fix only triggers semantic processing for new writes after the fix is deployed. Memory directories populated before the fix (e.g. from session commit/extraction) never had .abstract.md generated.

One-time reindex command

# Get user key (root_key cannot access data APIs)
USER_KEY=$(curl -s -H \"X-API-Key: \$ROOT_KEY\" http://127.0.0.1:{port}/api/v1/admin/accounts/default/users | python -c \"import sys,json; users=json.load(sys.stdin)[\\\"result\\\"]; print([u[\\\"api_key\\\"] for u in users if u[\\\"user_id\\\"]==\\\"home\\\"][0])\")

# Reindex each memory directory
for dir in entities cases preferences events experiences skills tools trajectories; do
  curl -s -X POST -H \"X-API-Key: \$USER_KEY\" -H \"Content-Type: application/json\" \
    -d \"{\\\"uri\\\": \\\"viking://user/home/memories/\$dir\\\", \\\"mode\\\": \\\"semantic_and_vectors\\\"}\" \
    http://127.0.0.1:{port}/api/v1/content/reindex
done

Why manual reindex is needed

The semantic queue only fires on write events — it does not retroactively scan existing directories for missing .abstract.md. The semantic_and_vectors reindex mode is the designed mechanism for backfilling existing content (each directory takes 20-70 seconds depending on file count).

jlin53882 avatar Sep 03 '26 13:09 jlin53882

Benchmark Comparison: Before Fix vs After Fix

Re-ran the same queries from the original benchmark after applying the semantic queue fix (commit 248618d9) + manual reindex of all memory directories.

Results

# Query Expected Match Before Fix After Fix Change
1 google calendar sync Google行事曆同步案例 profile.md (0.99) profile.md (0.988) ⚠️ Same result
2 option list management option_list_management.md 0 results 0 results (score 0.412 below threshold) ⚠️ See analysis
3 收尾紀錄 wrap up 收尾相關案例 0 results 收尾紀錄撰寫.md (0.852) ✅ Improved
4 DeepSeek 模型設定 模型設定案例 profile.md (0.987) AI模型/deepseek_v4_flash.md (0.992) ✅ Improved
7 openviking server openviking entity timeout AI記憶伺服器/openviking.md (0.984) ✅ Improved

Score: 3/5 improved, 2/5 same

Analysis of Flat Queries

Query 1 (google calendar sync → profile.md): profile.md abstract contains Google Calendar sync details as part of the user profile. The profile abstract is very broad and scores higher than narrower case/event memories. This is a score dominance issue — the profile file acts as a catch-all for system-level queries. Not directly related to abstract generation.

Query 2 (option list management → 0 results): The memory option_list_management.md exists in preferences/ directory (confirmed via viking_search "option list preference" → score 0.412). The score is too low to pass the search threshold. This suggests the file content or its abstract lacks sufficient semantic overlap with the query terms. The fix (abstract generation) helped but the underlying content density is thin — only 324 bytes.

Why Scores Are Flat

The flat queries are not caused by missing abstracts (all directories now have .abstract.md). The root causes are:

  1. Profile.md dominance: Broad profile abstract scores higher than specific case memories for system-level queries. This is a design tradeoff — more specific queries (e.g. "DeepSeek model") get correct results, but very generic ones (e.g. "google calendar sync") match profile.md first.

  2. Low content density: Some preference memories (e.g. option_list_management.md at 324B) have very thin content. The generated abstract inherits this thinness. Score 0.412 vs threshold means the file content itself needs enrichment for better retrieval.

  3. Query ambiguity: English queries against Chinese-language memories (e.g. "option list management" vs 「選項列表管理」) lose semantic alignment at the embedding level.

Conclusion

The fix successfully improves recall for queries that were previously returning 0 results or timeout (queries 3, 4, 7). The flat queries (1, 2) have different root causes — profile dominance and thin content — that are not addressed by abstract generation alone and would require richer memory content or profile separation.

jlin53882 avatar Sep 03 '26 13:09 jlin53882

The code path shows this is not simply an accidental missing refresh. Memory writes currently use the lightweight path: refresh template .overview.md + L2 file embedding, while skipping full SemanticQueue, which matches the historical #505/#3679 cost-control context. The resulting gap is that L0 .abstract.md is not generated from normal memory write events.

sponge225 avatar Sep 07 '26 11:09 sponge225

Claiming only the residual defect where VikingFS.write_context swallows the lock error type: its catch-all re-wraps every internal failure as a bare IOError without from e, so the #4615 except LockAcquisitionError: raise guards in the semantic queue never match and lock contention gets recorded against the circuit breaker. The fix is deliberately narrow — re-raise LockAcquisitionError unchanged and chain the generic wrap with from e — and is scoped separately from the content_write.py work in #4657 (no parent rollup, no memory-write enqueue). Opening a PR shortly.

akushonkamen avatar Oct 08 '26 12:10 akushonkamen

PR opened: #5764

akushonkamen avatar Oct 08 '26 12:10 akushonkamen