Skip to content

Mid Cuts v2: /v2/narrate pipeline + NarratedScene contract v1.2.0 - #71

Merged
macayaven merged 6 commits into
mainfrom
contract/narrated-scene-v1.2.0
Jun 19, 2026
Merged

macayaven merged 6 commits into
mainfrom
contract/narrated-scene-v1.2.0

Conversation

@macayaven

Copy link
Copy Markdown
Owner

Summary

Greenfield Mid Cuts (Small Cuts v2) narration pipeline plus the lockstep NarratedScene contract v1.2.0 bump. A user records a ≤30s clip → Modal /v2/narrate runs Qwen3-Omni (whole-clip, deadpan voice) → builds a contract-valid NarratedScene → publishes to the private macayaven/mid-cuts bucket. This is the focused, Safari-fix-free slice of the work (the unrelated fix/safari-stage-width viewer commit is intentionally not included).

Consolidates the previously-unmerged Mid Cuts Phases 1–3:

Phase What
1 — bucket + security private mid-cuts read/write tokens, same-origin media proxy + boot guard, token-isolation + Range/206 tests
2 — /v2/narrate Modal Omni app; contract-valid scene writer + atomic publish; swappable narration backend + GPU-free mock; caption cues
3 — contract v1.2.0 additive/minor bump + version-truth guard (this is the contract-change)

Contract change — NarratedScene v1.2.0 (additive / minor, lockstep)

  • Adds optional timed_captions, duration (authoritative playback = narration/voice-audio length, not clip length), keyframe_time (poster-frame offset; provenance).
  • contract_version tightened pattern:"^1\." → enum:["1.1.0","1.2.0"].
  • Version-truth allOf if/then: any scene carrying a 1.2.0-only field must stamp 1.2.0 — a producer can no longer emit new fields while claiming the old version.
  • Legacy v1 producers stay valid stamping 1.1.0 (they emit only the 1.1.0 subset; engine{} is not 1.2.0-only — the live engine emits it under 1.1.0).

Components

