Skip to content

fix(migration): close the old app reliably when moving to the Store version - #2360

Merged
bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess-flake-activation-router-shutdown
Nov 23, 2026
Merged

bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess-flake-activation-router-shutdown

Conversation

@bkudiess

@bkudiess bkudiess commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: bdbcb94fe5f009eb5b9930678144bc546e807d7c

Dimension Assessment Rationale
Change confidence 9/10 ↑ Each part of the fix has its own RED: without the wait, both new tests fail; without CancelIoEx, the timed-out request is still delivered.
↑ Soak 20/20 (screenshots 0 and 1, 6 runs under CPU contention) covering all 43 ActivationRouterTests.
↑ Full Tray 6,941 passed; Shared 5,972 passed, 0 failed; build.ps1 passed.
↑ Dual-model review (Opus, GPT) over 3 rounds ended with no MEDIUM+ findings.
↓ A real Inno-to-Store migration against an installed older app was not run; the proof uses real named pipes in one process.
↑ CI run 45271264350 passed on the first attempt; all checks green on current main.
Diagnosis confidence 9.5/10 ↑ Holding the receiver for 500 ms before accept reproduced the CI stack (TaskCanceledException at line 37 after the sender returned true).
↑ The receiver logged IOException 0x800700E8: The pipe is being closed (ERROR_NO_DATA), so the request was dropped at accept.
Evidence fit 9/10 ↑ Every recorded failure has this exact signature: the sender reports success, then the callback never arrives, only in full parallel Tray runs, passing when run alone (CI run 39489552662 and five local full runs between 10-21 and 11-23).
↑ Other causes were ruled out: pipe names are unique, the sender connected to this listener, and a read after accept cannot lose buffered data.
↓ No receiver log was captured from the failing runs themselves.

What Problem This Solves

When the Store version of Companion replaces an older installed (Inno) Companion, it asks the old app to exit over a local pipe. If the old app was just about to accept the connection, the request could be silently dropped while the new app believed it had been delivered. The migration then waited 10 seconds and asked the user to close the old app manually. The same race made ActivationRouterTests.MigrationShutdown_UsesCurrentUserIpcWithoutCreatingADeepLinkRoute time out in full Tray runs.

User Impact

User impact: moving from the old installer to the Store version now closes the old app automatically, instead of occasionally stalling and asking for a manual close and Retry.

Why This Change Was Made

A client can connect to a new pipe instance before the receiver accepts it. The sender used to write and close immediately. If it closed first, the receiver's accept failed with ERROR_NO_DATA and the request was lost.

The sender now waits until the receiver has read the request, as deep-link forwarding in the same file already does. This change is sender-only, so it works with old apps that are already installed.

The wait runs on its own thread and has a named 5 s receive budget. The existing 2 s connect budget is unchanged. On timeout, the sender cancels the blocked wait (CancelIoEx) and lets it end before returning false. This guarantees a timed-out request is withdrawn rather than delivered after the manual-close fallback appears.

Two internal test seams (before-accept on the receiver, after-write on the sender) let the tests hold the race window open deterministically.

Flake class: 10 (product race). Sibling sweep: ForwardToPrimaryAsync already waits for the receiver to read. No other NamedPipeClientStream sender exists in src.

Evidence

  • RED, CI stack reproduced. On main 72a67f35, a temporary 500 ms hold before the receiver's accept reproduced the failure:
    • MigrationShutdown_UsesCurrentUserIpcWithoutCreatingADeepLinkRoute failed with TaskCanceledException at ActivationRouterTests.cs:line 37;
    • the receiver logged IOException 0x800700E8: The pipe is being closed.
  • GREEN. With the fix and the same hold, the test passes in 1 s.
  • Regression tests, each with its own RED, using temporary toggles in one build:
    • MigrationShutdown_SenderKeepsRequestUntilReceiverAcceptsIt fails without the wait: the sender finished before accept.
    • MigrationShutdown_TimedOutRequestIsWithdrawnBeforeTheReceiverAccepts fails without the wait, and also fails without CancelIoEx: the stale request was delivered after false.
    • The full fix passes 5/5.
  • Soak. The CI soak (Invoke-CiTestSoak.ps1, under the shared desktop lock) passed 10/10 with OPENCLAW_GATEWAY_FIXTURE_SCREENSHOTS=0 and 10/10 with =1, 3 runs each under CPU contention, 43 tests per run.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

  • none: the change is confined to the same-user named-pipe sender. It is proven with real pipes in managed tests and doesn't depend on a custom host class. An end-to-end Inno-to-Store migration (windows-clean-installer-upgrade) would add confidence but was not run; see Not verified.

