Skip to content

fix: bypass idle check for silent start create task - #305

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
Johnson-zs:agent/bugfix/384711
Dec 1, 2026
Merged

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

Conversation

@Johnson-zs

@Johnson-zs Johnson-zs commented Nov 30, 2026 •

Copy link
Copy Markdown

Root Cause Analysis

After system upgrade, clicking "Update Index Now" shows "WaitingIdle" instead of creating the index. The root cause is in handleSilentStart() (textindexdbus.cpp:123), which calls startTask(Create, paths) with default forceBypass=false. The Create task is auto-graded as Heavy, and canRun(Heavy, false, env) returns false when the system is not idle, causing the task to be enqueued and currentIndexStatus() to return "WaitingIdle" instead of executing immediately.

Fix

Explicitly pass forceBypass=true to startTask() in handleSilentStart(), matching the existing pattern in ForceUpdateIndex() (line 331) which already uses forceBypass=true for user-initiated index operations. The change is a single-line parameter addition: startTask(Create, pathsToProcess, IndexTask::Grade::None, true).

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Single-line parameter addition in handleSilentStart() Create branch; no signature changes, no new interfaces, no public API changes
  • Target line originates from a feature migration commit (8d481bcd), not a prior bug fix — this change does not revert any historical fix

Business Impact Scope

  • Index service silent start: When index database does not exist after system upgrade, Create task now executes immediately instead of waiting for idle
  • Unchanged paths: Update branch in handleSilentStart() and ForceUpdateIndex() are unaffected

Verification Suggestion

  • Test clicking "Update Index Now" after system upgrade, verify index starts creating immediately
  • Verify existing index database still goes through Update branch
  • Verify manual force update behavior unchanged

根因分析

系统升级后点击"立即更新索引"显示"等待空闲"而非创建索引。根因位于 handleSilentStart()(textindexdbus.cpp:123),调用 startTask(Create, paths) 时使用默认参数 forceBypass=false。Create 任务被自动分级为 Heavy,非空闲状态下 canRun(Heavy, false, env) 返回 false,任务入队,currentIndexStatus() 返回"等待空闲"而非立即执行。

修复方案

在 handleSilentStart() 中显式传入 forceBypass=true,与 ForceUpdateIndex()(line 331)既有用法一致。改动为单行参数追加:startTask(Create, pathsToProcess, IndexTask::Grade::None, true)。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • handleSilentStart() Create 分支单行参数追加,无签名变更、无新增接口、无公开 API 变更
  • 目标行源自功能迁移 commit(8d481bcd),非历史 bug 修复产物,本次改动不撤销任何已有修复

业务影响范围

  • 索引服务静默启动:系统升级后索引数据库不存在时,Create 任务立即执行而非等待空闲
  • 不受影响路径:handleSilentStart() Update 分支及 ForceUpdateIndex() 不受影响

验证建议

  • 系统升级后点击"立即更新索引",验证索引立即开始创建
  • 验证索引数据库存在时静默启动仍走 Update 分支
  • 验证手动强制更新索引行为不变

Summary by Sourcery

Keep force-bypass full-scan and index-rebuild operations from being delayed or followed by redundant incremental work.

Bug Fixes:

  • Preserve force-bypass behavior when rebuilding a corrupted index so the rebuild can run without waiting for the system to become idle.
  • Discard incremental tasks queued during a successful force-bypass full scan, since that scan already covers their changes.

@Johnson-zs
Johnson-zs marked this pull request as draft November 30, 2026 12:50
@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 commented Nov 30, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Clear incremental work queued during a successful force-bypass full scan before corrupted-index handling can return early, and pass the force-bypass setting to any Create rebuild so it inherits the same queue-clearing behavior.

  • src/index/task/taskmanager.cpp L977-994, L1026, L1046
  • src/index/task/taskmanager.h L124

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

