Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(gen): a wait that wakes at the time limit or past it sends nothing
Soohong Kime886fdccc3f9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e9ea865..dd3b86e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,8 +4,8 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the## Unreleased-- **Behavior change: a refused provider request is sent again only within the time limit of its call, and the waits count in that limit.** Previously a request its provider documents as not taken (a 429, an overload) was sent again after 8 s and 16 s, or after the answer's `retry-after` (at most 120 s), twice, whatever time the call had left, and the time limits did not count those waits: `SPRITE_GEN_GEN_TIMEOUT_SECONDS` bounded each send of an OpenAI or Grok image and of the OpenAI facing check on its own, the Grok facing check's 120 s each read, the clip's poll timeout counted from the send xAI accepted, and a Message Batch's status and results reads waited outside `--batch-wait`. A caller that stops the run at its own ceiling, set above those limits, could kill a request taken after two refusals and hear nothing from the engine. Now each limit counts from the first send and holds the waits: the image calls and the OpenAI facing check count `SPRITE_GEN_GEN_TIMEOUT_SECONDS`, the Grok facing check its 120 s, each of their sends reading only what is left of it; the clip its poll timeout (`SPRITE_GEN_VIDEO_TIMEOUT_SECONDS`; the POST itself is still not cut, its answer being the one way to the request id); a batch's reads `--batch-wait`. A wait that would reach the limit is not waited: the refusal ends the call as any refusal does, after one stderr line, `[gen] openai refused the request (429 rate_limit_exceeded); nothing was made — not asking again: the 16s wait would reach the time limit (12s left)`. A realtime `pixel-draw` call has no time limit of its own and is unchanged.-- **Tests** — `tests/gen/test_retry.py` (a request sent again only while its wait ends before the time limit; the answer's `retry-after` counted the same; a wait that ends at the limit not waited; every direct provider call hands `retry` its limit), `tests/gen/test_openai_provider.py` and `tests/gen/test_grok_provider.py` (with 20 s, the second send waits only the 12 s left and the second 429 ends the call `sent 2 times`), `tests/gen/test_video.py` (the poll timeout counts from the first send; a 429 whose next wait would reach it ends the run with its status), `tests/gen/test_pixel_draw.py` (each batch read is handed the end of `--batch-wait`). `tests/http_answer.py` is one offline HTTP answer the provider tests share, read whole or a chunk at a time under a deadline.+- **Behavior change: a refused provider request is sent again only within the time limit of its call, and the waits count in that limit.** Previously a request its provider documents as not taken (a 429, an overload) was sent again after 8 s and 16 s, or after the answer's `retry-after` (at most 120 s), twice, whatever time the call had left, and the time limits did not count those waits: `SPRITE_GEN_GEN_TIMEOUT_SECONDS` bounded each send of an OpenAI or Grok image and of the OpenAI facing check on its own, the Grok facing check's 120 s each read, the clip's poll timeout counted from the send xAI accepted, and a Message Batch's status and results reads waited outside `--batch-wait`. A caller that stops the run at its own ceiling, set above those limits, could kill a request taken after two refusals and hear nothing from the engine. Now each limit counts from the first send and holds the waits: the image calls and the OpenAI facing check count `SPRITE_GEN_GEN_TIMEOUT_SECONDS`, the Grok facing check its 120 s, each of their sends reading only what is left of it; the clip its poll timeout (`SPRITE_GEN_VIDEO_TIMEOUT_SECONDS`; the POST itself is still not cut, its answer being the one way to the request id); a batch's reads `--batch-wait`. A wait that would reach the limit is not waited: the refusal ends the call as any refusal does, after one stderr line, `[gen] openai refused the request (429 rate_limit_exceeded); nothing was made — not asking again: the 16s wait would reach the time limit (12s left)`. The limit is read again after the wait, right before the send, as a sleep may wake later than it was asked to: one that woke at the limit or past it sends nothing either, and the refusal ends the call the same way (`… — not asking again: the time limit came during the 8s wait`). A clip's polls and downloads read their poll timeout the same way: a poll or download whose wait woke at it or past it is not sent, and the run ends unfinished on the last one as it came, where the one the transport found no time left to send was counted as a poll or download that got no answer (`timed out`). A realtime `pixel-draw` call has no time limit of its own and is unchanged.+- **Tests** — `tests/gen/test_retry.py` (a request sent again only while its wait ends before the time limit; the answer's `retry-after` counted the same; a wait that ends at the limit not waited; a wait that woke at the limit or past it sends nothing, the limit read by one judgment, `too_late`, before the wait and right before the send; every direct provider call hands `retry` its limit; the Grok facing check and a Message Batch read whose wait woke past their limit send nothing), `tests/gen/test_openai_provider.py` and `tests/gen/test_grok_provider.py` (with 20 s, the second send waits only the 12 s left and the second 429 ends the call `sent 2 times`; with 8.01 s, an 8 s wait that woke 20 ms late sends nothing and the 429 ends the image call, or the OpenAI facing check, as it came), `tests/gen/test_video.py` (the poll timeout counts from the first send; a 429 whose next wait would reach it ends the run with its status, and so does one whose 8 s wait woke 20 ms past an 8.01 s timeout, with no second POST; a poll or a download whose wait woke past the timeout is not sent, and the run ends on the last one as it came), `tests/gen/test_pixel_draw.py` (each batch read is handed the end of `--batch-wait`). `tests/http_answer.py` is one offline HTTP answer the provider tests share, read whole or a chunk at a time under a deadline.- **New verb: `video-stop` cuts a walk or run that stops from the clip's own start played backwards.** Given the clip's keyed frames and a walk or run loop (`--frames-dir`, `--loop`), it writes a one-shot strip (`<name>.strip.png`), sidecar (`loop: false`, `hold_last: true`), GIF, WebP, and report (`<name>.stop.report.json`). The stop leaves the loop from the cell nearest the entry (`from_cell`), the first frame after the opening rest within `SAME_POSE` (0.35 steps) of a loop cell, and ends on the clip's first frame, the still as filmed. A seam past the jump line (1.4 steps, `--seam-max`) is refused by `video-stop` with exit code 1 and `status: "failed"` in the report, and so is another motion in the run-up between the rest and the entry, however short: a run-up frame back within `SAME_POSE` (0.35 steps) of a pose the clip had left by `TURN_BACK_AWAY` (one step) or more (the still, or the run-up's own), refused with "the run-up turns back — another motion, that the stop would play backwards", naming the three frames (`turn_back`, the nearest such comeback, is reported either way). A run-up longer than `RUN_UP_MAX_CYCLES` (1.5 cycles) — `source_cut.length` frames, overridden by `--run-up-max` — which plays strides unlike the loop's, is refused with "strides unlike the loop's, that the stop would play backwards"; `--run-up-max` bounds only that length and never lets another motion through. The seam refusal, the another-motion refusal and the run-up refusal can all be named in one message. Drift is taken out by laying the entry on its cell and the first frame on the loop's ground and mean coverage, moving frames between by a straight share of the difference per step; a run leaning away moves the still a few pixels, and drift not straight leaves a little of itself. Strips wider than 32,000 px are refused, `--speed 2` plays every other frame (still kept last), `--max-frames N` spaces frames evenly, and frames shown pass the ghost screen (`interpolation_quality`) as filmed. The pose thumbnails (`gait_fallback.poses`, 48 px cut about the feet) are now public, as the verb reads poses with them ([video-pipeline](docs/video-pipeline.md#8-a-walk-or-run-that-stops--video-stop)).- **New: a motion plays as its request says — `--play loop|once-return|once-hold|lifetime` — and `video-set --motion` gives each state or item its own motion text.** A state's name used to fix its sentence, its end-frame pin, its cut and whether its strip loops, so every new motion (a punch, typing at a desk, a block, a tool swing) was a change to the engine. `video-set --play STATE=MODE` or `ITEM=MODE` and `video-prompt --play MODE` take the mode as a value of the request, and `video-set --motion STATE=TEXT` or `ITEM=TEXT` the caller's words in place of the state's sentence (an item's own value wins over its state's; a key that names neither, a key given twice or a mode the state cannot play is refused before any clip). A word the engine does not name is filmed under that name in that mode: a once-return is pinned to end on its first frame, asked for as one action that returns to the first pose, and cut whole by the new `video-loop --cycle once-return` (every frame, the last too, gated by the pin), its `strip.json` saying `loop: false`, `hold_last: false`, `returns: true` with the first pose in its first and last cells; a once-hold is cut at its held pose (`once`), the first settled pose whose drawing is not its first — a shield raised inside a body outline that keeps its size and floor is one, the first drawing come back, in place or slid sideways, is not — while the six terminal states keep their body-geometry screen (any other state cut `--cycle once` is screened by its drawing too); a lifetime is framed and filmed as an effect whatever its name; a loop asked for is searched as a loop (`periodic`) and never failed over to a single play. Named states are presets: without `--play` every state is filmed, prompted and cut as before, and an attack played once-return is the same prompt and the same pinned clip, cut whole and played once. `effect`, the six terminal states and the cyclic states refuse any other mode. `set.report.json` records each item's `play` (and `motion`); `video-prompt --json` records `play`. Not measured on a clip model: the sentences for a motion of your own ([video-pipeline](docs/video-pipeline.md#play-modes)).- **Tests** — `tests/video/test_play.py` (every named state given no mode is pinned, prompted and cut as before, and the same when its preset is named, save that a loop asked for is never failed over; a mode a state cannot play is refused; a once-return asked for pinned with its return sentence and cut whole, or searched where the source cannot pin; the attack played once-return is the attack's prompt; a named state played another way takes the mode's sentence; a once-hold with its end frame; a once-hold of your own ending on a new drawing inside the same body box cut at its held pose, the same clip as `cast` still refused by its body geometry, and one that comes back to its first drawing, in place or slid sideways, refused; a lifetime filmed as an effect whatever its name; a loop of your own; `video-set` modes and texts per state and per item, refused before any clip when a key or mode is wrong; a once-return that does not come back refused; a once-return cut subsampled with both ends kept and played once; the CLIs) and the once-return item filmed end to end in `tests/video/test_clip_prompt.py`, its strip's first and last cells the first pose. Synthetic fixtures only.diff --git a/docs/gen.md b/docs/gen.mdindex 7333b3a..f7aec94 100644--- a/docs/gen.md+++ b/docs/gen.md@@ -218,6 +218,10 @@ Anthropic transport of `pixel-draw` (docs/pixel-draw.md) — in `sprite_gen/gen/a Message Batch (docs/pixel-draw.md). A wait that would reach the limit is notwaited: the refusal ends the call after one line,`[gen] openai refused the request (429 rate_limit_exceeded); nothing was made — not asking again: the 16s wait would reach the time limit (12s left)`.+ The limit is read again after the wait, right before the send: a sleep may wake+ later than it was asked to, and one that woke at the limit or past it sends nothing —+ the refusal ends the call the same way,+ `[gen] openai refused the request (429 rate_limit_exceeded); nothing was made — not asking again: the time limit came during the 8s wait`.A realtime `pixel-draw` call has no time limit of its own.- **A request that got no answer it could read is never sent again** — the connectionbroke, it timed out, or the answer broke on the way, a refusal whose body brokediff --git a/docs/video.md b/docs/video.mdindex 1961636..8797990 100644--- a/docs/video.md+++ b/docs/video.md@@ -146,7 +146,7 @@ What happens, in order:URLs, optional `aspect_ratio` / `generate_audio`. A `429` — xAI's rate limit, arequest it did not take — is sent again, twice at most, after 8 s and 16 s, whilethe wait leaves some of the poll timeout (step 3); a wait that would reach it is not- waited and the run ends on that `429`+ waited, one that woke at it or past it sends nothing, and the run ends on that `429`([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.@@ -171,8 +171,9 @@ What happens, in order:- Each poll reads only what is left of it. One whose answer stalls, or comes tooslowly for its 120 s read timeout ever to fire, is cut when the timeout comes andcounts 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.+ - A poll whose wait would reach the timeout is not asked, nor one whose wait woke+ at it or past it (a sleep may wake late). A generation still pending, refused or+ unanswered then is *unfinished* (below) at once, on its last poll as it came.- The POST is not cut by it: its answer is the one way to the `request_id`, under itsown 120 s read timeout. One answered after the whole timeout is unfinished beforeany poll.@@ -191,9 +192,10 @@ What happens, in order:that the clip's host refuses with `429`, `500`, `502`, `503`, `504` or `529` is downloadedagain, after 8 s and then 16 s — three downloads in all, within the poll timeout: eachreads 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,+ cut when it comes (`timed out`), and one whose wait would reach it, or woke at it or+ past 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 bearertoken first), a download the timeout leaves no time for, or bytes that are not an mp4end the run *unfinished* (below).diff --git a/sprite_gen/gen/retry.py b/sprite_gen/gen/retry.pyindex be2bc17..b8571cc 100644--- a/sprite_gen/gen/retry.py+++ b/sprite_gen/gen/retry.py@@ -42,7 +42,11 @@ The waits are inside the time limit of the call the request belongs to (`ask(deaimage calls and the facing check count theirs from the first send, the clip request its polltimeout, a Message Batch's reads `--batch-wait`. A request is sent again only when its wait endsbefore that limit; one whose wait would reach it is returned as it came, and its stderr line says-why — so a caller whose own ceiling sits above the limit hears the refusal, not a kill.+why — so a caller whose own ceiling sits above the limit hears the refusal, not a kill. One+judgment reads the limit, `too_late`, before the wait and again after it, right before the send: a+sleep may wake later than it was asked to, and one that woke at the limit or past it sends nothing+either — the refusal is returned as it came, its line saying the time limit came during the wait.+A send at the limit is not made: it would have no time left to be answered in.A GET buys nothing, so one answered with any of GET_AGAIN is asked again; the `video` poll keepsasking for as long as its poll timeout lets it, the Anthropic batch reads ASKS_AGAIN times.@@ -142,11 +146,26 @@ def out_of_time(label: str, who: str, method: str, status: int, kind: str | Nonef"the {wait:g}s wait would reach the time limit ({max(left, 0.0):.0f}s left)")+def woke_late(label: str, who: str, method: str, status: int, kind: str | None, wait: float) -> str:+ """The stderr line of a request not sent again because the time limit of its call came during its wait:+ the sleep woke at the limit or past it."""+ return f"{_refused(label, who, method, status, kind)} — not asking again: the time limit came during the {wait:g}s wait"++def tail(asks: int) -> str:"""What a `gen` refusal line says was done after the answer: no retry, or how many times it was sent."""return "no retry or provider fallback" if asks == 1 else f"sent {asks} times, no provider fallback"+def too_late(deadline: float | None, wait: float = 0.0) -> bool:+ """Whether a request sent `wait` seconds from now would go at `deadline` or past it — the time limit of the+ call it belongs to, a `time.monotonic()` instant (None: none) — and so is not sent: one sent at the limit+ would have no time left to be answered in. The one reading of a call's time limit before a send: `ask`+ reads it before each wait and again after it, right before the send (a sleep may wake late), and the+ `video` polls and downloads read their poll timeout by it the same way."""+ return deadline is not None and time.monotonic() + wait >= deadline++def _sleep(seconds: float) -> None:time.sleep(seconds)@@ -158,8 +177,9 @@ def ask(send: Send, *, provider: str, who: str, label: str, method: str = "POST"`send` returns `(status, body, headers)` — `headers` None when the transport keeps none — andraises when no answer came; that is never asked again here. `kind` reads the provider's word forthe refusal off the body for the stderr line. `deadline`, a `time.monotonic()` instant (None:- none), is the time limit of the call: a wait that would reach it is not waited, and the refusal- is returned as it came."""+ none), is the time limit of the call, read by `too_late` before each wait and again after it, right+ before the send: a wait that would reach it is not waited, and a wait that woke at it or past it+ sends nothing — either way the refusal is returned as it came, after one line saying why."""asks = 0while True:status, body, headers = send()@@ -168,9 +188,11 @@ def ask(send: Send, *, provider: str, who: str, label: str, method: str = "POST"if wait is None:return status, body, headers, askssaid = kind(body) if kind else None- left = None if deadline is None else deadline - time.monotonic()- if left is not None and wait >= left:- print(out_of_time(label, who, method, status, said, wait, left), file=sys.stderr)+ if too_late(deadline, wait):+ print(out_of_time(label, who, method, status, said, wait, deadline - time.monotonic()), file=sys.stderr)return status, body, headers, asksprint(asking_again(label, who, method, status, said, wait, asks), file=sys.stderr)(sleep or _sleep)(wait)+ if too_late(deadline):+ print(woke_late(label, who, method, status, said, wait), file=sys.stderr)+ return status, body, headers, asksdiff --git a/sprite_gen/gen/video.py b/sprite_gen/gen/video.pyindex 45dd27f..8096e9a 100644--- a/sprite_gen/gen/video.py+++ b/sprite_gen/gen/video.py@@ -105,10 +105,11 @@ POLL_INTERVAL_SECONDS = 4.0# The poll timeout is the one time limit of a request: it counts from the POST's first send (a resume: its# first poll) and bounds the waits before a refused POST goes again (`retry`), the polls, their waits and# the clip's downloads alike. Each poll and download reads only what is left of it (xai.read_whole), and a-# send, poll or download whose wait would reach it is not asked: the run ends on the refusal, or unfinished-# on the request_id. So a caller that stops the run at a hard limit gets its line 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.+# send, poll or download whose wait would reach it, or woke at it or past it, is not asked (`retry.too_late`,+# read before the wait and again after it): the run ends on the refusal, or unfinished on the request_id.+# So a caller that stops the run at a hard limit gets its line 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, `retry.GET_AGAIN`), 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 —@@ -564,10 +565,10 @@ def _poll_publish(The poll timeout counts from `started`, the POST's first send (a resume: its first poll), andis 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."""+ `deadline=` and read only what is left of it, and a poll or download whose wait would reach it, or+ woke at it or past it, is not asked (`retry.too_late`). 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_timeoutdeadline = started + timeoutpolls = polls_refused = polls_unanswered = failed_in_a_row = downloads = 0@@ -585,7 +586,7 @@ def _poll_publish(elapsed_seconds=time.monotonic() - started, downloads=downloads, last_download=last_download,)- if time.monotonic() >= deadline:+ if retry.too_late(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)@@ -637,23 +638,27 @@ def _poll_publish(else:failed_in_a_row = 0wait = retry.backoff(failed_in_a_row) if failed_in_a_row else POLL_INTERVAL_SECONDS- 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)"- else:- 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)- 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)- elif failed_in_a_row:- # The status in plain digits: `(HTTP 429)` on this stream reads as a refused request to send again.- print(f"[{verb}] poll {polls} of generation {request_id} was refused ({http}); "- f"asking again in {wait:g}s", file=sys.stderr)- sleep(wait)+ # The next poll goes only before the poll timeout (`retry.too_late`): one whose wait would reach it would+ # leave no time to read its answer, and a wait that woke at it or past it sends none.+ if not retry.too_late(deadline, wait):+ 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)+ elif failed_in_a_row:+ # The status in plain digits: `(HTTP 429)` on this stream reads as a refused request to send again.+ print(f"[{verb}] poll {polls} of generation {request_id} was refused ({http}); "+ f"asking again in {wait:g}s", file=sys.stderr)+ sleep(wait)+ if not retry.too_late(deadline):+ continue+ # The run ends here, on the last poll as it came, 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)"+ else:+ 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)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@@ -681,26 +686,29 @@ def _poll_publish({"http": None, "error": "not an mp4 (no ftyp box)", "bytes": len(data)})again = said is not None or refused in retry.GET_AGAINwait = retry.backoff(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})"- elif again:- 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 {})})- # 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",- file=sys.stderr)- sleep(wait)+ # The next download goes only before the poll timeout (`retry.too_late`): one whose wait would reach it+ # would leave no time to read it, and a wait that woke at it or past it tries none.+ if again and downloads < DOWNLOAD_ATTEMPTS and not retry.too_late(deadline, wait):+ # 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",+ file=sys.stderr)+ sleep(wait)+ if not retry.too_late(deadline):+ continue+ if said is not None:+ failure = f"got no answer (last: {said})"+ elif again:+ 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 {})})elapsed = time.monotonic() - startedout.parent.mkdir(parents=True, exist_ok=True)