Files
magpie/docs/subsystems
yetone 8826a15ea4 gui: a Quit while agents go through magpie asks first, naming them (Aisiverto on X)
Aisiverto on X (Windows, v0.1.2519) wired Codex to magpie and quit magpie.
Codex then retried "unexpected status 502 Bad Gateway ... url:
http://127.0.0.1:3425/backend-api/codex/responses" five times and gave up,
and it took a long search to find magpie's openai_base_url in config.toml.

A Quit the user chooses (the tray's Quit, the panel's and window's Quit,
Command-Q on the Mac) now asks first when this process serves the gateway
and agents are wired to it. The window comes up on a sheet
(quitask.js, lazy-loaded) that names each agent cut off, says closing the
window keeps magpie running (menu bar on a Mac, system tray elsewhere),
and offers Quit (focused), Disconnect and quit, and Cancel. Disconnect and
quit puts each agent back as its row's Disconnect does, then quits; a
disconnect that fails keeps magpie open, named in the status line. A
second Quit within a minute of the question quits, so a window that
can't show it traps nobody. With nothing wired, or another magpie serving
the gateway, Quit quits at once.

Not asked: a restart to update, Uninstall, a browser's page (magpie web),
logging out or shutting down, and the Dock's Quit (AppKit terminate:).

Found while checking the report:
- Closing the window on Windows hides it; magpie stays in the tray and
  the gateway keeps serving (tried for real, below). Not a bug.
- Autostart is off by default on Windows.
- The proxy / NO_PROXY in the report isn't magpie's to fix: the 502 is
  magpie's port with nothing behind it.

Strings in en, zh, zh-TW, ja and de (existing terms: Agent, 退出). No
native dialog, no <select>. TestCoreScriptBudget met without a raise:
app.js gains two lines, the sheet is outside the core, and driftFix's
comment block is cut to six lines (453 bytes back; main's core had grown
to 258 bytes over with these lines in).

Run, at this head (on origin/main 94f6f6092), on mote unless said:
- gofmt -l internal/gui: clean.
- go vet ./..., GOOS=windows go vet ./..., GOOS=linux go vet -tags
  nogui ./..., go build, GOOS=linux go build -tags nogui, GOOS=windows
  go build: ok.
- go test ./internal/gui -run 'Budget|Quit|CommandQ', and with -tags
  nogui -run 'Budget|Quit': ok (TestCommandQAsksFirst runs AppKit in a
  child process).
- quit-ask.test.cjs, old-webkit.test.cjs, i18n-keys.test.cjs in chromium
  and webkit, en/zh/zh-TW/ja/de: 60/60 ok.
- At the previous base (9d08993c8): go test ./internal/gui (whole
  package, GUI build): two reds. TestCoreScriptBudget (258 over, fixed
  above) and TestMainWindowCorners/macOS_26_SDK, red the same at
  9d08993c8 itself (#3949, macOS 27). The nogui run of the package was
  not reached.
- The whole GUI suite: started at 24fd4a250 on WSL (magpie-desktop),
  stopped about halfway (3,915 results) to rebase; 68 reds in 28 files.
  Those 28 files with quit-ask, old-webkit and i18n-keys at 9d08993c8+this
  on mote: 74 reds in 7 files, none in this change's files. The 7 alone
  at origin/main 9d08993c8: the same 6 files red (73), and
  gateway-caller-keys red at main when run alone (1 of 4). All filed:
  balance-fix #4682 #4683, key-replace #4126 #3476, agent-panel-name-width
  #4203 (red on macOS too, commented), context-map #3488, header-centre
  #3479, gateway-key-models #4616, gateway-caller-keys #3797.
- Not run: go test ./... in full (mote at load 140-160 with others' full
  suites, WSL with two GUI suites), and the GUI suite to its end.

Broken by hand, each red:
- api.go's ask skipped (false &&): TestWindowQuitAsksFirst "the window's
  Quit didn't ask (AskQuit never ran)".
- askingQuit without RemoveMenuItem: TestCommandQAsksFirst "the app menu
  still has the Quit role".
- quitNow as asked == 0 ||: TestQuitNow "connected, never asked: quitNow
  = true, want false".
- The return after a failed disconnect removed: quit-ask 5/25 chromium
  red (the failed-disconnect test in every language).
- app.js's ?ask=quit line removed: 20/25 webkit red.

Windows, for real (xiaomi-gpu, sandbox HOME/APPDATA under
C:\Users\yeton\quitask-sb, MAGPIE_ADDR 127.0.0.1:3471, MAGPIE_NO_ACCOUNTS,
a -H windowsgui build of this branch, launched in the desktop session):
`magpie codex fakeq/m1` wired the sandbox Codex to
http://127.0.0.1:3471/backend-api/codex; WM_CLOSE on the window left
the process alive with no visible window and the gateway listening.

Not tried:
- The tray's Quit and the sheet on real Windows: WebView2's CDP port
  never listened and UI Automation didn't find the tray icon, so the
  sheet was tried in Playwright only.
- A real Codex run against the sandbox gateway before and after a quit.
- The Dock's Quit (not covered by design).
2026-11-01 21:16:35 +08:00
..

Subsystem design references

These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.

Subsystem Reference
Built-in subscriptions moving to plugins Provider and plugin ownership
Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) Plugin runtime
Plugins that run on the gateway's requests and replies Gateway middleware
Tools that plugins give, offered to every agent as an MCP server Plugin tools
Plugins that await context recall and observe completed replies Asynchronous gateway request hooks
Claude subscription turns across Claude Code runs Claude subscription bridge
How the gateway picks a provider, key or account, and falls back Gateway routing and fallback
Gateway Session Aggregation Gateway Session Aggregation
Connecting an agent's config to the gateway, drift, disconnect, WSL twins Agent wiring
Providers, keys, subscription accounts, refresh and allowance Providers and accounts
Instructions, MCP servers, skills and RTK written into agents Library
One MCP server, magpie, given to every agent in place of the Library's servers MCP router
Tray, panel, window, magpie web and the page's JSON API GUI app shell
Encrypted backups and setup synchronization over WebDAV, S3 or GitHub Sync and backup

A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.

Maintain a reference

Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.

Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.

For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.

Describe a PR's semantic changes

For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.

For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.

This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.

Review a change

  1. Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
  2. Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
  3. Check that changed contracts appear in the owning reference and that source links still resolve.
  4. Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.

A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.