Skip to content

Write HTML. Render video. Built for agents.

docs(cli): document segmented capture and record the Phase 2d gate

Vance Ingallsc4ccd9d6a209
diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx
index e8ed07bf3b..b10237504e 100644
--- a/docs/packages/cli.mdx
+++ b/docs/packages/cli.mdx
@@ -955,6 +955,36 @@ frame storage, the message names which of those applied; the usual fixes are
| `PRODUCER_STREAMING_ENCODE_DURATION_CAP_ENABLED` | `false` | `true` restores the duration ceiling below |
| `PRODUCER_STREAMING_ENCODE_MAX_DURATION_SECONDS` | `240` | The ceiling's value; inert unless the flag above is `true`, including the `0` ("never") setting |
+#### Segmented capture
+
+For long renders, capture can be split into fixed-size segments, each encoded
+by its own ffmpeg and stream-copied together at the end. It costs some speed
+against a single-encoder streaming render, and buys three things:
+
+- Scratch is encoded video rather than raw frames, at any duration.
+- The browser restarts at segment boundaries, so a session never accumulates
+ the tens of thousands of frames where Chrome starts losing its target.
+- A crash costs one segment. `--resume` re-runs the render and reuses the
+ segments a previous attempt finished, after re-validating each one; a
+ resumed render is byte-identical to an uninterrupted one.
+
+Segments live in `renders/.hf-segments/<hash>/`, where the hash covers
+everything that determines segment bytes, so changing the composition, fps,
+resolution, quality or segment size starts a fresh set instead of splicing
+mismatched encodes. The directory is deleted after a successful render unless
+`--keep-segments`, and deliberately kept after a failure, because that is what
+`--resume` reads next time.
+
+mp4 and mov only; png-sequence, gif, webm, HDR and shader-transition renders
+keep their existing routes.
+
+| Environment variable | Default | Effect |
+| ------------------------------ | ---------- | ------------------------------------------------------------------------------------------ |
+| `HF_SEGMENTED_CAPTURE` | unset | `true` segments any eligible render; `false` is the kill switch |
+| `HF_SEGMENTED_MIN_SECONDS` | off | Segment renders at least this long. Unset means duration never routes on its own |
+| `HF_SEGMENT_FRAMES` | `3000` | Frames per segment (~100 s at 30 fps); minimum 30 |
+| `HF_SEGMENT_BROWSER_RECYCLE` | `3` | Restart the browser every N segments; `0` keeps one session for the whole render |
+
#### Render the same composition with different content
Declare the variables on the composition root, read them inside it, then
diff --git a/packages/producer/tests/long-form/README.md b/packages/producer/tests/long-form/README.md
index 3b6383fc8d..f83fc9c147 100644
--- a/packages/producer/tests/long-form/README.md
+++ b/packages/producer/tests/long-form/README.md
@@ -34,7 +34,7 @@ Never run two of these concurrently on a dev Mac — the fleet limit is why the
| 2a | `HF_SEGMENTED_CAPTURE=true HF_SEGMENT_FRAMES=1500 render a-single --fps 30 -w 1` | log `Segmented capture complete: 6 segment(s)`; output 300.000 s and exactly 9000 frames; no per-frame PSNR dip at a segment boundary (see below) |
| 2b | kill the 2a render at ~40 %, rerun with `--resume` | log `resuming: N segments complete` + N × `segment skipped (resume)`; output byte-identical to an uninterrupted run; the segment dir is gone afterwards unless `--keep-segments` |
| 2c | 2a with `HF_SEGMENT_BROWSER_RECYCLE=1` | `segment browser recycled (cadence)` once per segment **after the first** (5 for 6 segments), each carrying the session's `rendererRssPeakMb`; output byte-identical to the single-session render |
-| 2d | 2a with `-w 4` | four `segment worker` lines; output 300.000 s |
+| 2d | 2a with `-w 3` | `Segmented capture complete: 6 segment(s)`; output 300.000 s, 9000 frames, byte-identical to the `-w 1` segmented render |
The Phase 0 mutation check is the same render with `PRODUCER_STREAMING_ENCODE_DURATION_CAP_ENABLED=true`: the gate line must flip to `"enabled":false,"reason":"duration_cap"` and the render must fail at the disk preflight on a host without ~75 GB free.
@@ -108,6 +108,20 @@ Determinism across restarts is also what makes the 2c retry safe: a segment
re-captured on a fresh session is indistinguishable from one that never
failed.
+### What the 2d gate is really testing
+
+That the worker count is invisible in the output. Measured 2026-09-17 with
+`-w 3`: byte-identical to the single-worker segmented render, 3 m 14 s against
+5 m 13 s (1.6x). Segments finish out of order, so a mismatch here would mean
+the concat list had picked up completion order.
+
+Do not run more than 3 Chrome fleets at once on a dev Mac (vault: kernel-panic
+history) — that is why this gate is `-w 3` and not `-w 4`.
+
+With the default recycle cadence of 3 and 6 segments over 3 workers, each
+worker only captures 2 segments, so no `segment browser recycled` line appears
+in this gate. Combine with `HF_SEGMENT_BROWSER_RECYCLE=1` to exercise both.
+
### Known cost: segmented capture is slower
The segmented stage runs the plain `captureFrameToBuffer` loop, while the