A video model will happily paint you a motion-graphics frame. Plausible is the problem: text comes back with warped letterforms, a product logo comes back adjacent to the original rather than identical, a button label reads "Sumbit". For a trailer nobody notices. For a product walkthrough, where the interface has to be the real interface, someone does.

That gap is why we render frames as code instead of generating pixels. Text, layout and logos are drawn, so they stay exact, and the model only decides the motion.

This post is about the boring half: the job pipeline and how we test it.

The job is a small, boring, idempotent object

A render request is a record, not an HTTP call that does work in the handler. It holds the prompt, the references, the aspect ratio, the duration ceiling, and the credits it will spend. The handler validates, writes the record, and returns an id. Nothing renders inside the request.

type RenderJob = { id: string; prompt: string; references: AssetRef[]; aspect: '16:9' | '9:16' | '1:1'; durationMs: number; credits: number; state: 'queued' | 'running' | 'done' | 'failed' | 'cancelled'; }; 

Because the job is a record, retries are cheap and safe to reason about. Two consequences we designed for from day one:

  • A client that retries a submission sends the same idempotency key, and gets the same job back instead of a second charge.
  • A worker that dies mid-run leaves a running row with a heartbeat; a reaper moves it to queued again, not to failed, so a restart does not look like a user error.

Polling beats webhooks for the first version

Everyone wants webhooks. We started with polling, because a poll is trivially correct and a webhook is a distributed system you have not built yet.

GET /jobs/:id returns state and a version counter. Clients poll with backoff. Webhooks, when we added them, were a thin fan-out on state transitions — not the source of truth.

One rule that saved us: the poll and the webhook must agree. If they can disagree, one of them is a bug, and it will be the one you trust.

"Done" needs a definition, not a feeling

State transitions are guarded by a table, not by if statements scattered across workers:

from to who
queued running worker claim
running done renderer success
running failed renderer error, retries exhausted
running queued reaper, heartbeat stale
any cancelled user

Anything not in the table is rejected and logged. When a job shows done, the artefact is already in storage and its checksum recorded; we never flip the bit first and upload after.

Refunding is part of the state machine

Failed and unsaved runs return credits. "Unsaved" matters: the user may have thrown the result away before it failed, and a refund for a video they deleted is noise. The refund runs in the same transaction as the failure, so there is no window where a job is failed and still charged.

Testing without a GPU

You cannot run a real render in CI at a useful speed, so the renderer hides behind an interface and the tests use three fixtures:

  1. Golden — a short job whose frame checksums are committed. Catches silent typography regressions.
  2. Hostile — a job that fails at 60%, then succeeds, to prove resume and refund.
  3. Idempotent — the same job submitted five times, asserting one row, one charge, one artefact.

The fixture harness asserts on state transitions and credit deltas, not on pixels. Pixel tests are for a nightly job, because a subpixel change in a font stack should not turn a PR red.

Failure modes we actually hit

  • The retry storm. A worker bug turned one poison job into 400 retries in a minute. Cap retries per job and add jitter; the queue does not care about your feelings.
  • The double charge. A client retried on a 500 that reached the server. The idempotency key is now mandatory, and the duplicate returns 200 with the original job.
  • The silent timeout. The renderer gave up but never reported, so jobs sat in running forever. The heartbeat plus reaper fixed it, and the dashboard now alerts on running older than the duration ceiling.

What this buys the product

None of this is novel; it is the standard shape of a job queue. That is the point. When the pipeline is boring, the interesting work — motion, timing, taste — gets all the attention, and a failed run costs a retry instead of a support ticket.

The frame-as-code choice and the boring queue are the same decision seen twice: make the deterministic parts deterministic, so the judgement stays with the person.

Claude Motion Video is the tool this pipeline serves: https://cmotionvideo.com/ - animated titles rendered as code, 1080p MP4 export.