Skip to content

fix: remove AI service check from StartManager constructor - #708

Merged
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/agent/05ed7d309235
Nov 3, 2026
Merged

pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/agent/05ed7d309235

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

The StartManager constructor in src/startmanager.cpp calls IflytekAiAssistant::instance()->checkAiExists(), which triggers construction of QDBusInterface("com.deepin.copilot", ...) during editor startup. When deepin-editor is set as autostart, this D-Bus interface construction causes the D-Bus daemon to auto-activate the com.deepin.copilot service (via /usr/share/dbus-1/services/com.deepin.copilot.service → Exec=/usr/bin/uos-ai-assistant), launching the UOS AI assistant process and popping up its window on boot.

Key evidence: iflytek_ai_assistant.cpp:143 constructs m_copilot as a QDBusInterface in the singleton constructor; startmanager.cpp:100 calls checkAiExists() during StartManager initialization. The D-Bus activation chain was confirmed by reproduction experiments observing the activation log.

Fix Approach

Remove the checkAiExists() call from the StartManager constructor, deferring AI service detection to first actual use of AI features (lazy loading). This eliminates the D-Bus auto-activation trigger during startup without modifying the IflytekAiAssistant class itself.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • Target line was introduced by commit 629f1617 ("feat: adapt new ai assistant") as a feature addition, not a bug fix — this change does not revoke any historical fix.
  • checkAiExists() method itself is not deleted or modified; only the call site in the constructor is removed. Unit tests that directly call checkAiExists() remain unaffected.

Business Impact Scope

  • AI assistant features (text-to-speech, voice input, translation): AI service initialization is deferred from startup to first use. All AI features remain functional — IflytekAiAssistant::instance() singleton is lazily created when first AI feature is invoked.
  • Editor startup: No longer triggers D-Bus auto-activation of com.deepin.copilot service, preventing UOS AI window from popping up when deepin-editor is set as autostart.

Verification Suggestion

Test deepin-editor autostart scenario (set as autostart, reboot) to verify UOS AI window does not appear. Then test AI features (text-to-speech, translation) to verify they still work when first invoked from within the editor.


根因分析

src/startmanager.cpp 中的 StartManager 构造函数调用了 IflytekAiAssistant::instance()->checkAiExists(),该方法在编辑器启动阶段构造 QDBusInterface("com.deepin.copilot", ...)。当 deepin-editor 被设为开机自启时,该 D-Bus 接口构造导致 D-Bus 守护进程根据 /usr/share/dbus-1/services/com.deepin.copilot.service(Exec=/usr/bin/uos-ai-assistant)自动激活 com.deepin.copilot 服务,拉起 uos-ai-assistant 进程并弹出 UOS AI 窗口。

关键证据:iflytek_ai_assistant.cpp:143 在单例构造函数中构造 m_copilot(QDBusInterface);startmanager.cpp:100 在 StartManager 初始化时调用 checkAiExists()。复现实验已完整观测 D-Bus 激活因果链。

修复方案

从 StartManager 构造函数移除 checkAiExists() 调用,将 AI 服务检测延迟到首次实际使用 AI 功能时执行(懒加载),不修改 IflytekAiAssistant 类本身。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 目标行由 commit 629f1617("feat: adapt new ai assistant")引入,属于功能引入而非 bug 修复——本次改动不撤销任何历史修复。
  • checkAiExists() 方法本身未删除或修改,仅移除构造函数中的调用点。直接调用该方法的单元测试不受影响。

业务影响范围

  • AI 助手功能(文本朗读、语音输入、翻译):AI 服务初始化从启动阶段延迟到首次使用时执行。所有 AI 功能保持可用——IflytekAiAssistant::instance() 单例在首次调用 AI 功能时延迟创建。
  • 编辑器启动:不再在启动时触发 D-Bus 自动激活 com.deepin.copilot 服务,避免开机自启时 UOS AI 窗口弹出。

验证建议

测试设置 deepin-editor 开机自启后重启,验证 UOS AI 窗口不再弹出。然后在编辑器中首次使用 AI 功能(文本朗读、翻译),验证功能正常初始化。

PMS: BUG-368911

Summary by Sourcery

Prevent AI service activation during editor startup by removing eager initialization and deferring service checks until needed.

Bug Fixes:

  • Prevent editor startup from activating the UOS AI assistant and displaying its window when launched automatically.

Enhancements:

  • Defer AI assistant service detection until AI functionality is actually used while preserving revalidation for invalid or unavailable states.

@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 reviewed your changes and they look great!


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

@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR prevents deepin-editor autostart from activating the UOS AI assistant by removing eager service detection from StartManager, while retaining AI functionality through lazy initialization and retrying service detection for invalid cached states.

Sequence diagram for deferred AI assistant initialization

