SessionCompressorV2 holds memory locks across LLM extraction without refreshing them — locks get removed as "stale" while the holder is still alive, breaking mutual exclusion
Environment
- OpenViking
v0.4.5(imageghcr.io/volcengine/openviking:v0.4.5), single-node docker compose deployment - Host: Linux, 24 cores / 64 GB RAM; the OpenViking data workspace is on local disk (default AGFS storage)
- Vector backend: qdrant
v1.18.1on the same host, collection dimension 4096, cosine,enable_text_index: true - Embedding/VLM/rerank: self-hosted OpenAI-compatible gateway (Qwen3-Embedding-8B / Qwen3-VL-8B-Instruct / Qwen3-Reranker-8B),
vlm.max_concurrent: 24,vlm.timeout: 300 - Workload: an agent platform committing sessions continuously (~4–5 session operations/sec at peak, concentrated on a handful of user ids)
- We run v0.4.5 with local patches for #3150–#3153 and #3224; none of them touch the lock subsystem
Sanitized ov.conf (keys redacted):
{
"server": { "host": "0.0.0.0", "port": 1933, "root_api_key": "<redacted>" },
"storage": {
"workspace": "/root/.openviking/data",
"vectordb": {
"backend": "qdrant",
"name": "context_4096",
"dimension": 4096,
"distance_metric": "cosine",
"qdrant": { "url": "http://<qdrant-host>:6333", "timeout_seconds": 30, "enable_text_index": true }
}
},
"memory": {},
"embedding": { "dense": { "api_base": "https://<internal-llm-gateway>/v1", "api_key": "<redacted>", "provider": "openai", "dimension": 4096, "model": "Embedding/Qwen3-Embedding-8B" } },
"vlm": { "api_base": "https://<internal-llm-gateway>/v1", "api_key": "<redacted>", "provider": "openai", "model": "Qwen-VL/Qwen3-VL-8B-Instruct", "max_tokens": 4096, "max_concurrent": 24, "timeout": 300 },
"rerank": { "api_base": "https://<internal-llm-gateway>/v1/rerank", "api_key": "<redacted>", "provider": "openai", "model": "Qwen/Qwen3-Reranker-8B", "threshold": 0.1 }
}
Symptom
Production logs are flooded with locks being removed as stale while their owners are still alive and mid-extraction:
2026-07-15 08:53:36,918 - openviking.storage.transaction.path_lock - WARNING - [TREE] Removing stale lock: /local/<workspace>/user/<user-id>/memories/tools/.path.ovlock
We observed ~74,000 stale-lock removals in 5 hours (15–20k/hour sustained), together with continuous compressor_v2 "Failed to acquire memory locks, retrying" churn and ~140% CPU on the server process. See companion issue #3274 about the poll interval for the CPU side.
Root cause
PathLocktreats a lock file as stale once its fencing-token timestamp is older thanlock_expire(default 300 s) and lets any waiter delete it (path_lock.py::is_lock_stale,Removing stale lockpaths).- The intended countermeasure exists:
OwnedLockLeasestarts a refresh task that re-stamps held locks everylock_expire / 2(lock_lease.py::OwnedLockLease._refresh_loop).resource_processorandqueuefs/semantic_lockuse it. SessionCompressorV2does not. In bothextract_memoriesand_run_extract_phaseit creates a raw handle vialock_manager.create_handle()(compressor_v2.py, v0.4.5: ~L294 and ~L768), acquires the user'smemories/*tree locks, and then runs the full multi-turn ReAct LLM extraction while holding the locks, with no refresh.- A single extraction routinely takes minutes (multiple VLM round-trips; with
vlm.timeout: 300one slow/timed-out call alone can exceed the expiry). The moment the hold exceeds 300 s, every waiter polling the same paths legitimately concludes the holder is dead, deletes the lock file, and takes the lock over.
Impact
- Mutual exclusion on
memories/trajectories|tools|experiencesis silently broken: two extractions write the same user's memory tree concurrently (risk of duplicate/conflicting memory files). - The victim task fails/retries and steals someone else's lock in turn — under sustained traffic this becomes a self-sustaining takeover storm (our 15–20k removals/hour) with heavy wasted LLM spend.
Fix we verified in production
Wrapping the acquired handle in OwnedLockLease so the existing refresh loop runs, and closing the lease in finally:
# after acquire_exact_tree_batch(...) succeeds, in both call sites:
transaction_lease = OwnedLockLease.from_handle(lock_manager, transaction_handle)
...
finally:
if transaction_lease is not None:
await transaction_lease.close() # stops refresh + releases
elif lock_manager and transaction_handle:
await lock_manager.release(transaction_handle)
After deploying this (plus the poll-interval change from #3274), stale-lock removals dropped from 15–20k/hour to zero (excluding one-time cleanup after restart) and extraction output (memory files, memory_diff.json) remained correct. Happy to send a PR.
Longer-term suggestion
Holding subtree locks across multi-turn LLM calls is fragile even with refreshing (lock hold time is unbounded and serializes all extraction for a user). Consider extracting first and only taking the lock for the short apply/write phase, or a per-user work queue instead of lock contention.
Thanks for the detailed report! The old V2 lock lifetime is no longer the active implementation. #3602 moved lock renewal into Rust, which renews held locks periodically, and #3346 removed SessionCompressorV2. Memory extraction no longer depends on the V2 code remembering to refresh a Python-owned lease during a long model call.
Closing this V2 defect as resolved by the replacement on main. If current extraction still loses a live lock, please reopen, or comment requesting reopening, with the server version, lock configuration, storage backend and a sanitized acquire/renew/release timeline around the failure.