Commit Graph
5 Commits
Author SHA1 Message Date
yetone 0ac26fb52d update: a magpie a package manager installed leaves updating to it (shuhai on Discord, AUR magpie-bin)
shuhai (Arch) installs magpie from the AUR's magpie-bin, which puts the
desktop build at /usr/bin/magpie. magpie's own updater saw a folder it
can't write and pkexec on the machine, so it downloaded the release and,
on restart, replaced the package's file as root. pacman's database then
no longer matched the file, and the next `yay` upgrade (magpie-bin lags
the releases, 0.1.2342 against 0.1.2357 today) put an older magpie back.
The two updaters fought each other.

Now magpie asks first who owns the binary it runs from
(update.PackagedBy): pacman's local database, dpkg's .list files, rpm
(`rpm -qf`, only where /var/lib/rpm exists), a Homebrew Cellar path or
/nix/store. Only a system path counts (/usr but not /usr/local, /bin,
/sbin, /opt), with merged-/usr aliases, and packages named magpie* are
looked at first. A packaged binary:

- GUI: the update is shown as available with "pacman installed magpie
  (magpie-bin), so pacman updates it, not magpie: yay -S magpie-bin"
  (apt, dnf, brew likewise; Nix with no command). Nothing is downloaded,
  there is no Download or Install, the Update pill isn't lit, and
  /api/update/install does nothing (state available, stuck "package").
- `magpie update` says the same and exits 1 before downloading. This
  takes the place of the Homebrew-only check it had.

An unpackaged magpie (~/.local/bin, /usr/local/bin, a file pacman doesn't
list in /opt) updates itself as before.

Run:
- mote: go test -tags nogui -run 'Packaged|Homebrew|NotWritable|InContainer'
  ./internal/update ./internal/gui ./internal/cli ok; full
  go test -tags nogui -count=1 -timeout 45m ./... at b1a1b950f: 81 ok, 3
  red. Two are on main and filed: TestNoCommandBypassesProc (claudetui,
  #4491) and TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll, #4514).
  The third, TestCoreScriptBudget, was this change: app.js is now 460
  bytes more (its comments cut to one line, one helper call per path),
  and both budgets are raised by exactly that, with no room added. After
  the rebase on bb5e68cea: TestCoreScriptBudget and the Packaged,
  NotWritable, InContainer and Homebrew tests ok on mote.
- mote: gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build for darwin, linux (nogui), windows.
- WSL magpie-desktop (Ubuntu 24.04), real package: built a 0.1.2300
  nogui magpie, packaged it as a .deb (magpie-aurpk-test) at
  /usr/bin/magpie, dpkg -i. `magpie update` as the user, through
  /bin/magpie, and as root each printed "magpie 0.1.2355 is out" and
  "this magpie was installed with apt (package magpie-aurpk-test), which
  updates it, not magpie: sudo apt install --only-upgrade
  magpie-aurpk-test", exit 1; the file's sha256 was unchanged and
  dpkg -V clean. Package removed after. An unpackaged copy in ~ still
  checked and offered the update.
- WSL GUI, both engines: every update-* file, i18n-keys, gui-de/ja/zh-tw,
  whats-new*, about-*: 390 pass. Reds: i18n-keys "Unmarked" (#4524, on
  main) and update-check's WebKit ResizeObserver notice (the previous
  commit). Rerun of every update-* file after it: 294 pass, 4 red, all
  timing reds filed as #4554 and #4555, none in update-stuck. After
  app.js was cut down, after the rebase: update-stuck, update-auto,
  update-hide and i18n-keys, both engines: 93 pass, 1 red (#4524).

Broken by hand:
- placeExe's and the CLI's package check turned off:
  TestUpdatePackagedLeavesItToTheManager red ("a packaged binary is to be
  replaced"), TestUpdatePackagedSaysTheManager red (it went on to the
  download).
- origin's app.js: the new update-stuck case times out (no text); only
  the pill condition reverted: red in WebKit.

Not tried:
- A real pacman/Arch install: the omarchy VM didn't answer ssh (banner
  exchange timed out twice), so pacman detection is from the database
  layout in tests only.