@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/dbus/textindexdbus.cpp" line_range="123" />
<code_context>
         if (!q->IndexDatabaseExists()) {
             qInfo() << "TextIndexDBus: Index database does not exist, starting create task for:" << pathsToProcess;
-            runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess);
+            runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess, IndexTask::Grade::None, true);
             return;
         }
</code_context>
<issue_to_address>
**Heavy scans ignore power limits**

When the silent-start Create task starts on battery or in power-save mode, or either state begins while it is running, `forceBypass` makes `TaskManager::canRun()` skip the battery and power-save checks, and `onEnvStateChanged()` skips pausing bypassed tasks, so the full scan runs and consumes resources instead of waiting.

Do not bypass the environment checks for this automatic Create task, so it is deferred or paused in those states.
</issue_to_address>

### Comment 2
<location path="src/index/dbus/textindexdbus.cpp" line_range="123" />
<code_context>
         if (!q->IndexDatabaseExists()) {
             qInfo() << "TextIndexDBus: Index database does not exist, starting create task for:" << pathsToProcess;
-            runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess);
+            runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess, IndexTask::Grade::None, true);
             return;
         }
</code_context>
<issue_to_address>
**Unavailable paths prevent startup retry**

When a configured indexed directory is temporarily unavailable when silent start runs, such as a mount that is not ready yet, `CreateIndexHandler` returns failure when a configured source directory is temporarily unavailable, while `handleSilentStart` has already consumed its `call_once`; task completion records the failure but does not retry, so indexing remains absent until another request or service restart.

Retry silent creation after transient path failures, or defer consuming the one-shot until creation succeeds.
</issue_to_address>

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

Comment thread src/index/dbus/textindexdbus.cpp Outdated
if (!q->IndexDatabaseExists()) {
qInfo() << "TextIndexDBus: Index database does not exist, starting create task for:" << pathsToProcess;
runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess);
runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess, IndexTask::Grade::None, true);

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 · Heavy scans ignore power limits

When the silent-start Create task starts on battery or in power-save mode, or either state begins while it is running, forceBypass makes TaskManager::canRun() skip the battery and power-save checks, and onEnvStateChanged() skips pausing bypassed tasks, so the full scan runs and consumes resources instead of waiting.

Do not bypass the environment checks for this automatic Create task, so it is deferred or paused in those states.

Prompt for AI agents
In `src/index/dbus/textindexdbus.cpp` at line 123:

**Heavy scans ignore power limits**

When the silent-start Create task starts on battery or in power-save mode, or either state begins while it is running, `forceBypass` makes `TaskManager::canRun()` skip the battery and power-save checks, and `onEnvStateChanged()` skips pausing bypassed tasks, so the full scan runs and consumes resources instead of waiting.

Do not bypass the environment checks for this automatic Create task, so it is deferred or paused in those states.

Comment thread src/index/dbus/textindexdbus.cpp Outdated
if (!q->IndexDatabaseExists()) {
qInfo() << "TextIndexDBus: Index database does not exist, starting create task for:" << pathsToProcess;
runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess);
runtime->taskManager()->startTask(IndexTask::Type::Create, pathsToProcess, IndexTask::Grade::None, true);

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 · Unavailable paths prevent startup retry

When a configured indexed directory is temporarily unavailable when silent start runs, such as a mount that is not ready yet, CreateIndexHandler returns failure when a configured source directory is temporarily unavailable, while handleSilentStart has already consumed its call_once; task completion records the failure but does not retry, so indexing remains absent until another request or service restart.

Retry silent creation after transient path failures, or defer consuming the one-shot until creation succeeds.

Prompt for AI agents
In `src/index/dbus/textindexdbus.cpp` at line 123:

**Unavailable paths prevent startup retry**

When a configured indexed directory is temporarily unavailable when silent start runs, such as a mount that is not ready yet, `CreateIndexHandler` returns failure when a configured source directory is temporarily unavailable, while `handleSilentStart` has already consumed its `call_once`; task completion records the failure but does not retry, so indexing remains absent until another request or service restart.

