Skip to content

fix: lazy-create copilot D-Bus interface to avoid startup auto-activation - #733

Closed
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bugfix/368911
Closed

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/bugfix/368911

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

fix: lazy-create copilot D-Bus interface to avoid startup auto-activation

  1. Root cause: IflytekAiAssistant constructor created QDBusInterface
    for com.deepin.copilot at init, triggering D-Bus auto-activation
    of uos-ai-assistant when the singleton is first accessed during startup
  2. Fix: move QDBusInterface creation to ensureCopilot(), called lazily
    from checkValid(); valid() remains read-only on m_status
  3. Impact: startup path instance()->valid() no longer touches D-Bus;
    AI functionality unaffected—interface created on first real use

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: 延迟创建copilot D-Bus接口避免启动时自动激活

  1. 根因:IflytekAiAssistant构造函数在初始化时创建QDBusInterface
    指向com.deepin.copilot,单例在启动路径首次访问时触发D-Bus
    自动激活uos-ai-assistant进程
  2. 方案:将QDBusInterface创建移至ensureCopilot(),由checkValid()
    首次使用时懒加载;valid()保持只读m_status不触发创建
  3. 影响:启动路径instance()->valid()不再触碰D-Bus;AI功能不受
    影响,接口在首次实际使用时创建

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

Influence:

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

PMS: BUG-368911

Summary by Sourcery

Defer Copilot D-Bus interface creation until AI functionality is actually accessed to prevent unwanted assistant activation during editor startup.

Bug Fixes:

  • Prevent startup auto-activation of the UOS AI assistant and the resulting unwanted AI window when the editor launches automatically.

Enhancements:

  • Lazily initialize the Copilot D-Bus interface on the first AI validity check or feature use while keeping startup validity checks side-effect free.

…tion

1. Root cause: IflytekAiAssistant constructor created QDBusInterface
   for com.deepin.copilot at init, triggering D-Bus auto-activation
   of uos-ai-assistant when the singleton is first accessed during startup
2. Fix: move QDBusInterface creation to ensureCopilot(), called lazily
   from checkValid(); valid() remains read-only on m_status
3. Impact: startup path instance()->valid() no longer touches D-Bus;
   AI functionality unaffected—interface created on first real use

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: 延迟创建copilot D-Bus接口避免启动时自动激活

1. 根因:IflytekAiAssistant构造函数在初始化时创建QDBusInterface
   指向com.deepin.copilot,单例在启动路径首次访问时触发D-Bus
   自动激活uos-ai-assistant进程
2. 方案:将QDBusInterface创建移至ensureCopilot(),由checkValid()
   首次使用时懒加载;valid()保持只读m_status不触发创建
3. 影响:启动路径instance()->valid()不再触碰D-Bus;AI功能不受
   影响,接口在首次实际使用时创建

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

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

PMS: BUG-368911
@pengfeixx
pengfeixx marked this pull request as draft November 16, 2026 14:57
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Defer creation of the Copilot D-Bus interface from construction to ensureCopilot(), invoked by checkValid(), so startup access to valid() does not trigger D-Bus activation.

  • src/common/iflytek_ai_assistant.cpp L143 (removed lines), L145-153, L179
  • src/common/iflytek_ai_assistant.h L66-67

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 1 issue

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

## Individual Comments

### Comment 1
<location path="src/common/iflytek_ai_assistant.cpp" line_range="149-150" />
<code_context>
+
+QSharedPointer<QDBusInterface> IflytekAiAssistant::ensureCopilot()
+{
+    if (!m_copilot) {
+        m_copilot = QSharedPointer<QDBusInterface>::create(kCopilotService, kCopilotPath, kCopilotInterface);
+        m_copilot->setTimeout(2000);
+    }
</code_context>
<issue_to_address>
**Concurrent first use races**

When two threads invoke `checkValid()` before `m_copilot` has been initialized, both calls can read and write `m_copilot` concurrently; `QSharedPointer` does not synchronize concurrent access to the same pointer object, so the assignments race and callers can use an invalid interface or crash.

Protect lazy initialization and subsequent access to `m_copilot` with synchronization, or guarantee all calls occur on the assistant's owning thread.
</issue_to_address>

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

Comment on lines +149 to +150
if (!m_copilot) {
m_copilot = QSharedPointer<QDBusInterface>::create(kCopilotService, kCopilotPath, kCopilotInterface);

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 · Concurrent first use races

When two threads invoke checkValid() before m_copilot has been initialized, both calls can read and write m_copilot concurrently; QSharedPointer does not synchronize concurrent access to the same pointer object, so the assignments race and callers can use an invalid interface or crash.

Protect lazy initialization and subsequent access to m_copilot with synchronization, or guarantee all calls occur on the assistant's owning thread.

Prompt for AI agents
In `src/common/iflytek_ai_assistant.cpp` at lines 149-150:

**Concurrent first use races**

When two threads invoke `checkValid()` before `m_copilot` has been initialized, both calls can read and write `m_copilot` concurrently; `QSharedPointer` does not synchronize concurrent access to the same pointer object, so the assignments race and callers can use an invalid interface or crash.

Protect lazy initialization and subsequent access to `m_copilot` with synchronization, or guarantee all calls occur on the assistant's owning thread.

@deepin-bot

deepin-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.10
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #746

@deepin-bot

deepin-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.11
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #757

@deepin-bot

deepin-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.6.12
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #758

@pengfeixx pengfeixx closed this Dec 1, 2026
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