- rpm and Nix on a real system; Homebrew only through the existing path
  test.
- The whole GUI suite.
2026-10-31 17:28:37 +08:00
yetone e6b851b0fe update: magpie update in a terminal restarts the app with its gateway handed over
gaubeebangeel on X has an agent run the magpie upgrade at 4am and had
to give that agent its own provider: magpie couldn't serve it through
the upgrade.

Cause: `magpie update` put the new version in and printed "quit and
reopen magpie to use it" (a .app) or "updated to X" (a binary). The
running app never restarted, so the agent (or the user) had to restart
it by hand, and a plain restart closes the port and drops streams.

Measured before, on mote, a sandbox HOME `magpie serve` with a fake
upstream streaming 61 chunks at 100ms, restarted by SIGTERM + start:
- the stream was cut at chunk 15 of 61 (unexpected EOF); SIGTERM to exit
  took ~18ms, no drain;
- requests during the restart: 289 answered, 5 refused over 87ms.

Now `magpie update`, once the new version is in, POSTs it to the
running app's /v1/magpie/restart (gateway/restart.go). It is answered
only to a program on this computer over loopback; a LAN caller, a page
(Origin / Sec-Fetch) and another Host get 403. The updater's
restartBeside (gui/update_beside.go) restarts only when its own exe was
the one replaced (replaced() now also compares a .app's binary,
bundleExe), takes the version as ready without the feed, and runs the
same restart as Settings' AutoRestart: at once when it cuts nothing
short, else through waitIdle. On macOS and Linux that restart is the
existing SCM_RIGHTS handover, so the port never closes and in-flight
streams finish in the old process. The command prints what happened:
restarting (handing the gateway over), waiting for N requests, another
copy (current), magpie serve (unsupported), not running, or too old
(404: the first update into this version still needs a manual
restart).

