fix(core): resolve FilePool race condition in ensureWatch#29
Merged
CrazyBoyM merged 1 commit intoshareAI-lab:mainfrom Jan 29, 2026
Merged
fix(core): resolve FilePool race condition in ensureWatch#29CrazyBoyM merged 1 commit intoshareAI-lab:mainfrom
CrazyBoyM merged 1 commit intoshareAI-lab:mainfrom
Conversation
- Remove redundant recordEdit/recordRead calls in agent.ts
(already called inside fs_read/fs_write/fs_edit/fs_multi_edit tools)
- Add per-path lock (watchPending Map) to prevent duplicate watchers
when concurrent calls race through the has() check
- Add unit tests for concurrent recordEdit scenarios
Fixes: duplicate watcher creation under concurrent fs operations
Contributor
|
Good Job |
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.
概述
FilePool.ensureWatch()中的竞态条件,该问题可能导致重复创建 file watcherrecordEdit()/recordRead()调用(工具内部已调用)问题描述
fs_write/fs_edit/fs_multi_edit/fs_read工具存在双重调用问题:recordEdit()/recordRead()这导致
ensureWatch()中出现竞态条件:T1: ensureWatch() -> has(path) = false -> await watchFiles()...
T2: ensureWatch() -> has(path) = false -> await watchFiles()... // 竞态!
T3: T1 设置 watchers[path] = id1
T4: T2 设置 watchers[path] = id2 // 覆盖,id1 成为孤儿
后果:
fs.watch()系统限制解决方案
agent.ts):工具内部已调用recordEdit()/recordRead(),Agent 层无需重复file-pool.ts):使用watchPendingMap 防止同一路径并发执行ensureWatch()测试验证
recordEdit()只创建 1 个 watcherrecordEdit()各自创建独立 watcher