[Bug]: v0.4.15 (V3 pipeline) still drops trajectory backlinks - pathlock lease coverage on the streaming policy trainer path (follow-up to #4031)
Bug Description
Follow-up to #4031, as requested in its closing comment ("If you encounter similar errors after upgrading, please let us know").
The trajectory backlink lease-coverage failure still occurs on v0.4.15 with the V3 pipeline. compressor_v2.py is no longer present in the wheel, so this is not the legacy V2 path — it is a structurally identical defect on a different call path inside V3: the streaming policy trainer.
2026-08-26 04:00:23.852 | ERROR | openviking.session.memory.memory_updater:write_stored_links:153 - [5989c71854d24064bc7c86896010a4df] Failed to apply links to viking://user/default/memories/trajectories/<traj>.md: internal error: lock lease error: invalid lock request: pathlock lease ref 'a82619b9-5660-4503-977f-077c5266cda1' does not cover the requested operation
Root cause (0.4.15 code, V3 path)
Captured with server.observability.traces enabled (protocol: "local"), so the whole call chain and the lease's write set are in one trace (trace_id 5989c71854d24064bc7c86896010a4df):
openviking-streaming-policy-trainer.flush
└─ train.policy_updater.memory_file.apply
└─ openviking.session.memory.memory_updater.apply_operations ← failure raised here
-
TrainingEngine._plan_and_apply(session/train/engine.py:87) opens the transaction withasync with policy_set.lock() as transaction_handle:and passes it topolicy_updater.apply(..., transaction_handle=transaction_handle)(engine.py:98). -
PolicySet.lock(session/train/domain.py:67-88) acquires a TREE lock over the policy root directory only:"""Acquire a tree lock for the whole policy root directory.""" path = uri_to_path(self.root_uri, ctx=self.request_context) lease = await self.viking_fs._async_agfs.pathlock_acquire_tree(path, timeout_secs=300.0)root_urihere is the experiences root, so the lease coversmemories/experiences/**and nothing else. -
MemoryFilePolicyUpdater.apply(session/train/components/policy_updater.py:104) constructsMemoryUpdater(..., transaction_handle=transaction_handle). -
MemoryUpdater.apply_operations(session/memory/memory_updater.py:977-985) then callsself._apply_links_to_existing_files(..., lease_ref=self._transaction_handle), whose own docstring states the mismatch explicitly (memory_updater.py:1200):"""Apply links to endpoint files that are NOT in the current upsert batch."""By construction those endpoints are outside the upsert set — and for
experience --derived_from--> trajectoryedges the other endpoint lives undermemories/trajectories/, which the experiences-root tree lease can never cover. -
write_stored_links(memory_updater.py:149) callsviking_fs.write_file(uri, ..., lease_ref=lease_ref); the Rust coverage check rejects it, and the broadexcept Exceptionat memory_updater.py:152-153 swallows it into a log line.
Trace evidence that the lease's write set and the attempted write disagree:
| value from the same trace | |
|---|---|
lease write set (written_uris) |
['viking://user/default/memories/experiences/<exp>.md'] |
| attempted link write | viking://user/default/memories/trajectories/<traj>.md |
| reported apply result | Memory operations applied: Written: 1, Edited: 0, Deleted: 0, **Errors: 0** |
The commit reports success with zero errors while the reverse edge is dropped — the same silent-loss behaviour described in #4031, reached through the V3 policy-trainer path instead of compressor_v2.
Note that the two stabilization mechanisms shipped for V3 do not cover this path:
_operation_lock_paths(streaming_memory_updater.py:1858) does add link endpoints to the lease, and_acquire_stable_operation_lease(streaming_memory_updater.py:1907) re-acquires on expansion — but both live inStreamingMemoryUpdater, which is not on this call chain.- The training path builds its lease from
PolicySet.lock()instead, and that lease is never expanded to the link endpoints.
Reproduction steps
Any session commit where the policy trainer writes an experience that carries a derived_from link to a trajectory written in an earlier phase:
- phase 1 writes trajectory files under their own lock scope
- the streaming policy trainer flushes an experience under
PolicySet.lock()(experiences root tree lease) _apply_links_to_existing_fileswrites the trajectory backlink under that lease
Deterministic on our instance; observed continuously since 2026-08-23.
Impact
-
73 lease-coverage failures in ~3 days (2026-08-23 → 2026-08-26); 71 target
memories/trajectories/*, 2 targetmemories/experiences/*. -
Asymmetric edges, worse than the ratios reported in #4031:
forward/back links present experiences ( links)63/68 (93%) trajectories ( backlinks)106/204 (52%) -
GET /api/v1/agent-evolution/experiences/trajectoriesreturnstotal: 0for experiences that have been revised up to 18 times, andoutcomesreturns all-zero distributions, so experience effectiveness cannot be evaluated. (We have not yet confirmed whether that endpoint's emptiness shares this root cause — it filters onsearch_tagsrather than on backlinks, and our trajectories carry nosearch_tagsat all. Filed here only as observed context, not as a diagnosis.) -
Silent:
Errors: 0is reported, and nothing surfaces above the ERROR log line.
Suggested fixes (any of)
- In
TrainingEngine._plan_and_apply, extend the lease to the union of the policy root and the resolved link endpoints before applying — analogous to what_acquire_stable_operation_leasealready does forStreamingMemoryUpdater. - In
_apply_links_to_existing_files, do not forward the ambient transaction lease (lease_ref=None), letting each out-of-batch endpoint auto-acquire; the function is by definition writing outside the batch the lease was taken for. - Rust-side: when the ambient lease belongs to the same operation, extend coverage instead of hard-failing (repeat of suggestion 3 in #4031).
- At minimum, stop swallowing the exception in
write_stored_linksso dropped links are visible and retriable — #4031's suggestion 4 is still unimplemented as of 0.4.15.
OpenViking Version
v0.4.15 (pip wheel). session/compressor_v2.py is absent; only compressor_v3.py ships.
Python Version
3.12.12
Operating System
Windows 11 (x86_64), single local server, NSSM service, 1 account / ~940 memory files
Adding a supporting reference from your own design docs, since it describes the exact boundary this bug crosses.
design/traj-exp-experience-learning-redesign — Trajectory / Experience 经验学习框架重构, §1.1 states the storage and serialization boundaries separately:
存储边界:trajectory 写入发生在
RolloutAnalyzer;experience 读取/合并/写入发生在 optimizer/updater;session archive 和memory_diff.json只出现在session.commit路径。串行边界:
ExperienceSet.lock()内的reload -> PolicyOptimizer.plan -> PolicyUpdater.apply必须串行。
So by design there are two distinct write boundaries — trajectories are written by RolloutAnalyzer, experiences by the optimizer/updater — while the only lock taken around the second one is ExperienceSet.lock(). The same doc's §3.1 confirms that lock's scope is the Experience policy root:
当前实现中,
ExperienceSet还负责提供并发安全能力:async with policy_set.lock(): latest_policy_set = await policy_set.reload()
PolicySet.lock (session/train/domain.py:67-88) implements that as a tree lock over root_uri, i.e. the experiences root only:
"""Acquire a tree lock for the whole policy root directory."""
path = uri_to_path(self.root_uri, ctx=self.request_context)
lease = await self.viking_fs._async_agfs.pathlock_acquire_tree(path, timeout_secs=300.0)
That lease is then handed all the way down to _apply_links_to_existing_files, whose docstring says it writes endpoints outside the batch the lease was taken for — and for derived_from edges that endpoint is under memories/trajectories/, i.e. the other write boundary.
In other words, the trace evidence in the report above (lease write set = one experiences/*.md, attempted write = trajectories/*.md) is the design's two storage boundaries meeting under a single lease that only covers one of them. Worth noting because it suggests the fix belongs at the lease-construction site (TrainingEngine._plan_and_apply, engine.py:87-98) rather than at the write site.
Happy to capture more traces on 0.4.15 if that would help — this instance reproduces it several times a day.
Still reproducing on v0.4.17 (latest release) — fresh evidence from a production deployment
Follow-up in the chain #4031 → #4332 → this issue. We hit the identical failure on v0.4.17 (pip wheel, released 2026-08-28), so the defect appears to persist past this issue's closure — I couldn't find a fixing commit in the timeline; if I missed one, please point me at it and I'll retest.
Environment: single-node local server, local AGFS + local vectordb, auth_mode: api_key, agent_evolution: enabled, local Ollama bge-m3 embedding, Ubuntu 24.04 / Python 3.12. Workload: 8 agent profiles with frequent cron sessions committing nearly every hour.
Signature on v0.4.17 (line moved 153 → 155):
ERROR | openviking.session.memory.memory_updater:write_stored_links:155 - Failed to apply links to viking://user/<agent>/memories/trajectories/<name>.md: internal error: lock lease error: invalid lock request: pathlock lease ref '<uuid>' does not cover the requested operation
Frequency: 81 occurrences since deployment (2026-08-28 → 2026-08-31) on this single small deployment; 36 of them after upgrading 0.4.16 → 0.4.17 (2026-08-30), i.e. on current release code. Bursts correlate with heavy post-commit extraction, consistent with the two-write-boundary analysis above.
Impact: trajectory bodies are written correctly; only links/backlinks application is silently skipped — knowledge-graph edges for trajectory nodes never materialize. Content retrieval is unaffected.
Happy to attach a sanitized journal excerpt or any diagnostics needed.
Thank you for the detailed follow-up and the production evidence — this is very helpful.
We confirmed that v0.4.17 does not contain the fix. The v0.4.17 tag was created before the fix was merged, even though the release page was published later.
The fix was implemented and merged into main in #4438:
- PR: https://github.com/volcengine/OpenViking/pull/4438
- Merge commit: 9ea659abe941a6d909b9f121b110943cd4a6ff1e
The change acquires a combined lease covering both experiences/** and the related trajectory files before any experience or backlink writes begin.
We also checked v0.4.17.1, and it does not include #4438 either. Therefore, the failures you observed on v0.4.17 are consistent with the old behavior and do not indicate that the merged fix has regressed.
Sorry that the issue status and release availability were unclear. Please retest with a future release that contains #4438. If the same error still occurs on that version, we would very much appreciate the additional diagnostics.
Confirmed fixed in production. Upgraded 0.4.17 -> 0.4.19 two days ago (thanks for the pointer to the combined lease fix).
Numbers: on 0.4.17 the write_stored_links lock-lease error kept accumulating (~196/day; 197 in the final 48h before the upgrade). Since the upgrade: 0 occurrences, including real session commits with trajectory writes and experience extraction. As noted earlier, content was never lost even when the error fired — only the link/backlink application was skipped.
Thanks for the quick triage and fix!