OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: session_commit fails on memory link endpoints in the policy/train apply path — `pathlock lease ref ... does not cover the requested operation` (v0.5.4)

Open feel-think opened this issue 3 weeks ago • 2 comments

Issue Origin

Observed or reproduced in a real environment (self-hosted v0.5.4, single node, local FS backend, single user, ~39.6k memory markdown files, default queue workers).

Bug Description

session_commit fails terminally on a large share of batches that delete or rename an experience page which has stored links/backlinks to trajectory/case pages. The primary writes of the batch succeed, then the link-endpoint writes are rejected by RagFS pathlock, deletes are skipped, and the whole commit is marked failed — half-applied and never re-extracted.

Error signature (repeated for every trajectory/case endpoint in the batch):

Memory update failed (Written: 11, Edited: 0, Deleted: 0, Errors: 3):
viking://user/<user>/memories/experiences:
viking://user/<user>/memories/trajectories/<name>.md: internal error: lock lease error:
invalid lock request: pathlock lease ref '<uuid>' does not cover the requested operation;
viking://user/<user>/memories/experiences:
viking://user/<user>/memories/cases/<name>.md: internal error: lock lease error:
invalid lock request: pathlock lease ref '<uuid>' does not cover the requested operation;
viking://user/<user>/memories/experiences:
viking://user/<user>/memories/experiences/<name>.md: Skipped delete because link migration did not complete

Every failing URI is a link endpoint (trajectory or case of the deleted/merged experience), never the primary write target. Written: N shows the batch's own writes already landed.