Tests:
- TestUpdateInATerminalRestartsTheAppWithoutCuttingIt (darwin, linux):
  a stream through the gateway, the exe rewritten, magpie update's ask
  answered "restarting" with handover; the successor serves a request
  while the stream runs, the stream ends whole, the old one quits only
  after it. Red by hand with the route removed ("magpie update's ask:
  404").
- TestUpdateOfAnotherCopyLeavesTheAppBe, TestRestartAskedOnlyFromThisComputer
  (refused cases never reach the restarter), TestUpdateAsksTheRunningMagpieToRestart
  (each reply, a 404 magpie, none running).

Run at this tree:
- rebased on bdc1617be, at this head on mote: gofmt -l clean;
  GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...;
  go test -run 'TestUpdate|TestRestartHandsTheGatewayOver|TestHandoverNotMade'
  ./internal/gui ./internal/cli and -run 'TestRestartAsked|TestReadOnlyKey'
  ./internal/gateway: ok
- before the rebase (88ecae173), mote: go test -count=1 ./internal/gui ./internal/cli ./internal/gateway:
  gateway ok (535s), cli ok; gui FAIL only on filed reds: the real-window AppKit
  tests killed at their deadline on mote (#4125, #2645) and
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514), both red the same
  run alone at 88ecae173, and TestColdTurnsTaken (#4510, a race in
  full gui runs, not touched here)
- wsl-run (magpie-desktop, -tags nogui): TestRestartHandsTheGatewayOver,
  TestUpdateInATerminal..., TestUpdateOfAnother...: ok
- mote: gofmt -l clean; go vet gui/gateway/cli; GOOS=linux go vet -tags
  nogui ./...; GOOS=windows go vet ./...: ok

Not tried: the real GUI app end to end with a real `magpie update`
against a published release; Windows (no handover there: the restart
waits for an idle gateway and the port closes while the new version
starts, #4521); `magpie serve` / the daemon, which has no handover and
says to restart it the way it was started.
2026-10-31 11:39:04 +08:00
yetone 4a33cf0a98 update: a Stable channel in Settings → About, and magpie update channel
ssharpcc on X reads every changelog before updating, for fear of a ban
when behind, and with many releases a day that is a lot of reading.
Settings → About → Update channel (zh: 更新渠道, 稳定版 / 每个版本) picks
Every version, the default and today's behaviour, or Stable: one version
a week, the newest that had been out three days as the week began
(Monday 00:00 UTC), and an urgent release at once. usemagpie.ai chooses
it from the release list (the previous commit); a release is urgent when
a line of its notes starts with "**Urgent release:**", which
magpie-releases' release run writes from an `Urgent: <why>` trailer
(magpie-releases 73f6cff).

- settings: updateChannel, "" or "stable"; anything else is refused.
- update: on Stable the feed is asked with channel=stable; What's new
  shows every release since the installed one (up to 1500) instead of
  the newest 40, so a week's notes read as one list.
- gui: the row is segs, never a <select>; a save that doesn't send the
  channel keeps it; switching asks the feed again at once, and a
  download from every version newer than Stable's pick is dropped,
  never restarted into. What's new's notes are kept per channel.
- cli: magpie update channel [stable|every] ("all" too), and it says
  which with nothing after it.
- docs: reference.md's Update channel (the rule and the marker); the
  privacy pages (en, zh, ja) name ?channel=stable on /api/latest.

The full Go and GUI suites were not run: the disk was at 3 GB free and
other sessions had GUI suites and a 45-minute gateway run going the
whole time.

Run, at this tree before the rebase:
- gofmt -l (clean); go vet on darwin, GOOS=linux -tags nogui and
  GOOS=windows for ./internal/update/... ./internal/cli/...
  ./internal/settings/... ./internal/gui/.
- go test -count=1 ./internal/update/... ./internal/cli/...
  ./internal/settings/...: ok. ./internal/gui -run
  'TestUpdateChannelSwitch|TestWhatsNewKeyedByChannel|TestCoreScriptBudget':
  ok (the app.js budget passes).
- GUI, chromium and webkit: update-channel (22: en, zh, zh-TW, ja, de at
  900 and 420 wide: default lit, Stable saved, kept by another save,
  kept over a reload, Every saved back, no click scrolls, no sideways
  scroll at 420), i18n-keys, gui-ja, gui-de, gui-zh-tw and every
  update-*.test.cjs: 253 of 253 pass.
- The live feed: /api/latest?channel=stable answers 0.1.1327 (out
  2026-10-22 21:55 UTC, the last before Friday 10-23 00:00) with 15
  assets after the first real cron run filled the ledger (400 releases
  back to 10-10); /api/notes 0.1.1200..0.1.1327 gives 124 notes, none
  empty (1213 and 1218 were never published).

After rebasing on afc99490f: TestCoreScriptBudget, the channel Go tests
(update, cli, gui) and GUI i18n-keys + update-channel (both engines,
26 of 26) pass again.

Broken by hand, each red: the feed asked without channel=stable
(TestLatestAsksTheChannel); Stable capped at 40 (TestStableNotesAreAll);
any channel saved (TestUpdateChannelSaved); "all" dropped
(TestUpdateChannelCmd); a save without the field clearing it, no new ask
on a switch, the newer download kept (TestUpdateChannelSwitch); one
notes key for both channels, What's new capped at 40 on Stable
(TestWhatsNewKeyedByChannel); app.js's other saves dropping the channel,
Stable's click saving "" (update-channel 11 of 11 red); the zh label or
a de subtitle taken out (update-channel and i18n-keys red).

Not tried: the full go test ./... and the whole GUI suite (above); a
real app switching channel against the live feed; Windows and Linux
runs (vet only); a real urgent release.

Requested by ssharpcc on X.
2026-10-26 21:09:44 +08:00
yetone ff670797a1 gui: an update found waits for Download update when Settings' Download updates automatically is off (#2296, meifu2027)
On a metered network or a proxy billed by traffic, a newer version was
downloaded as soon as a check found it, by the clock or by Settings'
Check. Settings → About now has "Download updates automatically", on by
default (as before). Off (settings.json noAutoDownload):

- a check, by the clock or by a click, only reports the version: the
  version row says "{v} is out · {size} MB" with its notes, and the
  header's Update pill shows; the updater's state is "found";
- "Download update" on that row, or a click on the pill, posts
  update/install, which downloads it (updater.download) as a retry does;
- a version downloaded on a click stays ready: a newer one found later
  isn't fetched over it;
- a settings save that doesn't send the field keeps it (api.go), so an
  older page can't switch it back on.

CLI: `magpie update auto notify|download` sets it, and the status says
which. The proxy-change retry in api.go goes through the same run, so it
respects the setting too.

hold() (the click guard that keeps what was clicked in place) took a
zero-height element as its anchor: the empty .val beside Settings' Add
to PATH. "Moved by less than half its height" never held for it, so
once the new row made About 27px taller than a 900x760 window, the click
slid the view 11px off its top (cli-path.test.cjs, red on this branch,
green on origin/main where About couldn't scroll). hold now prefers an
anchor with a height, and falls back to the old choice.

Run:
- go test -tags nogui ./internal/gui ./internal/cli ./internal/settings
  (sandbox HOME): ok (gui 547s, cli 678s; settings ok 253s). A first run
  with the default 10m timeout lost cli to it at load ~100
- TestUpdateDownloadWaitsForAClick broken by hand three ways, red each
  time: no `case hold` (Check gave ready, 1 download); no api.go keep
  ("a save without noAutoDownload turned it off"); no `|| hold` ("a
  newer one, downloads held: found 0.1.12").
- gofmt -l clean; go vet -tags nogui for darwin, linux and windows on
  gui, cli and settings: ok.
- GUI: update-download.test.cjs (en, zh, zh-TW, ja, de at 1100 and 420)
  passes in Chromium and WebKit; breaking the found case times it out.
  cli-path, click-scroll and update-download pass in both engines after
  the hold fix. Every GUI test that checks scrolling (327
  files): Chromium 2261 pass, WebKit 2263 pass,
  6-wide at load ~100. Red: refusal-retries-setting ja 420 (#2258; base
  95e7c6bcc red 2 of 3 alone too), usage-agents-hide (#2276) and
  usage-fold (#2163), red alone on base as well; fonts (chromium) and
  sessions-manage-paging (webkit zh) red only in the loaded run, green
  alone twice on both. gui-ja, gui-de, gui-zh-tw, i18n-keys and
  update-stuck: 32/32 in each engine.
- Not tried: a real metered connection or a real release download.

Full suite: SUITE_LINE
2026-10-15 23:08:03 +08:00
yetone 23e764d0e0 cli: magpie's commands move from the root into internal/cli; the root keeps only main.go
The root held 89 .go files (30 commands, 59 tests). They move as they are
to internal/cli (package cli), with git mv so history follows them. The
only code change is main() becoming cli.Main(version): the root's new
main.go keeps `var version` in package main, so -ldflags "-X
main.version=…" in the Makefile, the Dockerfile and magpie-releases, and
every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land
next to package main in the root.

Tests that read testdata by a root-relative path now go up one level
(../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links
point at internal/cli/.

Run:
- go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui)
- builds with tags production, dev, "production nogui"; windows
  -H windowsgui; linux CGO_ENABLED=0
- make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64
  android/arm64" VERSION=9.9.9-tidy: all four built, binary prints
  "magpie 9.9.9-tidy"
- docker build --build-arg VERSION=7.7.7-tidy: container prints
  "magpie 7.7.7-tidy"
- go test ./internal/cli (default and nogui): 152 tests, the same count
  as the root on main
- go test ./...: all packages pass (agent, gateway, library, provider
  timed out at 10m under other sessions' load and passed rerun alone
  with -timeout 40m; none of them changed)
- the built binary in a sandbox HOME: version, help, ls, providers,
  claude, and an unknown command's error
2026-10-12 20:40:22 +08:00