Skip to content

fix(companion): stop owned gateway during desktop exit - #212

Merged
Telli merged 1 commit into
mainfrom
codex/companion-shutdown-release
Sep 10, 2026
Merged

Telli merged 1 commit into
mainfrom
codex/companion-shutdown-release

Conversation

@Telli

@Telli Telli commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

The v0.2.0 desktop smoke reproduced an orphaned gateway: closing Companion exited the parent, but the owned gateway stayed alive on 127.0.0.1:18789 with PPID 1. The desktop Exit event does not await its async handler, so awaiting WebSocket disposal could prevent managed-process cleanup from running.

Stop the owned gateway synchronously before the handler reaches its first await. The existing bounded synchronous disposal also kills child processes. This keeps connection cleanup asynchronous while guaranteeing owned-process cleanup is attempted during shutdown.

Validation: the packaged pre-fix binary reproduced the failure during setup/start/restart/close testing. The locally published fixed candidate passed the same process-level check: it auto-started and connected, then closing the window exited both Companion PID 7938 and owned gateway PID 8138 and freed port 18789. The final release bundle will receive the same check before publication. The v0.2.0 release remains a draft until this passes.

Copilot AI lite review requested due to automatic review settings September 9, 2026 23:59
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: db72c40c-7d4d-4065-aaf4-45568fdb16a4

📥 Commits

Reviewing files that changed from the base of the PR and between 6105613 and 0cae542.

📒 Files selected for processing (1)
  • src/OpenClaw.Companion/App.axaml.cs

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The desktop Exit handler now calls _managedGateway.Dispose() before awaiting _client.DisposeAsync(). The previous asynchronous gateway disposal after client cleanup was removed.

Changes

Shutdown ordering

Layer / File(s) Summary
Exit cleanup sequence
src/OpenClaw.Companion/App.axaml.cs
The Exit handler disposes the managed gateway synchronously before disposing the WebSocket client asynchronously.

Priority: ➖ Normal

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 0cae5

Desktop exit now stops the owned gateway before asynchronous WebSocket cleanup, preventing the local gateway from being left running after the application closes. No merge-blocking risk remains.

Suggested reviewers: tellikoroma

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: stopping the owned gateway during Companion desktop exit.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/companion-shutdown-release

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

Comment @coderabbitai help to get the list of available commands.

Copilot AI 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.

🟢 Approval recommended

The change is narrowly scoped, aligns with the described shutdown behavior, and uses an existing bounded synchronous disposal path to reliably stop the owned gateway before the exit handler can yield.

Pull request overview

Fixes a desktop shutdown race in OpenClaw.Companion where the owned local gateway process could be orphaned because desktop.Exit uses an async void handler and does not await post-await cleanup work.

Changes:

  • Dispose the owned ManagedGatewayService synchronously at the start of the desktop exit handler to ensure the gateway process is stopped before the handler reaches its first await.
  • Keep WebSocket client cleanup asynchronous (DisposeAsync) without blocking guaranteed owned-process cleanup.
File summaries
File Description
src/OpenClaw.Companion/App.axaml.cs Moves owned gateway shutdown to a synchronous disposal before the first await in the desktop exit handler to avoid orphaned child processes.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Telli
Telli merged commit 1d35181 into main Sep 10, 2026
19 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