Skip to content

fix(launcher): don't block updates on detached or foreign-install Desktop records - #1314

Merged
iruriQ merged 1 commit into
mainfrom
fix/update-foreign-desktop-scope
Nov 27, 2026
Merged

iruriQ merged 1 commit into
mainfrom
fix/update-foreign-desktop-scope

Conversation

@iruriQ

@iruriQ iruriQ commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes automatic updates failing with Desktop belongs to a different CODEXHOST_DATA_DIR; no GUI action taken (or Desktop is still running without its Launcher; orphan cleanup refused) when an unrelated external Desktop GUI (Codex.app / ChatGPT.app) remains open from another CODEXHOST_DATA_DIR or a detached previous session.

Root Cause

On Unix, the Desktop lifecycle owner record (desktop-lifecycle-v1/owner.json) is stored per-user across all CODEXHOST_DATA_DIR instances. When an isolated test (or earlier dev run) launched an official Desktop GUI under a different CODEXHOST_DATA_DIR and its launcher / controller exited while the external GUI process stayed alive, owner.ended() remained false. Subsequent updates for the primary CODEXHOST_DATA_DIR called running_for_update() and stop_managed(), which unconditionally ran Owner::check_scope() and aborted the entire update.

Changes

  • crates/launcher/src/desktop_lifecycle.rs:
    • Added Owner::managed_ended, Owner::belongs_to_data, Owner::ignored_for_update_scope, and is_current_installation.
    • In running_for_update_at and stop_managed_at, ignore non-ended owner.json records (returning Ok(false) without touching the external GUI or removing owner.json) when either:
      1. all codexhost-managed processes (launcher, controller, and control listener) have already exited, or
      2. the owner belongs to both a different CODEXHOST_DATA_DIR and a different installation executable.
    • Preserved strict refusal when the same installation has an active launcher/controller on another CODEXHOST_DATA_DIR, or when another installation has an active launcher/controller on the same CODEXHOST_DATA_DIR, and included the conflicting CODEXHOST_DATA_DIR and launcher PID in the scope error message.
    • Kept Lifecycle::reconcile and Lifecycle::attachment strict scope checks intact for direct Desktop takeover/launch.
  • crates/launcher/src/desktop_lifecycle_tests.rs:
    • Added 5 regression tests covering foreign detached Desktop, active foreign-install Desktop, active same-install foreign-data Desktop (still rejected with directory + PID details), same-data detached Desktop, and same-data foreign-install active Desktop (still rejected).

Validation

  • cargo test -p codexhost-launcher desktop_lifecycle (8 passed, 0 failed, 1 ignored release-bundle test)
  • cargo test -p codexhost-launcher service_update (2 passed, 0 failed)
  • cargo fmt -p codexhost-launcher -- --check (passed)
  • cargo clippy -p codexhost-launcher --tests -- -D warnings (passed)

No visual changes: Rust launcher lifecycle/update logic only.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 问题修复
    • 更新或停止操作不再处理已完全退出的桌面实例,避免影响残留记录。
    • 活动实例的数据目录与安装位置不匹配时,将按适用范围处理;拒绝操作时会提供更清晰的目录和进程信息。

桌面生命周期逻辑新增更新作用域判断。更新和停止操作会根据实例状态、数据目录及 Launcher 安装路径决定是否继续处理。新增测试覆盖忽略和拒绝场景。

Changes: 桌面生命周期作用域

Layer / File(s) Summary
Owner 作用域与安装判断
crates/launcher/src/desktop_lifecycle.rs
Owner 根据受管理进程状态、数据目录和 Launcher 安装路径判断是否忽略更新作用域检查。目录不匹配错误现在包含数据目录和 Launcher PID。
更新与停止操作的作用域门控
crates/launcher/src/desktop_lifecycle.rs, crates/launcher/src/desktop_lifecycle_tests.rs
running_for_update 和 stop_managed 委托给可指定 descriptor 路径的内部函数,并在后续检查前读取 Owner。新增测试覆盖忽略和拒绝场景,并验证相关记录、进程、端口和错误信息。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: bytepioneer-ai

Merge Risk: Minimal · up to 11adc

Automatic updates are no longer blocked by unrelated Desktop GUI processes from another data directory or by detached sessions. Strict refusal is kept where the same installation is active under another data directory, or another installation is active under the same data directory. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题描述了本次变更的主要内容:更新流程不再因分离的或其他安装来源的 Desktop 记录而被阻塞。变更摘要显示 running_for_update 和 stop_managed 会忽略这类非结束的 owner 记录,与标题一致。标题为 81 个字符、10 个词,长度可接受。
Description check Passed 描述说明了问题原因(owner.json 按用户共享,外部 Desktop GUI 残留导致更新失败)、具体代码改动(新增 managed_ended、belongs_to_data、ignored_for_update_scope 等,并调整 running_for_update_at 和 stop_managed_at),以及新增的 5 个回归测试和验证命令。与变更集高度相关。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cec2495 and 11adc32.

Files selected for processing: 2

  • crates/launcher/src/desktop_lifecycle.rs
  • crates/launcher/src/desktop_lifecycle_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Recent review details

Context from checks skipped due to timeout: 8

  • GitHub Check: CodeRabbit
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Web Host tests
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check windows-latest
  • GitHub Check: Vitest
  • GitHub Check: Check macos-26
  • GitHub Check: Static checks
Additional context used

Code guidelines: 1

CLAUDE.md — auto-discovered
Path-based instructions: 1

Source excerpt: Rust owns native launch, process management, update installation, and platform integration.

CodeRabbit inference engine (CLAUDE.md)

Files:

  • crates/launcher/src/desktop_lifecycle.rs
  • crates/launcher/src/desktop_lifecycle_tests.rs
Additional comments: 1

crates/launcher/src/desktop_lifecycle.rs: 1

454-454: Data Integrity & Integration

Ignored owner records can hide an active Launcher on Windows.

On Unix, the managed launch replaces the owner record before it writes the descriptor, and reconcile refuses or stops any non-ended owner. The reported state, with a stale owner from another installation beside an active current-installation descriptor, does not arise on that path.

On Windows, the attachment branch acquires the launcher guard without reading the owner record. publish_runtime_descriptor at crates/launcher/src/main.rs:1120 then writes the descriptor. If that path runs while a non-ended owner from another data directory and installation remains on disk, the new gate in running_for_update_at and stop_managed_at returns before the generation check and can report the Desktop as not running. The enclosing function and its platform gate at main.rs:1120 are needed to decide whether that path can run in that state.

@iruriQ
iruriQ merged commit bde978a into main Nov 27, 2026
5 of 8 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.

2 participants