Skip to content

fix: stabilize tray quit/restart and automate version sync#21

Merged
zouyonghe merged 5 commits into
AstrBotDevs:mainfrom
zouyonghe:main
Feb 20, 2026
Merged

fix: stabilize tray quit/restart and automate version sync#21
zouyonghe merged 5 commits into
AstrBotDevs:mainfrom
zouyonghe:main

Conversation

@zouyonghe

@zouyonghe zouyonghe commented Feb 20, 2026

Copy link
Copy Markdown
Member

Summary

  • stabilize Windows tray restart/quit flow in Tauri (desktop-managed restart + async backend cleanup on exit)
  • add make update to sync desktop version from upstream AstrBot
  • support ASTRBOT_DESKTOP_VERSION injection in resource preparation
  • update CI workflow to sync version files on scheduled upstream-tag builds and pass resolved version into build steps
  • update README with version maintenance and CI sync behavior

Validation

  • cargo check --manifest-path src-tauri/Cargo.toml
  • node --check scripts/prepare-resources.mjs

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保后端关闭在 ExitRequested 时以异步方式运行,并且只在清理完成后才退出桌面进程。
  • 简化由托盘触发的后端重启逻辑,始终使用桌面应用托管的重启流程,而不是委托给 webview 的 origin。

功能增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并引入集中化的版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。

构建:

  • 扩展 build-desktop-tauri 工作流,新增 sync_repo_version 任务,在上游打 tag 的定时构建中先同步并提交版本文件,然后再运行各平台构建。
  • 将解析后的 AstrBot 版本传入所有 Tauri 构建任务,并支持在不克隆上游仓库的情况下解析类 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 以及由 CI 驱动的版本同步机制,并说明 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本号从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 通过异步运行后台关闭逻辑,并仅在清理完成后再退出,防止在收到 ExitRequested 时进程过早退出。
  • 简化由托盘发起的后台重启流程,始终使用由桌面应用管理的重启流程,而不是委托给 WebView 端。

增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并将版本解析逻辑集中化。
  • 新增 make update 目标,通过远程 git 引用而不是本地检出,从上游 AstrBot 仓库同步桌面版本相关文件。

构建:

  • 扩展 build-desktop-tauri 工作流,增加 sync_repo_version 任务,在按计划构建上游 tag 时,先同步并提交版本文件,再进行各平台构建。
  • 在所有 Tauri 构建步骤中传递解析后的 AstrBot 版本,并支持在不克隆上游仓库的情况下直接解析类 semver 的标签。

文档:

  • 记录桌面版本维护流程,包括 make sync-versionmake update 和由 CI 驱动的版本同步之间的交互方式,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 版本从 4.17.5 升级到 4.17.6,以与更新后的上游版本对齐。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保后端关闭在 ExitRequested 时以异步方式运行,并且只在清理完成后才退出桌面进程。
  • 简化由托盘触发的后端重启逻辑,始终使用桌面应用托管的重启流程,而不是委托给 webview 的 origin。

功能增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并引入集中化的版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。

构建:

  • 扩展 build-desktop-tauri 工作流,新增 sync_repo_version 任务,在上游打 tag 的定时构建中先同步并提交版本文件,然后再运行各平台构建。
  • 将解析后的 AstrBot 版本传入所有 Tauri 构建任务,并支持在不克隆上游仓库的情况下解析类 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 以及由 CI 驱动的版本同步机制,并说明 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本号从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保在 ExitRequested 时以异步方式执行后端关停逻辑,并仅在清理完成后才终止桌面进程,以避免过早退出。
  • 简化托盘重启处理流程,使后端始终通过桌面统一管理的流程重启,而不再依赖 WebView 的来源。

功能增强:

  • 允许在资源准备阶段通过 ASTRBOT_DESKTOP_VERSION 环境变量覆盖桌面版本,并集中管理版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用从上游 AstrBot 仓库同步桌面版本文件,而无需本地检出。

构建:

  • 引入 sync_repo_version CI 任务,在定时的上游标签构建中,先同步并提交版本文件,再执行各平台构建。
  • 在所有 Tauri 构建步骤中传入解析后的 AstrBot 版本,并支持在解析版本时直接处理类似 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 与 CI 驱动的版本同步之间的关系,以及使用示例。
  • 描述 CI 版本同步的行为,以及在何种情况下版本文件会被自动提交,何种情况下仅用于构建。

杂项:

  • 将桌面包和 Rust crate 版本从 4.17.5 升级到 4.17.6,以反映与上游对齐后的新版本。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保后端关闭在 ExitRequested 时以异步方式运行,并且只在清理完成后才退出桌面进程。
  • 简化由托盘触发的后端重启逻辑,始终使用桌面应用托管的重启流程,而不是委托给 webview 的 origin。

功能增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并引入集中化的版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。

构建:

  • 扩展 build-desktop-tauri 工作流,新增 sync_repo_version 任务,在上游打 tag 的定时构建中先同步并提交版本文件,然后再运行各平台构建。
  • 将解析后的 AstrBot 版本传入所有 Tauri 构建任务,并支持在不克隆上游仓库的情况下解析类 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 以及由 CI 驱动的版本同步机制,并说明 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本号从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 通过异步运行后台关闭逻辑,并仅在清理完成后再退出,防止在收到 ExitRequested 时进程过早退出。
  • 简化由托盘发起的后台重启流程,始终使用由桌面应用管理的重启流程,而不是委托给 WebView 端。

增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并将版本解析逻辑集中化。
  • 新增 make update 目标,通过远程 git 引用而不是本地检出,从上游 AstrBot 仓库同步桌面版本相关文件。

构建:

  • 扩展 build-desktop-tauri 工作流,增加 sync_repo_version 任务,在按计划构建上游 tag 时,先同步并提交版本文件,再进行各平台构建。
  • 在所有 Tauri 构建步骤中传递解析后的 AstrBot 版本,并支持在不克隆上游仓库的情况下直接解析类 semver 的标签。

文档:

  • 记录桌面版本维护流程,包括 make sync-versionmake update 和由 CI 驱动的版本同步之间的交互方式,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 版本从 4.17.5 升级到 4.17.6,以与更新后的上游版本对齐。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保后端关闭在 ExitRequested 时以异步方式运行,并且只在清理完成后才退出桌面进程。
  • 简化由托盘触发的后端重启逻辑,始终使用桌面应用托管的重启流程,而不是委托给 webview 的 origin。

功能增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并引入集中化的版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。