sequenceDiagram
    participant StartManager
    participant IflytekAiAssistant
    participant DBus as com.deepin.copilot D-Bus service
    participant AIFeature as AI feature

    StartManager->>StartManager: constructor
    Note over StartManager,DBus: No checkAiExists call during startup
    AIFeature->>IflytekAiAssistant: instance()
    IflytekAiAssistant->>IflytekAiAssistant: checkAiExists()
    IflytekAiAssistant->>DBus: QDBusInterface construction
    DBus-->>IflytekAiAssistant: service status
    IflytekAiAssistant-->>AIFeature: AI functionality available
Loading

State diagram for AI service status revalidation

stateDiagram-v2
    [*] --> Invalid
    Invalid --> Enabled: checkValid()
    NotInstalled --> Enabled: checkValid()
    Invalid --> NotInstalled: copilotInstalled(m_copilot)
    NotInstalled --> NotInstalled: copilotInstalled(m_copilot)
    Enabled --> Enabled: checkValid()
Loading

File-Level Changes

Change Details Files
Remove eager AI assistant service detection from editor startup to prevent unintended D-Bus activation.
  • Remove the StartManager dependency on the AI assistant header.
  • Stop calling checkAiExists() during StartManager construction.
  • Preserve AI initialization for later feature use through lazy singleton creation.
src/startmanager.cpp
Re-evaluate previously invalid AI service state when validating assistant availability.
  • Handle Invalid alongside NotInstalled in checkValid().
  • Retry copilot installation detection when the cached status is invalid, preserving AI feature availability after startup detection is deferred.
src/common/iflytek_ai_assistant.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

@pengfeixx
pengfeixx marked this pull request as draft November 2, 2026 16:13
1. Root cause: StartManager constructor called
   IflytekAiAssistant::instance()->checkAiExists(), which constructs
   QDBusInterface and calls copilotInstalled() during startup, triggering
   D-Bus auto-activation of com.deepin.copilot service
2. Fix: remove checkAiExists() call from constructor; add case Invalid
   to checkValid() switch so copilotInstalled() runs synchronously on
   first AI feature invocation, transitioning m_status from Invalid to
   a valid state (lazy loading); remove now-unused include from
   startmanager.cpp
3. Impact: deepin-editor autostart no longer activates com.deepin.copilot
   via D-Bus at boot; AI features (TTS, STT, translation) work normally
   when first invoked by the user

Log: Fix UOS AI window popping up when deepin-editor is set as autostart

Influence:
1. Test deepin-editor autostart does not trigger UOS AI window on boot
2. Test AI features (TTS, STT, translation) work on first invocation
3. Verify no regression on normal editor startup behavior

fix: 实现 checkValid 懒加载 AI 服务检测

1. 根因:StartManager 构造函数调用
   IflytekAiAssistant::instance()->checkAiExists(),该方法在启动阶段
   构造 QDBusInterface 并调用 copilotInstalled(),触发 D-Bus 自动
   激活 com.deepin.copilot 服务
2. 方案:从构造函数移除 checkAiExists() 调用;在 checkValid() 的
   switch 中增加 case Invalid 分支,首次调用 AI 功能时同步执行
   copilotInstalled() 检查,将 m_status 从 Invalid 转变为有效状态
   (懒加载);移除 startmanager.cpp 中已不再使用的 include
3. 影响:deepin-editor 开机自启不再通过 D-Bus 激活
   com.deepin.copilot;AI 功能(TTS、STT、翻译)在用户首次使用时
   正常工作

Log: 修复设置文本编辑器开机自启后 UOS AI 窗口弹出的问题

Influence:
1. 测试设置文本编辑器开机自启后,开机不再弹出 UOS AI 窗口
2. 测试在文本编辑器内首次使用 AI 功能时仍可正常工作
3. 验证编辑器正常启动行为无回归

PMS: BUG-368911
@pengfeixx
pengfeixx force-pushed the agent/agent/05ed7d309235 branch from 746f584 to 0eeff74 Compare November 2, 2026 20:33
@pengfeixx
pengfeixx marked this pull request as ready for review November 3, 2026 05:47
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交移除 StartManager 构造函数中的 AI 服务检查调用,并在 checkValid() 的 switch 语句中补充 Invalid 状态处理,变更范围小、逻辑清晰,四维度均无问题,OCR 审查同样未发现任何问题。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例


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

@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 reviewed your changes and they look great!


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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

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

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@pengfeixx
pengfeixx merged commit 6522633 into linuxdeepin:master Nov 3, 2026
17 checks passed
@pengfeixx
pengfeixx deleted the agent/agent/05ed7d309235 branch November 3, 2026 07:05
@deepin-bot

deepin-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unknown)

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.

3 participants