1 Commits
Author SHA1 Message Date
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