content/write holds subtree lifecycle lock through semantic refresh, serializing writes in a shared tree
Summary
POST /api/v1/content/write appears to hold a subtree lifecycle lock for the full duration of semantic refresh work (including LLM/VLM-derived summary generation and directory-level artifact refresh), not just the atomic source-content write.
This makes source writes effectively serialize on downstream semantic latency and causes ingestion throughput to scale with provider/LLM latency rather than filesystem write cost.
For workloads that import or ingest many files into the same tree, this becomes a structural bottleneck rather than ordinary lock contention.
Why this seems too conservative
From the current behavior and code paths:
- a write acquires a subtree lock on the relevant root/category directory
- the original file is written
- semantic refresh is enqueued
.abstract.md/.overview.mdare regenerated for affected directories- directory-level semantic artifacts are re-embedded
- the lifecycle lock is only released after semantic processing completes
That means unrelated source writes into the same tree are blocked by derived artifact maintenance, even when the source file write itself is already durable.
In practice this shows up as:
400 resource is busy and cannot be written now- ingestion throughput dominated by LLM/VLM latency
- effectively sequential writes for a shared tree
- operators needing retry loops around otherwise independent file writes
Evidence in the repo / prior related work
This issue seems related to, but broader than, the following existing work:
- #1461 ("feat(content): add POST /api/v1/content/write-batch for bulk memory writes")
- This PR explicitly describes the current flow as:
- acquiring the subtree lock
- writing/vectorizing the leaf
- triggering per-file summary generation
- recomputing directory
.abstract.md/.overview.md - re-embedding directory-level files
- holding the lock until the semantic worker finishes
- It also notes that this causes redundant directory maintenance and
[400] resource is busyduring bulk import.
- This PR explicitly describes the current flow as:
- #1940 / #1956
- Added
isLockedvisibility instat(), which improves observability of contention.
- Added
- #1274 / #1275
- Added configurable retry/timeout behavior for one lock-acquisition path, which helps operationally but does not address the lock scope itself.
- #1165 / #1171
- Fixed stale lock refresh/ownership handling, which fixes correctness bugs around long-lived locks but not the broader coupling.
So there is already evidence in the repo that lock contention around semantic processing is a real operational concern.
Why write-batch helps but does not fully solve it
write-batch is a good optimization for the case where:
- the caller already has a known batch of files
- all files belong to the same root/category tree
- one combined semantic refresh can replace N redundant refreshes
That definitely reduces wasted work.
But the deeper issue seems architectural:
source-content durability and derived semantic maintenance share the same subtree lifecycle lock boundary.
As a result, even outside bulk imports, a single slow semantic refresh can block subsequent independent writes to the same tree.
Proposed direction
Would it make sense to split this into two consistency domains?
1. Strongly consistent source write path
For the source document/file itself:
- acquire a narrow lock (per file or minimally scoped path)
- write the source content
- record a version / content hash / generation ID
- enqueue semantic refresh work
- release the source write lock immediately
2. Eventually consistent derived semantic path
For derived artifacts such as .abstract.md / .overview.md:
- process asynchronously
- coalesce/debounce parent-directory refreshes
- regenerate from the latest visible child versions
- use artifact-specific locking for the derived files being rewritten
- discard stale semantic jobs when a newer source version supersedes them
Expected benefits
- source write throughput no longer scales linearly with LLM/VLM latency
- fewer
resource is busywrite failures under ingestion load - simpler client behavior (less need for retry loops)
write-batchbecomes an optimization, not a workaround for lock scope- semantic/navigation artifacts remain correct, but with eventual consistency instead of blocking source writes
Questions
- Is the current broad subtree lock an intentional consistency guarantee, or mostly a conservative first implementation?
- Is there already an internal design discussion about decoupling source writes from semantic refresh / directory artifact regeneration?
- Would maintainers be open to an RFC or PR that narrows the critical section and versions semantic refresh work?
Context from external usage
I hit this while benchmarking OpenViking as a memory backend for agent-style multi-session retrieval. In that setting, ingestion involves many documents under a shared tree, and the semantic layer is valuable, so disabling it is not an attractive workaround.
The problem was not the raw write itself; it was that writes became serialized behind semantic refresh latency.
If helpful, I can follow up with a minimal reproduction and measured timings from this benchmark setup.
I'll fix it later.
I'll fix it later.
fixed?
yes
Issue Origin
Observed or reproduced in a real environment
Bug Description
Regression report on 0.5.1 for the behavior described in this issue: after many batch_write calls into the same resource tree, semantic refresh messages for the directory are continuously re-enqueued and further writes fail with resource is busy.
Observed while publishing ~280 Markdown pages to viking://resources/EMS-wiki with batch_write(root_uri=..., operations=[...], wait=False, skip_conflicts=True), in chunks of ~20 operations:
- Server log showed a sustained loop for the same directory:
59,363Processing semantic generation for: viking://resources/EMS-wiki (recursive=False) Re-enqueued semantic message: viking://resources/EMS-wikiRe-enqueuedlines were counted at 17:41 local (log has since rotated). - Client then received:
and had to retry each chunk with 8–80 s backoff. There was exactly one writer process (no concurrent user writes), so this is not a multi-writer race on our side.openviking_cli.exceptions.ConflictError: resource is busy and cannot be written now: viking://resources/EMS-wiki - Final state was consistent after retries (287 pages, 0 broken links), but publishing 280 pages took far longer than the write cost and required a custom retry loop.
Steps to Reproduce
- Create a target directory under
viking://resources/. - Publish 200+ Markdown files with repeated
batch_write(wait=False, skip_conflicts=True)calls (chunks of ~20) to the same directory. - Watch server log for repeated
Processing/Re-enqueued semantic messagelines for the directory. - Observe
ConflictError: resource is busy and cannot be written nowon later chunks.
Expected Behavior
Semantic refresh work for the same directory should be coalesced or deduplicated, and the lifecycle lock should not be held across the full semantic generation so that unrelated writes can proceed (as originally requested in this issue). batch_write(wait=False) should return a stable handle for the enqueued semantic work without blocking subsequent writes for minutes.
Actual Behavior
On 0.5.1 the directory-level semantic refresh enters a re-enqueue loop and holds the resource busy, causing write conflicts even with a single writer.
Minimal Reproducible Example
for chunk in chunks_of_20(pages):
client.batch_write(
root_uri="viking://resources/EMS-wiki",
operations=[{"uri": uri, "content": content, "mode": "replace"} for uri, content in chunk],
wait=False,
skip_conflicts=True,
)
# after ~200 files: ConflictError: resource is busy and cannot be written now
Error Logs
2026-10-20 17:xx:xx - openviking.storage.queuefs.semantic_processor - INFO - Processing semantic generation for: viking://resources/EMS-wiki (recursive=False)
2026-10-20 17:xx:xx - openviking.storage.queuefs.semantic_processor - INFO - Re-enqueued semantic message: viking://resources/EMS-wiki
...
ConflictError: resource is busy and cannot be written now: viking://resources/EMS-wiki
OpenViking Version
0.5.1
Python Version
3.12 (uv tool environment)
Operating System
Windows
Model Backend
Other
Additional Context
- Related original report: this issue (#2015). The closed fix does not appear to cover the 0.5.1 behavior above, or the trigger is different (many small writes with
wait=False+skip_conflicts=True). - Workaround used: chunk size 20, retries with exponential backoff, and an index rebuild at the end. Pages and abstracts were eventually consistent.
- If this is expected behavior, documentation should state that bulk
batch_writeinto one tree must be serialized with backoff and thatwait=Falsestill locks the parent directory during refresh.