Files
plugins/packages
yetone 7c44d02796 zcode 0.1.60: an unreachable plan key or a full plan is a wall, sent once (#1020)
takomitkm saw one GLM-5.3-Flash-Trial request tried 8 times over ~389s,
each failing with "ZCode's Z.ai coding plan key: ECONNRESET: The socket
connection was closed unexpectedly". That text is not the replay: it is
located(), ZCode 3.16's key-location read of the coding plan key
(api_keys/copy/<id>), which runs first in serve(), before any gift or
plan choice. Its failure was thrown, magpie read the throw as a 502 and
asked again (same-one retries, then patience rounds), and the read had
no timeout, so one hung read held the request for minutes. It also told
the user to sign in again for what was the network.

- located(): the key read is bounded (20s). A read that never reached
  Z.ai (ECONNRESET, refused, a timeout, a name that didn't resolve)
  uses the last key read for that location when there is one; with
  none, it is a 429 wall answer (error.code user_model_rate_limited,
  one of magpie's wallCodes, yetone/magpie@067e4c484): sent once,
  rested as a rate limit, the next account asked. An answer that
  refused the read (401, 500) is said as before, sign-in hint included.
- free first's replayOnPlan(): a coding plan whose last usage read
  (codingUsage, teamUsage) counted a window full with its reset ahead
  is not sent to; the replay answers the same wall. The mark is
  dropped by a read with room, at the reset, or 30 minutes after the
  read. A replay that can't reach the plan answers the wall too; a
  caller's abort stays an abort. The gift-first fallback is unchanged.
- The wall's words stay off magpie's quota and credit words, so it
  rests a minute, not a quota's rest.

Tests: packages/zcode/wall.test.mjs (new, 12), built on the reporter's
literal error text; no network (fetch is a fake).

Run:
- packages/zcode bun test on wsl-run (magpie-desktop): 255 pass 0 fail.
- Full suite: `HOME=$(mktemp -d) bun test` on wsl-run (magpie-desktop),
  since mote's and mica's suite locks were queued for hours: 8407 pass,
  0 fail, 19 skip, 593 files. `bun scripts/check.mjs`: exit 0, 59 ok
  (zcode among them).
- Broken by hand (wall.test.mjs on wsl-run), each red, then green
  restored: serve's catch off (2 red), the full-plan check off (1),
  the replay's catch rethrowing (1), the read's timeout removed (1),
  the last key unused (1), the old "sign in again" message (2).

Not changed: a socket error on the plain coding plan path (no free
first) still throws, and magpie still retries any thrown plugin error
as a 502 eight times; filed on yetone/magpie (yetone/magpie#6208).
Not tried: a real Z.ai account whose key read drops, or a real full
plan; magpie's classification of the wall body was read from
origin/main's walled()/failure(), not run.

Reported-by: takomitkm
Refs #1020
2026-11-12 03:15:36 +08:00
..
middleware: param-override, model-map, system-prompt, word-guard and think-tags — gateway middleware that magpie runs on every agent's requests and replies, mostly New API's channel settings with the same JSON (the owner) — magpie can now run a plugin as gateway middleware (onRequest, onEvent, onResponse, in-process on moejs), and these are the first ones: param-override is New API's param_override (both forms, operations with gjson paths and conditions, return_error); model-map is model_mapping (chains, /regex/ keys with $1) and puts the asked-for name back into replies; system-prompt adds a prompt in each API's own place, keeping an agent's own unless override (New API's semantics), by agent or model; word-guard is the sensitive-word filter (reject or mask the user's text, optionally replies); think-tags strips a leading <think>…</think> from replies across stream chunks, or puts Chat reasoning_content into the text (thinking_to_content). Each is one file with no imports, named @magpie-community/middleware-<name>, with magpie.options as the example the app's editor starts from; registry.json lists them with "kind": "middleware" and no providers; check.mjs skips middleware-only packages. scripts/middleware.mjs calls the hooks as the gateway does (events split, [DONE] passed by) and runs each package's cases.json. Tested with a real DeepSeek account and real Claude Code through magpie's gateway: a mapped model named back in message_start, max_tokens capped, a system prompt appended for claude only, a word turned away as a 400 in Anthropic's shape, return_error as a 403 in Chat's, <think> stripped from Chat and Responses streams and an Anthropic whole reply, reasoning_content moved into the text. bun test (61 for these five) and bun scripts/check.mjs pass; packages/devin's two image tests fail on this machine only, as on main. Their first npm version has to be published by hand (trusted publishing can't create a package); until then magpie shows them as Coming soon.
2026-10-05 20:49:42 +08:00