File Role
docs/contracts/narrated-scene.schema.json schema v1.2.0 + enum + version-truth conditional
src/small_cuts/narrate_v2.py importable, GPU-free writer (build_narrated_scene, atomic publish_scene, backend interface + mock)
modal_app/midcuts_narrate.py Modal /v2/narrate app (Bearer-gated, 202 + result), emits duration/keyframe_time
src/small_cuts/hf_relay.py private-bucket read/write tokens + same-origin proxy guard
docs/contracts/README.md, CLAUDE.md changelog + header bump
tests/* contract golden + version-truth, writer, token-isolation, Range/206, config

Usage

# Modal smoke (CPU, no GPU): image + writer wiring with the mock backend
modal run modal_app/midcuts_narrate.py::smoke
# end-to-end (H200): narrate a seed clip → mid-cuts bucket
modal run modal_app/midcuts_narrate.py::e2e --clip rayuela --language English

Test coverage

Local gate green on this branch — ruff check ✓ · ruff format --check ✓ · pytest ✓ (exit 0). Contract-specific: golden-sample validation, version-truth (a 1.2.0 field under a 1.1.0 stamp is rejected; a 1.1.0 subset still validates), writer conformance (real uuids, only-schema keys, engine{}, emits/omits the new optional fields), atomic media-before-scene publish ordering, relay token-isolation, Safari Range/206.

Review notes

  • Panel-reviewed (GLM 5.2 + GPT-5.5, independent families); adversarial diff review clean. Key catch adopted: duration already meant audio length in existing consumers — defining it as clip length would have been a valid-but-wrong semantic break.
  • Follow-ups (out of scope here): legacy undeclared-field sweep (source/source_icon in the relay, top-level provenance in old postcut.py); build_narrated_scene defaults visibility="public"; a lang/locale field for the 10-language selector; real keyframe selection so keyframe_time ≠ 0.0.

🤖 Generated with Claude Code

macayaven and others added 6 commits June 19, 2026 15:45
…igin proxy guard

Phase 1 (bucket + security) of Mid Cuts (Small Cuts v2). Surgical, in-place,
backward-compatible: every new env var is optional and defaults to today's
behavior, so the live macayaven/small-cuts Space is unaffected when unset.

- hf_relay.py: SMALL_CUTS_RELAY_READ_TOKEN -> HfFileSystem(token=...) (fixes the
  latent tokenless read on a private bucket, DESIGN §7 #2); SMALL_CUTS_RELAY_
  BUCKET_PRIVATE -> fail-closed boot guard refusing direct-media (cross-origin
  resolve) URLs against a private bucket, and proxies clip+audio same-origin so
  Safari can load + seek the video.
- postcut.py: SMALL_CUTS_RELAY_WRITE_TOKEN -> HfApi(token=...) (fixes the
  tokenless write, DESIGN §7 #1).
- tests: token isolation (CI mock + gated live cutover gate, verified live
  against macayaven/mid-cuts — read reads, read cannot write 403); same-origin
  Range/206 contract (Safari seek); Modal write-token AST contract.

verify: ruff check + ruff format --check + pytest -> 336 passed, 2 skipped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…end interface

Phase 2 foundation for /v2/narrate (Mid Cuts), greenfield + importable so it is unit-tested
(modal isn't in the CI venv). build_narrated_scene emits a NarratedScene that validates against
narrated-scene.schema.json v1.1.0 by construction — real uuid scene_id (§7 #4), only schema keys
with provenance under engine{} (§7 #3). publish_scene uploads media before scene.json so a relay
globbing uploads/*/scene.json never sees a scene whose media is missing (§7 #6). NarrationBackend
is the swappable seam (mock backend included; the Omni backend lives in the Modal app).

verify: ruff + pytest -> 344 passed, 2 skipped (8 new narrate_v2 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…bucket

Greenfield Phase 2 endpoint (never touches the live macayaven/small-cuts Space). Ports the proven
Qwen3-Omni invocation from the phase-0 probe, builds a contract-valid scene via small_cuts.narrate_v2,
validates it (format-checked, §6) and publishes media-before-scene.json to the private macayaven/mid-cuts
bucket with the write-only token from the "mid-cuts" Modal secret. Bearer is timing-safe + fail-closed
(§7 #5); uploads capped at 30 MB / 30 s; scale-to-zero, GPU bounded. CPU ::smoke + GPU ::e2e entrypoints.

Adversarially verified (writer/relay round-trip, security, Omni-port fidelity = all clean); applied the
format-checker + zero-frame guards it surfaced. modal isn't importable in CI, so config/safety is
asserted via AST/source (tests/test_midcuts_narrate_config.py).

verify: ruff + pytest -> 351 passed, 2 skipped; CPU smoke green (mock backend -> contract-valid scene).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ontract-change]

Additive/minor, lockstep. Adds optional timed_captions:[{t_start,t_end,text}] (speech-relative,
aligner-produced) to NarratedScene for the viewer CC track + accessibility; bumps schema $id to
1.2.0 and the golden sample. Not in `required`, so existing producers/consumers (emitting 1.1.0,
no captions) still validate — the live Space is unaffected. Ratified by Carlos (DESIGN §6).

Consumers updated in this lockstep series: the v2 writer (small_cuts.narrate_v2) emits the cues,
the viewer renders them via the existing data-sc-cues path + a CC toggle. iOS is inert (it consumes
ControlFrame/SceneAudio, not NarratedScene).

verify: pytest -> 351 passed, 2 skipped (contract golden validates at v1.2.0).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ve timed_captions

Adds the writer-side caption support for the v1.2.0 timed_captions field. carrier_cut_index finds
where the spoken warm-up carrier ends (normalized char-accumulation match, robust to aligner
segmentation + do_sample-varied duration); cues_from_words drops the carrier words and rebases the
real narration's aligned word times to the trimmed audio, grouping into ~5-word cues.
build_narrated_scene now accepts an optional timed_captions list (omitted when absent → still v1.1.0-
shaped). The v2 app will feed the aligner output through these to populate the scene.

verify: ruff + pytest -> 355 passed, 2 skipped (4 new caption tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…sion-truth guard [contract-change]

Phase 3 of Mid Cuts (Small Cuts v2): complete the additive/minor v1.2.0 bump (lockstep).

- schema: add optional `duration` (authoritative playback = narration/voice-audio length,
  NOT clip length) + `keyframe_time` (poster-frame offset, provenance). Tighten
  `contract_version` pattern -> enum[1.1.0,1.2.0]. Add an `allOf` if/then "version-truth"
  conditional so any scene carrying duration/keyframe_time/timed_captions must stamp 1.2.0
  (a producer can no longer emit new fields under the old version).
- narrate_v2: CONTRACT_VERSION 1.1.0 -> 1.2.0; build_narrated_scene emits the two new
  optional fields.
- midcuts_narrate (v2 producer): emit duration = len(wav)/sample_rate and keyframe_time.
- tests: golden gains the fields; new version-truth test + a 1.1.0-subset-still-valid test.
- docs: README changelog + contracts CLAUDE.md header.

Legacy v1 producers stay stamped 1.1.0 (they emit only the 1.1.0 subset; engine{} is NOT
1.2.0-only). Panel-reviewed (GLM 5.2 + GPT-5.5); full gate green; adversarial diff review clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@macayaven macayaven added the contract-change touches docs/contracts — orchestrator review required label Jun 19, 2026
@macayaven
macayaven merged commit 6a22896 into main Jun 19, 2026
2 checks passed
@macayaven
macayaven deleted the contract/narrated-scene-v1.2.0 branch June 19, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contract-change touches docs/contracts — orchestrator review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant