Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

docs: each rule written once where it is owned - when a refused provider request is sent again, with what each provider documents and the date it was read (gen.md, pointed to from video.md, video-pipeline.md and pixel-draw.md), a flag against the file that holds the same key (run-contract.md, pointed to from pixel-draw.md and pixel-unfake.md); pixel-draw's table names what it now takes; CHANGELOG Unreleased

Soohong Kimb98bd38ed58f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a862d6c..a905b1e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,13 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
## Unreleased
+- **Behavior change: a flag given together with a file that holds the same key wins, and one stderr line says so — for `prepare --request` / `--request-json` and `pixel-draw --spec` alike.** `pixel-draw` refused the pair; `prepare` let the flag win for most keys in silence, and let the request win for three: `--style`, `--cell-size` and `--safe-margin` were dropped when the request carried a style, a cell size or a margin. Now every such key takes the flag and the run says `[prepare] --style, --cell-size given both as a flag and in --request-json: the flag wins` (`gen.base.flags_over_spec`, the one answer, [run contract](docs/run-contract.md#1-pipeline-stages)). A cell flag replaces the measure however the request spelled it (`size`, `width`, `cell_width`). `prepare`'s note no longer lists a request's `subject` among the keys it drops — it was always carried.
+- **Behavior change: an answered provider request is sent again only when the provider documents the answer as a request it did not take — one rule for every direct call.** `gen`'s OpenAI and Grok image POSTs, the facing check and the clip POST of the video verbs were never sent again, and `pixel-draw`'s Anthropic transport sent 429 and every 5xx again after 10 s and 30 s. Now each asks `gen.retry`: OpenAI 429 (but its billing codes — a spent credit balance, a spend or usage limit, `insufficient_quota` — which ask you to act) and 503 overloaded; xAI 429; Anthropic 429 (but its spend cap), 500 and 529 — read off each provider's error and rate-limit pages on 2026-10-13 ([a refused request sent again](docs/gen.md#a-refused-request-sent-again)). Not sent again any more: Anthropic 502, 503 and 504 (`timed out while processing`). The wait is the answer's `retry-after` when it is at most 120 s (a longer one is not cut short: the request is not sent again), else the doubling the video polls already waited by, 8 s then 16 s; twice at most, each on stderr as `[gen] openai refused the request (429 rate_limit_exceeded); nothing was made — asking again in 8s (1 of 2)`. A refusal still there ends the call as before, its line saying `sent 3 times, no provider fallback` in place of `no retry or provider fallback`. A request with no answer it could read is still never sent again. `video-set` runs each clip once: its own rerun of a clip whose log said `HTTP 429` (15 s, 30 s) is gone, as it made every POST a second retry loop on top of the first. The video polls and downloads also ask again on `529`.
+- **Fix: a refusal whose body broke on the way is no answer on every transport.** `xai.http_json` already said so; `openai-gen` let the broken read escape as a traceback, and `pixel-draw`'s Anthropic transport read it as a refusal with an empty body (and sent a 429 or 5xx again). Both now end as a request that got no answer — the server may have taken it — through the one reader of a refusal's body, `xai.error_body`. An OpenAI answer cut short (`IncompleteRead`) is that line too, not a traceback.
+- **Fix: a hex colour is six hex digits, the `#` optional — read and written in one place (`util.hexcolor`).** `recolor`'s map, `slice-sheet --chroma-key`, `handed-check --marker` / `--strap` and the curation view's pixel edits took a sign or an underscore as a digit (`#-1-1-1` read as (-1, -1, -1); a non-hex six-letter edit stopped the request); each now refuses it in its own words, and the curation view skips it as it skips a value of the wrong length. `prepare --chroma-key` also takes `RRGGBB` without the `#`, as the other flags did. Written colours are unchanged: upper case, and lower case in `recolor`'s report and palette draft.
+- **Fix: a Python call of `gen.run`, the video verbs' `run`, `pixel-draw`'s `run` or `inspect-motion`'s `run` without a required flag is a TypeError naming it**, as the other verbs' `run(**kwargs)` always said; these four read their keywords by hand and went on with `None`. One reader for all, `util.cli_kwargs.namespace_from_kwargs`, in place of twelve copies and four hand-made readings.
+- **Internal: `pixel-draw`'s G8 sizes a frame by the image path's opaque box, `frames.extract.solid_alpha_bbox`**, in place of its own count of opaque rows and columns — the same box, read in one place; `gates.G8` is unchanged.
+- **Tests** — `tests/gen/test_retry.py` (the rule per provider and status, every direct call asking it, a broken refusal body is no answer on all three transports), `tests/gen/test_flags_over_spec.py`, `tests/test_cli_kwargs.py`, `tests/test_hexcolor.py` (each verb reads through the one function; a second copy turns them red), and the provider, video, video-set and G8 tests moved to the new answers.
- **New (experimental): `sprite-gen pixel-draw` — Claude Opus draws pixel art of 8–48 px directly, as a pixel grid.** The model writes a palette and one line of keys per pixel row (a character grid, or JSON with `--format json`); code checks it and renders it. `--subject` (or `--spec`), `--size` 8–48 (32), `--kind sprite|icon|tile`, `--frames` (up to four, drawn in one call; `--walk-cycle` for contact, passing, contact, passing), `--palette free[:N]|pico8|#hex,…|file`, `--candidates` (2), `--effort medium|high|xhigh` (high), `--batch` (Message Batches, half price), `--max-tokens` (32000 for one frame, 64000 for more), `--pick vision|human`. G1 reads every answer strictly; a row one key too long or short, a key outside the palette or rows missing at the end go back to the model on their own with a column ruler and are spliced in (two rounds), and an answer still broken — or broken beyond its rows — is drawn once more; a single frame written without its `FRAME` line is recovered and recorded. A sprite or icon is drawn to the engine's safe area — `prepare`'s margin, 9.4% of the side, floored, taken from `prepare` rather than copied — as a target for the body's average size, not a wall: at 32 px the body is about the size of the central 26×26 (16 → 14, 24 → 20, 48 → 40), a pose or a detail that needs the room (a raised weapon, a long blade, an effect, a wide stance) may reach past it into the margin, up to the canvas edge, and a sprite's feet stand on the safe area's bottom row, the row `prepare`'s fit grounds a frame on, in every frame; the prompt says it in rows and columns counted from 1. G2 palette, G3 alpha and G6 frames (one ground line, heights within a pixel, no two frames the same — a sprite's or icon's measured inside the safe area, so a staff or a spark that reaches into the margin in one frame is not a taller figure) fail a candidate; G4 tile seam, G5 stray pixels and a walk whose legs barely change sides warn. G3, G4 and G5 ask judgments sprite-gen already makes rather than keep their own, each lifted out of its owner unchanged: G3 is whether a frame's background is really transparent by the verdict `gen` reads a generated raw by (`chroma.alpha_verdict`, out of `classify_raw_alpha`: at least 5 % of the pixels and half the one-pixel border alpha 0 for a sprite or icon, with something drawn and the four corners clear; no alpha-0 pixel for a tile); G4 is `background-tile`'s join measure (`inspect_tile`), asked of a tile along x and along y, and warns with its reasons where it says `needs-review`; G5 counts the lone pixels the YCbCr matte cleanup erases (`frames.extract.isolated_dots`, out of `_cleanup_alpha_ycc`: no opaque pixel among the eight neighbours), so each pixel of a one-pixel diagonal stroke, which touches the next at a corner, is no longer a stray pixel. G8 safe area never fails a candidate: it takes the judgment the pixel snap already makes — one function, `safe_area_fit` in `frames/extract.py`, lifted out of the snap with its lines unchanged — on each frame's opaque box: past the physical cap (the canvas's width, its height less the margin under the floor row, 32×29 at 32 px) warns, a reroll candidate; past the safe area but within the cap is an info line, `info` in the report, which asks for nothing; and a sprite whose feet are off the floor row warns. Of two or more candidates that pass, one vision call at effort low picks (G7). An answer that spent every token thinking is drawn once more one effort lower; a refusal is reported as it came (`refused by the provider's content policy (stop_reason=refusal category=…)`); nothing falls back to another model. The run folder holds `grid.txt` (the truth: edit it and re-render with `--grid`), `palette.json`, `frame-<name>.png` written by an encoder whose bytes depend on the pixels alone, `preview-x<s>.png`, `tiled-3x3.png` for a tile, `anim.gif` for several frames, every call under `calls/` and `report.json` with each call's model, effort, usage (thinking tokens included), price, seconds and request id, the gate results and the repair history. A batch is recorded the moment it is submitted, and `--resume` collects it — and reads every answered call back — instead of buying it twice. It runs on `ANTHROPIC_API_KEY`, billed per call and said so on stderr; the transport is urllib, so the dependency surface stays Pillow and NumPy — [docs/pixel-draw.md](docs/pixel-draw.md).
- **Fix: a poll xAI answers 429 or 5xx asks the same request again — the clip is bought once.** `video`, `video-extend` and `video-edit` ended the run on any non-2xx poll, after xAI had accepted the request and may bill it, and the line read `(HTTP 429)` — what `video-set`, and any caller that backs off on a refused submission, answers by submitting the clip again: a second clip paid for, the first never published. A poll answered `429`, `500`, `502`, `503` or `504` is now asked again on the same `request_id`, after a wait that doubles from 8 s up to 60 s while the polls are refused and goes back to 4 s on an answer; a stderr note says each, the status in plain digits. The poll timeout (`SPRITE_GEN_VIDEO_TIMEOUT_SECONDS`) still bounds the whole poll, a pending poll's waits included (and, below, the downloads). A refused POST is still never sent again, and a `400` or `404` poll still ends the run with its status (a `401` or `403` poll is unfinished, below).
- **Output change: a generation the poll timeout cut short is unfinished, named by its `request_id`.** Polls still pending or still refused at the timeout end the run with a line that names `request_id=<id>`, says the generation may still finish and be billed, and carries no `(HTTP <n>)`, a refusal line's status — a caller that reads `(HTTP 429)` there sends the request again, unbilled only when it was refused. The pending line keeps its front (`still 'pending' after N polls — poll timeout;`). With `--report` the run leaves a `sprite-gen-video-unfinished` report there (`verb`, `auth_source`, `model`, `request_id`, `out`, `polls`, `polls_refused`, `last_poll`, `elapsed_seconds`) and prints nothing on stdout; Python callers catch `GenerationUnfinished`, a `SystemExit`. The success report gains `polls_refused`, how many of its `polls` xAI answered 429 or 5xx (docs/video.md, An unfinished generation).
diff --git a/docs/README.md b/docs/README.md
index 19ba962..c05ad58 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -60,7 +60,7 @@ grouping is derived from `sprite_gen/_modules.py`, the one taxonomy table.
| Doc | Owns |
|---|---|
-| [run-contract.md](run-contract.md) | The atlas pipeline's normative contract: stages, the run-dir folder tree, curation-view display, atomic extract, concurrency scope |
+| [run-contract.md](run-contract.md) | The atlas pipeline's normative contract: stages, a flag against the file that holds the same key, the run-dir folder tree, curation-view display, atomic extract, concurrency scope |
| [architecture.md](architecture.md) | How the code is laid out: domains, stage ownership, the numeric SSoT, the cell model, extraction internals, runtime manifest |
| [loop-comparison.md](loop-comparison.md) | Final loop artifact digests, comparable quality axes and explicit unknown verdicts |
@@ -77,7 +77,7 @@ grouping is derived from `sprite_gen/_modules.py`, the one taxonomy table.
| Doc | Owns |
|---|---|
-| [gen.md](gen.md) | `sprite-gen gen` / `gen-set`: providers, default resolution, transparency strategy per provider, row usage |
+| [gen.md](gen.md) | `sprite-gen gen` / `gen-set`: providers, default resolution, transparency strategy per provider, when a refused provider request is sent again, row usage |
| [pixel-draw.md](pixel-draw.md) | `sprite-gen pixel-draw` (experimental): Claude Opus draws 8–48 px pixel art as a pixel grid — the inputs, the safe area, the run folder and its report, gates G1–G8, the row repair and the one redraw, the pick between candidates, Message Batches and `--resume`, re-rendering an edited `grid.txt` |
| [prompt-assembly.md](prompt-assembly.md) | What the engine adds to a still or clip prompt and when: the pieces, the 2.22.0 freeze without `--handed`, what counts as already said, and the notes on the caller's own words |
| [video.md](video.md) | `sprite-gen video` / `video-extend` / `video-edit` / `video-resume`: stills and clips to mp4 through Grok Imagine (image-to-video, last-frame pin, references, extension, editing, asking again for an unfinished generation) with the user's own credential |
diff --git a/docs/gen.md b/docs/gen.md
index 876e7f7..4265baf 100644
--- a/docs/gen.md
+++ b/docs/gen.md
@@ -1,6 +1,6 @@
# `sprite-gen gen` — provider-backed image generation (engine SSoT)
-> Owns: `sprite-gen gen` / `gen-set`: providers, default resolution, transparency strategy per provider, the billed knobs (`--quality`, `--resolution`), row usage · Index: [docs/README.md](README.md)
+> Owns: `sprite-gen gen` / `gen-set`: providers, default resolution, transparency strategy per provider, the billed knobs (`--quality`, `--resolution`), when a refused provider request is sent again (every direct provider call), row usage · Index: [docs/README.md](README.md)
Generation is a first-class engine module (`sprite_gen/gen/`), not an external
skill. One call = a prompt (+ optional reference images) → one **verified** PNG on
@@ -87,7 +87,8 @@ precedence even when `XAI_API_KEY` is set. Only an absent login file permits the
API key (console credits); an invalid, expired or rejected login never does. See
[authentication and expiry](video.md#setup--pick-one-credential)
for setup; the video modes (last-frame pin, references, `video-extend`, `video-edit`) are in [video.md](video.md#modes--which-flags-call-what). No Grok executable is needed during generation with a valid credential.
-No agent, credential fallback or automatic retry is started on failure.
+No agent or credential fallback is started on failure; a refusal xAI documents as a request not
+taken (429) is sent again, nothing else is ([a refused request sent again](#a-refused-request-sent-again)).
New images use `/v1/images/generations`; one reference uses `/v1/images/edits`
with `image`, two to five use `images` in input order. A single-reference edit
@@ -112,9 +113,11 @@ API contracts: [image generation](https://docs.x.ai/developers/model-capabilitie
No `codex` CLI, no browser sign-in, no subprocess: the whole credential is
`OPENAI_API_KEY`, read from the environment at call time and never written
anywhere. Unset, the run stops naming the variable and where to get a key; set but
-empty, it says so. It never falls back to the codex ChatGPT login, to another key,
-or to a retry — and see [subscription first](#subscription-first--openai-is-named-or-it-does-not-run)
-for why nothing routes here on its own.
+empty, it says so. It never falls back to the codex ChatGPT login or to another key;
+a refusal OpenAI documents as a request not taken is sent again, nothing else is
+([a refused request sent again](#a-refused-request-sent-again)) — and see
+[subscription first](#subscription-first--openai-is-named-or-it-does-not-run) for why
+nothing routes here on its own.
The default model is `gpt-image-2.5-flare`; `--model` selects another gpt-image
model. New images use `POST /v1/images/generations` (JSON); attaching `--ref` uses
@@ -185,6 +188,40 @@ it, so whatever the images endpoints send is what the report holds.
API contract: [OpenAI Images](https://developers.openai.com/api/images/) (field names
and enums confirmed there 2026-09-20).
+## A refused request sent again
+
+One rule for every direct provider call — the OpenAI and Grok image calls here, the
+facing check, the clip request and polls of the video verbs (docs/video.md), and the
+Anthropic transport of `pixel-draw` (docs/pixel-draw.md) — in `sprite_gen/gen/retry.py`:
+
+- **A POST is sent again only when its provider documents the answer as a request it
+ did not take.** That request made nothing, so asking again buys nothing twice. What
+ the providers say, read 2026-10-13:
+
+ | Provider | Sent again | Not sent again |
+ |---|---|---|
+ | OpenAI ([error codes](https://developers.openai.com/api/docs/guides/error-codes), [rate limits](https://developers.openai.com/api/docs/guides/rate-limits)) | 429 "Rate limit reached for requests" and `slow_down`; 503 `server_is_overloaded` — the two its SDKs retry | 500 "The server had an error while processing your request"; the billing 429s (`credit_balance_exhausted`, `organization_spend_limit_exceeded`, `project_spend_limit_exceeded`, `organization_usage_limit_exceeded`, type `insufficient_quota`): "Don't retry quota, billing, or other errors that require you to take action" |
+ | xAI ([debugging](https://docs.x.ai/developers/debugging), [rate limits](https://docs.x.ai/developers/rate-limits)) | 429 "You are sending requests too frequently and have reached the rate limit" | everything else — it documents no 5xx |
+ | Anthropic ([errors](https://platform.claude.com/docs/en/api/errors), [rate limits](https://platform.claude.com/docs/en/api/rate-limits)) | 429 `rate_limit_error`; 529 `overloaded_error`; 500 `api_error` ("Retry the request with exponential backoff") | 504 `timeout_error` "The request timed out while processing"; the spend-cap 429 (`error.details.error_code: enforced_spend_limit_reached`, no `retry-after`), which "fails until access resumes"; 502, 503 |
+
+- **The wait** is the answer's `retry-after` when the run waits that long (at most
+ 120 s; a longer one is not waited out early — the request is not sent again), else
+ the doubling wait the video polls wait by: 8 s, then 16 s. **Twice at most**, each
+ said on stderr, the status in plain digits:
+ `[gen] openai refused the request (429 rate_limit_exceeded); nothing was made — asking again in 8s (1 of 2)`.
+ A refusal still there after that ends the call as any refusal does, its line saying
+ `sent 3 times, no provider fallback` where it says `no retry or provider fallback`.
+- **A request that got no answer it could read is never sent again** — the connection
+ broke, it timed out, or the answer broke on the way, a refusal whose body broke
+ included (`xai.error_body`: a refusal's status alone is not an answer read whole).
+ The server may have taken it.
+- **A GET buys nothing**, so one answered 429, 500, 502, 503, 504 or 529 is asked again
+ after the same doubling wait: the video polls for as long as their poll timeout lets
+ them (docs/video.md), the reads of a Message Batch twice.
+
+`video-set` runs each clip once: a 429 is sent again inside `sprite-gen video`, and a
+second run on top would make every one of its POSTs a second retry loop.
+
## CLI
```bash
diff --git a/docs/pixel-draw.md b/docs/pixel-draw.md
index e1582af..ad07303 100644
--- a/docs/pixel-draw.md
+++ b/docs/pixel-draw.md
@@ -67,7 +67,7 @@ candidate's files are at the top of the run folder.
| Flag | Values (default) | What it does |
|---|---|---|
| `--subject TEXT` | words | What to draw. For several frames, say what each one is (the frame names are listed for the model, their meaning comes from your words). |
-| `--spec FILE` | JSON object | `subject`, `size`, `kind`, `frames`, `walk_cycle`, `palette` instead of the flags. A key given both in the file and as a flag is refused. |
+| `--spec FILE` | JSON object | `subject`, `size`, `kind`, `frames`, `walk_cycle`, `palette` instead of the flags. A key given both in the file and as a flag takes the flag, said on one stderr line ([run contract](run-contract.md#1-pipeline-stages)). |
| `--size N` | 8–48 (32) | Canvas side in pixels; every frame is N×N, a sprite's or icon's body about the size of the [safe area](#the-safe-area) (26×26 at 32). Measured best at 32 or less. |
| `--kind` | `sprite`, `icon`, `tile` (`sprite`) | Sprites and icons have a transparent background, a dark outline and a margin around the body; a tile fills every pixel and repeats seamlessly. |
| `--frames a,b,…` | 1–4 names (one frame named after `--kind`) | Frames drawn **in one call**, so they share one palette and one design. Names are letters, digits, `_` and `-`. |
@@ -181,12 +181,16 @@ answers a question the verb asks, it asks that function; a part that is its own
| G3 transparent background | `gen.chroma.alpha_verdict`, which `classify_raw_alpha` reads a raw by | [gen.md](gen.md#transparent-output--strategy-per-provider) |
| G4 tile seam | `background.tile.inspect_tile`, `background-tile`'s join measure | [asset-tools.md](asset-tools.md#repeating-tiles) |
| G5 stray pixels | `frames.extract.isolated_dots`, the YCbCr matte cleanup's lone pixels | [chroma-alpha.md](chroma-alpha.md#chromamode-ycbcr--chrominance-plane-matting-opt-in) |
-| G8 safe area | `frames.extract.safe_area_fit`, the pixel snap's judgment | [pixel-unfake.md](pixel-unfake.md#pixel_unfake-mode) |
+| G8 safe area | `frames.extract.safe_area_fit`, the pixel snap's judgment; a frame's opaque box, `frames.extract.solid_alpha_bbox` | [pixel-unfake.md](pixel-unfake.md#pixel_unfake-mode) |
+| `--spec` and a flag with the same key | `gen.base.flags_over_spec`, `prepare --request`'s answer: the flag wins, said on one line | [run-contract.md](run-contract.md#1-pipeline-stages) |
+| A call sent again, and the wait | `gen.retry`, every direct provider call's rule | [gen.md](gen.md#a-refused-request-sent-again) |
+| A palette colour read and written | `util.hexcolor` | — |
+| `run(**kwargs)` | `util.cli_kwargs.namespace_from_kwargs` | — |
| `anim.gif` | `util.gif_utils.save_clean_gif` | — |
| The pick sheet's checker | `qa.preview.checker`, the contact sheets' | — |
| The billing line, the printed report | `gen.base.announce_api_billing`, `gen.base.print_json` | [gen.md](gen.md) |
| The refusal line | `gen.refusal` (`CONTENT_POLICY`) | [gen.md](gen.md#direct-openai-calls-and-authentication) |
-| What ends a call unanswered, and its words | `gen.xai` (`NO_ANSWER`, `no_answer_reason`) | — |
+| What ends a call unanswered, and its words; a refusal's body | `gen.xai` (`NO_ANSWER`, `no_answer_reason`, `error_body`) | — |
Its own, because nothing in sprite-gen does it: the grid and its parse (G1), the row repair, the palette
rules (`--palette`), `frame-<name>.png`'s encoder (its bytes depend on the pixels alone, which Pillow's
@@ -245,10 +249,12 @@ The run ends non-zero with one line on stderr, and the report says the rest:
- **Every candidate refused** — `pixel-draw: refused by the provider's content policy
(stop_reason=refusal category=<category>); every candidate was refused` (the
[refusal marker](gen.md#direct-openai-calls-and-authentication) callers already read).
-- **A call failed** — a request the API refused before answering (429, 5xx, 529 overloaded) made
- nothing and is asked again twice, each wait said on stderr. Anything else — a 400, a rejected key,
- a stream that broke after it began (what was written may be billed) — ends that candidate with
- the API's line (the key masked) and is not asked again.
+- **A call failed** — a request the API refused before answering in a way Anthropic documents as a
+ request not taken (429 but its spend cap, 500, 529 overloaded) made nothing and is asked again
+ twice, each wait said on stderr ([a refused request sent again](gen.md#a-refused-request-sent-again)).
+ Anything else — a 400, a rejected key, a 502, 503 or 504, a stream that broke after it began
+ (what was written may be billed) — ends that candidate with the API's line (the key masked) and
+ is not asked again.
- **A batch not collected** — `unfinished`, below.
## Message Batches and `--resume`
diff --git a/docs/pixel-unfake.md b/docs/pixel-unfake.md
index f047c74..da3344f 100644
--- a/docs/pixel-unfake.md
+++ b/docs/pixel-unfake.md
@@ -24,7 +24,7 @@ Optional `fit` object (opt-in; absent means legacy behavior). For pixel-art targ
- `align_x` — `bbox-center` | `centroid` | `foot-centroid` (default) | `alpha-centroid`. Bbox-centering shifts the body left/right whenever a pose's content bbox width changes (extended arm/leg), which reads as per-frame horizontal jitter. `centroid` aligns the whole-alpha centroid; `foot-centroid` aligns the bottom-20% alpha (the legs), so trailing hair/capes do not pull the body off the cell axis — use it when the runtime mirrors the cell for left/right facing (flip pivots on the leg axis instead of teleporting the body). `alpha-centroid` (opt-in, perfectpixel-studio port — github.com/gykim80/perfectpixel-studio `internal/sprite/extract.go`, MIT) aligns the alpha-weighted centroid ignoring soft-matte fringe (α ≤ 10); crucially, in the `pixel_unfake` row path it is applied **per frame** instead of once per row union, so residual registration jitter from `register_row_frames` is cancelled (upstream measured σ 27.2px → 0.2px; jump arcs stay preserved via `ground_frames: false`).
- `align_y` — `center` (default) | `bottom`. Bottom pins feet to a shared baseline (`cell_height - safe_margin_y`).
-`prepare_sprite_run.py` exposes these as `--fit-resample`, `--fit-align-x`, `--fit-align-y`, and `--fit-ground-frames` / `--no-fit-ground-frames`, plus the `pixel_unfake` family below as `--fit-pixel-unfake`, `--fit-logical-height`, `--fit-palette-size`, `--fit-detail-bias`, `--fit-outline {on,off,STRENGTH}`, `--fit-pitch-hint`. CLI flags override the same keys in `--request` JSON; either way the merged result is recorded in the run's `sprite-request.json` `fit` object (SSoT).
+`prepare_sprite_run.py` exposes these as `--fit-resample`, `--fit-align-x`, `--fit-align-y`, and `--fit-ground-frames` / `--no-fit-ground-frames`, plus the `pixel_unfake` family below as `--fit-pixel-unfake`, `--fit-logical-height`, `--fit-palette-size`, `--fit-detail-bias`, `--fit-outline {on,off,STRENGTH}`, `--fit-pitch-hint`. CLI flags override the same keys in `--request` JSON, one stderr line naming them ([run contract](run-contract.md#1-pipeline-stages)); either way the merged result is recorded in the run's `sprite-request.json` `fit` object (SSoT).
## `pixel_unfake` mode
diff --git a/docs/run-contract.md b/docs/run-contract.md
index f42c4c0..72972ee 100644
--- a/docs/run-contract.md
+++ b/docs/run-contract.md
@@ -1,6 +1,6 @@
# Run Contract — pipeline stages · run-dir folder tree · curation-view display (SSoT)
-> Owns: The atlas pipeline's normative contract: stages, the run-dir folder tree, curation-view display, atomic extract, concurrency scope · Index: [docs/README.md](README.md)
+> Owns: The atlas pipeline's normative contract: stages, a flag against the file that holds the same key (every verb), the run-dir folder tree, curation-view display, atomic extract, concurrency scope · Index: [docs/README.md](README.md)
> Status: **contract** (normative). This doc is the single source of truth for
> three things every sprite-gen run must satisfy so that **any agent who serves a
@@ -57,6 +57,15 @@ canonical files, not hidden imports.
| Export stills | `export_curated_pngs.py` | curated `frames/` | named PNGs under `curated/` |
| Chroma guard | `scripts/dev/check_visible_magenta.py` | screenshot | leakage warning |
+**A flag and the file that holds the same key.** A key given both as a flag and in the file a
+verb reads with its flags — `prepare --request` / `--request-json`, `pixel-draw --spec` — takes
+the flag, and one stderr line names every flag the file also set:
+`[prepare] --style, --cell-size given both as a flag and in --request-json: the flag wins`. A
+value the file holds is never replaced in silence, and no verb answers this question another
+way (`gen.base.flags_over_spec`). For `prepare` a flag replaces a cell measure however the
+request spelled it (`--cell-size`, `--cell-width` and `--cell-height` the width and height
+whether the request said `size`, `width` or `cell_width`; `--safe-margin` both margins).
+
The happy path is `prepare -> gen -> extract -> compose`, followed by delivery and an optional curation view. Curation is opened only when requested or enabled in saved defaults; edits are composed again for export. Stage internals (chroma removal, connected
components, pixel-unfake path, the `.sprite-gen.lock` single-writer rule, the
inspect/score/loop split) are described in
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 433e2ac..10d5569 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -1072,7 +1072,8 @@ Outputs:
`sprite-gen video-set --base side=side.png --base front=front.png --states idle,walk,run,jump,attack --out-dir set/`
runs canvas → video → frames → loop for every (direction, state). The xAI team quota
is **2 requests per second** (five parallel starts produced two HTTP 429s): starts are
-staggered (`--start-gap 2`) and a 429 gets a bounded, logged retry (15 s, 30 s). Clip length
+staggered (`--start-gap 2`); a 429 is sent again inside `sprite-gen video` (8 s, 16 s,
+[a refused request sent again](gen.md#a-refused-request-sent-again)) and each clip runs once. Clip length
is each state's own default (3 s, attack 2 s) unless `--duration` sets one for all, and an
attack or idle clip is pinned to end on its canvas and cut whole (`--cycle pinned`). States use differently shaped canvases (square, tall, wide),
so the same character films at different pixel heights; `--body-height N` gives every state's loop the
diff --git a/docs/video.md b/docs/video.md
index a678d0c..3e58f7b 100644
--- a/docs/video.md
+++ b/docs/video.md
@@ -143,24 +143,27 @@ What happens, in order:
classic model) and resolve the credential — all before any network call.
2. `POST /v1/videos/generations` with `model`, `prompt`, `duration`, `resolution`,
then `image.url` / `last_frame.url` / `reference_images[].url` as base64 data
- URLs, optional `aspect_ratio` / `generate_audio`. A `401/403` names the
- credential source and its fix; any reply without a `request_id` fails with the
- API's own error text.
+ URLs, optional `aspect_ratio` / `generate_audio`. A `429` — xAI's rate limit, a
+ request it did not take — is sent again, twice at most, after 8 s and 16 s
+ ([a refused request sent again](gen.md#a-refused-request-sent-again)). A `401/403`
+ names the credential source and its fix; any other reply without a `request_id`
+ fails with the API's own error text.
3. `GET /v1/videos/{request_id}` every 4 s until `status` is `done`. `failed`,
`expired` or a non-2xx poll fails loudly — except a poll answered `429` or `500`,
- `502`, `503`, `504`, or one that gets no answer it can read (the connection failed
+ `502`, `503`, `504`, `529`, or one that gets no answer it can read (the connection failed
or timed out; the answer broke on the way — a body shorter than its
`Content-Length`, a status line that is not one, a refusal's body cut the same way;
or a `200` body that is not JSON): the request was accepted, so that poll is asked
again on the same `request_id` (a new POST would buy the clip twice; a GET buys
nothing), after a wait that doubles from 8 s up to 60 s while the polls fail and goes
- back to 4 s on an answer. A `[video] poll N of generation <id> was refused (429);
+ back to 4 s on an answer — the doubling every direct provider call waits by
+ ([a refused request sent again](gen.md#a-refused-request-sent-again)). A `[video] poll N of generation <id> was refused (429);
asking again in 8s` line — or `… got no answer (timed out); asking again in 8s`,
the reason `IncompleteRead(10 bytes read, 190 more expected)` or `response was not
valid JSON` for an answer it could not read — goes to stderr each time.
The poll timeout (`SPRITE_GEN_VIDEO_TIMEOUT_SECONDS`, default 600) is the one time
- limit of the accepted request. It counts from the POST's send and bounds the polls,
+ limit of the accepted request. It counts from the send of the POST xAI accepted and bounds the polls,
their waits and the clip's downloads (step 4) alike:
- Each poll reads only what is left of it. One whose answer stalls, or comes too
@@ -183,7 +186,7 @@ What happens, in order:
a done poll that names no URL to download (none, an empty one, anything but an
`http(s)://` string) is *unfinished* too. A download that gets no answer it can read
(the connection refused or timed out, the body cut short of its `Content-Length`) or
- that the clip's host refuses with `429`, `500`, `502`, `503` or `504` is downloaded
+ that the clip's host refuses with `429`, `500`, `502`, `503`, `504` or `529` is downloaded
again, after 8 s and then 16 s — three downloads in all, within the poll timeout: each
reads only what is left of it, so one that stalls or whose bytes come too slowly is
cut when it comes (`timed out`), and one whose wait would reach it is not tried. A
@@ -358,9 +361,10 @@ transport's words in `reason`.
## Quotas and limits
- Imagine quota is a weekly SuperGrok allowance; when it is exhausted the API
- refuses the POST and the run fails with that message. A refused POST is never sent
- again here — the provider may have taken it; only a poll of an accepted request is
- asked again (step 3).
+ refuses the POST and the run fails with that message. A refused POST is sent again
+ only when xAI's answer is `429`, a request it did not take (step 2); any other refusal
+ is never sent again here — the provider may have taken it. A poll of an accepted
+ request is asked again (step 3).
- A refused request or a failed poll names the provider's code after the status,
`(HTTP 400) code=invalid_argument`, read from a top-level `code` or the `error`
object. `invalid_argument` covers moderation and bad parameters alike, so it is