Commit Graph
2 Commits
Author SHA1 Message Date
yetone ea3573bfe9 zcode 0.1.58: an account served fewer than three is narrowed, not held; trial entries are free (#438)
takomitkm (plugins#438, 0.1.57, default settings) had the busy hold arm
with one account, one agent and at most two in flight, at about five
asks a minute, and arm again within a minute of its end. A coding plan
model's weekly or monthly limit (1310) also rested the whole account, so
its -Trial models got the cached 1310 without being asked.

Busy hold. ZCode serves that account one Start Plan request at a time,
so every second request was refused again at its 1s re-ask and counted
toward the process-wide hold. A sustained cap with others of the same
account in flight (the gate's lane busy >= 2) now narrows that account's
gate to busy-1, at least one, for NARROW_FOR (5 minutes; startGate.now
is its injectable clock) and counts toward no hold. A lone sustained
cap still counts, so the hold stays process-wide and keeps the firewall
protection: #801's caps came with up to ~10 in flight, which the gate
never sends, and an account whose slots are taken elsewhere narrows
3 -> 2 -> 1 within a few caps and is then refused alone, which arms the
hold as before. The queue answer says the account's current number.

Rest. The models hook marks each -Trial entry free: true, so magpie's
PaidBesideFree makes a coding plan model's quota refusal rest that
model, not the account. Gift-only accounts' plain names stay unmarked.
Side effects: the Free mark in pickers, free-preferring groups pick the
trials first, and they price at 0, which they are.

Run (mote, bun 1.4.2, HOME=$(mktemp -d)): packages/zcode bun test,
240 pass, 0 fail, 17 files, at this head rebased on 60acd62b;
bun scripts/check.mjs exit 0.

Broken by hand:
- narrowing off (if (false && ...)): the three new inflight tests fail;
  the reporter's case shows the hold armed (until=1000000240000).
- lone caps narrow too (busy < 1): seven hold tests fail (the
  saturated-elsewhere replay, refused-even-one-at-a-time, start.test's
  hold tests, dual's hold test).
- free: true removed: the new gift test fails.

Tests: inflight.test's reporter's case (fake caps at >= 2 in flight,
injected clocks), the narrowing's expiry, and a lone refusal still
arming the hold; gift.test's free trial entries. start.test's in-flight
guard now uses twelve accounts of one request each, and dual.test's hold
test a gate of one, so their caps stay lone ones.

Not tried: a real ZCode account served one at a time; the core side
(magpie's TestZCodeCodingPlanLimitLeavesTrials) is in magpie with the
mover min.

Reported-by: takomitkm
2026-11-11 03:26:57 +08:00
yetone a313a00306 zcode 0.1.56: the Start Plan goes three at a time and re-asks a cap twice, as ZCode's client does
Users of other agent apps on the ZCode plugin saw "rate limited 5 times
in a minute" (star21321321124 on Discord). That is the plugin's own
3-minute busy hold (0.1.54, #801), which trips after ZCode refuses five
requests in a minute as over its in-flight cap (429 3008/3009). The
plugin drove those refusals itself:

- It sent every request magpie passed it. magpie's lane is 3 per
  account, but nothing in the plugin held the Start Plan to that.
- It re-asked a capped request up to six times over about 10s
  (BUSY_WAITS 250..4000, from #395). That kept slots taken and drew
  more caps.
- It counted every capped request toward the hold, including ones the
  next re-ask got past.

ZCode 3.17.2, read from its bundle: wqo = {3008, 3009, 3010} and
kqo = [1e3, 2e3]. So a busy cap is re-asked at most twice, after 1s and
2s, Start Plan only. There is no hold, and one main turn runs per
session.

What changes:
- BUSY_WAITS is [1000, 2000], with no jitter, and 3010 counts as busy.
  This applies to every plan, since the coding plan goes through the
  same askBusy.
- startGate: on the Start Plan, an account has at most 3 requests in
  flight (#395 measured about 3: 3 of 12 and 4 of 12 served). The
  account is keyed by uid, then accountId, then key. Further requests
  wait in a FIFO queue in the plugin and are not sent. A slot is freed
  when the upstream body ends, the agent cancels, or its signal aborts
  (the body is pumped eagerly so an unread reply cannot hold a slot).
  After 2 minutes of waiting, the plugin answers 429 rate_limit_error
  with Retry-After 5: "ZCode's free Start Plan serves this account 3
  requests at a time; this one waited 120s behind the others and was
  not sent. Run fewer agents or subagents on ZCode at once, or try
  again". The coding plan stays ungated. Its cap follows the tier (the
  #395 review), and magpie's lane covers it.
- Free first skips the gift while its account's gate is full, so the
  plain model goes to the coding plan rather than queueing.
- The hold counts a request only when ZCode refuses it again at the 1s
  re-ask. N=5, the 60s window and the 3-minute hold are unchanged, as
  is the rule that an in-flight or queued request stops once the hold
  is armed. Its message now says what happened and what to do: "ZCode
  turned away 5 requests in the last minute as too many requests at
  once, each again when asked a second later. So that ZCode's firewall
  does not block this network, magpie sends no free Start Plan
  requests for the next Ns. Wait, run fewer agents or subagents on
  ZCode at once, or use a GLM Coding Plan model". The words avoid
  "plan"+"limit" after "exceeded", which magpie's usedUpWords would
  read as spent.

History checked: #395 (0.1.32) added the long waits and had an
in-plugin gate removed in review, because it held Max coding-plan
accounts to 3 and was keyed on the jwt. This gate is Start Plan only
(one tier) and keyed per account. #801 (0.1.54) added the hold from
the logs of 11-05 23:06 and 11-06 06:23: about 16 to 18 req/min, 7 to
10 in flight, and the first 405 after 205 to 517s. The hold still
trips on sustained refusals: the replay below has the account
saturated elsewhere, and the hold arms within the replayed minute with
nothing sent after it.

Run on mote, HOME=$(mktemp -d), at the rebased head, Bun 1.4.2:
- bun test packages/zcode: 235 pass, 0 fail.
- New inflight.test.mjs: 13 pass. It covers re-ask count and timing
  (3 asks, gaps of about 1s and 2s), 3010, at most 3 in flight of 12
  sent at once, per-account slots, a slot held across re-asks, the
  queue wait running out (nothing sent, plain 429), abort while queued,
  a cancelled stream freeing its slot, the coding plan ungated, a cap
  the 1s re-ask got past not counting, and the hold message. It also
  replays #801's two days at 20x speed against a fake that refuses past
  3 in flight: 0 refusals, peak 3, no hold, all served. A second replay
  with the account saturated elsewhere arms the hold within a minute.
- bun scripts/check.mjs zcode: ok (registry.json, zcode). Repo bun test: 6780 pass, 0 fail, 20 skip, 491 files.
Broken by hand: inflight.test.mjs against 0.1.55's index.mjs gives 11
of 13 red. 0.1.55 made 7 asks, had 12 in flight, drew 24 refusals in
the replay, and armed the hold on caps a re-ask got past. Two pass on
both, as expected: the coding plan stays ungated, and the saturated
replay still holds.
Not tried: real ZCode Start Plan accounts, live; the replay is
synthetic from the #801 figures, as the raw logs are not in the repo.
Not copied from ZCode's client: its "no re-ask on a session's first
turn" rule, since the plugin cannot tell a first turn reliably.

Reported-by: star21321321124
2026-11-07 17:54:55 +08:00