Skip to content

Support seekable video and audio in page media - #1658

Merged
max-sixty merged 8 commits into
mainfrom
codex/authored-page-media
Oct 3, 2026
Merged

max-sixty merged 8 commits into
mainfrom
codex/authored-page-media

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

An authored recording could not be reused in a Leaf page: page media rejected its type and HTTP refused its URL. Page media now admits MP4/WebM video and MP3/M4A/Ogg/WAV audio through the existing content-addressed owner. Live and captured URLs answer single byte ranges for native playback and seeking; HEAD preserves the representation length without reading a body. Browser uploads keep their raster-only validation.

Captured resources retain immutable file paths until a consumer needs their bytes. Cold document startup does not load recording bodies, and the shared HTTP response reads only the requested span. Offline export embeds each complete recording once, with no arbitrary size cap or omitted media. One document-lifetime allocator shares addresses across native attributes, CSS and runtime/widget lookups; the import map preserves module identity. Queries identify the same captured bytes and meaningful fragments survive playback.

Offline embedded images, fonts and recordings require JavaScript. With scripts disabled, the normal composer preserves authored text, layout and alt text and explains unavailable graphics. Both modes preserve native HTML parsing; the export reports its actual total bytes. The feature gallery includes real eight-second video/audio recordings, a matching poster and native controls. preload="none" defers recording requests until playback.

Validation: everyday gate (2,016 passed, one skipped) plus its corrected first-paint test; real HTTP cold-start/HEAD/span/range/upload checks; Chrome live and file playback, seeking, Tab/Space and narrow touch controls; repeated native/API address identity, CSS/import graphs, modules/deferred data, UTF8/parser/shadow/prose and scripts-off layout with no asset requests. Runtime 194, browser folds 74, Worker 66/typecheck, bundles, instruction tests 56, eval predicates and lint pass. Independent full resource-owner review and a combined staged-publication recovery integration pass found no remaining issues. The instruction case passes both baseline and candidate, establishing coverage rather than an improvement claim.

The served repair startup comparison retains 262 requests by presentation and adds 417 bytes; it requests neither recordings nor the offline allocator. The original gallery addition costs about 17.5 KB of markup/poster.

Native video after seeking to six seconds, with the audio player's controls beside it

Closes #1083

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range response still materializes the complete recording before it slices a requested span. On a cold page visit, _serve_root calls read_artifact, whose _materialize reads every captured resource with read_bytes; the live /media/ route also calls file.read_bytes before _resource_content sees the range. Thus preload="none" defers the browser request but a large recording still blocks the first document response and occupies server memory, while live seeking rereads the whole file. With recordings admitted without a size limit, this is a regression on the claimed playback path. The resource owner needs to keep captured identity while reading only the requested media span. See _resource_content and _materialize.

The offline export embeds each recording twice: embedded_resources puts a base64 copy in the runtime payload, and compose_document calls AssetInliner.address for the native player's src. I counted two complete base64 copies of each recording in the HTML produced by the new browser test. A recording therefore costs about 2⅔ times its source bytes before other page content, while the new author guidance says base64 adds about a third. For recordings of useful length, the extra copy makes the exported page substantially heavier; the export should share one embedded copy or state its actual size cost. See export_document.

