8 Commits
Author SHA1 Message Date
stringke 13a6f4c226 kiro 0.1.40: Kiro sign-ins made elsewhere are imported from a JSON file or paste by their refresh token (#1132)
Accounts signed in to Kiro elsewhere (Kiro Account Manager lists and
exports, kiro2api, the Kiro IDE's kiro-auth-token.json with its
<clientIdHash>.json client, kiro-cli's tokens) are imported in magpie's
"Import accounts from a file…" by their refresh token. Each is renewed
where its kind is renewed (Google/GitHub at prod.us-east-1.auth.desktop.kiro.dev,
Builder ID / Identity Center at oidc.<region>.amazonaws.com with its client)
and named by the email Kiro has for it. Other providers' entries in a
sign-in store are skipped, duplicates are renewed once, at most 100 a time.

A region or profile ARN read from a file can't pick a host any more, on
every route (import, the IDE's file, kiro-cli's DB, a saved sign-in):
regionOf takes only Kiro's API regions (us-east-1, eu-central-1) from a
profile, arnOf keeps only arn:aws:codewhisperer:<region>:<12 digits>:profile/<id>
(else Kiro is asked for it), and oidc/runtime/management/refreshURL refuse
a region that isn't an AWS region's shape.

Version 0.1.40: #1156 published 0.1.39 first, so main was merged into the
branch and the version raised (f8af341f). With arnOf, #1156's test fixture
ARN (account "1") was dropped and its reasoning-replay test went red on
the merge; every test fixture ARN now has a 12-digit account (0b899428).

What was run, on mote with HOME=$(mktemp -d) as CI:
- PR head 41938ff0, packages/kiro: bun test, 202 pass, 0 fail.
- The earlier review's repro (imported Google sign-in, fresh access
  token, profileArn arn:aws:codewhisperer:attacker.example/#:1:profile/X):
  at 41938ff0 every request goes to *.kiro.dev, nothing saved with the
  crafted ARN. With 5dd9e682's index.mjs put back it and all five
  profile-host.test.mjs tests are red (hosts [management.attacker.example]).
- Merged head f8af341f (main at baeb95a4): root bun test, 8771 pass,
  1 fail (reasoning-replay's fixture, above).
- Reviewed head 0b899428: root bun test, 8772 pass, 0 fail, 613 files.
  Main since gained only 2523b43a (packages/agy-cli/test/smoke.mjs).

Read for credential safety: no logging; errors carry no token; refresh
tokens and client secrets go only to Kiro's auth service and AWS OIDC;
an imported sign-in has no dbKey/idePath, so renewing it writes back to
no kiro-cli or IDE file. No .github, dependency or new host.

Not tried: a real Kiro account imported from a real export.
2026-11-15 13:58:11 +08:00
yetone 966cf71764 kiro: a 429 throttle is waited out and tried again, as the Kiro IDE does (0.1.32)
onemezao on Discord: a "hi" answered, and the next message straight
after was Kiro's 429 USER_REQUEST_RATE_EXCEEDED, while the Kiro IDE on
the same Builder ID account and model (claude-haiku-5.5) took two
messages in a row (plugins#842, plugins#848).

The IDE gets the same throttles; it rides them out. Its chat client
(kiro.kiro-agent 1.1.787, dist/extension.js) classifies a
ThrottlingException with reason USER_REQUEST_RATE_EXCEEDED or
CREDIT_CONSUMPTION_RATE_EXCEEDED (ClientThrottleError) or any other
throttle (ServiceThrottleError) as retryErrorType THROTTLING, and its
QClientRetryStrategy tries 3 times: Kiro's retryAfterMilliseconds when
said, else 1s doubling (20% jitter, 20s max), counting each try in
amz-sdk-request and x-amzn-kiro-attempt. It shows "Retrying in N
seconds" over 2s. The plugin sent the first 429 back at once, and
since 0.1.30 with Retry-After 30s, so magpie didn't retry either.

Now paced() sends a chat call the same way: a 429 throttle (those three
reasons, or a reasonless "too many requests"/throttling) is waited out
and sent again, up to 3 tries, one invocation id, attempt=N; max=3. A
wait Kiro says is over 20s isn't held: the 429 goes back with it as
before. Usage limits (MONTHLY/DAILY/..., USAGE_LIMIT), model capacity
and other statuses aren't retried. A cancelled request ends during the
pause and isn't sent again. The last try's 429 keeps 0.1.30's words and
Retry-After.

The 47.3K input tokens of a "hi" are Kiro's own contextUsagePercentage
times the model's window: the agent's system prompt and tools, not
something the plugin adds.

Run (mote, HOME and TMPDIR inside the run dir):
- packages/kiro: bun test, 157 pass 0 fail.
- repo root: bun test; bun scripts/check.mjs kiro.
  Root: 6867 pass, 0 fail, 6887 tests across 499 files; check ok.

Broken by hand: paced() returning the first answer (n >= 1) turns 5
tests red (the four new throttle tests in errors.test.mjs and
region.test.mjs's rate-limit case).

Not tried: a real throttled Kiro account. No Builder ID account that
Kiro throttles was at hand, so the retry is checked against the IDE's
code and mocked answers only, not against Kiro.

Reported-by: onemezao (Discord)
2026-11-08 04:52:34 +08:00
yetone 44df5f0505 kiro 0.1.30: an account's request rate (USER_REQUEST_RATE_EXCEEDED) says whose limit it is, and isn't re-asked at 1/2/4s
onemezao on Discord: through pi, every request of a one-account Kiro
setup (claude-haiku-5.5, 965KB sent) failed after 42s with Kiro's "Too
many requests, please wait before trying again.
(USER_REQUEST_RATE_EXCEEDED)", while the Kiro IDE answered on the same
account. Kiro's words say neither whose limit it is nor what to do, and
with no wait given magpie sent the whole request to the same account
again at 1, 2 and 4s, each try one more against that account's rate.

- failure() and the stream's exception() turn that reason into a 429
  that says Kiro is limiting this account's requests, to wait a minute,
  and that a limit persisting while the Kiro app works is on the account
  for Kiro support, with the request ID (x-amzn-requestid, as the IDE
  reads it) when Kiro gave one.
- When Kiro gives no wait for that reason, Retry-After is 30s, past
  magpie's same-account retries (8s), so the 1/2/4s re-asks stop. A
  wait Kiro does give still wins; other reasons keep magpie's pauses.

Cause, from a real account (the owner's existing kiro-cli sign-in, no
sign-in or refresh, sandbox HOME): a 975KB request is not refused as a
rate: claude-haiku-4.5 answers 400 CONTENT_LENGTH_EXCEEDS_THRESHOLD and
auto (1M) answers 200 in 8.9s; 467KB on haiku 200 in 5.2s; "?" 200. So
the reporter's 429 is Kiro's per-account request-rate state, not the
body or the model. Kiro's own tracker has the same reason on the IDE
for hours (kirodotdev/Kiro#10937, #8549), answered by support.

Run on mote: bun test packages/kiro (146 pass), bun scripts/check.mjs
kiro, and the repo's bun test (6759 pass, 0 fail), each in a temp HOME.
Broken by hand: the new tests against the old index.mjs, 3 red (the
Retry-After cases, the plain message with request ID, the stream case).
Not tried: a real USER_REQUEST_RATE_EXCEEDED (couldn't be drawn without
hammering an account), claude-haiku-5.5 (not on the owner's account),
and whether the Kiro IDE's other request path (CreateResponse) is
rate-counted apart from generateAssistantResponse.

Reported-by: onemezao
2026-11-07 16:58:27 +08:00
yetone ab0d3fe54a kiro 0.1.27: Kiro's wait before asking again goes on as Retry-After
A 429 Kiro answered before any of the reply (USER_REQUEST_RATE_EXCEEDED,
"Too many requests, please wait before trying again.") reached magpie
with no word of when, as the plugin built its error response from
nothing. With one account magpie then asked it again after 1, 2 and 4s
and on through its patience: onemezao's one small message took six asks,
five of them 429.

The plugin now reads the wait where Kiro's own clients read it and sends
it on as Retry-After (whole seconds, rounded up): the Kiro IDE's
x-amzn-kiro-ratelimit-retry-after header and the body's
retryAfterMilliseconds (both ms; kiro.kiro-agent 1.1.499, decompiled in
hj01857655/kiro-account-manager docs/Kiro-1.4.5/re/pfd-full.txt), the
x-amz-retry-after header kiro-cli 2.35's AWS SDK honours (ms, found in
the binary's strings), and HTTP's Retry-After. magpie's gateway already
waits a Retry-After: past 8s it skips the quick retries and rests the
account that long. With none said, nothing changes.

Run (mote, HOME a temp dir): bun test packages/kiro, 127 pass;
bun scripts/check.mjs, ok.
Broken by hand: generate without the wait argument; the new test fails
(Expected "13", Received null).
Not tried: a real Kiro 429. Which of these headers Kiro sends on
generateAssistantResponse's 429 is not seen; the IDE reads them on its
CreateResponse path. Hammering a real account to get one was not done.

Reported-by: onemezao
2026-11-07 03:17:09 +08:00
yetone e8050e812d kiro 0.1.24: a conversation past the model's window is a 400 that says too long
Kiro says a conversation is too long for the model three ways: an HTTP
400 ValidationException "Input is too long." (CONTENT_LENGTH_EXCEEDS_THRESHOLD),
the same ValidationException as an exception frame in the event stream,
or a metadataEvent with stopReason MODEL_CONTEXT_WINDOW_EXCEEDED. Only the
first came out as the 400 "input is too long for the model's context: ..."
that magpie's gateway reads as an overflow (tooLong). The stream exception
went out as a 502 (failedBefore), and the stop reason as end_turn.

As a 502, magpie counted a passing failure: it asked the same Kiro model
again, could rest the account, and in a group routed by intent only moved
on as for any vendor error; a lone agent got a vendor error instead of
context_length_exceeded, so it never compacted. Reported by
ergou0954_54426 on Discord (Kiro's Claude/GPT and DeepSeek in intent
routing, "kiro 那边报错说超出上下文").

Now failedBefore, and the turn after a web search, answer a too-long
exception with that 400. A MODEL_CONTEXT_WINDOW_EXCEEDED stop before any
of the reply is the same 400; after some of it, the reply ends with stop
reason model_context_window_exceeded (Anthropic's word for it). Other
exceptions keep 502, quota and throttling keep 429.

Run on mote: HOME=$(mktemp -d) bun test in packages/kiro, 122 pass;
bun scripts/check.mjs ok. Broken by hand: with index.mjs at HEAD the
three new too-long tests fail (13 pass, 3 fail in errors.test.mjs).
Not tried: a real Kiro account pushed past its window; the stream shapes
come from Kiro's own clients (amazon-q-developer-cli's error enums,
kiro.rs, opencodex's kiro stream reader).
2026-11-01 11:11:02 +08:00
yetone 01aee5da28 all: a usage read says what it means for the sign-in, and a renewal clears the mark whatever follows, as the built-ins did (要保证插件跟内置的所有逻辑都要一模一样) — auth.usage returns signIn on every path: expired where the built-in's quota read marked the account (Zed's /users/me 401, Factory's and MiMo's refused renewals, Qoder's refused job refresh), renewed after a renewal, which took the mark off, kept everywhere else, so magpie no longer guesses from the words 'sign in again' (Kiro's, Devin's and ZCode's usage errors marked accounts their built-ins never did) nor clears on a clean read. A request after a renewal says renewed on any status; one without says kept, as the built-ins cleared only on renewal. Kiro, Cursor, Devin, Command Code, WorkBuddy, Grok and ZCode, whose built-ins never marked an account, say kept on every answer. New tests fail against 85d7dd0's index.mjs. 2026-10-01 04:53:29 +08:00
yetone 85d7dd0d0a all: each plugin fails with its built-in's status and marks the sign-in as it did, through X-Magpie-Sign-In (要保证插件跟内置的所有逻辑都要一模一样) — Factory's and MiMo's refused renewals are the built-ins' 502 marked expired, not 401s; Qoder's vendor 403 is the built-in's 401 kept, its model list's failure a 400, its job refresh refused marked expired; Zed's retried 401 is a 401 kept, not a 403; Kiro's unreachable refresh a 401 kept; Cursor's expired trial a 401 kept; a vendor 401 WorkBuddy, Grok, Devin, Command Code and ZCode passed on no longer marks the account, as their built-ins never did, and Grok and MiMo no longer retry what their built-ins sent once. Messages take the built-ins' words. New tests fail against the previous index.mjs. 2026-10-01 04:47:03 +08:00
yetone 8efe85163c kiro 0.1.4: an exception Kiro sends before any of the answer (a throttle, a quota, a server error) is a status, not a 200 stream holding an error event, as the built-in's relay answers it: a 429 when it reads as a quota or rate limit (magpie's quotaWords), else a 502, so magpie moves on to the next account exactly as it did; unstreamed, what was said before a later exception is the answer, as the built-in's collector gives it, where the plugin answered 502. errors.test.mjs fails without the change. 2026-10-01 03:45:12 +08:00