Validation

All local runs were at bdbcb94fe, on base 72a67f35, with isolated OPENCLAW_TRAY_* directories.

Check Result
./build.ps1 ✅ exit 0 (Cli, WinNodeCli, SetupEngine, Shared, WinUI)
dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj ✅ 5,972 passed, 29 skipped (opt-in), 0 failed
dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore ✅ 6,941 passed, 0 failed
dotnet test ... --filter ActivationRouterTests.MigrationShutdown ✅ 5/5 passed, with the RED variants listed above
scripts/Invoke-CiTestSoak.ps1, screenshots 0 and 1 ✅ 20/20 runs, 6 under contention
pwsh -NoProfile -File ./scripts/validate-test-timing-patterns.ps1 ✅ passed; one marked test-timing-exception for the bounded sender-hold window
git diff --check ✅ clean
Dual-model review (Claude Opus 5.5, GPT-6 Astra) ✅ no MEDIUM+ after 3 rounds; see below
Review findings fixed in this PR
  • Timeout didn't cancel the blocked wait (MEDIUM, both reviewers). A late delivery could follow a false result. Fixed with CancelIoEx plus a bounded wait for the drain to end; covered by the withdrawal test.
  • Blocking wait on the shared thread pool (LOW). It now runs on a dedicated LongRunning thread.
  • The hold test didn't anchor its window (LOW and MEDIUM). It now waits for the sender's after-write checkpoint and asserts that the sender is still waiting.
  • One budget covered connect and the receiver's read (LOW). These are now split into 2 s for connect and 5 s for receive.
  • The withdrawal test could pass without a write (MEDIUM). It now requires the after-write checkpoint.

Real Behavior Proof

  • Environment tested: local Windows 11 x64 dev box (THE-HIVE), .NET SDK 10.0.404, isolated OPENCLAW_TRAY_* directories.
  • PR head or commit tested: bdbcb94fe5f009eb5b9930678144bc546e807d7c
  • Exact steps or command run:
    • Temporary, uncommitted, env-gated 500 ms hold before WaitForConnectionAsync.
    • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-build --filter "FullyQualifiedName~ActivationRouterTests.MigrationShutdown_UsesCurrentUserIpc"
  • Evidence after fix: before the fix, the receiver logged SERVER-ERROR IOException 0x800700E8: The pipe is being closed. and the test failed at line 37. After the fix, it passed with the same hold, and the receiver logged no error.
  • Observed result: the shutdown callback runs every time. With a 5 s hold, longer than the old 2 s budget, the sender returned false (manual fallback) instead of hanging.
  • Screenshot or artifact links verified? N/A
  • Not verified or blocked:
    • A real Inno-to-Store migration against an installed older Inno app (two processes, real CloseSourceAsync) was not run.
    • No receiver log was captured from the original failing runs.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? No (same-user local named pipe only; CurrentUserOnly unchanged)
  • Command or tool execution surface changed? No
  • Data access scope changed? No
  • If any answer is Yes, explain the risk and mitigation: N/A

Compatibility and Migration

  • Backward compatible? Yes. Only the sender changed, and the pipe protocol and message are unchanged, so it works with already-installed receivers.
  • Config or environment changes? No
  • Migration needed? No
  • If yes, list the exact upgrade steps: N/A

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

The migration shutdown sender wrote, flushed and closed without waiting.
A client can connect to a new pipe instance before the receiver calls
ConnectNamedPipe; if the sender closed in that window the accept failed
with ERROR_NO_DATA and the request was dropped, so CloseSourceAsync waited
10 s and fell back to a manual close.

The sender now waits for the receiver to read the request
(WaitForPipeDrain, as ForwardToPrimaryAsync does) on a dedicated thread,
bounded by a named receive budget. On timeout it cancels the blocked drain
with CancelIoEx so disposing the pipe withdraws the request instead of
delivering it after the manual-close fallback.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 23, 2026
@clawsweeper

