Repository navigation
fix(watch): 避免资源移动期间持有全局锁 - #3833
Merged
Merged
Conversation
added 6 commits
August 10, 2026 15:56
Allow unrelated watch operations to continue while viking_fs.mv is running, while serializing overlapping resource paths with a move fence. Preserve transaction integrity across persistence failures, rollback, and caller cancellation.
KCHENPENGFEI
force-pushed
the
codex/fix-watch-move-global-lock
branch
from
August 10, 2026 08:04
1553be9 to
af7de88
Compare
qin-ctx
approved these changes
Aug 10, 2026
skloxo
pushed a commit
to skloxo/OpenVikingStudio
that referenced
this pull request
Aug 22, 2026
* fix(watch): avoid global lock during resource moves Allow unrelated watch operations to continue while viking_fs.mv is running, while serializing overlapping resource paths with a move fence. Preserve transaction integrity across persistence failures, rollback, and caller cancellation. * feat(resource): add URI mutation coordinator * refactor(watch): separate target rewrites from resource moves * refactor(fs): own resource move watch transaction * feat(watch): coordinate refreshes with URI mutations * refactor(core): share URI mutation coordinator * test(watch): focus URI move coverage * test(watch): reuse existing URI move coverage --------- Co-authored-by: chenpengfei <chenpengfei@bytedance.com> Co-authored-by: qin-ctx <qinhaojie.exe@bytedance.com> (cherry picked from commit 8acaf7f)
frankyang2008-eng
added a commit
to frankyang2008-eng/OpenViking
that referenced
this pull request
Oct 9, 2026
Sync upstream main (e546b79) - 19 commits, 315 files: - refactor(client): remove Python embedded mode (volcengine#3712) - perf(queue): stream semantic vectorization tasks (volcengine#3636) - perf(queuefs): defer embedding content materialization (volcengine#3871) - feat(memory): support event tag filtering (volcengine#3850) - feat(pathlock): keep lease alive across handoff (volcengine#3903) - feat(server): refresh read-replica API key index via store watcher (volcengine#3857) - feat(agent-evolution): add trajectory date filters (volcengine#3915) - feat(agent-evolution): add trajectory task query (volcengine#3856) - feat(web-studio): add account deletion workflow (volcengine#3912) - feat(web-studio): add scheduled resource sync management (volcengine#3909) - fix(watch): avoid global lock during resource moves (volcengine#3833) - fix(observer): ignore historical lock diagnostics in health (volcengine#3920) - fix(session): validate archive names when loading history (volcengine#3922) - fix(task-tracker): delete expired persisted tasks (volcengine#3913) - fix(storage): exclude zero-byte files from index expectations (volcengine#3904) - fix(semantic): reduce entity hallucinations in summaries (volcengine#3908) - fix(retrieval): record first-turn session recalls (volcengine#3907) - fix(opencode-plugin): serialize saveState to prevent ENOENT race (volcengine#3885) - fix(examples): align quick start with server mode (volcengine#3923) Reviewed: zero conflicts, all local dev-branch modifications preserved, no references to deleted embedded client modules, config backward-compatible.
frankyang2008-eng
pushed a commit
to frankyang2008-eng/OpenViking
that referenced
this pull request
Oct 9, 2026
* fix(watch): avoid global lock during resource moves Allow unrelated watch operations to continue while viking_fs.mv is running, while serializing overlapping resource paths with a move fence. Preserve transaction integrity across persistence failures, rollback, and caller cancellation. * feat(resource): add URI mutation coordinator * refactor(watch): separate target rewrites from resource moves * refactor(fs): own resource move watch transaction * feat(watch): coordinate refreshes with URI mutations * refactor(core): share URI mutation coordinator * test(watch): focus URI move coverage * test(watch): reuse existing URI move coverage --------- Co-authored-by: chenpengfei <chenpengfei@bytedance.com> Co-authored-by: qin-ctx <qinhaojie.exe@bytedance.com>
skloxo
pushed a commit
to skloxo/OpenVikingStudio
that referenced
this pull request
Nov 9, 2026
* fix(watch): avoid global lock during resource moves Allow unrelated watch operations to continue while viking_fs.mv is running, while serializing overlapping resource paths with a move fence. Preserve transaction integrity across persistence failures, rollback, and caller cancellation. * feat(resource): add URI mutation coordinator * refactor(watch): separate target rewrites from resource moves * refactor(fs): own resource move watch transaction * feat(watch): coordinate refreshes with URI mutations * refactor(core): share URI mutation coordinator * test(watch): focus URI move coverage * test(watch): reuse existing URI move coverage --------- Co-authored-by: chenpengfei <chenpengfei@bytedance.com> Co-authored-by: qin-ctx <qinhaojie.exe@bytedance.com> (cherry picked from commit 8acaf7f)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
WatchManager.sync_tasks_with_resource_move_internal()原先在整个viking_fs.mv调用期间持有 WatchManager 全局锁。资源移动耗时较长时,与 source/target 完全无关的 watch 查询、创建和调度也会被串行阻塞。同时,直接把
mv、回滚等业务语义继续下沉到 WatchManager,会让通用 watch 管理组件与文件系统操作耦合。方案
新增进程内
UriMutationCoordinator,只负责按account_id + URI 范围协调并发,不感知mv、watch 或 add-resource 等业务语义:access:操作期间要求 URI 保持稳定;多个 access 可以并发。mutation:正在修改 URI;与相交路径的 access/mutation 互斥。wiki与wiki/page相交,和wiki-old不相交。改动内容
FSService 负责资源移动事务
FSService.mv()在 source + target 的 mutation lease 内执行:viking_fs.mv(source, target)。.watch_tasks.json。viking_fs.mv(target, source)回滚。正向移动失败时不会改写 watch;回滚再次失败时抛出 rollback error,并将原 watch commit error 保留为 cause。
事务运行在独立 task 中并使用
asyncio.shield。调用方取消时,会先等待事务完成提交或回滚、释放 mutation lease,再向调用方返回CancelledError,避免留下“资源已移动但 watch 未更新”的中间状态。WatchManager 只保留 watch 语义
删除 WatchManager 中的资源移动 callback、回滚 callback 和 move 状态,改为两个通用的 watch 原语:
validate_target_prefix_rewrite_internal():只校验改写冲突。rewrite_target_prefix_internal():原子更新 task、URI 索引和持久化文件;保存失败时恢复内存状态。watch CRUD/query 在访问具体 target URI 时使用 access lease。通过 task ID 操作时采用“读取 URI 快照 -> 获取 lease -> 重新校验”的方式,避免按旧 URI 获取 lease 后继续处理已迁移的 task。
WatchScheduler 在稳定 URI 上执行刷新
due task 在等待 semaphore 期间可能被移动,因此执行前会:
这样,同路径
mv与 watch refresh 继续串行,无关路径仍可并发。Core 共享同一协调器
Core 创建唯一的
UriMutationCoordinator,注入 FSService、WatchScheduler 和 WatchManager,确保 mutation/access 位于同一个协调域。行为边界
.watch_tasks.json的单文件格式和串行保存逻辑。get_due_tasks()不持有所有 URI 的 lease,执行前由 scheduler 重新校验。get_all_tasks()保持轻量查询;资源移动事务期间可能短暂返回旧 target URI,事务结束后恢复一致。测试
相关测试共 96 个通过,覆盖:
格式、Ruff 和 Python compileall 检查通过。
完整
pytest tests在收集阶段被仓库现有可选测试依赖阻断:当前环境缺少pytest-html、psutil和google.genai;相关测试集没有失败。