gui: the Linux app's sidebar button switches the layout at once, no view transition, which WebKitGTK with compositing off crashed in (depravity_wings on X)

Since 18e82adc6 (v0.1.1197) the sidebar button, Ctrl+Shift+S and dragging
the sidebar's edge past its narrowest trade the two layouts in a view
transition (navMorph). Under Wayland magpie turns WebKitGTK's compositing
off (webkit_linux.go), and WebKitGTK 2.52 then crashes in the transition:
SIGSEGV on the GTK main thread inside libwebkit2gtk-4.1, from a
JavaScriptCore run-loop timer. The reporter saw the window freeze.

The Linux app (body.linux) now has the new layout at once, the path reduced
motion already takes; magpie web in a Linux browser keeps the motion. Other
webviews get a guard: a transition still going after MORPH_MAX (1.5s, three
times its length) is skipped, so one that never ends can't leave the window
on the old layout's picture.

Run:
- Reproduced on the omarchy VM (Hyprland/Wayland, webkit2gtk-4.1 2.52.6),
  v0.1.1207 under a scratch HOME: the button crashed the app 4 of 4 clicks;
  with WEBKIT_DISABLE_COMPOSITING_MODE=0 it didn't.
- The fixed build there (same Linux path, compositing at magpie's default):
  8 button clicks, 4 Ctrl+Shift+S and an edge drag past its narrowest all
  switched the layout, checked by screenshot each step; no crash, no freeze.
- side-toggle.test.cjs: "Linux: at once, no transition" and "a transition
  that never ends is cut short", chromium and webkit; both go red with the
  change undone by hand. side-toggle, sidebar, side-width, header-centre
  pass in both engines (60 tests). go test -tags nogui ./internal/gui ok.
Not run: the 1.5s guard on a real webview that never ends a transition
(none found); it is tested with a stub.
This commit is contained in:
yetone
2026-10-12 19:13:14 +08:00
parent 9964535adc
commit f5dd4d604e
3 changed files with 74 additions and 4 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ three.
| API and assets | `Handler` serves `assets/` (embedded with `//go:embed assets`) and the `/api/*` routes, such as `/api/state`, `/api/set` and `/api/agents/{action}/{id}`. `held` lets one API request's reads share one catalog build (`provider.Hold`), and drops it after any write. `revalidated` and `versionedPage` name each script by its content hash, so a cache never serves an old `app.js` under a new page; a file asked for under its current hash (`?v=`) is cached for good (`immutable`), anything else is revalidated by its ETag. | [`api.go`](../../internal/gui/api.go) |
| Browser mode | `StartWeb` serves the page and the gateway for `magpie web`. The browser signs in with a run key in a link. Gateway mode shows Providers, Gateway, Routing, Usage, Sessions, Plugins and Settings on a machine that is only a gateway. `webHandler` gzips the page's text files and the API's JSON for a browser that takes gzip (`webCompressed`, with a `-gzip` ETag that still answers 304); the app's own windows read the page in-process and get it uncompressed. | [`web.go`](../../internal/gui/web.go), [`gatewaymode.go`](../../internal/gui/gatewaymode.go) |
| The page | `app.js` keeps one state object per view and renders it into a list, with no framework. The views have their own files: `routing.js`, `library.js`, `plugins.js`, `sessions.js` and `context.js` (Usage's Context tab, and the context window card the Routing page draws under a request's story, fed by `/api/context` in `context.go`, which scores and tags each agent; clicking a part, a cell or an item opens its text from `/api/context/text`, the last 10 requests' masked bodies in memory (`openCtxText`), rendered 100 items and 20000 characters at a time; its "Tuned for you" cards are fed by `/api/tune` in `tune.go`, see [agent wiring](agent-wiring.md)). Strings go through `t()` with translations in `i18n.js` (zh, zh-TW, ja and de; the English text is the key and the fallback). zh-TW is Traditional Chinese with Taiwan's words; a system language of zh-TW, zh-HK, zh-MO or any zh-Hant picks it, and the tray menu and notifications follow (`trayLang`). Dropdowns use `openProtoMenu`. Every app menu (`openProtoMenu`, `openRowMenu`, `openSessCombo`) is placed by `placeMenu`: under its anchor, or over it when the window runs out below; one that fits neither way takes the larger room, its height held to it, and scrolls inside itself, and a scroll inside a menu doesn't close it (#1437, `removed-groups-menu-scroll.test.cjs`). The highest any popover goes is `popTop`: 8px under `header.top` on a Mac window, where the traffic lights are drawn over the page, and 8px from the top elsewhere; `placeMenu`, the field picker's `placePop` (which also holds `#pop`'s height to that room) and an agent's model list (`openAgentModels`) all use it (#1573, `popover-mac-chrome.test.cjs`). Scrolling is done only by `scrollOnPurpose(e)` with the reader's event. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/i18n.js`](../../internal/gui/assets/i18n.js) |
| Window navigation | In the window from 1024 points wide (`SIDE_AT`, the same width as app.css's `side-nav` rules), `layoutNav` moves the brand, the pages (`#nav`) and Settings into the sidebar (`#side`): the pages in four groups (Work, Models, Insights, Extend; a group none of whose pages shows, as in gateway mode, leaves out its name), the gateway's address at its foot (`sideGwRead`, read from `/api/providers` only while there is a sidebar), and the header a breadcrumb (`renderCrumb`). The open page's own tabs (`NAV_SUBS`: Usage, Library, Plugins, Settings) are listed under it as `.nav-s` rows (`role="tab"`, `data-of` the page tab's id) and the page's strip is hidden; a row's click clicks that tab at once, the selection (`.nav-hl`) having set off as the row was pressed (`navSubGlide`; back if the press leaves the row), and is the list's only shape: a row hovered or pressed has no ground of its own, and a `MutationObserver` draws the list again when the strip changes. The list opens and folds with an iOS-like spring (`navSubEnter`, `navSubLeave`; none under reduced motion), and a folding list is out of reach at once. Narrower, the page beside a sidebar would be narrower than Usage's requests table needs (768 points), so they go back into the header's row, as a Mac sidebar gives way in a narrow window. At every width the reader can pick the sidebar or the header's tabs from the title bar's button (`#sideToggle`, ⌃⌘S or Ctrl+Shift+S; `toggleSideNav`), kept in localStorage `magpie.navLayout` (`side` or `top`) and so laid out from the first frame; none picked, the sidebar comes from `SIDE_AT`. Picked in a narrow window the sidebar is narrower (184 points under 860), and magpie web on a phone keeps its own tab bar and has no button. The two layouts trade places in a view transition (`navMorph`, app.css `.nav-morph`): the sidebar slides, each page's tab flies to its place in the other, and the page slides as one (its old image dropped, so no line prints twice); without view transitions or under reduced motion the change is at once. See `side-toggle.test.cjs`. A window made wider or narrower drops what a click held (`heldWidth`): the page laid out again isn't the click's doing. See `sidebar.test.cjs`. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/app.css`](../../internal/gui/assets/app.css) |
| Window navigation | In the window from 1024 points wide (`SIDE_AT`, the same width as app.css's `side-nav` rules), `layoutNav` moves the brand, the pages (`#nav`) and Settings into the sidebar (`#side`): the pages in four groups (Work, Models, Insights, Extend; a group none of whose pages shows, as in gateway mode, leaves out its name), the gateway's address at its foot (`sideGwRead`, read from `/api/providers` only while there is a sidebar), and the header a breadcrumb (`renderCrumb`). The open page's own tabs (`NAV_SUBS`: Usage, Library, Plugins, Settings) are listed under it as `.nav-s` rows (`role="tab"`, `data-of` the page tab's id) and the page's strip is hidden; a row's click clicks that tab at once, the selection (`.nav-hl`) having set off as the row was pressed (`navSubGlide`; back if the press leaves the row), and is the list's only shape: a row hovered or pressed has no ground of its own, and a `MutationObserver` draws the list again when the strip changes. The list opens and folds with an iOS-like spring (`navSubEnter`, `navSubLeave`; none under reduced motion), and a folding list is out of reach at once. Narrower, the page beside a sidebar would be narrower than Usage's requests table needs (768 points), so they go back into the header's row, as a Mac sidebar gives way in a narrow window. At every width the reader can pick the sidebar or the header's tabs from the title bar's button (`#sideToggle`, ⌃⌘S or Ctrl+Shift+S; `toggleSideNav`), kept in localStorage `magpie.navLayout` (`side` or `top`) and so laid out from the first frame; none picked, the sidebar comes from `SIDE_AT`. Picked in a narrow window the sidebar is narrower (184 points under 860), and magpie web on a phone keeps its own tab bar and has no button. The two layouts trade places in a view transition (`navMorph`, app.css `.nav-morph`): the sidebar slides, each page's tab flies to its place in the other, and the page slides as one (its old image dropped, so no line prints twice); without view transitions, under reduced motion, or in the Linux app the change is at once: WebKitGTK with compositing off (`WEBKIT_DISABLE_COMPOSITING_MODE`, which `webkit_linux.go` sets under Wayland) crashes in a view transition. Elsewhere a transition still going after `MORPH_MAX` (1.5s) is skipped, so a webview that never ends one can't leave the window on the old layout's picture. See `side-toggle.test.cjs`. A window made wider or narrower drops what a click held (`heldWidth`): the page laid out again isn't the click's doing. See `sidebar.test.cjs`. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/app.css`](../../internal/gui/assets/app.css) |
| No GUI build | `-tags nogui` builds magpie without the GUI: `hasGUI` is false and `runGUI` says to use `magpie tui`. The files of `internal/gui` that need Wails build under `!nogui`. | [`gui_off.go`](../../gui_off.go) |
## Runtime path
+10 -3
View File
@@ -23096,13 +23096,20 @@ function toggleSideNav() {
// the two layouts trade places as one motion (app.css .nav-morph): the old
// drawn and the new laid out, the sidebar sliding and each tab flying to
// its place in the other; a webview without view transitions, or a reader
// who asked for less motion, has the new at once
// who asked for less motion, has the new at once. So does the Linux app:
// WebKitGTK with compositing off (webkit_linux.go turns it off under
// Wayland) crashes in a view transition, the click on the sidebar's button
// taking the window down (depravity_wings on X). Anywhere else, a transition
// still going well past its half second is cut short, so a webview that
// never ends one can't leave the window on the old layout's picture
var MORPH_MAX = 1500;
function navMorph(change) {
if (navCalm() || !document.startViewTransition) { change(); return; }
if (navCalm() || !document.startViewTransition || document.body.classList.contains("linux")) { change(); return; }
const root = document.documentElement;
root.classList.add("nav-morph");
const vt = document.startViewTransition(change);
vt.finished.finally(() => root.classList.remove("nav-morph"));
const stuck = setTimeout(() => vt.skipTransition(), MORPH_MAX);
vt.finished.finally(() => { clearTimeout(stuck); root.classList.remove("nav-morph"); });
}
// where the page shown keeps its own tabs: the sidebar lists them under it
// and picks them there, the page's own strip hidden (app.css)
+63
View File
@@ -180,6 +180,69 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await context.close();
});
// WebKitGTK with compositing off crashes in a view transition, the click
// taking the window down (depravity_wings on X): the Linux app has none,
// the new layout at once
await t.test("Linux: at once, no transition", async () => {
const context = await browser.newContext({ viewport: { width: 1280, height: 760 } });
const page = await context.newPage();
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.addInitScript(() => {
Object.defineProperty(Navigator.prototype, "platform", { get: () => "Linux x86_64" });
window.morphs = 0;
const real = Document.prototype.startViewTransition;
if (real) Document.prototype.startViewTransition = function (...a) { window.morphs++; return real.apply(this, a); };
});
await page.route("**/*", serve("en"));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
assert.ok(await page.evaluate(() => document.body.classList.contains("linux")));
for (const want of [false, true, false]) {
await page.locator("#sideToggle").click();
assert.equal(await side(page), want, "the other layout at once");
assert.equal(await page.evaluate(() => document.documentElement.classList.contains("nav-morph")), false);
}
assert.equal(await page.evaluate(() => window.morphs), 0, "no view transition started");
assert.ok(await page.locator(".top #nav").isVisible(), "the tabs in the header, the page answering clicks");
assert.deepEqual(errors, []);
await context.close();
});
// a webview whose transition never ends anywhere else: cut short soon
// after its half second, so the window never stays on the old picture
await t.test("a transition that never ends is cut short", async () => {
const context = await browser.newContext({ viewport: { width: 1280, height: 760 } });
const page = await context.newPage();
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.addInitScript(() => {
window.skipped = 0;
Document.prototype.startViewTransition = function (change) {
let done;
const finished = new Promise((r) => { done = r; });
Promise.resolve().then(change);
return { finished, updateCallbackDone: Promise.resolve(), ready: Promise.resolve(), skipTransition() { window.skipped++; done(); } };
};
});
await page.route("**/*", serve("en"));
await page.goto("http://magpie.test/");
await page.waitForSelector("#nav button.on");
const t0 = Date.now();
await page.locator("#sideToggle").click();
await page.waitForFunction(() => document.documentElement.classList.contains("nav-morph"));
await page.waitForFunction(() => !document.documentElement.classList.contains("nav-morph"), null, { timeout: 5000 });
const took = Date.now() - t0;
assert.ok(took >= 1000, `not cut while it could still be playing: ${took}ms`);
assert.equal(await page.evaluate(() => window.skipped), 1, "skipped once");
assert.equal(await side(page), false);
// and the button works again after
await page.locator("#sideToggle").click();
await page.waitForFunction(() => document.body.classList.contains("side-nav"));
assert.deepEqual(errors, []);
await context.close();
});
await t.test("less motion: at once", async () => {
const context = await browser.newContext({ viewport: { width: 1280, height: 760 }, reducedMotion: "reduce" });
const page = await context.newPage();