clawsweeper Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

The migration sender waits for the old app to read its shutdown request and cancels the drain when that wait expires.

Example: The old Companion delays accepting its migration pipe connection by 500 ms.

  • Before: The sender can report success and close before acceptance, losing the shutdown request.
  • After: The sender keeps the connection open until the receiver reads the request.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch and distinct regressions are sound on inspection, but supplied test results do not satisfy the changed-behavior proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Moving to the Store version can stall because the old Companion never receives the request to exit.
Reason: Reliable automatic shutdown restores the existing migration behavior, and maintainer authorship establishes direction.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a shutdown-delivery race still present on main; no concrete introduced correctness or security defect was found.

Priority: P2
Reviewed head: bdbcb94fe5f009eb5b9930678144bc546e807d7c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a current-head production-path pipe trace showing delayed-read recovery and timeout withdrawal, or installed migration logs/recording showing those outcomes; redact credentials and private endpoints.
Agent review details

How this fits together

StoreMigrationOperations asks ActivationRouter to send the private shutdown message to the old Companion, whose consent-checked handler requests exit; migration separately waits for the old app's mutex to be released.

flowchart LR
  A[Store migration workflow] --> B[StoreMigrationOperations]
  B --> C[ActivationRouter sender]
  C --> D[Current user named pipe]
  D --> E[Old Companion receiver]
  E --> F[Consent checked exit]
  F --> G[Mutex release permits migration]
Loading

Technical review

Best possible solution:

Keep the bounded drain and cancellation in ActivationRouter while preserving the v1 receiver and existing mutex-based migration gate.

Do we have a high-confidence way to reproduce the issue?

Main closes the sender immediately after writing, and the PR reports reproducing the matching ERROR_NO_DATA failure by delaying receiver acceptance; this read-only review ran no target code.

Is this the best way to solve the issue?

The change repairs delivery in the existing sender without requiring an updated installed receiver; its helper encapsulates the blocking Windows drain and cancellation boundary, and both added tests protect distinct failures.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 72a67f35675a.

Provenance checked

  • Private migration shutdown sender keeps the original intent (244f684: Request graceful shutdown of the consented old installation over current-user IPC, falling back to manual close without force-killing it.)
  • Activation transport ownership keeps the original intent (17a8b03: The activation refactor retained custom current-user named pipes and deferred AppInstance replacement pending separate compatibility proof.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Natalie Aguinaldo: Raw commit 244f684 adds src/OpenClaw.Tray.WinUI/Services/ActivationRouter.cs:297 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 244f684ef291; files: src/OpenClaw.Tray.WinUI/Services/ActivationRouter.cs)
  • Barbara Kudiess: Raw commit 17a8b03 adds src/OpenClaw.Tray.WinUI/Services/ActivationRouter.cs:270 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 17a8b0363a82; files: src/OpenClaw.Tray.WinUI/Services/ActivationRouter.cs)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Focused production and regression growth Production +69/-1 lines; tests +66/-0 lines Growth stays within the existing owner and covers distinct premature-close and timeout-withdrawal failures.

Labels

Label changes:

  • add P2: The intermittent migration stall has an existing manual-close and Retry recovery path and a focused repair.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The intermittent migration stall has an existing manual-close and Retry recovery path and a focused repair.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 23, 2026, 4:49 PM ET / 21:49 UTC.

@bkudiess
bkudiess merged commit 01eeb99 into openclaw:main Nov 23, 2026
38 checks passed
vincentkoc added a commit that referenced this pull request Nov 24, 2026
…ersion7-coordinated-2355-20261124

* commit 'f86e395d5c8edbc968d8d6e789d1ac16a1124a80':
  fix(tests): read chat text from complete UIA snapshots (#2364)
  fix: reduce typing lag in long chats (#2343)
  fix(tests): wait for the Sessions gallery window (#2337)
  fix(migration): keep the shutdown request until the receiver reads it (#2360)
  fix(tests): isolate settings publication tests from ThreadPool pressure (#2359)
  fix: keep candidate builds from contending on GitHub environment exports
  fix(tests): prevent stale chat ink captures (#2357)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant