Repository navigation
fix(migration): close the old app reliably when moving to the Store version - #2360
Conversation
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]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThe 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherStoreMigrationOperations 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
Preflight sourceSource 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
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 23, 2026, 4:49 PM ET / 21:49 UTC. |
…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)
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
bdbcb94fe5f009eb5b9930678144bc546e807d7cCancelIoEx, 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.ps1passed.↑ 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.
TaskCanceledExceptionat line 37 after the sender returnedtrue).↑ The receiver logged
IOException 0x800700E8: The pipe is being closed(ERROR_NO_DATA), so the request was dropped at accept.↑ 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_UsesCurrentUserIpcWithoutCreatingADeepLinkRoutetime 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_DATAand 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 returningfalse. This guarantees a timed-out request is withdrawn rather than delivered after the manual-close fallback appears.Two
internaltest 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:
ForwardToPrimaryAsyncalready waits for the receiver to read. No otherNamedPipeClientStreamsender exists insrc.Evidence
72a67f35, a temporary 500 ms hold before the receiver's accept reproduced the failure:MigrationShutdown_UsesCurrentUserIpcWithoutCreatingADeepLinkRoutefailed withTaskCanceledExceptionatActivationRouterTests.cs:line 37;IOException 0x800700E8: The pipe is being closed.MigrationShutdown_SenderKeepsRequestUntilReceiverAcceptsItfails without the wait: the sender finished before accept.MigrationShutdown_TimedOutRequestIsWithdrawnBeforeTheReceiverAcceptsfails without the wait, and also fails withoutCancelIoEx: the stale request was delivered afterfalse.Invoke-CiTestSoak.ps1, under the shared desktop lock) passed 10/10 withOPENCLAW_GATEWAY_FIXTURE_SCREENSHOTS=0and 10/10 with=1, 3 runs each under CPU contention, 43 tests per run.Change Type
Scope
winnodeRequired 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 base72a67f35, with isolatedOPENCLAW_TRAY_*directories../build.ps1dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csprojdotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restoredotnet test ... --filter ActivationRouterTests.MigrationShutdownscripts/Invoke-CiTestSoak.ps1, screenshots 0 and 1pwsh -NoProfile -File ./scripts/validate-test-timing-patterns.ps1test-timing-exceptionfor the bounded sender-hold windowgit diff --checkReview findings fixed in this PR
falseresult. Fixed withCancelIoExplus a bounded wait for the drain to end; covered by the withdrawal test.LongRunningthread.Real Behavior Proof
OPENCLAW_TRAY_*directories.bdbcb94fe5f009eb5b9930678144bc546e807d7cWaitForConnectionAsync.dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-build --filter "FullyQualifiedName~ActivationRouterTests.MigrationShutdown_UsesCurrentUserIpc"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.false(manual fallback) instead of hanging.CloseSourceAsync) was not run.Security Impact
CurrentUserOnlyunchanged)Yes, explain the risk and mitigation: N/ACompatibility and Migration
Review Conversations