Retry silent creation after transient path failures, or defer consuming the one-shot until creation succeeds.

@Johnson-zs
Johnson-zs force-pushed the agent/bugfix/384711 branch 2 times, most recently from 7bc01ab to af70ebf Compare December 1, 2026 02:05
1. Root cause: ForceUpdateIndex starts a force-bypass Update task that
   clears the queue at launch. During near-instant zero-file execution,
   FS events enqueue incremental tasks (forceBypass=false). When the
   Update task fails with a corrupted index, handleCorruptedIndex()
   starts a Create rebuild and returns true, causing onTaskFinished to
   return early. The queue-clearing logic placed in finalizeIndexState
   is never reached because it sits after the handleCorruptedIndex
   guard. Even when the Create rebuild finishes, finalizeIndexState
   may return early if result.success is false, leaving the queue
   non-empty. currentIndexStatus() returns "WaitingIdle" instead of
   "Idle"
2. Fix: move the queue-clearing block from finalizeIndexState into
   onTaskFinished, placed before the handleCorruptedIndex call. This
   guarantees the queue is cleared regardless of whether
   handleCorruptedIndex returns true or false. Also pass wasForceBypass
   through to handleCorruptedIndex so the Create rebuild inherits
   forceBypass, ensuring the queue is cleared again when the rebuild
   finishes
3. Impact: only affects force-bypass full-scan tasks (Create/Update)
   that are not interrupted; non-force-bypass tasks and interrupted
   tasks are unchanged

fix: 将队列清空逻辑移至 onTaskFinished 中 handleCorruptedIndex 之前

1. 根因:ForceUpdateIndex 启动的 forceBypass Update 任务在启动时清空
   队列,但零文件场景下任务近乎瞬时完成,执行期间 FS 事件触发的增量
   任务(forceBypass=false)被入队。当 Update 任务失败且索引损坏时,
   handleCorruptedIndex() 启动 Create 重建并返回 true,导致
   onTaskFinished 提前返回。队列清空逻辑位于 finalizeIndexState 中,
   在 handleCorruptedIndex 守卫之后,永远不会被执行到。即使 Create
   重建完成,若 result.success 为 false,finalizeIndexState 也会提前
   返回,队列仍非空。currentIndexStatus() 返回"等待空闲"而非"空闲"
2. 方案:将队列清空逻辑从 finalizeIndexState 移至 onTaskFinished 中
   handleCorruptedIndex 调用之前,确保无论 handleCorruptedIndex 返回
   true 还是 false,队列都能被清空。同时将 wasForceBypass 传递给
   handleCorruptedIndex,使 Create 重建继承 forceBypass,确保重建完成
   时再次清空队列
3. 影响:仅影响非中断的 forceBypass 全量任务(Create/Update);
   非 forceBypass 任务及中断任务行为不变

Log: Fixed index showing "waiting idle" instead of "idle" after force update with no files to index
Influence:
  - Test clicking "update index now" with no indexable files, verify status shows "idle"
  - Test clicking "update index now" with indexable files, verify index updates normally
  - Verify incremental file changes still trigger correct tasks after force update
Log: 修复无待索引文件时点击"立即更新索引"后状态显示"等待空闲"而非"空闲"的问题
Influence:
  - 测试无待索引文件时点击"立即更新索引",验证状态显示"空闲"
  - 测试有待索引文件时点击"立即更新索引",验证索引正常更新
  - 验证强制更新后增量文件变更仍能正确触发任务
PMS: BUG-384711
Change-Id: I6cd10d69c4b7dc787a561a66c82220ed56f85748
@Johnson-zs
Johnson-zs marked this pull request as ready for review December 1, 2026 05:18
@Johnson-zs

Copy link
Copy Markdown
Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit 7db884c into linuxdeepin:develop/snipe Dec 1, 2026
18 of 20 checks passed
@deepin-bot

deepin-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable, merge_method: rebase)

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