Skip to content

fix(index): drop same-device paths outside monitored roots before enqueue - #292

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
Johnson-zs:develop/snipe
Oct 26, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
Johnson-zs:develop/snipe

Conversation

@Johnson-zs

@Johnson-zs Johnson-zs commented Oct 26, 2026 •

Copy link
Copy Markdown

The event dispatcher broadcasts every write on a device, so the userspace
watcher received events for paths that share a device with a monitored root
but sit outside it. On a split-disk install "/", "/ostree" and similar
siblings live on the same device, which meant every ostree checkout burst
was enqueued even though /ostree is blacklisted.

The per-runtime blacklist could not help: FSEventCollector applies it in
shouldTrackPath() after dequeue, so a burst can overflow the queue and drop
genuine root events first. Those drops raise eventsLost, which schedules a
compensating full-index UPDATE and can interrupt an in-flight task.

resolveAndFilterFullPath() already resolves the absolute path, so enforce
root membership there with isDescendantOfRoot() before the event reaches
the queue. rootPaths comes from the configured indexing_paths, so paths a
user adds to the whitelist (for example under /media) keep working.

Guarded on a non-empty rootPaths so the filter degrades to the previous
behaviour instead of dropping every event.

Summary by Sourcery

Bug Fixes:

  • Filter same-device filesystem events to monitored roots before enqueueing them, preventing out-of-root activity from filling the event queue and causing genuine events to be lost.

…ueue

The event dispatcher broadcasts every write on a device, so the userspace
watcher received events for paths that share a device with a monitored root
but sit outside it. On a split-disk install "/", "/ostree" and similar
siblings live on the same device, which meant every ostree checkout burst
was enqueued even though /ostree is blacklisted.

The per-runtime blacklist could not help: FSEventCollector applies it in
shouldTrackPath() after dequeue, so a burst can overflow the queue and drop
genuine root events first. Those drops raise eventsLost, which schedules a
compensating full-index UPDATE and can interrupt an in-flight task.

resolveAndFilterFullPath() already resolves the absolute path, so enforce
root membership there with isDescendantOfRoot() before the event reaches
the queue. rootPaths comes from the configured indexing_paths, so paths a
user adds to the whitelist (for example under /media) keep working.

Guarded on a non-empty rootPaths so the filter degrades to the previous
behaviour instead of dropping every event.
@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds an early monitored-root boundary check to resolved filesystem events, preventing same-device paths outside configured roots from being enqueued while preserving whitelist behavior and empty-root compatibility.

Sequence diagram for pre-enqueue monitored-root filtering

sequenceDiagram
    participant Dispatcher
    participant Watcher as VfsMonitorFileSystemWatcher
    participant Queue
    participant Indexer

    Dispatcher->>Watcher: resolveAndFilterFullPath(dev, path)
    Watcher->>Watcher: excludePredicate(fullPath)
    alt rootPaths is non-empty
        Watcher->>Watcher: isDescendantOfRoot(fullPath, monitoredRoot)
        alt path is outside monitored roots
            Watcher-->>Dispatcher: discard path
        else path matches a monitored root
            Watcher->>Queue: enqueue fullPath
            Queue->>Indexer: process event
        end
    else rootPaths is empty
        Watcher->>Queue: enqueue fullPath
        Queue->>Indexer: process event
    end
Loading

File-Level Changes

Change Details Files
Filter resolved filesystem events by monitored-root membership before they enter the queue.
  • Check each resolved path against configured rootPaths using exact-match or descendant-path semantics.
  • Skip same-device events outside all monitored roots to prevent irrelevant bursts from consuming queue capacity.
  • Preserve prior behavior when rootPaths is empty and retain existing exclusion filtering.
src/index/fsmonitor/vfsmonitorwatcher.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/index/fsmonitor/vfsmonitorwatcher.cpp" line_range="574-582" />
<code_context>
+        // which in turn triggers a compensating full-index UPDATE. Same-device
+        // aliases cannot be told apart later, so the membership test has to
+        // happen before enqueue.
+        if (!rootPaths.isEmpty()) {
+            const bool inMonitoredRoot = std::any_of(rootPaths.cbegin(), rootPaths.cend(),
+                                                     [&fullPath](const QString &monitoredRoot) {
+                                                         return fullPath == monitoredRoot
+                                                                 || isDescendantOfRoot(fullPath, monitoredRoot);
+                                                     });
+            if (!inMonitoredRoot)
+                continue;
+        }
+
         return fullPath;
</code_context>
<issue_to_address>
**Outside renames overflow the queue**

When a burst of RENAME_TO events resolves outside every configured root, `drainSocket()` enqueues events with an empty destination, and `flushPendingBatch()` counts them against the queue limit. The queue overflows, dropping genuine root events and triggering a compensating full-index update.

Skip enqueuing a RENAME_TO event when its resolved destination is empty.
</issue_to_address>

### Comment 2
<location path="src/index/fsmonitor/vfsmonitorwatcher.cpp" line_range="575" />
<code_context>
+        // aliases cannot be told apart later, so the membership test has to
+        // happen before enqueue.
+        if (!rootPaths.isEmpty()) {
+            const bool inMonitoredRoot = std::any_of(rootPaths.cbegin(), rootPaths.cend(),
+                                                     [&fullPath](const QString &monitoredRoot) {
+                                                         return fullPath == monitoredRoot
</code_context>
<issue_to_address>
**New variables violate naming rule**

`inMonitoredRoot` and `monitoredRoot` use camelCase, so these new local variables violate the required snake_case naming convention.

Rename the variables to `in_monitored_root` and `monitored_root`.

Also at `src/index/fsmonitor/vfsmonitorwatcher.cpp:576`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +574 to +582
if (!rootPaths.isEmpty()) {
const bool inMonitoredRoot = std::any_of(rootPaths.cbegin(), rootPaths.cend(),
[&fullPath](const QString &monitoredRoot) {
return fullPath == monitoredRoot
|| isDescendantOfRoot(fullPath, monitoredRoot);
});
if (!inMonitoredRoot)
continue;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Outside renames overflow the queue

When a burst of RENAME_TO events resolves outside every configured root, drainSocket() enqueues events with an empty destination, and flushPendingBatch() counts them against the queue limit. The queue overflows, dropping genuine root events and triggering a compensating full-index update.

Skip enqueuing a RENAME_TO event when its resolved destination is empty.

Prompt for AI agents
In `src/index/fsmonitor/vfsmonitorwatcher.cpp` at lines 574-582:

**Outside renames overflow the queue**

When a burst of RENAME_TO events resolves outside every configured root, `drainSocket()` enqueues events with an empty destination, and `flushPendingBatch()` counts them against the queue limit. The queue overflows, dropping genuine root events and triggering a compensating full-index update.

Skip enqueuing a RENAME_TO event when its resolved destination is empty.

// aliases cannot be told apart later, so the membership test has to
// happen before enqueue.
if (!rootPaths.isEmpty()) {
const bool inMonitoredRoot = std::any_of(rootPaths.cbegin(), rootPaths.cend(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Low · New variables violate naming rule

inMonitoredRoot and monitoredRoot use camelCase, so these new local variables violate the required snake_case naming convention.

Rename the variables to in_monitored_root and monitored_root.

Also at src/index/fsmonitor/vfsmonitorwatcher.cpp:576.

Prompt for AI agents
In `src/index/fsmonitor/vfsmonitorwatcher.cpp` at line 575:

**New variables violate naming rule**

`inMonitoredRoot` and `monitoredRoot` use camelCase, so these new local variables violate the required snake_case naming convention.

Rename the variables to `in_monitored_root` and `monitored_root`.

Also at `src/index/fsmonitor/vfsmonitorwatcher.cpp:576`.

From AGENTS.md L59:

- Variables: `snake_case` (e.g., `config_ptr`, `event_handler`)

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交在入队前对同设备但处于受监控根目录之外的路径进行成员关系过滤,修复了 ostree 检出等突发场景导致队列溢出、丢失真实根事件并触发补偿性全量索引更新的问题。语法逻辑正确、注释详尽、性能改善(提前过滤减少入队与后续处理负担)、无安全漏洞。OCR 因代码克隆失败未产出结果,以 AI 四维度分析为准。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['逻辑无明显缺陷,建议确认 isDescendantOfRoot 对路径规范化(如尾部斜杠、符号链接)的处理与 fullPath 解析口径一致,避免同设备别名误判。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['可考虑将 rootPaths 为空时的语义(当前直接放行)在注释中补充说明,明确空列表表示不做根成员限制而非全部丢弃。']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['若 rootPaths 规模未来显著增长,可考虑使用有序集合或前缀树加速成员判定;当前规模下无需优化。']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 当前实现已满足修复目标,无需额外修改。建议保持如下结构:
// 1. excludePredicate 过滤(已有)
// 2. 同设备根成员关系过滤(本次新增)
// 3. return fullPath;
//
// 可选:在 rootPaths 为空时显式注释放行语义,避免后续维护误判。

本报告由 AI 代码审查工具自动生成

@Johnson-zs

Copy link
Copy Markdown
Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit e5e8b63 into linuxdeepin:develop/snipe Oct 26, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants