Commit Graph
2 Commits
Author SHA1 Message Date
yetone 257eab646d update: a click that updates takes the newest the feed has, not the last check's
coeo91 on Discord: "更新行为不对,他会在点击更新按钮后下载上一次或最近一次
获取到的最新版本,而不是实际的最新版本". Clicking Restart to update asked the
feed again, but four paths still acted on what an earlier check had found:

- With Settings' "Download updates automatically" off, the click's check
  found the newer version and kept the staged older one (the hold), so the
  restart went into the older one. The click's check now counts as a click
  (fetch), so the newest is downloaded, then restarted into.
- When the feed took longer than the 10s wait, the route restarted into
  the staged version anyway. It now answers "checking". The header pill
  reads again and restarts once the answer is in; About's Version row
  redraws, and a second click restarts into what the answer found.
- The tray's Restart to update didn't ask the feed at all. It now goes
  through restartAsked: it checks first, or waits for the gateway as the
  page's click does (#577).
- A magpie that can't replace itself opened the release page the last
  check found. When that check is over a minute old, it checks again first.

A current version that is already downloaded is not downloaded again:
the check finds the same version and keeps it. The wait on the feed is
the one the click had already (at most 10s, usually one round trip).

Not changed: usemagpie.ai/api/latest is cached at the edge for 5 minutes
(site/worker.js), so a release less than 5 minutes old may still be
unseen. magpie web's "Open the release page" opens the URL the page
holds, since window.open must run in the click for the popup blocker.

Tests (internal/gui/update_fresh_test.go, a fake feed, no network):
TestRestartClickTakesTheNewest, TestRestartWaitsForTheFeed,
TestTrayRestartTakesTheNewest, TestAvailableOpensTheNewestPage.

Run on mote (macOS 27), at this tree:
- gofmt -l internal/gui: nothing
- go vet ./internal/gui; GOOS=linux go vet -tags nogui; GOOS=windows
  go vet: clean
- go test -tags nogui -count=1 -run 'TakesTheNewest|WaitsForTheFeed|
  NewestPage|Update|Restart' ./internal/gui: ok
- the same five with -race -count=10, with RestartWhenIdle and
  RestartToUpdate: ok

Broken by hand, one at a time, each red in its own test only:
- recheck's fetch = false: TestRestartClickTakesTheNewest, "went into the
  version the last check found: ... Latest:0.1.11"
- the "checking" answer taken out: TestRestartWaitsForTheFeed,
  "restarted before the feed answered: {State:ready ... 0.1.11}"
- restartAsked restarting at once: TestTrayRestartTakesTheNewest, "the
  tray restarted into 0.1.11 with 0.1.12 out"
- the available recheck taken out: TestAvailableOpensTheNewestPage,
  opened [v0.1.11 v0.1.11]

Not tried: a real update from a published release; the tray item on
Windows and Linux (the code is shared, the menu callback runs in its own
goroutine on Wails v3 beta.24).
2026-10-28 23:22:14 +08:00
yetone 52e7e4fc8d update: a restart to update waits until the gateway is idle instead of cutting off what the agents have in flight (#577: 正式版更新时保持网关请求与工具链不中断 — a Codex reply streaming through magpie, or a tool chain under way, was cut off by Restart to update) — the app serves the gateway in its own process and a restart to update is install, quit, relaunch, so whatever was in flight ended with it: a stream mid-reply, and a Claude Code turn of the subscription bridge waiting on its caller's tool results, whose Claude Code lives only in this process. The gateway now says what a restart would cut short (Server.Busy): its requests in flight (all but GETs and the bridge's own MCP callbacks), the bridge's runs parked on tool results, and when the last request ended. Restart to update (Settings → Version, the header's Update pill, the tray's item) restarts at once only when nothing is in flight, no turn waits on tools and nothing ended in the last 10 s (a tool chain's gap, the agent running a tool between two requests); otherwise it waits, saying what for: Settings shows "restarts once the gateway is idle · 2 in flight · 1 awaiting tool results" (网关空闲后自动重启 · 2 个请求进行中 · 1 个工具调用待返回) with Restart now and Cancel, the pill reads "Waiting to update" (等待更新) and its next click (not a double click's second half) restarts now, the tray item becomes "Restart Now to Update (3 in flight)" (立即重启以更新(3 个进行中)). The wait asks the feed again once idle, so versions out meanwhile collapse into the newest, downloaded before the restart; it gives up after an hour, saying so, the update then going in at the next restart or quit. A gateway served by another magpie (magpie serve, an older one) is not this one's to wait for. Handing the gateway over to the new version instead (the dev handover, e0c6892) is not used for releases: it rests on SO_REUSEPORT, which Windows lacks, and the new app would have to start beside the old one (single-instance, the Mac's bundle swapped under it). TestBusy (a stream counts until it ends, a GET never, a parked bridge run until it is answered or ends), TestRestartToUpdateWaitsForTheGateway (fails without the change: the click restarted with 2 requests in flight), TestRestartWhenIdle (not while streaming, parked or in a tool chain's gap; then once; an hour's wait gives up), TestRestartWhenIdleIntoTheNewest (0.1.11 staged, 0.1.12 and 0.1.13 out while waiting: restarted into 0.1.13) and TestTrayRestartNow are new; update-wait.test.cjs (WebKit, en and zh: what is in flight, waiting with Restart now and Cancel, counts following the gateway, the hour's give-up, the pill's wait and restart now, an idle click restarting at once, no click scrolling, no left border) fails without the change and passes with it. update-hide, update-check, sync-update, update-auto and click-scroll pass in WebKit. go vet ./internal/..., go build (darwin GUI), go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass (TestFXInState's known TempDir cleanup flake aside; passes on rerun). 2026-10-02 23:36:43 +08:00