lazyeo on Discord (Apple M2, 16 GB, macOS 27.0.1, since v0.1.1577): with
Settings → Privacy's local model on, every request, even the first after
a restart, waited out the gateway's 2-minute 504 ("still loading"), and
Settings showed "pf-serve ended: ggml_metal_device_init: tensor API
disabled for pre-M5 and pre-A19 devices … recommendedMaxWorkingSetSize".
Their goroutine dump has startOne(path, cpu=true): a GPU pf-serve had
failed and every request was loading the CPU one.
What was wrong:
- macOS had one pf-serve candidate, the Metal one; a load that hung on
the GPU waited out loadTimeout (3m) with no CPU to fall back to.
- The error was pf-serve's stderr, which on every pre-M5 Mac starts with
ggml's Metal init lines (the CPU mode too), so a kill by magpie's own
classify watchdog read as a Metal crash. On an M4 Pro the CPU mode
reads ~1.4 KB/s, below classifyTimeout's 4 KB/s, so a slower Mac's CPU
pf-serve is killed by magpie on larger requests.
- Each failed request left the next one to load again, so a model that
keeps failing held every request for its full 2 minutes.
Changes (internal/pii):
- candidates(): the GPU one (Vulkan, or macOS's Metal pf-serve), then
pf-serve with PF_DEVICE=cpu. A GPU load gets gpuLoadTimeout (40s, inside
the gateway's 2m); a GPU that fails or hangs moves the run to the CPU
and sets gpuLost, as one dying in classify already did.
- died(): "didn't answer in Xs (N KB on the CPU), so magpie ended it"
when the watchdog killed it, else "ended (exit status/signal)", then
the last 3 stderr lines that aren't ggml/Metal/Vulkan startup chatter
(a line saying error/fail/assert/abort is always kept).
- After a failure, FindContext holds requests back at once with that
error (before and after taking the turn), until a retry 30s later,
doubling to 10m while it keeps failing; a success or Stop resets it.
The request is still held, not sent masked by the rules alone; the
message says how to turn the model off.
- pii.go's comment and docs/subsystems/gateway-routing.md say so.
- Tests: a cleanup race in fakeInstall, and the seam above (cache.go
gets disk.saves).
Run (worktree at origin/main a6c808b68 + this, sandbox HOME):
- go test -count=1 ./internal/pii/ ok; -race -count=1 ok (54.7s).
- Broken by hand, each red, then restored:
- old candidates (macOS Metal alone, plain one not forced to CPU):
TestHungGPULoadMovesToCPU both subtests "didn't load in 3s on the
GPU" and TestVulkanThatWontStartFallsBack starts = [vulkan MTL0,
pf-serve MTL0].
- not remembering the fallen-back GPU: TestHungGPULoadMovesToCPU red
(starts = [CPU] only after Stop, GPUError empty).
- old died(): TestEndedForSlownessSaysSo and
TestDeathSaysExitAndLastWords red with the M2's Metal lines as the
error.
- heldBack() returning nil: TestFailedModelHoldsRequestsBackAtOnce red
("didn't answer in 300ms", a queued request loaded again).
- Real pf-serve and model (pf-v2-darwin-arm64) on an M4 Pro, macOS 26.2,
outside magpie: GPU load 9.9s cold / 0.86s warm, 200 KB in 2.3s; CPU
load ~20s, 50 KB in 36.4s; the CPU mode's stderr also has the
"tensor API disabled for pre-M5" lines.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... ok; go build for darwin, linux (nogui),
windows ok.
- After the first full run, TestHungGPULoadMovesToCPU was red at load
~220 (the stand-in hadn't logged its GPU start inside a 3s budget). It
now gives the GPU load up once the stand-in has started on it
(`giveUp`, a seam over time.After), not after a duration: 8 of 8 green
at load 220, and still red with the old candidates.
- -race then caught fakeInstall's cleanup restoring dir while the disk
cache's 2s save timer, already fired, was writing (cleanup stopped
only a timer that hadn't fired). disk.saves now counts a timer's
write until it is done, and cleanup waits on it. -race -count=3
./internal/pii/ ok (143.9s).
- go test ./internal/gateway/ ./internal/redact/ ./plugins/redact/ ok
(gateway 601.5s); internal/masking has no tests.
- Full suite: not completed. go test ./... -timeout 45m at 18:06
(load 118, no other Go suite running) failed to build 16 packages and
failed TestWarm, proc's TestEndProbesThenExitLeavesNothing and
settings' TestSaveConcurrent, all "no space left on device": the
disk was at 189 MB free (900 of 926 GB used, not by this run). By the
time space came back, other sessions' suites were running (a gateway
run, a -p 3 multi-package run, the GUI suite), so a second full run
would have broken one suite per machine. Every package that ran and
isn't named above was ok.
- Rebased on 7d075df9d (pushed head's parent): go build and
go test ./internal/pii/ ./internal/redact/ ok there.
Not tried: an M2 or macOS 27 (no such machine), so why lazyeo's GPU
pf-serve failed first is still unknown; the new error and gpuLost will
show it. No known llama.cpp/ggml issue for macOS 27 or the pre-M5 tensor
line turned up. A CPU too slow for a large request is still killed by
classifyTimeout; it now says so and holds the requests after it back at
once.
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 |
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
- Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
- Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
- Check that changed contracts appear in the owning reference and that source links still resolve.
- 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.