Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(video): the poll timeout bounds the downloads and every read, so a run ends unfinished on its request_id within it; a done poll with no url is unfinished too
Soohong Kimb9c810abb055
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c3e6332..9d66cdd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,19 +4,23 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the## Unreleased-- **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: no wait runs past it, a pending poll's last wait included, and one last poll is asked at it. 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).+- **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).-- **`tests/gen/test_video.py`** scripts the polls: each of the five statuses refused twice, then pending, then done, is asked on the one request with waits 8, 16, 4 and published with `polls_refused` 2; polls refused until a 300 s timeout wait 8, 16, 32, 60 × 4 and 4, ask a ninth poll at the timeout and end unfinished with no `(HTTP n)` and no `HTTP 429` on stderr; a pending timeout names the request; a 400 or 404 poll ends at once; a refused POST is sent once; the CLI leaves the unfinished report and an empty stdout. The 500-poll case of the failure table is a 404 now, the status that still ends a run.+- **`tests/gen/test_video.py`** scripts the polls: each of the five statuses refused twice, then pending, then done, is asked on the one request with waits 8, 16, 4 and published with `polls_refused` 2; polls refused until a 300 s timeout wait 8, 16, 32, 60 × 4, ask no poll whose wait would reach the timeout and end unfinished after eight with no `(HTTP n)` and no `HTTP 429` on stderr; a pending timeout names the request; a 400 or 404 poll ends at once; a refused POST is sent once; the CLI leaves the unfinished report and an empty stdout. The 500-poll case of the failure table is a 404 now, the status that still ends a run.- **New verb: `video-resume` asks again for a generation a run left unfinished — by its `request_id`, with no new POST.** A run cut short named the request to ask for again, but no verb could ask for it: a caller had to submit the clip again, a second purchase, or give the clip up. `sprite-gen video-resume --request-id <id> --out clip.mp4 [--report r.json]` polls `GET /v1/videos/{id}` as the generating verbs do — the same retries, backoff and poll timeout — then downloads, verifies and publishes the clip. Nothing is submitted, so nothing is bought twice and the `XAI_API_KEY` route prints no charge notice. Its report is a `sprite-gen-video-report` with `mode: "resume"`, the same `request_id`, `inputs: {}` and `duration_requested: null`; cut short again it is unfinished on the same id, `verb: "video-resume"`, `model: null`; an id xAI does not know ends with its `(HTTP 404)`. The id is refused before any call unless it is letters, digits, `.`, `_` and `-`. A resumed clip is checked as an mp4 only — `video-extend`'s length rule needs the input clip (docs/video.md, `sprite-gen video-resume`).- **Fix: a poll that gets no answer, or whose credential xAI rejects, leaves the request's id.** After xAI had accepted the request, a poll whose connection failed or timed out ended the run with the transport's line and no `request_id`, and a poll answered `401` ended it with its status. A poll that gets no answer is a GET, which buys nothing, so it is now asked again with the refused polls' backoff (a refused poll and a lost one are two failures in a row) and a stderr note, `poll N of generation <id> got no answer (<reason>); asking again in 8s`; lost until the poll timeout, the run is unfinished. A poll answered `401` or `403` — the credential stopped working after the POST, typically an expired login — ends the run unfinished at once, naming the credential's fix (refresh the grok login, or check `XAI_API_KEY`) before the request to ask for. A POST that gets no answer ends as before: no `request_id` came back. `xai.http_json` raises `xai.TransportError` for a request that got no answer, still a `SystemExit` with the same line, the socket's words in `reason`.- **Output change: the unfinished line names the command that asks again; reports count the polls that got no answer.** The line reads ``ask for request_id=<id> again with `sprite-gen video-resume --request-id <id> --out <out>` instead of submitting a new request``, `request_id=<id>` kept as it was. The success and unfinished reports gain `polls_unanswered`, how many of `polls` got no answer, each asked again; the unfinished report's `last_poll` gains `error`, what the socket said, when its last poll got none (`http` then `null`).-- **`tests/gen/test_video.py`** asks again by id and loses polls: `xai.http_json` raises `xai.TransportError` with the old line for a DNS failure, a timeout and a reset; lost, pending, refused, lost, done is asked on the one request with waits 8, 4, 8, 16 and published with `polls_unanswered` 2; lost until a 30 s timeout waits 8, 16, 6 and ends unfinished with `last_poll.error`; a lost POST is sent once and is not unfinished; a 401 or 403 poll, on the login or on the key, ends unfinished at once naming its fix; `video-resume` polls with no POST and announces no charge, ends unfinished on the same id when refused, lost or pending past the timeout or when its credential is rejected, ends with `(HTTP 404)` for an unknown id, refuses eight ids that cannot be one before any call, and its CLI writes the resume report, the unfinished report and an empty stdout; the unified CLI routes it under `gen`.+- **`tests/gen/test_video.py`** asks again by id and loses polls: `xai.http_json` raises `xai.TransportError` with the old line for a DNS failure, a timeout and a reset; lost, pending, refused, lost, done is asked on the one request with waits 8, 4, 8, 16 and published with `polls_unanswered` 2; lost until a 30 s timeout waits 8 and 16 and ends unfinished with `last_poll.error`; a lost POST is sent once and is not unfinished; a 401 or 403 poll, on the login or on the key, ends unfinished at once naming its fix; `video-resume` polls with no POST and announces no charge, ends unfinished on the same id when refused, lost or pending past the timeout or when its credential is rejected, ends with `(HTTP 404)` for an unknown id, refuses eight ids that cannot be one before any call, and its CLI writes the resume report, the unfinished report and an empty stdout; the unified CLI routes it under `gen`.- **Fix: a poll whose answer is cut short, garbled or not JSON is asked again on the same request — the run no longer ends with no `request_id`.** A poll answer that broke after it began — a body that closed before its `Content-Length` (`http.client.IncompleteRead`), a status line that is not one (`BadStatusLine`), a refusal's body cut the same way — escaped `video`, `video-extend`, `video-edit` and `video-resume` as a raw exception, with no `request_id`, no unfinished report and no resume command, so a caller could only submit the clip again and buy it twice; a `200` poll whose body is not JSON ended the run on `xai: response was not valid JSON`, also with no id. Both are now a poll that got no answer it could read, as a lost one is: asked again on the same `request_id` with the same backoff and stderr note (`got no answer (IncompleteRead(10 bytes read, 190 more expected))`, `got no answer (response was not valid JSON)`), counted in `polls_unanswered`, and unfinished at the poll timeout with that reason in `last_poll.error`. A POST so answered still ends at once and is never sent again — no `request_id` could be read: on the transport's line for a broken answer (a raw exception before), on the not-JSON line it always had. `xai.http_json` raises `xai.TransportError` for every answer it cannot read whole, each with the line it always had; `reason` is the `http.client` exception's repr for a broken answer, `response was not valid JSON` for the other.- **`tests/gen/test_video.py`** answers over a real socket from a local server: `xai.http_json` raises `xai.TransportError` for a body closed 10 bytes into its 200, a 503 body cut the same way, a garbage status line (the transport's line) and a whole non-JSON `200` (the not-JSON line); cut, garbled, not JSON, cut refusal, pending, done is asked on the one request with waits 8, 16, 32, 60, 4 and published with `polls_unanswered` 4; a resumed poll cut short is asked again and published; cut until a 30 s timeout, the CLI leaves the unfinished report with `last_poll.error` the `IncompleteRead` and an empty stdout; a cut POST is sent once and is not unfinished.- **Fix: a clip that is done and whose download fails leaves the run unfinished on its `request_id` — never a second purchase.** Once the poll said done the clip is made and may be billed, yet a failed download ended `video`, `video-extend`, `video-edit` and `video-resume` with no `request_id`, no unfinished report and no resume command: a refused connection on `video: cannot download the clip: …`, a body cut short of its `Content-Length` (`http.client.IncompleteRead`) or a read that timed out as a raw exception, a refused download on `video: download failed with HTTP <n>`, and bytes that are not an mp4 on `… refusing to publish` — so a caller could only submit the clip again and buy it twice. A download that gets no answer it can read, or that the clip's host refuses with `429`, `500`, `502`, `503` or `504`, is now downloaded again after 8 s and then 16 s, three downloads in all, with a stderr note before each (`download N of generation <id> got no answer (<reason>); downloading again in 8s`, `… was refused (503); …`); one still failing, one refused with another status (a `401` or `403` still asked once more with the bearer token first), or bytes that are not an mp4 end the run unfinished on that id: ``… is done, but its download got no answer (last: <reason>) after 3 attempts; the clip is made and may be billed — ask for request_id=<id> again with `sprite-gen video-resume --request-id <id> --out <out>` …``, no `(HTTP <n>)` on it. `video-resume` polls afresh, so it downloads from the URL the new poll names. `video.http_download` raises `xai.TransportError` (its line still `video: cannot download the clip: <reason>`) for a download that got no answer and `video.DownloadRefused`, a `SystemExit` carrying `status`, for a refused one; `xai.NO_ANSWER` and `xai.no_answer` are the transport's classifier, now shared by both.- **Output change: bytes that came whole and are not an mp4 are unfinished, not a refusal.** xAI's one content-policy signal is `respect_moderation: false` on the done poll, read before any download; anything else at the clip's URL — an expired link's page, a proxy's error page served `200` — is a fault in delivering a clip that is made, and the `request_id` is the only way back to it. `video-resume` costs a poll and asks for a fresh URL; a refusal left only a new submission. The same URL brings the same bytes, so the run does not download it again itself (docs/video.md, An unfinished generation). `video.verify_mp4` is gone.- **Output change: reports count the clip's downloads.** The success report gains `downloads`, how many downloads the clip took, the last one whole (1 unless one failed). An unfinished report of a clip that could not be downloaded gains `downloads` and `last_download` — `http` the status the clip's host refused it with, else `null`; `error` what the transport said, or `not an mp4 (no ftyp box)` with the `bytes` that came — and its `last_poll` is the done poll; an unfinished report of a poll is unchanged.- **`tests/gen/test_video.py`** downloads the clip over a real socket from the local server: a clip body closed 10 bytes into its 76, a read held open past a 1 s timeout and a connection to a port nothing holds are each downloaded three times with waits 8 and 16, and the CLI leaves the unfinished report naming the request with `downloads` 3, `last_download.error` the transport's words and an empty stdout; a cut download, then a `503`, then the whole clip publishes with `downloads` 3; a `503` three times and a `404` once end unfinished with `last_download.http`, no `(HTTP n)`; 34 whole bytes of HTML end unfinished at once with `last_download.bytes`; and a run left unfinished by its downloads is published by `video-resume` on the id its report names, from the fresh URL of a new poll and with no POST. The fake transport's non-mp4 refusal test is that HTML test now. A port held bound and not listening is no refused port on macOS (its SYN is dropped and the connect times out), so the test takes a free port and lets it go.+- **Fix: the poll timeout bounds the clip's downloads and every read — a caller that stops the run at a hard limit gets the `request_id` back before it.** The downloads after a done poll ran outside the poll timeout — up to three, each with its own 120 s read timeout, 8 s and 16 s between — and a poll in flight when the timeout came could read on for its own 120 s. A run could so outlive a limit its caller set a little over the timeout and be killed before it wrote its unfinished report: no `request_id`, and a clip that may be billed could only be bought again. The poll timeout (`SPRITE_GEN_VIDEO_TIMEOUT_SECONDS`) is now the one time limit of an accepted request, counted from the POST's send. Every poll and download reads only what is left of it — one that stalls, or whose bytes come too slowly for a read's timeout ever to fire, is cut when it comes (`timed out`) — a poll or download whose wait would reach it is not asked, and the run is unfinished on the `request_id` then: `… is done, but its download got no answer (last: timed out) until the poll timeout (210s, 1 attempt); …`, `… was refused (last answer 503) until the poll timeout (20s, 2 attempts); …`. The POST is not cut by it, its answer being the one way to the id; one answered after the whole timeout is unfinished before any poll (`… was accepted after the poll timeout (600s) had run out, before any poll; …`, `polls` 0). `xai.http_json` and `video.http_download` take `deadline=`, a `time.monotonic()` instant, and read the body a chunk at a time by it (`xai.read_whole`, `xai.time_left`); without one they read as before (docs/video.md, step 3).+- **Output change: the poll timeout ends the run when the next poll's wait would reach it, not with a last poll at it.** That poll would have no time left to be answered. A run cut short by the timeout ends up to one wait before it (4 s while pending, up to 60 s while refused), with one poll fewer: a 300 s timeout of refused polls ends after 8 polls at 296 s, where it asked a ninth at 300 s.+- **Fix: a done poll that names no URL to download is unfinished on its `request_id`.** It ended on `<verb>: generation <id> is done but reported no video url`, with no unfinished report, and a `url` that is not a string or not a web address escaped as a raw exception: a clip xAI says is made, and may bill, left only a second purchase. A done poll with no `http(s)://` URL — none, empty, `null`, not a string, no `video` object — now ends ``… is done, but its poll named no video url to download; the clip is made and may be billed — ask for request_id=<id> again with `sprite-gen video-resume …` …``, the report's `last_poll` the done poll and no `downloads`; `video-resume` polls it afresh. `respect_moderation: false` is still the content-policy refusal it was.+- **`tests/gen/test_video.py`** runs the time limit on the real clock against the local server, with a 1.5 s timeout: a clip download that stalls past it (its read timeout longer than what is left) or comes a byte every 20 ms is downloaded once and cut at the timeout, and the CLI leaves the unfinished report by then (`last_download.error` `timed out`, `elapsed_seconds` under 2.5); a poll that stalls or trickles is cut the same way. A `503` download whose next wait would reach a 20 s timeout is not downloaded again; a POST that took 12 of 20 s leaves the polls 8 s, and one that took 25 s is unfinished before any poll. A done poll with no url, an empty, null or numeric one, one with no scheme or no `video` object is unfinished on its id for `video` and `video-resume`. `xai.http_json` reads a cut, garbled or not-JSON answer as no answer with a deadline as without one. The poll-timeout cases end a poll earlier: refused polls until 300 s wait 8, 16, 32, 60 × 4 and end after 8 polls at 296 s; lost or cut polls until 30 s wait 8 and 16 and end after 3; pending polls until 10 s end after 3. The failure table's done poll with an empty `video` expects the unfinished line.- **Output change: an `openai` image report carries the response's rate-limit headers — `extra.rate_limit`.** The provider dropped the response headers, so what the account may spend per minute and has left could not be read off real traffic. `extra.rate_limit` now holds every `x-ratelimit-*` header the response carried, names lower-cased and values as sent, and `{}` when none came (docs/gen.md). `openai_provider.http_image` returns the response headers as a third value.- **`tests/gen/test_openai_provider.py`** answers with headers: the report holds exactly the `x-ratelimit-*` ones among others of any case, and `{}` for a response without any.diff --git a/docs/video.md b/docs/video.mdindex 076fe06..a678d0c 100644--- a/docs/video.md+++ b/docs/video.md@@ -157,25 +157,41 @@ What happens, in order:back to 4 s on an answer. 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, counted from the POST's- answer) bounds the whole poll: no wait runs past it, one last poll is asked at it,- and a generation still pending, refused or unanswered then is *unfinished* (below).- A poll answered `401` or `403` — the credential stopped working after the POST,+ 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,+ 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+ slowly for its 120 s read timeout ever to fire, is cut when the timeout comes and+ counts as a poll that got no answer (`timed out`).+ - A poll whose wait would reach the timeout is not asked. A generation still+ pending, refused or unanswered then is *unfinished* (below) at once.+ - The POST is not cut by it: its answer is the one way to the `request_id`, under its+ own 120 s read timeout. One answered after the whole timeout is unfinished before+ any poll.++ So a caller that kills the run at a hard limit gets the `request_id` back when it+ sets the timeout under that limit, with room for the process to start and for the+ POST. A poll answered `401` or `403` — the credential stopped working after the POST,typically a login that expired — is unfinished at once. No clip is written on anyfailure path.4. Download `video.url`, verify the bytes start with an mp4 `ftyp` box, then movethe file into `--out` atomically (`.part` staging). The clip is made by now and may- be billed, so a download that fails never ends the run without its `request_id`. One- 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 again, after 8 s and then 16 s — three downloads- in all, each with its own 120 s read timeout and none bounded by the poll timeout —- and a `[video] download N of generation <id> got no answer (<reason>); downloading- again in 8s` (or `… was refused (503); …`) line goes to stderr before each. One still- failing, one refused with another status (a `401` or `403` is asked once more with- the bearer token first), or bytes that are not an mp4 end the run *unfinished*- (below).+ be billed, so a download that fails never ends the run without its `request_id`, and+ 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+ 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+ `[video] download N of generation <id> got no answer (<reason>); downloading again in+ 8s` (or `… was refused (503); …`) line goes to stderr before each. One still failing,+ one refused with another status (a `401` or `403` is asked once more with the bearer+ token first), a download the timeout leaves no time for, or bytes that are not an mp4+ end the run *unfinished* (below).Reference-to-video tends to lock the opening composition to a referenced sceneimage (probe m3: the clip opened on the third reference's framing), so put@@ -226,7 +242,7 @@ sprite-gen video-resume \```No POST: it polls `GET /v1/videos/{id}` exactly as step 3 above (the same retries,-backoff and poll timeout, counted from the first poll), then downloads, verifies and+backoff and poll timeout, counted from the first poll and bounding the downloads too), then downloads, verifies andpublishes the clip as step 4. Nothing is submitted, so nothing is bought twice and the`XAI_API_KEY` route prints no charge notice. Run it on the credential that submittedthe request — the unfinished report's `auth_source`; refresh an expired login first.@@ -260,8 +276,9 @@ printed or written** — only the download host (`vidgen.x.ai`).### An unfinished generationxAI accepted the request and the run ended before it did — the poll timeout came with-its polls still pending, refused or unanswered, xAI rejected the credential on a-poll, or the poll said done and the clip could not be downloaded (step 4). It may+its polls still pending, refused or unanswered (or before any poll), xAI rejected the+credential on a poll, or the poll said done and the clip could not be downloaded in+time or at all, or the poll named no URL to download it from (step 4). It mayfinish and be billed — a clip that is done is made — so the run ends naming therequest and the `video-resume` command that asks for it again, never as a refusal tosend again:@@ -269,11 +286,14 @@ send again:```video: generation <id> was accepted, but its polls were refused (last answer 429) until the poll timeout (600s, 14 polls); it may still finish and be billed — ask for request_id=<id> again with `sprite-gen video-resume --request-id <id> --out /abs/clip.mp4` instead of submitting a new request; nothing was writtenvideo: generation <id> was accepted, but its polls got no answer (last: timed out) until the poll timeout (600s, 14 polls); it may still finish and be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was written-video: generation <id> still 'pending' after 151 polls — poll timeout; it may still finish and be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was written+video: generation <id> still 'pending' after 150 polls — poll timeout; it may still finish and be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was written+video: generation <id> was accepted after the poll timeout (600s) had run out, before any poll; it may still finish and be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was writtenvideo: generation <id> was accepted, but xAI rejected the credential (grok-login) on poll 30 (answer 401); it may still finish and be billed — refresh the login with `grok models` run from an empty directory (e.g. `cd "$(mktemp -d)"`) or `grok login`, then ask for request_id=<id> again with `…` instead of submitting a new request; nothing was writtenvideo: generation <id> is done, but its download got no answer (last: IncompleteRead(1048576 bytes read, 3195904 more expected)) after 3 attempts; the clip is made and may be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was writtenvideo: generation <id> is done, but its download was refused (last answer 503) after 3 attempts; the clip is made and may be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was writtenvideo: generation <id> is done, but its download was refused (answer 404); the clip is made and may be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was written+video: generation <id> is done, but its download got no answer (last: timed out) until the poll timeout (210s, 1 attempt); the clip is made and may be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was written+video: generation <id> is done, but its poll named no video url to download; the clip is made and may be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was writtenvideo: generation <id> is done, but its download brought 34 bytes that are not an mp4 (no ftyp box); the clip is made and may be billed — ask for request_id=<id> again with `…` instead of submitting a new request; nothing was written```diff --git a/sprite_gen/gen/video.py b/sprite_gen/gen/video.pyindex 19e1435..424bf7b 100644--- a/sprite_gen/gen/video.py+++ b/sprite_gen/gen/video.py@@ -67,6 +67,7 @@ from .xai import (API_BASE, AUTH_ENV, AUTH_SOURCE_API_KEY, AUTH_SOURCE_GROK_LOGIN,HTTP_TIMEOUT_SECONDS, GROK_REFRESH_COMMAND, GROK_REFRESH_WHERE, GROK_LOGIN_COMMAND,NO_ANSWER, Credential, HttpCall, TransportError, grok_home, resolve_credential, http_json, no_answer,+ read_whole, time_left,)DEFAULT_MODEL = "grok-imagine-video-1.5"@@ -100,21 +101,27 @@ MODE_RESUME = "resume"# What `video-resume` takes for an id: it goes into the `/videos/{id}` path, so no `/`, `?`, `#` or `%`.REQUEST_ID = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*")POLL_INTERVAL_SECONDS = 4.0+# The poll timeout is the one time limit of an accepted request: it counts from the moment the request is+# sent (a resume: its first poll) and bounds its polls, their waits and the clip's downloads alike. Each+# poll and download reads only what is left of it (xai.read_whole), and one whose wait would reach it is+# not asked: the run ends unfinished on the request_id instead. So a caller that stops the run at a hard+# limit gets the id back when it sets the timeout under that limit. The POST is not cut by it — its+# answer is the one way to the id; an answer that comes after the whole timeout ends the run at once.POLL_TIMEOUT_SECONDS = int(os.environ.get("SPRITE_GEN_VIDEO_TIMEOUT_SECONDS", "600"))# A poll xAI throttles (429) or fails on its own side (5xx), or one that gets no answer it can read (the# connection failed or timed out, the answer broke on the way or was not JSON — xai.TransportError), is# asked again, on the same request: the POST was accepted, so a# new submission would buy the clip twice, and a GET buys nothing. The wait doubles from-# POLL_INTERVAL_SECONDS while the polls fail, up to the ceiling; no wait runs past the poll timeout,-# which bounds the whole poll however its polls are answered.+# POLL_INTERVAL_SECONDS while the polls fail, up to the ceiling.POLL_RETRY_STATUSES = frozenset({429, 500, 502, 503, 504})POLL_BACKOFF_MAX_SECONDS = 60.0# A clip the poll says is done is made, and may be billed: its request_id is the one way back to it. A# download that gets no answer it can read, or that the clip's host refuses with one of# POLL_RETRY_STATUSES, is downloaded again after the polls' doubling wait (8 s, then 16 s), up to-# DOWNLOAD_ATTEMPTS downloads in all. One still failing, one refused with another status, or bytes-# that are not an mp4, end the run unfinished on that request_id: `video-resume` polls it again for-# a fresh URL, where a new submission would buy the clip twice.+# DOWNLOAD_ATTEMPTS downloads in all, within the poll timeout. One still failing, one refused with+# another status, bytes that are not an mp4, or a done poll that names no URL to download, end the run+# unfinished on that request_id: `video-resume` polls it again for a fresh URL, where a new submission+# would buy the clip twice.DOWNLOAD_ATTEMPTS = 3# Every mp4/mov starts with a size-prefixed `ftyp` box: bytes 4..8 spell it.MP4_FTYP_OFFSET = 4@@ -125,7 +132,8 @@ _FAILED_STATUSES = ("failed", "error", "expired")class GenerationUnfinished(SystemExit):"""xAI accepted the request (it may bill it) and the run ended before it did: the poll timeout- came, xAI rejected the credential on a poll, or the clip it made could not be downloaded.+ came, xAI rejected the credential on a poll, or the clip it made could not be downloaded (or its+ done poll named no URL to download it from).The line names `request_id=<id>` and the `video-resume` command that asks for it again, andcarries no `(HTTP n)`, a refusal line's status: a caller that reads `(HTTP 429)` there sends the@@ -171,6 +179,10 @@ class GenerationUnfinished(SystemExit):}+# How a clip is downloaded: `(url, token, *, deadline)` -> its bytes, read whole by the deadline (http_download).+Download = Callable[..., bytes]++class DownloadRefused(SystemExit):"""The clip's host answered its download with an error `status` (a 401 or 403 once more with the bearer token)."""@@ -179,22 +191,23 @@ class DownloadRefused(SystemExit):self.status = status-def http_download(url: str, token: str) -> bytes:- """The clip's bytes, read whole. An error status raises DownloadRefused; a download that gets no answer- it can read whole — the connection failed or timed out, the body broke on the way — raises- xai.TransportError, its words in `reason`."""+def http_download(url: str, token: str, *, deadline: float | None = None) -> bytes:+ """The clip's bytes, read whole — by `deadline` (a `time.monotonic()` instant) when one is given: each+ wait is cut to what is left of it (xai.read_whole). An error status raises DownloadRefused; a download+ that gets no answer it can read whole — the connection failed or timed out, the body broke on the way,+ the deadline came — raises xai.TransportError, its words in `reason`."""request = urllib.request.Request(url)try:try:- with urllib.request.urlopen(request, timeout=HTTP_TIMEOUT_SECONDS) as response:- return response.read()+ with urllib.request.urlopen(request, timeout=time_left(HTTP_TIMEOUT_SECONDS, deadline)) as response:+ return read_whole(response, HTTP_TIMEOUT_SECONDS, deadline)except urllib.error.HTTPError as first:if first.code not in (401, 403):raise DownloadRefused(first.code, f"video: download failed with HTTP {first.code}") from firstrequest.add_header("Authorization", f"Bearer {token}")try:- with urllib.request.urlopen(request, timeout=HTTP_TIMEOUT_SECONDS) as response:- return response.read()+ with urllib.request.urlopen(request, timeout=time_left(HTTP_TIMEOUT_SECONDS, deadline)) as response:+ return read_whole(response, HTTP_TIMEOUT_SECONDS, deadline)except urllib.error.HTTPError as second:raise DownloadRefused(second.code, f"video: download failed with HTTP {second.code} even with the bearer token"@@ -486,7 +499,7 @@ def _submit_poll_publish(out: Path,credential: Credential,call: HttpCall,- download: Callable[[str, str], bytes],+ download: Download,sleep: Callable[[float], None],poll_timeout: float | None,accept: Callable[[Path, dict[str, Any]], None] | None = None,@@ -537,7 +550,7 @@ def _poll_publish(out: Path,credential: Credential,call: HttpCall,- download: Callable[[str, str], bytes],+ download: Download,sleep: Callable[[float], None],poll_timeout: float | None,started: float,@@ -549,13 +562,16 @@ def _poll_publish(still the `.part` file — `video-extend` measures the staged bytes with ffprobe; thestaged file is removed and `out` is never written.- The poll timeout counts from here. A run that ends before the request does — the timeout- came, xAI rejected the credential, or the clip it made could not be downloaded (DOWNLOAD_ATTEMPTS)- — raises GenerationUnfinished naming the request."""+ The poll timeout counts from `started`, when the request was sent (a resume: its first poll), and+ is one deadline for the polls and the downloads: `call` (as http_json) and `download` take it as+ `deadline=` and read only what is left of it, and a poll or download whose wait would reach it is+ not asked. A run that ends before the request does — the deadline came, xAI rejected the credential,+ the done poll named no URL, or the clip it made could not be downloaded (DOWNLOAD_ATTEMPTS) — raises+ GenerationUnfinished naming the request."""timeout = POLL_TIMEOUT_SECONDS if poll_timeout is None else poll_timeout- deadline = time.monotonic() + timeout+ deadline = started + timeoutpolls = polls_refused = polls_unanswered = failed_in_a_row = downloads = 0- video_url: str | None = None+ video_url: Any = Noneduration_reported: float | None = Nonemodel_reported: str | None = Nonefinal: dict[str, Any] = {}@@ -569,11 +585,15 @@ def _poll_publish(elapsed_seconds=time.monotonic() - started, downloads=downloads, last_download=last_download,)+ if time.monotonic() >= deadline:+ # The POST is not cut by the deadline (its answer is the one way to the id); this one came after it.+ raise unfinished(f"was accepted after the poll timeout ({timeout:g}s) had run out, before any poll; "+ f"it may still finish and be billed — {_ask_again(request_id, out)}", None, None, None)while True:polls += 1lost: str | None = Nonetry:- http, poll = call("GET", f"{API_BASE}/videos/{request_id}", credential.token, None)+ http, poll = call("GET", f"{API_BASE}/videos/{request_id}", credential.token, None, deadline=deadline)except TransportError as failed:lost, http, poll = failed.reason, None, Nonepoll_status = poll.get("status") if isinstance(poll, dict) else None@@ -619,8 +639,8 @@ def _poll_publish(failed_in_a_row = 0wait = (min(POLL_INTERVAL_SECONDS * 2 ** failed_in_a_row, POLL_BACKOFF_MAX_SECONDS) if failed_in_a_rowelse POLL_INTERVAL_SECONDS)- now = time.monotonic()- if now >= deadline:+ if time.monotonic() + wait >= deadline:+ # The next poll would leave no time to read its answer: the run ends here, not at the deadline.if failed_in_a_row:last = f"got no answer (last: {lost})" if lost is not None else f"were refused (last answer {http})"stopped = f"was accepted, but its polls {last} until the poll timeout ({timeout:g}s, {polls} polls)"@@ -628,7 +648,6 @@ def _poll_publish(stopped = f"still {poll_status!r} after {polls} polls — poll timeout"raise unfinished(f"{stopped}; it may still finish and be billed — {_ask_again(request_id, out)}",http, poll_status, lost)- wait = min(wait, deadline - now)if lost is not None:print(f"[{verb}] poll {polls} of generation {request_id} got no answer ({lost}); "f"asking again in {wait:g}s", file=sys.stderr)@@ -638,15 +657,18 @@ def _poll_publish(f"asking again in {wait:g}s", file=sys.stderr)sleep(wait)- if not video_url:- raise SystemExit(f"{verb}: generation {request_id} is done but reported no video url")+ if not (isinstance(video_url, str) and video_url.lower().startswith(("https://", "http://"))):+ # Done is xAI's word that the clip is made, so it may be billed: a poll that names nothing to download+ # (no url, an empty one, not a web address) ends naming the request, and video-resume polls it afresh.+ raise unfinished(f"is done, but its poll named no video url to download; the clip is made and may be billed — "+ f"{_ask_again(request_id, out)}", http, poll_status, None)# The clip is made: whatever stops its download, the run ends naming the request, never a second purchase.while True:downloads += 1said: str | None = None # what the transport said when the download got no answer it could readrefused: int | None = None # the status the clip's host refused it withtry:- data = download(video_url, credential.token)+ data = download(video_url, credential.token, deadline=deadline)except TransportError as failed:said = failed.reasonexcept DownloadRefused as failed:@@ -660,17 +682,22 @@ def _poll_publish(f"the clip is made and may be billed — {_ask_again(request_id, out)}", http, poll_status, None,{"http": None, "error": "not an mp4 (no ftyp box)", "bytes": len(data)})again = said is not None or refused in POLL_RETRY_STATUSES- if not again or downloads == DOWNLOAD_ATTEMPTS:+ wait = POLL_INTERVAL_SECONDS * 2 ** downloads+ out_of_time = time.monotonic() + wait >= deadline # the next download would leave no time to read it+ if not again or downloads == DOWNLOAD_ATTEMPTS or out_of_time:if said is not None:- failure = f"got no answer (last: {said}) after {downloads} attempts"+ failure = f"got no answer (last: {said})"elif again:- failure = f"was refused (last answer {refused}) after {downloads} attempts"+ failure = f"was refused (last answer {refused})"else:failure = f"was refused (answer {refused})"+ if again and downloads == DOWNLOAD_ATTEMPTS:+ failure += f" after {downloads} attempts"+ elif again:+ failure += f" until the poll timeout ({timeout:g}s, {downloads} attempt{'s' if downloads > 1 else ''})"raise unfinished(f"is done, but its download {failure}; the clip is made and may be billed — "f"{_ask_again(request_id, out)}", http, poll_status, None,{"http": refused, **({"error": said} if said is not None else {})})- wait = POLL_INTERVAL_SECONDS * 2 ** downloads# The status in plain digits, as the poll notes say it.failure = f"got no answer ({said})" if said is not None else f"was refused ({refused})"print(f"[{verb}] download {downloads} of generation {request_id} {failure}; downloading again in {wait:g}s",@@ -708,7 +735,7 @@ def generate_video(*,credential: Credential | None = None,call: HttpCall | None = None,- download: Callable[[str, str], bytes] | None = None,+ download: Download | None = None,sleep: Callable[[float], None] | None = None,poll_timeout: float | None = None,) -> VideoResult:@@ -797,7 +824,7 @@ def extend_video(*,credential: Credential | None = None,call: HttpCall | None = None,- download: Callable[[str, str], bytes] | None = None,+ download: Download | None = None,sleep: Callable[[float], None] | None = None,poll_timeout: float | None = None,probe: Callable[[Path], float] | None = None,@@ -866,7 +893,7 @@ def edit_video(*,credential: Credential | None = None,call: HttpCall | None = None,- download: Callable[[str, str], bytes] | None = None,+ download: Download | None = None,sleep: Callable[[float], None] | None = None,poll_timeout: float | None = None,probe: Callable[[Path], float] | None = None,@@ -911,7 +938,7 @@ def resume_video(*,credential: Credential | None = None,call: HttpCall | None = None,- download: Callable[[str, str], bytes] | None = None,+ download: Download | None = None,sleep: Callable[[float], None] | None = None,poll_timeout: float | None = None,) -> VideoResult:diff --git a/sprite_gen/gen/xai.py b/sprite_gen/gen/xai.pyindex 010625d..3154cea 100644--- a/sprite_gen/gen/xai.py+++ b/sprite_gen/gen/xai.py@@ -10,6 +10,7 @@ from __future__ import annotationsimport http.clientimport jsonimport os+import timeimport urllib.errorimport urllib.requestfrom dataclasses import dataclass, field@@ -162,7 +163,50 @@ def no_answer(exc: BaseException) -> TransportError:return TransportError((str(said) or type(said).__name__)[:200])-def http_json(method: str, url: str, token: str, body: dict | None = None, *, timeout: float = HTTP_TIMEOUT_SECONDS) -> tuple[int, Any]:+ANSWER_CHUNK = 1 << 16 # what one read of an answer bounded by a deadline asks for+++def time_left(timeout: float, deadline: float | None) -> float:+ """What one read may wait: `timeout`, cut to what is left before `deadline`, a `time.monotonic()`+ instant (None: no deadline). With nothing left it is a TimeoutError before anything is sent or read."""+ if deadline is None:+ return timeout+ left = deadline - time.monotonic()+ if left <= 0:+ raise TimeoutError("timed out")+ return min(timeout, left)+++def read_whole(response: http.client.HTTPResponse, timeout: float, deadline: float | None) -> bytes:+ """`response`'s body read whole, as `response.read()` reads it — and with a `deadline`, by then.++ A socket's timeout bounds one read, so an answer that keeps coming a little at a time is never cut+ by it. With a deadline the body is read a chunk at a time, each read waiting only what is left, so+ an answer that stalls or comes too slowly ends in `TimeoutError('timed out')` when the deadline+ comes. A body that ends short of its Content-Length raises IncompleteRead, as `read()` does."""+ if deadline is None:+ return response.read()+ chunks: list[bytes] = []+ while not response.isclosed():+ # http.client keeps no public handle on the connection once its answer began; the socket under+ # the response's reader is where a read's wait is set.+ response.fp.raw._sock.settimeout(time_left(timeout, deadline))+ chunk = response.read1(ANSWER_CHUNK)+ if not chunk:+ break+ chunks.append(chunk)+ data = b"".join(chunks)+ if response.length: # read1 stops where the connection closed, short of the Content-Length, without a word+ raise http.client.IncompleteRead(data, response.length)+ return data+++def http_json(method: str, url: str, token: str, body: dict | None = None, *, timeout: float = HTTP_TIMEOUT_SECONDS,+ deadline: float | None = None) -> tuple[int, Any]:+ """One request, its JSON answer read whole. `timeout` bounds each wait on the connection. A `deadline`+ (a `time.monotonic()` instant) cuts the waits for the answer to what is left of it when the request+ goes and the reads of its body to what is left at each (read_whole): an answer that stalls or comes+ too slowly is no answer when it comes (TransportError, `timed out`)."""data = None if body is None else json.dumps(body).encode("utf-8")request = urllib.request.Request(url, data=data, method=method)request.add_header("Authorization", f"Bearer {token}")@@ -170,15 +214,15 @@ def http_json(method: str, url: str, token: str, body: dict | None = None, *, tiif body is not None:request.add_header("Content-Type", "application/json")try:- with urllib.request.urlopen(request, timeout=timeout) as response:- raw = response.read().decode("utf-8")+ with urllib.request.urlopen(request, timeout=time_left(timeout, deadline)) as response:+ raw = read_whole(response, timeout, deadline).decode("utf-8")return response.status, (json.loads(raw) if raw else {})except (json.JSONDecodeError, UnicodeDecodeError) as exc:raise TransportError("response was not valid JSON", NOT_JSON) from excexcept urllib.error.HTTPError as exc:# A refusal's status alone is not an answer read whole: its body broken on the way is no answer too.try:- raw = exc.read().decode("utf-8", "replace")+ raw = read_whole(exc.fp, timeout, deadline).decode("utf-8", "replace")except NO_ANSWER as cut:raise no_answer(cut) from cuttry:diff --git a/tests/gen/test_video.py b/tests/gen/test_video.pyindex 27cc83f..f31655d 100644--- a/tests/gen/test_video.py+++ b/tests/gen/test_video.py@@ -179,7 +179,7 @@ def test_audio_default_is_left_to_the_api(tmp_path: Path) -> None:((200, {"request_id": "r"}), [(200, {"status": "failed", "error": "nsfw"})], "status='failed'"),((200, {"request_id": "r"}), [(200, {"status": "expired"})], "status='expired'"),((200, {"request_id": "r"}), [(404, {"raw": "boom"})], "HTTP 404"),- ((200, {"request_id": "r"}), [(200, {"status": "done", "video": {}})], "reported no video url"),+ ((200, {"request_id": "r"}), [(200, {"status": "done", "video": {}})], "poll named no video url to download"),],)def test_api_failures_are_named_and_write_nothing(tmp_path: Path, post, polls, expected) -> None:@@ -588,18 +588,18 @@ def test_polls_refused_until_the_poll_timeout_end_naming_the_request_to_ask_agaiassert isinstance(unfinished.value, SystemExit)assert [call[0] for call in api.calls].count("POST") == 1assert {call[1] for call in api.calls[1:]} == {f"{video.API_BASE}/videos/req-1"}- # Doubling, held at the ceiling, the last wait cut to the timeout — and one more poll asked there.- assert slept == [8.0, 16.0, 32.0, 60.0, 60.0, 60.0, 60.0, 4.0]- assert clock["t"] == 300 and len(api.calls) == 1 + 9+ # Doubling, held at the ceiling; the poll at 296 s would wait past the timeout for the next, so it is the last.+ assert slept == [8.0, 16.0, 32.0, 60.0, 60.0, 60.0, 60.0]+ assert clock["t"] == 296 and len(api.calls) == 1 + 8message = str(unfinished.value)assert message == ("video: generation req-1 was accepted, but its polls were refused (last answer 429) until the "- "poll timeout (300s, 9 polls); it may still finish and be billed — ask for request_id=req-1 "+ "poll timeout (300s, 8 polls); it may still finish and be billed — ask for request_id=req-1 "f"again with `sprite-gen video-resume --request-id req-1 --out {request.out.resolve()}` ""instead of submitting a new request; nothing was written")# No `(HTTP n)`, a refusal line's status: a caller reading `(HTTP 429)` sends the request again.assert HTTP_STATUS.search(message) is Noneassert "HTTP 429" not in message + capsys.readouterr().err- assert (unfinished.value.request_id, unfinished.value.last_http, unfinished.value.polls) == ("req-1", 429, 9)+ assert (unfinished.value.request_id, unfinished.value.last_http, unfinished.value.polls) == ("req-1", 429, 8)assert not request.out.exists() and not list(tmp_path.glob("*.part")) and api.downloads == []@@ -610,7 +610,7 @@ def test_a_poll_timeout_while_pending_names_the_request_to_ask_again(tmp_path: Pvideo.generate_video(_request(tmp_path), credential=video.Credential("t", "XAI_API_KEY"),call=api.call, download=api.download, sleep=sleep, poll_timeout=10)message = str(unfinished.value)- assert message.startswith("video: generation req-1 still 'pending' after 4 polls — poll timeout; ")+ assert message.startswith("video: generation req-1 still 'pending' after 3 polls — poll timeout; ")assert "request_id=req-1" in message and HTTP_STATUS.search(message) is Noneassert (unfinished.value.request_id, unfinished.value.last_http, unfinished.value.last_status) == ("req-1", 200, "pending")@@ -650,11 +650,11 @@ def test_the_cli_leaves_an_unfinished_report_naming_the_request(tmp_path: Path,"model": video.DEFAULT_MODEL,"request_id": "req-1","out": str(out.resolve()),- "polls": 4,- "polls_refused": 4,+ "polls": 3,+ "polls_refused": 3,"polls_unanswered": 0,"last_poll": {"http": 503, "status": None},- "elapsed_seconds": 30.0,+ "elapsed_seconds": 24.0,}assert capsys.readouterr().out == "" and not out.exists()@@ -725,15 +725,15 @@ def test_polls_that_get_no_answer_until_the_poll_timeout_end_unfinished_naming_tvideo.generate_video(request, credential=video.Credential("t", video.AUTH_SOURCE_GROK_LOGIN),call=api.call, download=api.download, sleep=sleep, poll_timeout=30)assert [call[0] for call in api.calls].count("POST") == 1- assert slept == [8.0, 16.0, 6.0] and clock["t"] == 30 and len(api.calls) == 1 + 4+ assert slept == [8.0, 16.0] and clock["t"] == 24 and len(api.calls) == 1 + 3message = str(unfinished.value)assert message == ("video: generation req-1 was accepted, but its polls got no answer (last: timed out) until the "- "poll timeout (30s, 4 polls); it may still finish and be billed — ask for request_id=req-1 "+ "poll timeout (30s, 3 polls); it may still finish and be billed — ask for request_id=req-1 "f"again with `sprite-gen video-resume --request-id req-1 --out {request.out.resolve()}` ""instead of submitting a new request; nothing was written")assert HTTP_STATUS.search(message) is Nonereport = unfinished.value.to_dict()- assert (report["polls"], report["polls_refused"], report["polls_unanswered"]) == (4, 0, 4)+ assert (report["polls"], report["polls_refused"], report["polls_unanswered"]) == (3, 0, 3)assert report["last_poll"] == {"http": None, "status": None, "error": "timed out"}assert not request.out.exists() and not list(tmp_path.glob("*.part")) and api.downloads == []@@ -885,11 +885,11 @@ def test_the_resume_cli_leaves_an_unfinished_report_on_the_same_request(tmp_path"model": None,"request_id": "req-7","out": str(out.resolve()),- "polls": 4,+ "polls": 3,"polls_refused": 0,"polls_unanswered": 0,"last_poll": {"http": 200, "status": "pending"},- "elapsed_seconds": 10.0,+ "elapsed_seconds": 8.0,}assert capsys.readouterr().out == "" and not out.exists()@@ -1090,11 +1090,11 @@ def test_polls_cut_short_until_the_poll_timeout_leave_an_unfinished_report_naminout, report = tmp_path / "clip.mp4", tmp_path / "clip.report.json"with pytest.raises(video.GenerationUnfinished) as unfinished:video.run(image=_still(tmp_path), prompt="sway", out=out, report=report)- assert server.seen == [("POST", "/v1/videos/generations")] + [("GET", "/v1/videos/req-1")] * 4- assert slept == [8.0, 16.0, 6.0] and clock["t"] == 30+ assert server.seen == [("POST", "/v1/videos/generations")] + [("GET", "/v1/videos/req-1")] * 3+ assert slept == [8.0, 16.0] and clock["t"] == 24message = str(unfinished.value)assert message == (f"video: generation req-1 was accepted, but its polls got no answer (last: {CUT_SAID}) until the "- "poll timeout (30s, 4 polls); it may still finish and be billed — ask for request_id=req-1 "+ "poll timeout (30s, 3 polls); it may still finish and be billed — ask for request_id=req-1 "f"again with `sprite-gen video-resume --request-id req-1 --out {out.resolve()}` ""instead of submitting a new request; nothing was written")assert HTTP_STATUS.search(message) is None@@ -1106,11 +1106,11 @@ def test_polls_cut_short_until_the_poll_timeout_leave_an_unfinished_report_namin"model": video.DEFAULT_MODEL,"request_id": "req-1","out": str(out.resolve()),- "polls": 4,+ "polls": 3,"polls_refused": 0,- "polls_unanswered": 4,+ "polls_unanswered": 3,"last_poll": {"http": None, "status": None, "error": CUT_SAID},- "elapsed_seconds": 30.0,+ "elapsed_seconds": 24.0,}assert capsys.readouterr().out == "" and not out.exists() and not list(tmp_path.glob("*.part"))