Which code path (this matters — it is not the streaming path of #7407)

All failures on our node enter through the policy/train apply path, not the streaming apply path:

compressor_v3.py:1199  train_from_extracted_cases  -> raise MemoryUpdateError(training_failures)
  -> _train_commit_analysis(trainer=exp_trainer)      # streaming policy trainer
  -> PatchMergePolicyOptimizer
  -> MemoryFilePolicyUpdater.apply()
  -> MemoryUpdater.apply_operations()
  -> MemoryUpdater._inherit_deleted_link_relations()  # memory_updater.py:2053, where the endpoint writes fail

Evidence: in both days' failure windows the stack contains compressor_v3, session.py, model_retry.py, memory_updater; a grep for streaming_memory_updater in the same windows returns 0 hits. Every failure logs Commit streaming train failed from compressor_v3.

Mechanism in v0.5.4 (installed package, all paths verified):

  1. openviking/session/train/components/policy_optimizer.py::_operations_to_plan_items() builds delete plan items as PolicyPlanItem(kind="delete", ..., before_content=old_file.plain_content(), links=_source_trajectory_links_for_plan_item(...)) — and no before_file (the field does not exist on PolicyPlanItem in v0.5.4, see session/train/domain.py:206-225).
  2. When the deleted source page is a historical page loaded by prefetch and absent from the current PolicySet, policy_updater._policy_or_plan_item_memory_file() can only rebuild it from before_content + the plan item links, so the page's stored links/backlinks are lost.
  3. policy_updater.apply() builds the lock set from operations.resolved_links, delete_replacements, and — crucially — for source in operations.delete_file_contents: source.links + source.backlinks (lines ~99-113), then calls pathlock_acquire_exact_tree_batch(exact_paths, [policy_set.root_uri]) (~L117-135).
  4. Missing links ⇒ missing neighbor paths in exact_paths ⇒ the combined lease does not cover the subsequent inheritance writes to trajectories/ and cases/ ⇒ invalid lock request ... does not cover the requested operation ⇒ _inherit_deleted_link_relations marks the batch incomplete ⇒ all deletes whose migration was scheduled are skipped ⇒ MemoryUpdateError ⇒ Phase 2 long_term fails ⇒ archive .failed.json, task terminal failed.

This is exactly the trigger and fix described by PR #7384 (fix(session): preserve delete source links for memory locking, open, unmerged): add before_file=old_file to delete plan items and reuse that snapshot in _policy_or_plan_item_memory_file() so neighbor endpoints enter the lock set. We cannot test the patch here, but the field evidence matches its description one-to-one (historical delete source not in PolicySet, lost links, missing trajectory/case neighbor locks, identical error string).

Relation to #7407: same error string, different code path. #7407 reports the streaming apply path (_exclude_tree_covered_paths drops exact locks for endpoints covered by a tree lock, then write_stored_links issues Exact requests). We see no streaming frames at all; our failures are the policy-path link loss described above. A fix for #7407 alone should not fix this report, and #7384 alone would not fix #7407's path — both paths appear to exist in 0.5.4.

v0.5.4.1 does not fix it: I fetched openviking/session/memory/memory_updater.py, streaming_memory_updater.py, openviking/session/train/components/policy_optimizer.py, policy_updater.py and session/train/domain.py from tag v0.5.4.1 and diffed against the installed v0.5.4 — all byte-identical; the v0.5.4.1 release notes contain no memory-link/pathlock change. PyPI still only serves 0.5.4 at the time of writing.

Steps to Reproduce

Not minimized to a standalone script (extraction output is LLM-generated), same as #7407. Reproduced on every day of operation with this shape:

  1. Run a deployment with memory.link_enabled: true and a corpus where experiences link to trajectories/cases (ours: 11,413 trajectories / 3,058 cases / 9,656 experiences).
  2. Let a session_commit extraction batch contain (a) a delete/replacement of an existing experience page that is not part of the current PolicySet (loaded by prefetch), and (b) link inheritance to that page's trajectory/case neighbors.
  3. Observe the commit fail with the signature above: primary writes land, endpoint writes rejected, delete skipped, task terminal failed.

Our failing batches are ordinary single-session commits; nothing is needed beyond the normal per-archive extraction.

Expected Behavior

Either of:

  • The delete plan / lock set should retain the source page's stored links/backlinks even when the page is not in the current PolicySet, so neighbor endpoints are covered by the lease (as #7384 proposes); or
  • If the batch cannot be applied completely, fail before partial writes, or surface the condition structurally so the commit is not half-applied and silently terminal.

Actual Behavior

  • Batch partially applied (Written: 2..25), endpoint link writes rejected, all affected deletes skipped.
  • Commit goes terminal failed; the archive is written to .failed.json and is not automatically re-extracted.
  • There is a supported manual retry (POST /api/v1/sessions/{sid}/archives/{aid}/retry with expected_messages_sha256, #5802), which re-rolls Phase-2 extraction, but it is a workaround: when the re-run extraction produces the same delete+links shape it fails again.

Minimal Reproducible Example

Not available — extraction is LLM-driven and the batch shape depends on model output. We can provide the archive messages.jsonl of a failing archive plus the .failed.json of a second, similar archive if useful.

Error Logs

Real excerpt (2026-11-11 11:00, one archive; identifiers redacted):

ERROR openviking.session.memory.memory_updater:_inherit_deleted_link_relations:2053 -
  Failed to inherit deleted memory links for viking://user/<user>/memories/trajectories/<a>.md:
  internal error: lock lease error: invalid lock request:
  pathlock lease ref '3f1b599f-...' does not cover the requested operation
ERROR openviking.session.memory.memory_updater:_inherit_deleted_link_relations:2053 -
  Failed to inherit deleted memory links for viking://user/<user>/memories/cases/<b>.md:
  internal error: lock lease error: invalid lock request:
  pathlock lease ref '3f1b599f-...' does not cover the requested operation
ERROR openviking.session.memory.memory_updater:apply_operations:1255 -
  Skipping delete for viking://user/<user>/memories/experiences/<c>.md:
  Skipped delete because link migration did not complete
WARNING openviking.session.compressor_v3 -
  Commit streaming train failed: Memory update failed (Written: 11, Edited: 0, Deleted: 0, Errors: 3): ...
ERROR openviking.session.session - Phase 2 step long_term failed: ...
  File ".../openviking/session/compressor_v3.py", line 1199, in train_from_extracted_cases
    raise MemoryUpdateError(training_failures)

Two-day statistics on this node (journal + per-archive .failed.json):

Day does not cover lines Failed to inherit Skipped delete (link migration) extraction failures distinct lease refs distinct endpoint URIs (trajectories / cases)
2026-11-10 80 62 23 3 3 23 / 21
2026-11-11 78 48 38 5 5 25 / 23

14 unique archives failed in 2 days, across 6 sessions (both dsh-session-* and dsh-worker-*), every failure with the same signature: deleted source = experience page, rejected endpoints = trajectory/case, Deleted: 0 in all of them.

Day Session (prefix) Archive Written / Errors Rejected endpoint types Outcome
11-10 277d91c3 039 25 / 6 traj 3, case 1 recovered via retry
11-10 277d91c3 041 19 / 3 traj 1, case 1 recovered via retry
11-10 277d91c3 043 19 / 4 traj 1, case 1 recovered via retry
11-10 277d91c3 049 5 / 5 traj 2, case 2 retry failed again → still failing
11-10 f044f01b 004 14 / 5 traj 2, case 2 recovered via retry
11-10 fa6d6e69 005 8 / 10 traj 5, case 4 recovered via retry
11-10 worker-84183b 006 3 / 3 traj 1, case 1 recovered via retry
11-10 worker-84183b 008 4 / 19 traj 9, case 8 recovered via retry
11-10 worker-84183b 009 5 / 22 traj 10, case 9 recovered via retry
11-10 worker-c58d51 005 4 / 26 traj 13, case 11 recovered via retry
11-11 worker-84183b 011 4 / 26 traj 13, case 11 recovered via retry
11-11 worker-d132c2 001 3 / 9 traj 3, case 3 recovered via retry
11-11 orchestrator-dd410bee 115 11 / 3 traj 1, case 1 retry failed again → still failing
11-11 worker-223d59 005 2 / 15 traj 7, case 7 not retried (session busy) → still failing

Retry behavior (adds weight to the "deterministic batch shape" reading):

  • The hash-bound retry endpoint re-rolled extraction and recovered 11 of 14 archives.
  • The two retried archives that failed again (049, 115) re-emitted a delete+links batch; after the retry the task is failed again with the same error string.
  • Note: the existing /retry endpoint is not mentioned in #7407's ask #3 ("no supported replay path") and is not auto-invoked by anything upstream (#6266 was closed unmerged); we built an operator-side monitor that retries each failed archive exactly once.

OpenViking Version

0.5.4 (PyPI; also verified v0.5.4.1 tag has byte-identical files for the whole call chain above)

Python Version

3.14.6

Operating System

Linux (Ubuntu 22.04.5 LTS, x86_64, single node, local FS backend; installed via uv tool install, no Docker)

Model Backend

Other — OpenAI-compatible gateway: extraction deepseek/deepseek-v4.1-flash-1017, embeddings qwen/qwen3-embedding-8b.

Additional Context

Relevant configuration (all defaults except the ones listed):

  • memory.link_enabled: true
  • memory.session_auto_commit.enabled: true
  • server.agent_evolution.enabled: true
  • no queue_workers overrides (single node, default worker pool)
  • corpus at report time: 39,588 memory .md files (11,413 trajectories, 3,058 cases, 9,656 experiences)

Related reports: #7407 (same error string, streaming apply path — different code path), #7384 (open PR fixing the policy-path link loss described here), #5802 (hash-bound archive retry, shipped in 0.5.4), #4332 / #5087 (older reports of the same error string under memories/trajectories/, closed as not planned).

Asks:

  1. Merge/backport the #7384-class fix (retain delete-source links/backlinks through plan items) for the policy/train path; it directly matches the failures above.
  2. Consider guarding the partial-apply: when a delete source's persisted links cannot be resolved while building the lock set, collect them from the file under the tree lock (or fail before applying), instead of applying the batch half-way and marking it terminal.
  3. Surface this condition structurally in MemoryUpdateResult.errors (today it is a long concatenated string), and mention the hash-bound retry endpoint in the docs/issue #7407 as the current operator workaround.

feel-think avatar Nov 11 '26 03:11 feel-think

Fixed in https://github.com/volcengine/OpenViking/pull/7384

yeshion23333 avatar Nov 11 '26 06:11 yeshion23333

Confirming this is still present on the released openviking==0.5.4.1 (tag v0.5.4.1, commit 86edb40a0) — #7384 landed on main after the 0.5.4.1 release cut.

Environment: Windows 11, self-hosted 0.5.4.1, local FS backend, local vectordb, single user, dev auth mode, ~5.4k memory markdown files, 1.4k experience pages (1.2k of them carry memories/trajectories/ links).

Observed 2026-11-11T07:47Z, same signature and same code path as reported here (compressor_v3.train_from_extracted_cases → _train_commit_analysis → MemoryFilePolicyUpdater.apply → MemoryUpdater.apply_operations):

Memory update failed (Written: 1, Edited: 0, Deleted: 0, Errors: 4):
viking://user/default/memories/experiences:
viking://user/default/memories/trajectories/<historical>.md: internal error: lock lease error:
invalid lock request: pathlock lease ref '<uuid>' does not cover the requested operation

One difference from the original report: this batch shows Deleted: 0, Edited: 0 — no delete and no rename. It was an upsert of an existing experience page whose stored links[] still point at older trajectory pages. The combined lease was acquired over three requests only:

requests=[Exact memories/cases/<case>.md,
          Exact memories/trajectories/<this-batch>.md,
          Tree memories/experiences]

while the apply then wrote the backlink into memories/trajectories/<historical>.md, which is not in that covered set.

So the question: does #7384 also cover this upsert path? An existing experience page keeps links=list(existing.links or []) (openviking/session/train/components/policy_updater.py:231), but related_uris (policy_updater.py:102-121) is derived from operations.resolved_links and delete_file_contents only — not from the stored links being carried over. If #7384 only restores links for the delete path, the same endpoint-coverage gap remains for updates that inherit stored links.

With #7384 applied locally to 0.5.4.1 (the three touched files are byte-identical to bfb15baec^), the same two-round commit smoke has not re-entered that path yet, but I have no stable minimal repro to confirm the fix either way.

Mainly asking whether a follow-up issue is needed, or a patch release containing #7384 is expected to close this out.

lkaiiu avatar Nov 11 '26 08:11 lkaiiu