Files
orca/src
JinjingandClaude 75f07139fa fix(artifacts): explain artifact API rate limits and replay once on a short Retry-After (#42882)
* fix(artifacts): explain artifact API rate limits and retry once on a short Retry-After

A 429 from the artifact API now carries the server's message and its reset
time in local time to the CLI and the desktop share toast; older servers'
bare 429s say the request was rate limited and when to retry. A Retry-After
of 60s or less replays the request once with the same Idempotency-Key;
longer waits fail fast and keep the pending create intent so a later share
reuses its key.

* fix(artifacts): cancel a rate-limit replay when the account changed during the wait

A Retry-After replay waited up to 60s and then resent with the token captured
before the wait, so a sign-out, account switch or revoked session in between
could still create, update or delete an artifact under the old account. Every
artifact request now passes a check that runs immediately before the replay:
the profile, its cloud link and share lifecycle must be unchanged and, for a
stored session, the session must still be signed in. A request without the
check never replays.

The auth-context builders move unchanged into artifact-cloud-auth-context.ts to
keep the service under its line budget.

* fix(artifacts): cancel a rate-limit replay once sign-out has started

Sign-out advances the session-owner generation before it awaits remote logout,
but only marks the session signed out and unlinks the profile afterwards. A
Retry-After replay that came due during that wait still passed the account
checks and resent with the old token. The replay check now also requires the
session generation captured with the request to be unchanged; token rotation
does not advance it, so normal refreshes still replay.

* refactor(cli): keep the artifact timeout floor in the request-timeout module

Main grew the CLI client to its 300-line budget, so the artifact timeout floor
now lives beside the other per-method timeout helpers and the client reaches
them through its existing import, adding no module to the CLI's load path.

* fix(artifacts): keep one rate-limit wait per operation across a 401 session refresh

A 401 makes the session refresh re-run the whole artifact operation, and each
run got a fresh 429 wait-and-replay. So 429 -> 401 -> 429 -> 200 sent four
POSTs with the same Idempotency-Key, and a reconciled create plus its update
could wait twice and outrun the CLI's 210s request timeout.

The allowance is now created once per operation, before the refresh re-run,
and every request in the operation draws from it. 429 -> 401 -> 200 still
finishes in three calls; 429 -> 401 -> 429 surfaces the second 429 without
another wait. The CLI timeout is now the sum of the most requests one share
can send (five), the single wait and both session refreshes, still 210s.

* test(artifacts): drop timeout tests that pinned production constants and timing

Addresses FARTIFACT429-C4-B1: remove the CLI artifact timeout arithmetic test and
the slow re-run timing/work-count test, plus the imports and stub latency/update
helpers only they used. No production code changes.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-16 22:35:27 -08:00
..