Files
magpie/internal/update
yetone 830177ae53 update: a restart on Windows waits for the old magpie's WebView2 to end (vsoullai on X)
vsoullai on X (0.1.4096, Windows 10.0.26300): "自动更新 relaunch 未等待旧
WebView2 释放 EBWebView 导致新实例死锁" - after an update's restart the new
magpie hung.

Two holes, both in what the new process waits for before its WebView2
opens the same profile folder:

- AwaitPredecessor waited 20s at most for MAGPIE_REPLACES. An old magpie
  still in OnShutdown after that (Codex rollouts, agents' configs put back,
  an update installed) still holds Wails' single instance mutex, so
  webView2Ready's instanceHeld shortcut skipped the folder wait and
  application.New handed the start to the magpie quitting
  (SendMessage to its -siw window) and exited: no magpie at all.
- The old magpie gone is not its WebView2 gone: the folder's lockfile is
  let go before the browser's last msedgewebview2 processes end (seen on
  the box: lockfile free at 0.07s, two of the old one's processes ending
  at 0.10s).

Now, on Windows, AwaitPredecessor (awaitGone) opens the old magpie by pid
first (so its pid is no other's), takes every msedgewebview2.exe under it
from a Toolhelp snapshot and opens those too, then waits up to 60s for the
old magpie and up to 30s more for those processes, logging when it goes
on without them. Mac and Linux keep the 20s poll. Every restart passes
here: the update's restart and Settings' restart (RelaunchBinary), the
folder move's, and Respawn after a WebView2 failure, since all set
MAGPIE_REPLACES and every start runs AwaitPredecessor (cli startUp)
before gui.Run.

Tests (Windows):
- update TestAwaitGoneWaitsForTheOldWebView: a fake old magpie with a
  copy of the test binary named msedgewebview2.exe that outlives it by 3s.
  Red with the old 20s poll put back by hand ("went on after 402ms, while
  the old magpie's WebView2 still ran"), green with the fix (3.5s).
- gui TestRestartWaitsForTheOldWebView: real Wails windows and WebView2
  with Wails' single instance on, in the signed-in session on xiaomi-gpu
  (skips in session 0). The old app, its page loaded, starts the new one
  detached with MAGPIE_REPLACES and quits; the new one starts as Run does
  and must load its own page. slow (OnShutdown 25s) is red on the old
  code: the new one went on at 20.09s, handed over and never came up.
  Green with the fix: quick 1.3s, slow 27.4s, page loaded both times.

Run at this head (6faac2636 rebased on origin/main e730a14dc):
- xiaomi-gpu (win-run): both tests above green; earlier, at a8fa771a6
  plus this change, go test ./internal/update ./internal/gui in full: 10
  reds, the same 10 on fresh origin/main e730a14dc with no change, all
  filed (#6068, #4603): TestPackagedByDpkg, TestGatewayHeldByAContainer,
  TestLodyImportHandoff, TestImportStatusUnreadableIsUnknown,
  TestAionUiImportRow, TestCherryStudioImportRow,
  TestProviderSaveClientCert, TestPluginAgentMissingSaysSo,
  TestGatewayModeStatsNameTheGatewaySessions, TestUpdateThatWontStart.
- mote: go test ./internal/update ./internal/cli ok; gofmt -l clean;
  GOOS=windows go vet ./... and GOOS=linux go vet -tags nogui ./... clean.

Not run: the full go test ./... - mote's suite lock had a ~3h GUI+go run
and a 120m e2e queued ahead; the change touches Windows-only code plus
one call in AwaitPredecessor, whose non-Windows body is the old loop
moved as is. Not tried: a real update of a built magpie.exe in a sandbox
(the restart is played with real windows in the test instead), and an
old magpie that never quits within 60s (the start goes on as before).
2026-11-14 08:12:09 +08:00
..
…