构建:

  • 扩展 build-desktop-tauri 工作流,新增 sync_repo_version 任务,在上游打 tag 的定时构建中先同步并提交版本文件,然后再运行各平台构建。
  • 将解析后的 AstrBot 版本传入所有 Tauri 构建任务,并支持在不克隆上游仓库的情况下解析类 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 以及由 CI 驱动的版本同步机制,并说明 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本号从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 通过在 ExitRequested 时异步运行后端关闭逻辑,并仅在清理完成后才允许应用终止,防止进程过早退出。
  • 简化托盘后端的重启行为,无论 WebView 来源如何,始终使用由桌面端管理的重启流程。

增强:

  • 在资源准备阶段添加基于环境变量驱动的桌面版本解析,允许使用 ASTRBOT_DESKTOP_VERSION 进行显式覆盖。
  • 引入 Makefile 的 update 目标,通过远程 git refs 而不是本地检出,从上游 AstrBot 同步桌面版本。
  • 扩展 README,增加桌面版本维护、make update 用法以及 CI 版本同步行为的相关说明。

构建:

  • 添加专用的 sync_repo_version CI 任务,在计划的上游 tag 构建中,在执行各平台构建之前同步并提交版本文件。
  • 在所有操作系统目标的 Tauri 构建步骤中传递解析后的 AstrBot 版本,并允许在 CI 中直接从类 semver 的 tag 解析版本。

文档:

  • 记录版本维护工作流,包括 make sync-versionmake update 与 CI 驱动的版本同步之间的关系。

杂项:

  • 将桌面包和 Rust crate 版本从 4.17.5 提升到 4.17.6,以反映与上游同步后的版本。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保后端关闭在 ExitRequested 时以异步方式运行,并且只在清理完成后才退出桌面进程。
  • 简化由托盘触发的后端重启逻辑,始终使用桌面应用托管的重启流程,而不是委托给 webview 的 origin。

功能增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并引入集中化的版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。

构建:

  • 扩展 build-desktop-tauri 工作流,新增 sync_repo_version 任务,在上游打 tag 的定时构建中先同步并提交版本文件,然后再运行各平台构建。
  • 将解析后的 AstrBot 版本传入所有 Tauri 构建任务,并支持在不克隆上游仓库的情况下解析类 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 以及由 CI 驱动的版本同步机制,并说明 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本号从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 通过异步运行后台关闭逻辑,并仅在清理完成后再退出,防止在收到 ExitRequested 时进程过早退出。
  • 简化由托盘发起的后台重启流程,始终使用由桌面应用管理的重启流程,而不是委托给 WebView 端。

增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并将版本解析逻辑集中化。
  • 新增 make update 目标,通过远程 git 引用而不是本地检出,从上游 AstrBot 仓库同步桌面版本相关文件。

构建:

  • 扩展 build-desktop-tauri 工作流,增加 sync_repo_version 任务,在按计划构建上游 tag 时,先同步并提交版本文件,再进行各平台构建。
  • 在所有 Tauri 构建步骤中传递解析后的 AstrBot 版本,并支持在不克隆上游仓库的情况下直接解析类 semver 的标签。

文档:

  • 记录桌面版本维护流程,包括 make sync-versionmake update 和由 CI 驱动的版本同步之间的交互方式,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 版本从 4.17.5 升级到 4.17.6,以与更新后的上游版本对齐。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保后端关闭在 ExitRequested 时以异步方式运行,并且只在清理完成后才退出桌面进程。
  • 简化由托盘触发的后端重启逻辑,始终使用桌面应用托管的重启流程,而不是委托给 webview 的 origin。

功能增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并引入集中化的版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。

构建:

  • 扩展 build-desktop-tauri 工作流,新增 sync_repo_version 任务,在上游打 tag 的定时构建中先同步并提交版本文件,然后再运行各平台构建。
  • 将解析后的 AstrBot 版本传入所有 Tauri 构建任务,并支持在不克隆上游仓库的情况下解析类 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 以及由 CI 驱动的版本同步机制,并说明 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本号从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保在 ExitRequested 时以异步方式执行后端关停逻辑,并仅在清理完成后才终止桌面进程,以避免过早退出。
  • 简化托盘重启处理流程,使后端始终通过桌面统一管理的流程重启,而不再依赖 WebView 的来源。

功能增强:

  • 允许在资源准备阶段通过 ASTRBOT_DESKTOP_VERSION 环境变量覆盖桌面版本,并集中管理版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用从上游 AstrBot 仓库同步桌面版本文件,而无需本地检出。

构建:

  • 引入 sync_repo_version CI 任务,在定时的上游标签构建中,先同步并提交版本文件,再执行各平台构建。
  • 在所有 Tauri 构建步骤中传入解析后的 AstrBot 版本,并支持在解析版本时直接处理类似 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 与 CI 驱动的版本同步之间的关系,以及使用示例。
  • 描述 CI 版本同步的行为,以及在何种情况下版本文件会被自动提交,何种情况下仅用于构建。

杂项:

  • 将桌面包和 Rust crate 版本从 4.17.5 升级到 4.17.6,以反映与上游对齐后的新版本。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保后端关闭在 ExitRequested 时以异步方式运行,并且只在清理完成后才退出桌面进程。
  • 简化由托盘触发的后端重启逻辑,始终使用桌面应用托管的重启流程,而不是委托给 webview 的 origin。

功能增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并引入集中化的版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。

构建:

  • 扩展 build-desktop-tauri 工作流,新增 sync_repo_version 任务,在上游打 tag 的定时构建中先同步并提交版本文件,然后再运行各平台构建。
  • 将解析后的 AstrBot 版本传入所有 Tauri 构建任务,并支持在不克隆上游仓库的情况下解析类 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 以及由 CI 驱动的版本同步机制,并说明 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本号从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 通过异步运行后台关闭逻辑,并仅在清理完成后再退出,防止在收到 ExitRequested 时进程过早退出。
  • 简化由托盘发起的后台重启流程,始终使用由桌面应用管理的重启流程,而不是委托给 WebView 端。

增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并将版本解析逻辑集中化。
  • 新增 make update 目标,通过远程 git 引用而不是本地检出,从上游 AstrBot 仓库同步桌面版本相关文件。

构建:

  • 扩展 build-desktop-tauri 工作流,增加 sync_repo_version 任务,在按计划构建上游 tag 时,先同步并提交版本文件,再进行各平台构建。
  • 在所有 Tauri 构建步骤中传递解析后的 AstrBot 版本,并支持在不克隆上游仓库的情况下直接解析类 semver 的标签。

文档:

  • 记录桌面版本维护流程,包括 make sync-versionmake update 和由 CI 驱动的版本同步之间的交互方式,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 版本从 4.17.5 升级到 4.17.6,以与更新后的上游版本对齐。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

Bug 修复:

  • 确保后端关闭在 ExitRequested 时以异步方式运行,并且只在清理完成后才退出桌面进程。
  • 简化由托盘触发的后端重启逻辑,始终使用桌面应用托管的重启流程,而不是委托给 webview 的 origin。

功能增强:

  • 在资源准备阶段允许通过环境变量 ASTRBOT_DESKTOP_VERSION 覆盖桌面版本,并引入集中化的版本解析逻辑。
  • 新增 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。

构建:

  • 扩展 build-desktop-tauri 工作流,新增 sync_repo_version 任务,在上游打 tag 的定时构建中先同步并提交版本文件,然后再运行各平台构建。
  • 将解析后的 AstrBot 版本传入所有 Tauri 构建任务,并支持在不克隆上游仓库的情况下解析类 semver 的标签。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 以及由 CI 驱动的版本同步机制,并说明 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本号从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

稳定桌面托盘的退出/重启流程,并引入一条自动化流水线,用于将桌面版本与上游 AstrBot 同步,包括本地工具、CI 以及文档更新。

Bug 修复:

  • ExitRequested 时异步运行后端关闭逻辑,并确保桌面进程只在清理完成后才退出,同时在 Exit 时进行兜底清理。
  • 简化由托盘发起的后端重启操作,统一使用由桌面管理的重启流程,而不是委托给 webview 的来源(origin)。

增强功能:

  • 在资源准备阶段,通过 ASTRBOT_DESKTOP_VERSION 环境变量支持覆盖桌面版本,并集中化版本解析逻辑。
  • 引入 make update 目标,通过远程 git 引用而非本地检出,从上游 AstrBot 仓库同步桌面版本文件。
  • 从 Tauri 桌面桥和托盘处理逻辑中移除旧的 Electron runtime bridge 命令以及基于 origin 的托盘重启线路。

构建:

  • 允许构建工作流在可能的情况下,直接从类 semver 的标签解析 AstrBot 版本,而无需克隆上游仓库。
  • build-desktop-tauri 工作流中添加 sync_repo_version 任务,在计划的上游标签构建之前更新并提交桌面版本文件,并使所有平台构建都通过 ASTRBOT_DESKTOP_VERSION 使用解析后的 AstrBot 版本。

文档:

  • 记录桌面版本维护工作流,包括 make sync-versionmake update 和由 CI 驱动的版本同步的作用,以及 CI 何时会将版本变更提交回仓库。

杂项:

  • 将桌面包和 Rust crate 的版本从 4.17.5 提升到 4.17.6,以与更新后的上游版本保持一致。
Original summary in English

Summary by Sourcery

Stabilize the desktop tray quit/restart flow and introduce an automated pipeline for syncing the desktop version with upstream AstrBot, including local tooling, CI, and documentation updates.

Bug Fixes:

  • Run backend shutdown asynchronously on ExitRequested and ensure the desktop process exits only after cleanup completes, with a fallback cleanup on Exit.
  • Simplify tray-initiated backend restarts to always use the desktop-managed restart flow rather than delegating to the webview origin.

Enhancements:

  • Add support for overriding the desktop version during resource preparation via the ASTRBOT_DESKTOP_VERSION environment variable, with centralized version resolution logic.
  • Introduce a make update target that syncs desktop version files from the upstream AstrBot repository using remote git refs instead of a local checkout.
  • Remove legacy Electron runtime bridge commands and origin-based tray restart wiring from the Tauri desktop bridge and tray handling.

Build:

  • Allow the build workflow to resolve AstrBot versions directly from semver-like tags without cloning the upstream repository when possible.
  • Add a sync_repo_version job to the build-desktop-tauri workflow that updates and commits desktop version files before scheduled upstream-tag builds, and wire all platform builds to consume the resolved AstrBot version via ASTRBOT_DESKTOP_VERSION.

Documentation:

  • Document the desktop version maintenance workflow, including the roles of make sync-version, make update, and CI-driven version sync, and when CI will commit version changes back to the repository.

Chores:

  • Bump the desktop package and Rust crate versions from 4.17.5 to 4.17.6 to align with the updated upstream version.

@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 - 我发现了两个问题,并给出了一些高层面的反馈:

  • 请考虑对新的 exit_cleanup_started / exit_allowed 标志使用 Ordering::Relaxed 是否足够,或者使用更明确的内存序(例如 Acquire/Release)是否能让并发退出协议更易于推理,并减少跨线程的微妙竞争条件风险。
  • RunEvent::ExitRequested 中新的异步退出流程先启动一个异步任务,然后在其中嵌套 spawn_blocking;你可以通过只使用 spawn_blocking(或只保留一个异步任务)来简化结构,减少分层,让关闭路径更容易追踪。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider whether `Ordering::Relaxed` is sufficient for the new `exit_cleanup_started` / `exit_allowed` flags, or if clearer memory ordering (e.g. `Acquire/Release`) would make the concurrent exit protocol easier to reason about and less prone to subtle races across threads.
- The new async exit flow in `RunEvent::ExitRequested` spawns an async task and then a nested `spawn_blocking`; you could simplify this by only using `spawn_blocking` (or a single async task) to reduce layering and make the shutdown path easier to trace.

## Individual Comments

### Comment 1
<location> `.github/workflows/build-desktop-tauri.yml:130-139` </location>
<code_context>
+  sync_repo_version:
</code_context>

<issue_to_address>
**suggestion (performance):** The `sync_repo_version` job currently does relatively heavy work on all events, not just scheduled ones.

Because `sync_repo_version` is in `needs` for all build jobs, its initial steps (`checkout`, `setup-toolchains`, `pnpm/action-setup`) run on every event type, even though only the later version-sync/commit steps are gated on `github.event_name == 'schedule'`.

To avoid unnecessary CI work on push/PR/manual runs while keeping scheduled auto-sync, consider either:
- applying the same `if: github.event_name == 'schedule'` condition to the earlier, expensive steps, or
- splitting the job so only the version-sync part (with write permissions and toolchain setup) runs on schedule, and build jobs don’t depend on it for other events.

Suggested implementation:

```
  sync_repo_version:
    name: Sync Repository Version
    needs: resolve_build_context
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout branch
        if: github.event_name == 'schedule'
        uses: actions/checkout@v6.0.2
        with:
          ref: ${{ github.ref_name }}

```

Within the same `sync_repo_version` job, apply the identical condition:

```yaml
if: github.event_name == 'schedule'
```

to any other heavy setup steps such as `setup-toolchains`, `pnpm/action-setup`, or similar toolchain/package manager initialization steps. This ensures that on push/PR/manual events, those steps are skipped while the job structure and scheduled auto-sync behavior remain unchanged. No changes are needed for the later version-sync/commit steps if they are already gated on `github.event_name == 'schedule'`.
</issue_to_address>

### Comment 2
<location> `src-tauri/src/main.rs:1259` </location>
<code_context>
         .expect("error while building tauri application")
         .run(|app_handle, event| match event {
-            RunEvent::ExitRequested { .. } => {
+            RunEvent::ExitRequested { api, .. } => {
                 let state = app_handle.state::<BackendState>();
-                state.mark_quitting();
</code_context>

<issue_to_address>
**issue (complexity):** Consider simplifying the exit shutdown logic by using a single atomic flag and a single blocking task instead of multiple flags and nested async spawns.

You can simplify the exit flow by removing one atomic flag and the nested async/blocking spawn without changing the essential behaviour (non‑blocking graceful shutdown).

### 1. Drop `exit_allowed` and its methods

`exit_allowed` is only used to short‑circuit `ExitRequested` after cleanup finished; the process will exit immediately anyway after `exit(0)`. You already guard re‑entrancy with `exit_cleanup_started`, so you can keep the semantics with a single flag.

**Before:**

```rust
struct BackendState {
    // ...
    exit_cleanup_started: AtomicBool,
    exit_allowed: AtomicBool,
}

impl BackendState {
    fn is_exit_allowed(&self) -> bool {
        self.exit_allowed.load(Ordering::Relaxed)
    }

    fn try_begin_exit_cleanup(&self) -> bool {
        self.exit_cleanup_started
            .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
            .is_ok()
    }

    fn allow_exit(&self) {
        self.exit_allowed.store(true, Ordering::Relaxed);
    }
}
```

**After (single flag):**

```rust
struct BackendState {
    // ...
    exit_cleanup_started: AtomicBool,
    // exit_allowed removed
}

impl BackendState {
    fn try_begin_exit_cleanup(&self) -> bool {
        self.exit_cleanup_started
            .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
            .is_ok()
    }
    // is_exit_allowed / allow_exit removed
}
```

### 2. Linearise `ExitRequested` and remove nested spawn

You can handle graceful shutdown with a single `spawn_blocking` call that runs `stop_backend()` and then exits, and use `exit_cleanup_started` to avoid re‑entrancy. No extra async layer or `exit_allowed` check is needed.

**Before:**

```rust
RunEvent::ExitRequested { api, .. } => {
    let state = app_handle.state::<BackendState>();
    if state.is_exit_allowed() {
        return;
    }

    api.prevent_exit();
    state.mark_quitting();
    if !state.try_begin_exit_cleanup() {
        append_desktop_log("exit requested while backend cleanup is already running");
        return;
    }

    append_desktop_log("exit requested, stopping backend asynchronously");
    let app_handle_cloned = app_handle.clone();
    tauri::async_runtime::spawn(async move {
        let worker_handle = app_handle_cloned.clone();
        let stop_result = tauri::async_runtime::spawn_blocking(move || {
            let state = worker_handle.state::<BackendState>();
            state.stop_backend()
        })
        .await;

        match stop_result {
            Ok(Ok(())) => {}
            Ok(Err(error)) => append_desktop_log(&format!(
                "backend graceful stop on ExitRequested failed: {error}"
            )),
            Err(error) => append_desktop_log(&format!(
                "backend graceful stop task failed on ExitRequested: {error}"
            )),
        }

        let state = app_handle_cloned.state::<BackendState>();
        state.allow_exit();
        append_desktop_log("backend stop finished, exiting desktop process");
        app_handle_cloned.exit(0);
    });
}
```

**After (simpler control flow):**

```rust
RunEvent::ExitRequested { api, .. } => {
    let state = app_handle.state::<BackendState>();

    api.prevent_exit();
    state.mark_quitting();

    if !state.try_begin_exit_cleanup() {
        append_desktop_log("exit requested while backend cleanup is already running");
        return;
    }

    append_desktop_log("exit requested, stopping backend asynchronously");
    let app_handle_cloned = app_handle.clone();

    tauri::async_runtime::spawn_blocking(move || {
        let state = app_handle_cloned.state::<BackendState>();
        if let Err(error) = state.stop_backend() {
            append_desktop_log(&format!(
                "backend graceful stop on ExitRequested failed: {error}"
            ));
        }
        append_desktop_log("backend stop finished, exiting desktop process");
        app_handle_cloned.exit(0);
    });
}
```

`RunEvent::Exit` can remain a no‑op, since all exits go through this cleanup + `exit(0)` path.

This keeps the async, non‑blocking shutdown behaviour, still prevents multiple concurrent cleanups, but reduces the number of atomics and makes the control flow much easier to follow.
</issue_to_address>

Sourcery 对开源项目免费——如果你觉得我们的 Review 有帮助,请考虑分享一下 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据反馈改进 Review 质量。
Original comment in English

Hey - I've found 2 issues, and left some high level feedback:

  • Consider whether Ordering::Relaxed is sufficient for the new exit_cleanup_started / exit_allowed flags, or if clearer memory ordering (e.g. Acquire/Release) would make the concurrent exit protocol easier to reason about and less prone to subtle races across threads.
  • The new async exit flow in RunEvent::ExitRequested spawns an async task and then a nested spawn_blocking; you could simplify this by only using spawn_blocking (or a single async task) to reduce layering and make the shutdown path easier to trace.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider whether `Ordering::Relaxed` is sufficient for the new `exit_cleanup_started` / `exit_allowed` flags, or if clearer memory ordering (e.g. `Acquire/Release`) would make the concurrent exit protocol easier to reason about and less prone to subtle races across threads.
- The new async exit flow in `RunEvent::ExitRequested` spawns an async task and then a nested `spawn_blocking`; you could simplify this by only using `spawn_blocking` (or a single async task) to reduce layering and make the shutdown path easier to trace.

## Individual Comments

### Comment 1
<location> `.github/workflows/build-desktop-tauri.yml:130-139` </location>
<code_context>
+  sync_repo_version:
</code_context>

<issue_to_address>
**suggestion (performance):** The `sync_repo_version` job currently does relatively heavy work on all events, not just scheduled ones.

Because `sync_repo_version` is in `needs` for all build jobs, its initial steps (`checkout`, `setup-toolchains`, `pnpm/action-setup`) run on every event type, even though only the later version-sync/commit steps are gated on `github.event_name == 'schedule'`.

To avoid unnecessary CI work on push/PR/manual runs while keeping scheduled auto-sync, consider either:
- applying the same `if: github.event_name == 'schedule'` condition to the earlier, expensive steps, or
- splitting the job so only the version-sync part (with write permissions and toolchain setup) runs on schedule, and build jobs don’t depend on it for other events.

Suggested implementation:

```
  sync_repo_version:
    name: Sync Repository Version
    needs: resolve_build_context
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout branch
        if: github.event_name == 'schedule'
        uses: actions/checkout@v6.0.2
        with:
          ref: ${{ github.ref_name }}

```

Within the same `sync_repo_version` job, apply the identical condition:

```yaml
if: github.event_name == 'schedule'
```

to any other heavy setup steps such as `setup-toolchains`, `pnpm/action-setup`, or similar toolchain/package manager initialization steps. This ensures that on push/PR/manual events, those steps are skipped while the job structure and scheduled auto-sync behavior remain unchanged. No changes are needed for the later version-sync/commit steps if they are already gated on `github.event_name == 'schedule'`.
</issue_to_address>

### Comment 2
<location> `src-tauri/src/main.rs:1259` </location>
<code_context>
         .expect("error while building tauri application")
         .run(|app_handle, event| match event {
-            RunEvent::ExitRequested { .. } => {
+            RunEvent::ExitRequested { api, .. } => {
                 let state = app_handle.state::<BackendState>();
-                state.mark_quitting();
</code_context>

<issue_to_address>
**issue (complexity):** Consider simplifying the exit shutdown logic by using a single atomic flag and a single blocking task instead of multiple flags and nested async spawns.

You can simplify the exit flow by removing one atomic flag and the nested async/blocking spawn without changing the essential behaviour (non‑blocking graceful shutdown).

### 1. Drop `exit_allowed` and its methods

`exit_allowed` is only used to short‑circuit `ExitRequested` after cleanup finished; the process will exit immediately anyway after `exit(0)`. You already guard re‑entrancy with `exit_cleanup_started`, so you can keep the semantics with a single flag.

**Before:**

```rust
struct BackendState {
    // ...
    exit_cleanup_started: AtomicBool,
    exit_allowed: AtomicBool,
}

impl BackendState {
    fn is_exit_allowed(&self) -> bool {
        self.exit_allowed.load(Ordering::Relaxed)
    }

    fn try_begin_exit_cleanup(&self) -> bool {
        self.exit_cleanup_started
            .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
            .is_ok()
    }

    fn allow_exit(&self) {
        self.exit_allowed.store(true, Ordering::Relaxed);
    }
}
```

**After (single flag):**

```rust
struct BackendState {
    // ...
    exit_cleanup_started: AtomicBool,
    // exit_allowed removed
}

impl BackendState {
    fn try_begin_exit_cleanup(&self) -> bool {
        self.exit_cleanup_started
            .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
            .is_ok()
    }
    // is_exit_allowed / allow_exit removed
}
```

### 2. Linearise `ExitRequested` and remove nested spawn

You can handle graceful shutdown with a single `spawn_blocking` call that runs `stop_backend()` and then exits, and use `exit_cleanup_started` to avoid re‑entrancy. No extra async layer or `exit_allowed` check is needed.

**Before:**

```rust
RunEvent::ExitRequested { api, .. } => {
    let state = app_handle.state::<BackendState>();
    if state.is_exit_allowed() {
        return;
    }

    api.prevent_exit();
    state.mark_quitting();
    if !state.try_begin_exit_cleanup() {
        append_desktop_log("exit requested while backend cleanup is already running");
        return;
    }

    append_desktop_log("exit requested, stopping backend asynchronously");
    let app_handle_cloned = app_handle.clone();
    tauri::async_runtime::spawn(async move {
        let worker_handle = app_handle_cloned.clone();
        let stop_result = tauri::async_runtime::spawn_blocking(move || {
            let state = worker_handle.state::<BackendState>();
            state.stop_backend()
        })
        .await;

        match stop_result {
            Ok(Ok(())) => {}
            Ok(Err(error)) => append_desktop_log(&format!(
                "backend graceful stop on ExitRequested failed: {error}"
            )),
            Err(error) => append_desktop_log(&format!(
                "backend graceful stop task failed on ExitRequested: {error}"
            )),
        }

        let state = app_handle_cloned.state::<BackendState>();
        state.allow_exit();
        append_desktop_log("backend stop finished, exiting desktop process");
        app_handle_cloned.exit(0);
    });
}
```

**After (simpler control flow):**

```rust
RunEvent::ExitRequested { api, .. } => {
    let state = app_handle.state::<BackendState>();

    api.prevent_exit();
    state.mark_quitting();

    if !state.try_begin_exit_cleanup() {
        append_desktop_log("exit requested while backend cleanup is already running");
        return;
    }

    append_desktop_log("exit requested, stopping backend asynchronously");
    let app_handle_cloned = app_handle.clone();

    tauri::async_runtime::spawn_blocking(move || {
        let state = app_handle_cloned.state::<BackendState>();
        if let Err(error) = state.stop_backend() {
            append_desktop_log(&format!(
                "backend graceful stop on ExitRequested failed: {error}"
            ));
        }
        append_desktop_log("backend stop finished, exiting desktop process");
        app_handle_cloned.exit(0);
    });
}
```

`RunEvent::Exit` can remain a no‑op, since all exits go through this cleanup + `exit(0)` path.

This keeps the async, non‑blocking shutdown behaviour, still prevents multiple concurrent cleanups, but reduces the number of atomics and makes the control flow much easier to follow.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread .github/workflows/build-desktop-tauri.yml
Comment thread src-tauri/src/main.rs
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@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 - 我在这里给了一些总体反馈:

  • sync_repo_version 这个 job 里,push 命令使用的是 HEAD:${GITHUB_REF_NAME},但在 Actions 中只提供了 github.ref_name;建议改成 HEAD:${{ github.ref_name }},或者显式导出这个变量,以避免 push 到一个为空或命名错误的 ref。
  • 新增的 exit_cleanup_started 标志和 try_begin_exit_cleanup 对防止重复关闭很有帮助,不过你可能需要在 RunEvent::ExitRequested 附近加一个简短的注释,说明在这里将 prevent_exit()spawn_blocking 一起使用是安全的原因,因为对于后续维护者来说,异步运行时关闭与进程退出的交互可能比较微妙。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- In the `sync_repo_version` job, the push command uses `HEAD:${GITHUB_REF_NAME}`, but only `github.ref_name` is provided by Actions; consider switching this to `HEAD:${{ github.ref_name }}` or exporting it explicitly to avoid pushing to an empty/misnamed ref.
- The new `exit_cleanup_started` flag and `try_begin_exit_cleanup` are a good guard against duplicate shutdown, but you might want to add a brief comment near `RunEvent::ExitRequested` explaining why `prevent_exit()` + `spawn_blocking` is safe here, since mixing async runtime shutdown and process exit can be subtle for future maintainers.

Sourcery 对开源项目是免费的——如果你觉得我们的代码评审有帮助,欢迎分享 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • In the sync_repo_version job, the push command uses HEAD:${GITHUB_REF_NAME}, but only github.ref_name is provided by Actions; consider switching this to HEAD:${{ github.ref_name }} or exporting it explicitly to avoid pushing to an empty/misnamed ref.
  • The new exit_cleanup_started flag and try_begin_exit_cleanup are a good guard against duplicate shutdown, but you might want to add a brief comment near RunEvent::ExitRequested explaining why prevent_exit() + spawn_blocking is safe here, since mixing async runtime shutdown and process exit can be subtle for future maintainers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the `sync_repo_version` job, the push command uses `HEAD:${GITHUB_REF_NAME}`, but only `github.ref_name` is provided by Actions; consider switching this to `HEAD:${{ github.ref_name }}` or exporting it explicitly to avoid pushing to an empty/misnamed ref.
- The new `exit_cleanup_started` flag and `try_begin_exit_cleanup` are a good guard against duplicate shutdown, but you might want to add a brief comment near `RunEvent::ExitRequested` explaining why `prevent_exit()` + `spawn_blocking` is safe here, since mixing async runtime shutdown and process exit can be subtle for future maintainers.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@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 - 我发现了 1 个问题

给 AI Agent 的提示
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src-tauri/src/main.rs:1274` </location>
<code_context>
+                    app_handle_cloned.exit(0);
+                });
             }
+            RunEvent::Exit => {}
             _ => {}
         });
</code_context>

<issue_to_address>
**question:** 移除 `RunEvent::Exit` 中关闭后端的路径会改变现有行为;请确认对所有退出来源来说,这都是有意而为。

此更改让 `RunEvent::Exit` 从之前调用 `state.stop_backend()`,变成现在什么都不做。尽管 `ExitRequested` + `prevent_exit()` 可能已经覆盖了正常的用户退出场景,但 `Exit` 仍然可能由其他来源触发(例如 `app_handle.exit` 或平台事件)。如果有调用方在未经过 `ExitRequested` 的情况下直接调用 `app_handle.exit`,后端清理就会被跳过。建议要么在 `Exit` 分支中保留一次 `stop_backend()` 调用作为安全兜底,要么明确保证/文档化所有相关退出在调用 `exit` 前都会先经过 `ExitRequested`。
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得我们的评论有帮助,欢迎分享给他人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've found 1 issue

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

## Individual Comments

### Comment 1
<location> `src-tauri/src/main.rs:1274` </location>
<code_context>
+                    app_handle_cloned.exit(0);
+                });
             }
+            RunEvent::Exit => {}
             _ => {}
         });
</code_context>

<issue_to_address>
**question:** Dropping the `RunEvent::Exit` backend shutdown path changes existing behavior; ensure this is intentional for all exit sources.

This change makes `RunEvent::Exit` do nothing where it previously called `state.stop_backend()`. While `ExitRequested` + `prevent_exit()` may cover normal user exits, `Exit` can still occur from other sources (e.g., `app_handle.exit` or platform events). If any callers invoke `app_handle.exit` without going through `ExitRequested`, backend cleanup will be skipped. Consider either keeping a `stop_backend()` call in the `Exit` arm as a safety net, or explicitly guaranteeing/documenting that all relevant exits flow through `ExitRequested` before `exit` is called.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src-tauri/src/main.rs Outdated
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@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 - 我发现了 3 个问题,并给出了一些整体性的反馈:

  • scripts/prepare-resources.mjs 中,即使提供了 ASTRBOT_DESKTOP_VERSION 且版本可以在不克隆仓库的情况下解析成功,ensureSourceRepo(sourceDir) 仍然会被调用;如果你的意图是在 CI 等场景下避免访问上游仓库,可以考虑在存在桌面版本覆盖且 mode === 'version' 时(或者更一般地,在不需要上游仓库时)跳过调用 ensureSourceRepo
  • build-desktop-tauri.yml 里的 sync_repo_version 任务在每个步骤上都重复了条件 if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }};你可以把这个条件挪到 job 级别(并继续把它作为一个独立 job 仅用于依赖顺序),以减少重复、让控制流更易于理解。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `scripts/prepare-resources.mjs`, `ensureSourceRepo(sourceDir)` is still called even when `ASTRBOT_DESKTOP_VERSION` is provided and the version can be resolved without cloning; if the intent is to avoid touching the upstream repo (e.g., in CI), consider skipping `ensureSourceRepo` when a desktop version override is present and `mode === 'version'` or in general when the source repo is not needed.
- The `sync_repo_version` job in `build-desktop-tauri.yml` repeats the `if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}` condition on every step; you could move this condition to the job level (and keep it as a separate job purely for dependency ordering) to reduce duplication and make the control flow easier to follow.

## Individual Comments

### Comment 1
<location> `.github/workflows/build-desktop-tauri.yml:130-139` </location>
<code_context>
+  sync_repo_version:
</code_context>

<issue_to_address>
**suggestion:** `sync_repo_version` pushes directly to the current branch; consider handling push races or protected-branch failures more defensively.

Because this job commits and pushes directly to `HEAD:${TARGET_REF_NAME}`, scheduled runs can fail if a new commit lands between checkout and push or if branch protections/status checks block the push. Consider rebasing before push (e.g., `git pull --rebase origin "${TARGET_REF_NAME}"` and handling failures gracefully) and/or constraining when this job runs so that branch protections don’t cause noisy, non-code-related failures.

Suggested implementation:

```
  sync_repo_version:
    name: Sync Repository Version
    needs: resolve_build_context
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout branch
        if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
        uses: actions/checkout@v6.0.2
        with:
          # Fetch full history so we can rebase safely before pushing
          fetch-depth: 0

      - name: Rebase onto latest branch tip
        if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
        env:
          TARGET_REF_NAME: ${{ needs.resolve_build_context.outputs.target_ref_name || github.ref_name }}
        run: |
          set -euo pipefail

          echo "Rebasing local changes onto origin/${TARGET_REF_NAME}"

          # Ensure we have the latest remote ref
          git fetch origin "${TARGET_REF_NAME}"

          # Attempt a rebase; if this fails, we exit cleanly so the job
          # reports a real conflict/race instead of a noisy push failure.
          if ! git pull --rebase origin "${TARGET_REF_NAME}"; then
            echo "::warning::Failed to rebase onto origin/${TARGET_REF_NAME}. Another commit may have landed. Skipping push."
            # Mark the step as failed so the schedule noise is visible, but
            # leave the repo state untouched for debugging if needed.
            exit 1
          fi

```

To fully implement the defensive handling you described, the following additional changes are needed elsewhere in the `sync_repo_version` job (not visible in the snippet):

1. **Push step ordering and guard:**
   - Ensure that any `git push` or `actions/github-script` step that pushes commits runs *after* the “Rebase onto latest branch tip” step.
   - Gate the push on prior success, e.g.:
     ```yaml
     - name: Push updated version
       if: ${{ success() && needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
       run: |
         set -euo pipefail
         git push origin "HEAD:${TARGET_REF_NAME}"
     ```
   - Reuse the same `TARGET_REF_NAME` environment variable or define it at the job level to avoid duplication.

2. **TARGET_REF_NAME sourcing:**
   - The example above assumes `resolve_build_context` exposes `target_ref_name`. If it does not, either:
     - Add that output to `resolve_build_context`, or
     - Replace `${{ needs.resolve_build_context.outputs.target_ref_name || github.ref_name }}` with `${{ github.ref_name }}` (or the appropriate ref for your workflow).

3. **Branch protection handling:**
   - If branch protections or status checks can block this push, consider:
     - Restricting this job to branches that are not protected, or
     - Allowing the job to fail softly when `git push` is rejected:
       ```bash
       if ! git push origin "HEAD:${TARGET_REF_NAME}"; then
         echo "::warning::Push to ${TARGET_REF_NAME} was rejected (likely branch protection or status checks)."
         exit 0
       fi
       ```
     - Choose `exit 0` vs `exit 1` depending on whether you want scheduled failures to be visible or silent.

These additional changes will ensure the job rebases before pushing, handles push races more gracefully, and reduces noise from protected-branch failures.
</issue_to_address>

### Comment 2
<location> `scripts/prepare-resources.mjs:11-14` </location>
<code_context>
 const sourceRepoUrlRaw =
   process.env.ASTRBOT_SOURCE_GIT_URL?.trim() || DEFAULT_ASTRBOT_SOURCE_GIT_URL;
 const sourceRepoRefRaw = process.env.ASTRBOT_SOURCE_GIT_REF?.trim() || '';
+const desktopVersionOverride = process.env.ASTRBOT_DESKTOP_VERSION?.trim() || '';
 const PYTHON_BUILD_STANDALONE_RELEASE =
   process.env.ASTRBOT_PBS_RELEASE?.trim() || '20260211';
</code_context>

<issue_to_address>
**question (bug_risk):** `ASTRBOT_DESKTOP_VERSION` overrides only the synced version files but not necessarily the actual upstream source version; ensure this divergence is intentional.

Because `desktopVersionOverride` only affects the stamped desktop version, but `ensureSourceRepo(sourceDir)` may reuse an existing checkout, you can end up with version files set to `${ASTRBOT_DESKTOP_VERSION}` while the embedded AstrBot runtime still comes from an older `pyproject.toml` version.

If you need the runtime to strictly match the stamped desktop version, consider either:
- Binding `ASTRBOT_DESKTOP_VERSION` to a specific upstream ref and forcing a refresh of `sourceDir`, or
- Emitting a clear log when the override differs from the version resolved from `pyproject.toml`, so drift is visible in CI/logs.
</issue_to_address>

### Comment 3
<location> `README.md:141` </location>
<code_context>
+- `make sync-version`:从当前解析到的 AstrBot 源同步版本,受本地环境变量影响(例如 `ASTRBOT_SOURCE_DIR`)。
+- `make update`:用于“对齐上游”,会忽略 `ASTRBOT_SOURCE_DIR`,并使用 `ASTRBOT_SOURCE_GIT_URL` + `ASTRBOT_SOURCE_GIT_REF` 同步版本。
+
+推荐日常使用 `make update`,避免本地切分支导致版本漂移。
+
+示例:
</code_context>

<issue_to_address>
**nitpick (typo):** Consider using “切换分支” instead of “切分支” for clearer, more standard wording.

This is particularly helpful in written documentation, where more formal phrasing improves clarity and consistency.

```suggestion
推荐日常使用 `make update`,避免本地切换分支导致版本漂移。
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Original comment in English

Hey - I've found 3 issues, and left some high level feedback:

  • In scripts/prepare-resources.mjs, ensureSourceRepo(sourceDir) is still called even when ASTRBOT_DESKTOP_VERSION is provided and the version can be resolved without cloning; if the intent is to avoid touching the upstream repo (e.g., in CI), consider skipping ensureSourceRepo when a desktop version override is present and mode === 'version' or in general when the source repo is not needed.
  • The sync_repo_version job in build-desktop-tauri.yml repeats the if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }} condition on every step; you could move this condition to the job level (and keep it as a separate job purely for dependency ordering) to reduce duplication and make the control flow easier to follow.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `scripts/prepare-resources.mjs`, `ensureSourceRepo(sourceDir)` is still called even when `ASTRBOT_DESKTOP_VERSION` is provided and the version can be resolved without cloning; if the intent is to avoid touching the upstream repo (e.g., in CI), consider skipping `ensureSourceRepo` when a desktop version override is present and `mode === 'version'` or in general when the source repo is not needed.
- The `sync_repo_version` job in `build-desktop-tauri.yml` repeats the `if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}` condition on every step; you could move this condition to the job level (and keep it as a separate job purely for dependency ordering) to reduce duplication and make the control flow easier to follow.

## Individual Comments

### Comment 1
<location> `.github/workflows/build-desktop-tauri.yml:130-139` </location>
<code_context>
+  sync_repo_version:
</code_context>

<issue_to_address>
**suggestion:** `sync_repo_version` pushes directly to the current branch; consider handling push races or protected-branch failures more defensively.

Because this job commits and pushes directly to `HEAD:${TARGET_REF_NAME}`, scheduled runs can fail if a new commit lands between checkout and push or if branch protections/status checks block the push. Consider rebasing before push (e.g., `git pull --rebase origin "${TARGET_REF_NAME}"` and handling failures gracefully) and/or constraining when this job runs so that branch protections don’t cause noisy, non-code-related failures.

Suggested implementation:

```
  sync_repo_version:
    name: Sync Repository Version
    needs: resolve_build_context
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout branch
        if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
        uses: actions/checkout@v6.0.2
        with:
          # Fetch full history so we can rebase safely before pushing
          fetch-depth: 0

      - name: Rebase onto latest branch tip
        if: ${{ needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
        env:
          TARGET_REF_NAME: ${{ needs.resolve_build_context.outputs.target_ref_name || github.ref_name }}
        run: |
          set -euo pipefail

          echo "Rebasing local changes onto origin/${TARGET_REF_NAME}"

          # Ensure we have the latest remote ref
          git fetch origin "${TARGET_REF_NAME}"

          # Attempt a rebase; if this fails, we exit cleanly so the job
          # reports a real conflict/race instead of a noisy push failure.
          if ! git pull --rebase origin "${TARGET_REF_NAME}"; then
            echo "::warning::Failed to rebase onto origin/${TARGET_REF_NAME}. Another commit may have landed. Skipping push."
            # Mark the step as failed so the schedule noise is visible, but
            # leave the repo state untouched for debugging if needed.
            exit 1
          fi

```

To fully implement the defensive handling you described, the following additional changes are needed elsewhere in the `sync_repo_version` job (not visible in the snippet):

1. **Push step ordering and guard:**
   - Ensure that any `git push` or `actions/github-script` step that pushes commits runs *after* the “Rebase onto latest branch tip” step.
   - Gate the push on prior success, e.g.:
     ```yaml
     - name: Push updated version
       if: ${{ success() && needs.resolve_build_context.outputs.should_build == 'true' && github.event_name == 'schedule' }}
       run: |
         set -euo pipefail
         git push origin "HEAD:${TARGET_REF_NAME}"
     ```
   - Reuse the same `TARGET_REF_NAME` environment variable or define it at the job level to avoid duplication.

2. **TARGET_REF_NAME sourcing:**
   - The example above assumes `resolve_build_context` exposes `target_ref_name`. If it does not, either:
     - Add that output to `resolve_build_context`, or
     - Replace `${{ needs.resolve_build_context.outputs.target_ref_name || github.ref_name }}` with `${{ github.ref_name }}` (or the appropriate ref for your workflow).

3. **Branch protection handling:**
   - If branch protections or status checks can block this push, consider:
     - Restricting this job to branches that are not protected, or
     - Allowing the job to fail softly when `git push` is rejected:
       ```bash
       if ! git push origin "HEAD:${TARGET_REF_NAME}"; then
         echo "::warning::Push to ${TARGET_REF_NAME} was rejected (likely branch protection or status checks)."
         exit 0
       fi
       ```
     - Choose `exit 0` vs `exit 1` depending on whether you want scheduled failures to be visible or silent.

These additional changes will ensure the job rebases before pushing, handles push races more gracefully, and reduces noise from protected-branch failures.
</issue_to_address>

### Comment 2
<location> `scripts/prepare-resources.mjs:11-14` </location>
<code_context>
 const sourceRepoUrlRaw =
   process.env.ASTRBOT_SOURCE_GIT_URL?.trim() || DEFAULT_ASTRBOT_SOURCE_GIT_URL;
 const sourceRepoRefRaw = process.env.ASTRBOT_SOURCE_GIT_REF?.trim() || '';
+const desktopVersionOverride = process.env.ASTRBOT_DESKTOP_VERSION?.trim() || '';
 const PYTHON_BUILD_STANDALONE_RELEASE =
   process.env.ASTRBOT_PBS_RELEASE?.trim() || '20260211';
</code_context>

<issue_to_address>
**question (bug_risk):** `ASTRBOT_DESKTOP_VERSION` overrides only the synced version files but not necessarily the actual upstream source version; ensure this divergence is intentional.

Because `desktopVersionOverride` only affects the stamped desktop version, but `ensureSourceRepo(sourceDir)` may reuse an existing checkout, you can end up with version files set to `${ASTRBOT_DESKTOP_VERSION}` while the embedded AstrBot runtime still comes from an older `pyproject.toml` version.

If you need the runtime to strictly match the stamped desktop version, consider either:
- Binding `ASTRBOT_DESKTOP_VERSION` to a specific upstream ref and forcing a refresh of `sourceDir`, or
- Emitting a clear log when the override differs from the version resolved from `pyproject.toml`, so drift is visible in CI/logs.
</issue_to_address>

### Comment 3
<location> `README.md:141` </location>
<code_context>
+- `make sync-version`:从当前解析到的 AstrBot 源同步版本,受本地环境变量影响(例如 `ASTRBOT_SOURCE_DIR`)。
+- `make update`:用于“对齐上游”,会忽略 `ASTRBOT_SOURCE_DIR`,并使用 `ASTRBOT_SOURCE_GIT_URL` + `ASTRBOT_SOURCE_GIT_REF` 同步版本。
+
+推荐日常使用 `make update`,避免本地切分支导致版本漂移。
+
+示例:
</code_context>

<issue_to_address>
**nitpick (typo):** Consider using “切换分支” instead of “切分支” for clearer, more standard wording.

This is particularly helpful in written documentation, where more formal phrasing improves clarity and consistency.

```suggestion
推荐日常使用 `make update`,避免本地切换分支导致版本漂移。
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread .github/workflows/build-desktop-tauri.yml
Comment thread scripts/prepare-resources.mjs
Comment thread README.md Outdated
@zouyonghe

Copy link
Copy Markdown
Member Author

@sourcery-ai review

@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 - 我已经审查了你的更改,看起来很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,请考虑分享 ✨
帮我变得更有用吧!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进评审质量。
Original comment in English

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 ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zouyonghe zouyonghe merged commit bbfb06d into AstrBotDevs:main Feb 20, 2026
4 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.

1 participant