Files
magpie/internal/imagemcp
yetone f0dc9ea695 imagemcp, gateway: a 4K image a relay answers by URL is saved, and one that can't be downloaded is answered with its URL, not lost (#1576, david-zdw)
What the reporter saw: generate_image (magpie mcp image) failed on 4K and
2048x1152 with "image 1: context deadline exceeded" and "no image: context
deadline exceeded", while the same request to /v1/images/generations came
back in ~40 s, and usage.jsonl showed the upstream's 200. Their relay
answers with a URL whatever response_format says.

Two causes, one per error:

- "image 1: context deadline exceeded" was generate_image's own download
  of the URL (imagemcp.download): 2 minutes for the whole of it, on
  http.DefaultTransport, which knows the global proxy but not a provider's
  own (#237). A 10 MB PNG that was still coming was cut, and the error
  dropped the URL of an image already drawn and paid for. Any earlier
  image of n was saved but not said either.
- "no image: context deadline exceeded" (the usage log's 502s at
  300002-300032 ms) was the gateway's drawTimeout (5 min) expiring while
  it read a vendor's answer that had already begun: sendWith passed the
  bare context error up. The vendor really took over 5 minutes there;
  this commit doesn't change that limit, it says what happened.

What changed:

- gateway: an images caller that asks response_format "b64_json" gets the
  image itself. One the vendor gave only a URL for is fetched by the
  gateway's own client, through the provider's proxy (p.Via), after the
  draw and outside drawTimeout. One that can't be fetched is answered by
  its URL, as before, never dropped. A caller that asks no format still
  gets the URL. Nothing is sent to the vendor differently.
- gateway.FetchImage: an image download gives up when nothing has come
  for ImageStall (1 min) or it has taken ImageLongest (5 min), and says
  which and how much had come. A slow download goes on while it moves.
  The edits' fetchPicture uses it too.
- gateway: a vendor that began answering but hadn't finished in
  drawTimeout is a 504 "<name> began answering after Ns (200 OK) but
  hadn't sent all of its answer in 5m0s", not a 502 "context deadline
  exceeded".
- imagemcp: asks for b64_json; downloads a URL the gateway still hands it
  with FetchImage; an image it can't have is answered with the vendor's
  URL to download it from, beside the ones saved (an error only when
  none was). Its client to the gateway waits ToolTimeout (11 min), past
  the draw and the fetch together, not 6 minutes.

What was run:

- Reproduced on the old code: the new TestFourKImageByURLIsSaved (a real
  3840x2160 PNG, 9.8 MB, served by URL in 256 KB pieces over ~4 s) with
  the old download's 2-minute cap scaled to 1 s fails with the
  reporter's exact "image 1: context deadline exceeded"; the stalled
  case fails the same way, with no URL in the error.
- Broke each part by hand and watched its test go red: no inline fetch,
  fetch not through the provider's proxy, the bare deadline message, the
  stall timer not reset (a total cap again), a lost image ending the
  call, the MCP not asking b64_json.
- go test ./internal/imagemcp/ ./internal/gateway/ ; the full
  go test -tags nogui ./... ; gofmt -l ; GOOS=linux and GOOS=windows
  go vet on both packages.
- On the Windows box (Windows 11 x64): imagemcp.test.exe all passed, and
  gateway.test.exe for the new tests and the images/ModelScope tests.

Not tried: the reporter's relay itself (never contacted), and a real
4K draw end to end. Why their URL took over 2 minutes from the MCP when
their own download took 7.5 s isn't known from here: a provider proxy
the MCP didn't use is one way it happens; a slow file host is another.
Both are covered now.
2026-10-11 14:59:23 +08:00
..
library, imagemcp: magpie's own image server is given to agents in WSL, started through WSL's interop with the paths crossing over (#900, cjyrainbow) — on Windows the Library names magpie-image by this machine's binary ('D:\tools\Magpie\magpie-windows-amd64.exe' mcp image), and turning it on for "Codex · WSL Ubuntu" or "Claude Code · WSL Ubuntu" failed: a Windows program was refused for every agent in WSL. WSL's interop starts a Windows .exe from inside the distro, so magpie's own server (args mcp image, whatever its binary) is now written for an agent in WSL by the binary's path in the distro, asked of the distro itself (wslpath -u, so a custom automount root is followed; asked once in ten minutes; /mnt/<drive>/ when it can't be asked), with --wsl <distro>, --mount where the drives aren't under /mnt/, --home the distro's $HOME, and WSLENV naming the variables it is given (MAGPIE_ADDR), which a Windows program otherwise doesn't get. A distro whose interop is off (no WSLInterop in binfmt_misc) is told so: turn it on in /etc/wsl.conf. A user's own Windows program is still refused, as before: its paths and variables wouldn't cross over. A Linux magpie in the distro isn't looked for: the Windows one reaches the gateway at 127.0.0.1 and reads this machine's settings, the same version as the app, which a Linux one would need the gateway's address from inside WSL for. With --wsl, magpie mcp image opens the paths the agent gives (its roots, reference images, where to save, ~/) as the distro's — /home/me/x through \\wsl.localhost\<distro>\home\me\x (\\wsl$\ where that isn't), /mnt/c/x as C:\x — answers the saved paths as the distro's (/home/me/app/generated-images/…, /mnt/c/…), and with no project falls back to the distro's ~/Pictures/Magpie. Tested on the Windows 11 test box: in a WSL2 Ubuntu 24.04 distro the library's probe gave /mnt/c/…/magpie.exe and interop:on, and this build, started from the distro as the library writes it (the .exe's /mnt/c path, mcp image --wsl, MAGPIE_GATEWAY through WSLENV to a stand-in gateway in the distro), answered initialize and generate_image with a root of /home/yeton/m900proj: a relative path and an absolute reference image (sent as /v1/images/edits), ~/m900proj/home.png and /mnt/c/… were each saved there and answered as the distro's paths. TestWSLMagpieImage (the /mnt/d command, --wsl, WSLENV, nothing rewritten or asked again at the next sync, a custom mount, interop off as a problem) and TestLinuxHome in internal/library, TestWSLPaths in internal/imagemcp are new and fail without the change; TestWSLServers (npx.cmd still refused) passes. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (internal/provider failed once under load and passes alone).
2026-10-05 20:09:34 +08:00
library, imagemcp: magpie's own image server is given to agents in WSL, started through WSL's interop with the paths crossing over (#900, cjyrainbow) — on Windows the Library names magpie-image by this machine's binary ('D:\tools\Magpie\magpie-windows-amd64.exe' mcp image), and turning it on for "Codex · WSL Ubuntu" or "Claude Code · WSL Ubuntu" failed: a Windows program was refused for every agent in WSL. WSL's interop starts a Windows .exe from inside the distro, so magpie's own server (args mcp image, whatever its binary) is now written for an agent in WSL by the binary's path in the distro, asked of the distro itself (wslpath -u, so a custom automount root is followed; asked once in ten minutes; /mnt/<drive>/ when it can't be asked), with --wsl <distro>, --mount where the drives aren't under /mnt/, --home the distro's $HOME, and WSLENV naming the variables it is given (MAGPIE_ADDR), which a Windows program otherwise doesn't get. A distro whose interop is off (no WSLInterop in binfmt_misc) is told so: turn it on in /etc/wsl.conf. A user's own Windows program is still refused, as before: its paths and variables wouldn't cross over. A Linux magpie in the distro isn't looked for: the Windows one reaches the gateway at 127.0.0.1 and reads this machine's settings, the same version as the app, which a Linux one would need the gateway's address from inside WSL for. With --wsl, magpie mcp image opens the paths the agent gives (its roots, reference images, where to save, ~/) as the distro's — /home/me/x through \\wsl.localhost\<distro>\home\me\x (\\wsl$\ where that isn't), /mnt/c/x as C:\x — answers the saved paths as the distro's (/home/me/app/generated-images/…, /mnt/c/…), and with no project falls back to the distro's ~/Pictures/Magpie. Tested on the Windows 11 test box: in a WSL2 Ubuntu 24.04 distro the library's probe gave /mnt/c/…/magpie.exe and interop:on, and this build, started from the distro as the library writes it (the .exe's /mnt/c path, mcp image --wsl, MAGPIE_GATEWAY through WSLENV to a stand-in gateway in the distro), answered initialize and generate_image with a root of /home/yeton/m900proj: a relative path and an absolute reference image (sent as /v1/images/edits), ~/m900proj/home.png and /mnt/c/… were each saved there and answered as the distro's paths. TestWSLMagpieImage (the /mnt/d command, --wsl, WSLENV, nothing rewritten or asked again at the next sync, a custom mount, interop off as a problem) and TestLinuxHome in internal/library, TestWSLPaths in internal/imagemcp are new and fail without the change; TestWSLServers (npx.cmd still refused) passes. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass (internal/provider failed once under load and passes alone).
2026-10-05 20:09:34 +08:00