Skip to content

fix(systemd): bind autostart to the graphical session - #11

Open
hualet wants to merge 1 commit into
mainfrom
fix/graphical-session-autostart
Open

hualet wants to merge 1 commit into
mainfrom
fix/graphical-session-autostart

Conversation

@hualet

@hualet hualet commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

EchoFlow could start before the desktop display settings were ready, causing incorrect UI scaling, and did not reliably start again after logout and login. Both services now start with the graphical session and stop when it ends.

  • Require and order startup after graphical-session.target, with session stop propagation.
  • Migrate old default.target links in user installs and Debian upgrades, preserving disabled services and first-install preset policy.
  • Add upgrade regression checks and document user-install overrides of system packages.

Validation

  • cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo
  • cmake --build build -j 8
  • ctest --test-dir build --output-on-failure: 28/28 passed.
  • Installation and Debian migration checks cover enabled, disabled, fresh-install, and preset-disabled cases; shell syntax and git diff --check passed.
  • Isolated systemd lifecycle check: services stay stopped before a graphical session and start/stop correctly over two login/logout cycles.
  • User verified on deepin that both reboot and logout/login restore autostart with correct UI scaling.

Existing installations need the updated service units and migrated enablement links. Source installs can rerun ./install-user.sh; package upgrades migrate system-wide links through the maintainer script. Existing per-user units continue to override packaged units, as documented.

Summary by Sourcery

Bind EchoFlow autostart to the graphical session and migrate existing installations without changing service enablement policy.

Bug Fixes:

  • Start EchoFlow services with the graphical session so UI scaling is ready, stop them when the session ends, and restore autostart after relogin.

Enhancements:

  • Migrate existing user and Debian service links from default-target startup to graphical-session startup while preserving disabled services, preset policy, and user-installed overrides.

Deployment:

  • Add Debian upgrade migration handling for existing system-wide service enablement links without restarting active user sessions.

Documentation:

  • Document graphical-session lifecycle behavior and how source-installed user units interact with Debian packages.

Tests:

  • Add regression coverage for Debian upgrade migration across enabled, disabled, fresh-install, and preset-disabled scenarios.

Starting from default.target can launch the UI before display settings
are ready and does not restart it on subsequent graphical logins.

Start both services after the graphical session is active and stop them
when it ends. Replace old user-install links, migrate enabled Debian
services while preserving disabled states and first-install presets,
and cover installation and upgrade behavior with regression checks.
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hualet

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 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR moves EchoFlow autostart from user boot to the graphical-session lifecycle, updates source-install and Debian upgrade paths to migrate legacy links without overriding disabled or preset policy, and adds documentation plus isolated regression checks for installation and upgrade behavior.

Sequence diagram for graphical-session service lifecycle

sequenceDiagram
    participant Session as GraphicalSession
    participant Systemd as systemd_user
    participant EchoFlow as echoflow.service
    participant UI as echoflow_ui.service

    Session->>Systemd: graphical-session.target starts
    Systemd->>EchoFlow: start echoflow.service
    Systemd->>UI: start echoflow-ui.service
    Session->>Systemd: graphical-session.target stops
    Systemd->>EchoFlow: stop echoflow.service
    Systemd->>UI: stop echoflow-ui.service
Loading

Flow diagram for migrating EchoFlow autostart links

flowchart TD
    Install[Source install or Debian upgrade] --> Reload[systemctl user daemon-reload]
    Reload --> Reenable[Reenable EchoFlow services]
    Reenable --> Session[graphical-session.target]
    Session --> Start[Start services after graphical session is ready]
    Session --> Stop[Stop services when session ends]
Loading

File-Level Changes

Change Details Files
Tie both user services to the graphical-session lifecycle instead of the generic user boot target.
  • Require and order startup after graphical-session.target.
  • Propagate session stop so services terminate on logout.
  • Update installation expectations for the new session-scoped enablement.
systemd/user/echoflow.service.in
systemd/user/echoflow-ui.service.in
README.md
Migrate existing user and Debian service enablement links while preserving administrator intent.
  • Use systemctl --user reenable to replace legacy default.target links during source installs.
  • Add Debian post-install migration before debhelper state updates.
  • Preserve disabled services and first-install preset-disabled behavior.
  • Document precedence of existing per-user units over packaged units.
install-user.sh
debian/postinst
README.md
Expand regression coverage for installation and package-upgrade lifecycle behavior.
  • Update install-script and onboarding assertions for reenable semantics.
  • Exercise enabled, disabled, fresh-install, and preset-disabled Debian migration scenarios in an isolated package root.
  • Verify old links are removed, new graphical-session links are created only when appropriate, and maintainer scripts avoid restarting sessions.
tests/spec/run_spec.sh
tests/spec/test_onboarding_install.sh
tests/spec/test_systemd_upgrade.sh

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="tests/spec/test_onboarding_install.sh" line_range="98" />
<code_context>
 default_output="$(run_install "$DEFAULT_HOME")"
 assert_logged "systemctl --user daemon-reload"
-assert_logged "systemctl --user enable echoflow.service echoflow-ui.service"
+assert_logged "systemctl --user reenable echoflow.service echoflow-ui.service"
 assert_logged "systemctl --user restart echoflow.service echoflow-ui.service"
 assert_logged "fcitx5 -rd"
</code_context>
<issue_to_address>
**User link migration goes unverified**

When the fake `systemctl` is used for the user-install migration check, `test_onboarding_install.sh` accepts the logged `reenable` command at line 98 as migration success; its fake `systemctl` at lines 41–48 only logs arguments and always exits zero, so the test passes with the old `default.target` link unchanged.

Assert the resulting link state using an isolated systemd-compatible helper, or make the fake model `reenable` and verify that it replaces the old link.
</issue_to_address>

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

default_output="$(run_install "$DEFAULT_HOME")"
assert_logged "systemctl --user daemon-reload"
assert_logged "systemctl --user enable echoflow.service echoflow-ui.service"
assert_logged "systemctl --user reenable echoflow.service echoflow-ui.service"

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 · User link migration goes unverified

When the fake systemctl is used for the user-install migration check, test_onboarding_install.sh accepts the logged reenable command at line 98 as migration success; its fake systemctl at lines 41–48 only logs arguments and always exits zero, so the test passes with the old default.target link unchanged.

Assert the resulting link state using an isolated systemd-compatible helper, or make the fake model reenable and verify that it replaces the old link.

Prompt for AI agents
In `tests/spec/test_onboarding_install.sh` at line 98:

**User link migration goes unverified**

When the fake `systemctl` is used for the user-install migration check, `test_onboarding_install.sh` accepts the logged `reenable` command at line 98 as migration success; its fake `systemctl` at lines 41–48 only logs arguments and always exits zero, so the test passes with the old `default.target` link unchanged.

Assert the resulting link state using an isolated systemd-compatible helper, or make the fake model `reenable` and verify that it replaces the old link.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将 echoflow 两个用户级 systemd 服务的自启动从 default.target 绑定到 graphical-session.target,使服务在图形会话就绪后启动、注销时停止。变更涵盖 service 单元文件、用户安装脚本、Debian postinst 迁移逻辑及配套测试。代码 逻辑正确、结构清晰、注释完整,未发现安全漏洞。OCR 提出的 4 项建议(DPKG_ROOT 迁移限制文档化、测试脚本 TEST_PACKAGE_ROOT 空值守卫、systemctl 可用性检查、 双写单元文件注释补充)均为防御性编程与可维护性改进建议,不影响功能正确性, 不构成安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: ['无语法逻辑问题']


2. 代码质量 ✅

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

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

建议: ['在 test_systemd_upgrade.sh 第 38 行和第 47 行各添加一行注释,说明先写旧版单元文件用于创建 default.target.wants 链接、再覆盖为新版以模拟升级后状态']


3. 代码性能 ✅

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

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

建议: ['无性能问题']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['建议在 test_systemd_upgrade.sh 的 wrapper 脚本中添加 [ -n "$TEST_PACKAGE_ROOT" ] || { echo \'REFUSE\' >&2; exit 1; } 守卫,作为防御性编程加固(OCR 建议,当前代码无实际风险)', '建议在 test_systemd_upgrade.sh 中添加 systemctl 可用性检查,与 deb-systemd-helper 检查保持一致(OCR 建议,测试健壮性改进)']


💡 改进建议代码示例

# tests/spec/test_systemd_upgrade.sh — 防御性加固建议(非必须修复)
# 在 wrapper 脚本中添加空值守卫:
cat > "$TEST_ROOT/bin/deb-systemd-helper" <<'EOF'
#!/bin/sh
[ -n "$TEST_PACKAGE_ROOT" ] || { echo 'REFUSE - TEST_PACKAGE_ROOT is empty' >&2; exit 1; }
DPKG_ROOT="$TEST_PACKAGE_ROOT" exec "$HELPER" "$@"
EOF

# 在 systemctl 符号链接创建前添加可用性检查:
if ! command -v systemctl >/dev/null 2>&1; then
  echo 'SKIP - systemctl is not installed'
  exit 0
fi
ln -s "$(command -v systemctl)" "$TEST_PACKAGE_ROOT/usr/bin/systemctl"

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

This branch has not been deployed

No deployments
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