Revision materialization now retains immutable file descriptors, so cold document reads and HEAD do not load recording bodies; the shared HTTP response reads only a requested range. Export uses one document-lifetime resource allocator for native attributes, CSS and runtime lookups, while the existing import map preserves module identity. A normal-composer scripts-off record keeps authored text, layout and alt text and explains unavailable captured graphics. Asset queries identify the same bytes and meaningful fragments survive delivery; module suffixes remain refused.
The fallback is the outer normal-composer document, with a small scripts-off notice. Offline construction runs outside parser-script nesting so document.open replaces that document before handing the captured interactive source back to the native parser. A permitted CSS string containing a noscript closing tag retains one page copy with scripts enabled and disabled.
@max-sixty
max-sixty merged commit 7a30228 into main Oct 3, 2026
4 checks passed
@max-sixty
max-sixty deleted the codex/authored-page-media branch October 3, 2026 19:26
leaf-agent added a commit that referenced this pull request Nov 15, 2026
…amps from files.py (#6039)

This is the weekly duplicate sweep of `src/leaf/` and `hooks/` (ISO week
46). It moves four capabilities that were implemented more than once to
one home each, and moves every caller. Behavior does not change. Every
replaced copy computed the same result as the home it now calls.

- **Applying non-overlapping `(start, end, text)` edits to a source.**
The new home is `structure.splice`, which is
`revision_delivery._spliced` moved and generalised to str or bytes. It
replaces five copies:
  - `revision_delivery._spliced`, from #3313, removed.
- The reverse-slice loop in `revision_artifact.bind_imports`, from
#1280.
  - The loop in `structure.rewrite_attribute_references`, from #1658.
  - The loop in `leaf_dev.docs.compose`, from #2660.
  - The loop in `leaf_dev.arrangement_eval`, from #4629.

The four reverse-slice loops copied the whole source once per edit. Each
of them applies edits that don't overlap and don't start at the same
offset, so splicing them in one pass gives the same output.
- **The file name of a stamped version.** `live_shell` wrote
`f"v{version}.html"` inline, from #666. It now calls
`files.version_name`.
- **Whether a note stamps a revision.** `validation/source_history.py`
scanned for the note inline, from fe4e8ea. It now calls
`files.stamped_version`, which was added in the same commit.
- **The `sha256:` digest of a revision's HTML.**
`revision_artifact._capture_artifact` hashed `document.data` again, from
#666. It now reads `SourceDocument.digest`, from #606, which holds the
same value.

I left `compose_document`'s two-insertion loop in `revision_delivery.py`
alone. `splice` orders edits at the same offset by their text, but that
loop relies on list order when `<html>` and `<head>` are both implicit.

**Verification.** `ruff` and `ty` pass on the touched files. These model
tests pass: `test_module_url_delivery`, `test_revision_delivery`,
`test_live_shell_artifact`, `test_product_page`,
`test_interact_document`, `test_interact_anchors` and
`test_interact_layer`, 626 tests in all. In
`dev/tests/model/test_product_page.py`, the second case of
`test_a_composed_part_refuses_an_authored_copy` fails at `assert slot in
authored`, before `compose` runs. Its fixture string expects `<img`
followed by `alt="Sandbox` at 16 spaces of indentation, and
`docs/index.html` on `main` now indents that line by 18. The failure is
in the test's fixture, not in this change.

<details><summary>Sets found but not consolidated here</summary>

Another open pull request already changes each of these:

- **Claude Code and Codex config homes, and the inline-delivery opening,
repeated in `leaf_dev`.** #6014 moves them onto
`harness.claude_code_config`, `harness.codex_home` and
`hook_transport.INLINE_OPENING`.
- **`hooks._awaits_agent` repeats `holding.running_turns`.** #6032
rewrites `running_turns`.
- **The "N user updates with no answer" sentence**, written in both
`activity.unanswered` and the `page-open-owes` finding. `activity.py`,
`findings.py` and `session.py` are all being changed in #5979, #6018 and
#6032.
- **Raster magic bytes**, read in both `media._UPLOAD_TYPES` and
`revision_delivery.media_size`. `media.py` is being changed in #6014.

These are not worth a shared helper, because they are one-line stdlib
idioms or the copies differ in meaning:

- `json.dumps(..., sort_keys=True)` used as a cache key.
- Compact `json.dumps` with `separators=(",", ":")`.
- The `script_kind(...) in {"module", "classic"}` membership test.
- `lock_is_held(page_dir / SERVER_LOCK)`.
- Inline closed-object JSON schemas.

**Not consolidated, needs a separate look.**
`sample_content._non_json_number` repeats `http.reject_json_constant`.
The real question is where Leaf refuses non-finite numbers. The HTTP
path refuses NaN and numbers past a double's range. Sample fixtures
refuse only NaN and infinity. No other reader of event JSON in
`src/leaf/` passes `parse_constant`. Sharing the helper would change the
`sample-json` message without settling that question, so it is left out
of this PR.

</details>

Co-authored-by: leaf-agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow video and audio in page media

2 participants