spec: A7, the media spike's values and above-1080p minutes
Records what the 2026-11-20 dev spike measured and Paul's option A: x264 medium, 75 minutes for HDR video up to 1080p, nothing above 1080p on the short video class, and video above 1080p weighing 2 against the allowance (4K HDR costs about 1 cent of engine time a minute). Where these differ from sections 6, 7.1, 7.3, 7.4 or decision 6, A7 overrides them; the body carries pointers. Notes what the spike left open: Paul's Safari checks, and ECS's stoppedAt landing 23 to 35 s after the codec. Plans 2 and 3 carry the new values and interfaces; plan 3 Tasks 4 and 6 are marked no longer provisional.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+92
−16
docs/superpowers/plans/2026-11-16-media-conversion-plan-2-console.md+6 −4docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md+7 −3docs/superpowers/specs/2026-11-16-video-conversion-design.md+74 −4internal/media/media.go+3 −3internal/mediahandler/probe.go+2 −2
diff --git a/docs/superpowers/plans/2026-11-16-media-conversion-plan-2-console.md b/docs/superpowers/plans/2026-11-16-media-conversion-plan-2-console.md| index 8653fb5b9..8bf0f97aa 100644 |
| --- a/docs/superpowers/plans/2026-11-16-media-conversion-plan-2-console.md |
| +++ b/docs/superpowers/plans/2026-11-16-media-conversion-plan-2-console.md |
| @@ -16,10 +16,10 @@ |
| - Execution id: 32 hex characters from 16 bytes of `crypto/rand`. It is RunTask's `startedBy` and its idempotency token. |
| - Output keys: `derived/<key>/<etag>/<preset>/<execution>/` + `video.mp4`, `video.m3u8`, `poster.jpg` (video) or `audio.mp4`, `audio.m3u8`, `peaks.json` (audio). Result object: `media-results/<execution>.json` in the deployment bucket, read bounded to 64 KiB. |
| - Classes (§7.1): video short (picked up to 1 GiB): 4 vCPU, 8 GB, deadline 15 min, granted 10 min; video long: 16 vCPU, 32 GB, 50 min, the video maximum; audio short (up to 256 MiB): 1 vCPU, 2 GB, 10 min, 2 h; audio long: 2 vCPU, 4 GB, 50 min, the audio maximum. Ephemeral storage 20 GiB, or source size plus 8 GiB when more. |
| -- Provisional maximums (settings, `CARLOS_MEDIA_LIMITS`; plan 1's report may change them): video 2 h up to 1080p and 30 min above, 40 GiB; audio 8 h, 10 GiB; 3840x2160, 60 fps. |
| +- Maximums (settings, `CARLOS_MEDIA_LIMITS`; plan 1's values, spec §11 A7): video 2 h up to 1080p, 75 min for HDR up to 1080p (`video_max_hdr`), 30 min above 1080p, 40 GiB; audio 8 h, 10 GiB; 3840x2160, 60 fps. The short video class takes nothing above 1080p (A7). |
| - Fair use: 6 short and 2 long tasks in the deployment, 2 short and 1 long per account, counted as rows with a dispatched execution and `task_stopped` false; per account 20 queued or running (429) and 30 submissions a minute with a burst of 10 (429); deployment-wide 200 queued (503). |
| - Stop grace 30 s. Full bound = `deadline_s` + 30 s. Grant lifetime 1 h. Deadline at most 50 min. Under 3 min of deadline: wait while the account has another execution running, else fail `allowance_exceeded` uncharged. |
| -- Weights: `video-720p` 1, `audio-aac` 0.1, held as tenths (10 and 1) so every allowance figure is an integer: units = milliseconds × weight-tenths. |
| +- Weights: `video-720p` 1, video above 1080p 2 (spec §11 A7, Paul's option A), `audio-aac` 0.1, held as tenths (10, 20 and 1) so every allowance figure is an integer: units = milliseconds × weight-tenths. A settled row is charged at the weight its probe measured (`weight_tenths`); a running long video row is reserved at 2. |
| - Allowance: `media_minutes_month`, monthly, warning at the limit, 402 from `capMessage` at twice the limit, ops accounts exempt, 0 = no limit, `capID` `media`. No catalog: `account_minutes` from `CARLOS_MEDIA_LIMITS`. |
| - One SQLite connection (`internal/console/store.go:122`): every query inside a transaction goes through its `*sql.Tx`, and no network call (engine, grants, storecfg) is ever made inside a transaction. |
| - Lock order: the store walk lock (`storeWalks.lock(acct, app, "")`) before any transaction, never the reverse. `mediajobs.Retire` never takes the lock; its caller holds it. |
| @@ -111,12 +111,12 @@ The deck holds every string Tasks 3 to 11 write. Drafts below; implementers copy |
| - `type ClassKey struct{ Preset, Class string }`, `func (k ClassKey) String() string` (`"video-720p/short"`). |
| - `type ClassSpec struct{ Key ClassKey; PickUpTo int64; CPU, MemoryMiB int; Deadline, Granted time.Duration }` (`Granted` 0 = the preset maximum) and `func Class(k ClassKey) (ClassSpec, bool)` with the four rows of Global Constraints. |
| - `func PickClass(preset, requested string, bytes int64) string`: `requested == "long"`, or bytes over the short row's `PickUpTo`, gives `long`; otherwise `short` (an explicit `short` above the threshold becomes `long`). |
| - - `func WeightTenths(preset string) int64` (10, 1); `func OutputNames(preset string) []string`; `func ContentType(name string) string` (`video/mp4`, `application/vnd.apple.mpegurl`, `image/jpeg`, `audio/mp4`, `application/json`). |
| + - `func WeightTenths(preset string, above1080p bool) int64` (10, 20 above 1080p, audio 1), `func ReserveWeightTenths(k ClassKey) int64` and `func ChargeWeightTenths(k ClassKey, above1080p bool) int64` (spec §11 A7); `func OutputNames(preset string) []string`; `func ContentType(name string) string` (`video/mp4`, `application/vnd.apple.mpegurl`, `image/jpeg`, `audio/mp4`, `application/json`). |
| - `func JobID(key, etag, preset, class string) string`; `func NewExecutionID() (string, error)`; `func OutputPrefix(key, etag, preset, execution string) string`; `func ResultKey(execution string) string`; `func ValidKey(key string) bool` (non-empty, at most 512 bytes, valid UTF-8, no byte below 0x20 or 0x7f, no `.` or `..` segment, not prefixed `derived/`). |
| - `const (StopGrace = 30*time.Second; GrantLifetime = time.Hour; GrantMintSlack = 5*time.Minute; EngineRecordRetention = time.Hour; MinDeadline = 3*time.Minute; MaxDeadline = 50*time.Minute; PassEvery = 5*time.Second; FailedRetention = 90*24*time.Hour; MaxResultBytes = 64 << 10; MaxOverrideBytes = 8192; MaxPutBytes = 5 << 30; ScratchFloorGiB = 20; ScratchHeadroom = 8 << 30)`. `EngineRecordRetention` and `MaxOverrideBytes` are plan 1 measurements. |
| - `func DeadlineSleep(start time.Time, deadline time.Duration, expiry time.Time) time.Duration`: the earlier of `start+deadline` and `expiry−StopGrace`, minus `start` (may be ≤ 0). Plan 3's deadline container and local runner both use it. |
| - `func EphemeralGiB(sourceBytes int64) int`: 0 when `ceil((bytes+8 GiB)/GiB) <= 20`, else that figure (at most 200). |
| - - `type Limits struct{ VideoMax, VideoMaxHi, AudioMax time.Duration; VideoBytes, AudioBytes int64; AccountMinutes int64; Short, Long, AccountShort, AccountLong, AccountActive, PerMinute, Burst, Queue int }` and `func ParseLimits(v string) (Limits, error)`: comma-separated `key=value`; keys `video_max`, `video_max_hi`, `video_bytes`, `audio_max`, `audio_bytes`, `account_minutes`, `short`, `long`, `account_short`, `account_long`, `account_active`, `per_minute`, `burst`, `queue`; durations in Go syntax, bytes as an integer or `<n>GiB`/`<n>MiB`; `""` gives `2h,30m,40GiB,8h,10GiB,0,6,2,2,1,20,30,10,200`; unknown, duplicate, negative or zero-count keys are errors; `account_minutes` may be 0. |
| + - `type Limits struct{ VideoMax, VideoMaxHDR, VideoMaxHi, AudioMax time.Duration; VideoBytes, AudioBytes int64; AccountMinutes int64; Short, Long, AccountShort, AccountLong, AccountActive, PerMinute, Burst, Queue int }` and `func ParseLimits(v string) (Limits, error)`: comma-separated `key=value`; keys `video_max`, `video_max_hdr` (A7, default 75m), `video_max_hi`, `video_bytes`, `audio_max`, `audio_bytes`, `account_minutes`, `short`, `long`, `account_short`, `account_long`, `account_active`, `per_minute`, `burst`, `queue`; durations in Go syntax, bytes as an integer or `<n>GiB`/`<n>MiB`; `""` gives `2h,30m,40GiB,8h,10GiB,0,6,2,2,1,20,30,10,200`; unknown, duplicate, negative or zero-count keys are errors; `account_minutes` may be 0. |
| - `func (l Limits) MaxBytes(preset string) int64`, `func (l Limits) Granted(k ClassKey) time.Duration` (the class figure, or the preset maximum for long). |
| - Error codes as `const Code… = "…"` for every code in the deck's `media.job.*` rows plus `CodeRetired = "retired"`; `var HandlerCodes map[string]bool` (the codes a result object may carry: every `media.job.*` code except `grant_expired`, `deadline_exceeded`, `engine_unavailable`, `engine_lost`, `retired`, `store_changed`, `store_writes_denied`). |
| - Exit codes: `ExitDone = 0`, `ExitFailed = 1`, `ExitGrantExpired = 75`, `DeadlineExitReached = 0`, `DeadlineExitBadInput = 3`, `DeadlineExitStopped = 143`; container names `ContainerCodec = "codec"`, `ContainerDeadline = "deadline"`; env names `PayloadEnv = "CARLOS_MEDIA_JOB"`, `DeadlineEnv = "CARLOS_MEDIA_DEADLINE_S"`, `ExpiryEnv = "CARLOS_MEDIA_GRANT_EXPIRY"`. |
| @@ -150,8 +150,10 @@ The deck holds every string Tasks 3 to 11 write. Drafts below; implementers copy |
| GrantedMS int64 `json:"g"` |
| GrantedBy string `json:"gb"` // "class" | "allowance" |
| MaxMS int64 `json:"d"` |
| + MaxHDRMS int64 `json:"dr,omitempty"` // HDR video up to 1080p, spec §11 A7; 0 is MaxMS |
| MaxHiMS int64 `json:"dh"` // video sources above 1080p; 0 for audio |
| OutputBytes int64 `json:"o"` |
| + Above1080pNeedsLong bool `json:"hl,omitempty"` // the short video class, spec §11 A7 |
| } |
| type Payload struct { |
| V int `json:"v"` |
diff --git a/docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md b/docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md| index 3b9f569cc..994be6449 100644 |
| --- a/docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md |
| +++ b/docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md |
| @@ -11,7 +11,7 @@ |
| ## Global Constraints |
| - Plan 2's Global Constraints apply. This plan consumes `internal/media` exactly as plan 2 Task 1 declares it: `Payload`, `Transfers`, `Transfer`, `JobLimits`, `Result`, `SourceFacts`, `OutputFact`, `ParseResult`, the exit codes, `ContainerCodec`/`ContainerDeadline`, `PayloadEnv`/`DeadlineEnv`/`ExpiryEnv`, `OutputNames`, `ContentType`, `HandlerCodes`, `StopGrace`, `MaxPutBytes`, `MaxResultBytes`, `MaxOverrideBytes`, `TaskDefinition`, `CheckTaskDefinition`, `Engine`, `Grants`, `RunRequest`, `Task`, `Rejected`, `Misconfigured`, `ImageInfo`. No new shared name is defined here. |
| -- Plan 1's report (`docs/superpowers/reviews/2026-11-16-media-conversion-spike.md`) must be committed and Paul must have confirmed it before Task 4 starts. Its figures replace the provisional constants named "spike" below; if a proof failed, the spec amendment it lists lands first. |
| +- Plan 1's report (`docs/superpowers/reviews/2026-11-16-media-conversion-spike.md`) must be committed and Paul must have confirmed it before Task 4 starts. Its figures replace the provisional constants named "spike" below; if a proof failed, the spec amendment it lists lands first. Done: the report's values and amendments 1 to 3 are spec §11 A7 (branch `media-spike-values`, 2026-11-21). |
| - The task: two containers from one arm64 image pinned by digest, both essential, `stopTimeout` 30 each, `codec` `dependsOn` `deadline` `START`, no task role, no `pidMode`, no volume shared between them, user `65534:65534`, read-only root, every capability dropped, `enableExecuteCommand` false. `codec` alone mounts the volume `scratch` at `/scratch`. The image holds `/scratch` owned by `65534:65534`, mode `0700`, and declares it a volume in its config, so the Fargate bind mount there is writable by the codec's user (ECS bind mounts are otherwise root-owned `0755`); plan 1 Task 4 Step 4 proves it. |
| - Every path the handler and its argument builders use is under `Config.Scratch` (`<scratch>/in/source`, `<scratch>/out/<name>`, `<scratch>/tmp`), from `CARLOS_MEDIA_SCRATCH`, default `/scratch`. `/scratch/…` below means that default. |
| - Deadline container: sleep until the earlier of its start plus `CARLOS_MEDIA_DEADLINE_S` and `CARLOS_MEDIA_GRANT_EXPIRY` less 30 s; exit `DeadlineExitReached` (0) at once if that has passed; `DeadlineExitStopped` (143) on SIGTERM; `DeadlineExitBadInput` (3) on bad input, at once. |
| @@ -83,7 +83,7 @@ Expected; `make census-card` decides. In scope: every new file under `infra/` (` |
| **Interfaces:** |
| - Produces: `func runChild(ctx context.Context, cfg Config, name string, args []string, dir string) (stderrTail []byte, err error)` (Linux: the handler sets `PR_SET_CHILD_SUBREAPER` at start; the child gets its own process group and `Pdeathsig: SIGKILL`; when it exits or the context ends, `kill(-pgid, SIGKILL)`, then repeatedly kill every process whose parent is the handler (from `/proc/*/stat`) and `wait4(-1, WNOHANG)` until `ECHILD`, at most 5 s, else `engine_failed`; nothing reads `/scratch/out` before it returns; a non-zero exit is `unreadable`; the last 64 KiB of stderr is kept for the task's log and never holds a transfer; `procs_other.go` returns an error, as the handler runs only on Linux); `func sniff(head []byte, preset string) (demuxer string, err error)`; `type probeFacts struct{ VideoIndex, AudioIndex int; Width, Height, Rotation int; FPS float64; HDR bool; DolbyVisionProfile int; VideoCodec, AudioCodec string; Channels int; DurationMS int64 }` (`-1` for an absent stream); `func probe(ctx context.Context, cfg Config, demuxer string) (probeFacts, error)`; `func parseProbe(b []byte) (probeFacts, error)`; `func check(f probeFacts, preset string, l media.JobLimits) error` (a `jobError` or nil). |
| -- Rules: streams with `disposition.attached_pic` 1 are skipped; the first remaining video and first audio stream are taken (`audio-aac`: audio only); rotation from the display matrix side data, else the `rotate` tag; FPS from `avg_frame_rate`, `r_frame_rate` only when the average is `0/0`; HDR when `color_transfer` is `smpte2084` or `arib-std-b67`, or Dolby Vision side data is present; duration from `format.duration`, else the longest stream duration, else a second ffprobe pass over the chosen stream's packets (`-show_entries packet=pts_time,duration_time -of csv=p=0`) taking the largest `pts+duration`, else `unreadable`. Checks in spec §6's order: `no_video`/`no_audio`; video codec not `h264`, `hevc`, `vp8`, `vp9`, `av1` → `unsupported_video_codec`; audio codec not `aac`, `opus`, `vorbis`, `mp3`, `flac` or `pcm_*` → `unsupported_audio_codec`; a side over 4096 or more than 3840·2160 pixels → `source_dimensions`; FPS over 60 → `source_frame_rate`; duration over `MaxHiMS` (video above 1080p: longer side over 1920 or shorter side over 1080) or `MaxMS` → `source_too_long`; over `GrantedMS` → `needs_long_class` when `GrantedBy` is `class`, else `allowance_exceeded`; Dolby Vision profile 5 → `unsupported_hdr` only when the spike report sets `refuseDolbyVision5 = true` (spike; default false: decoded as HEVC and tone-mapped); probe failure or timeout → `unreadable`. |
| +- Rules: streams with `disposition.attached_pic` 1 are skipped; the first remaining video and first audio stream are taken (`audio-aac`: audio only); rotation from the display matrix side data, else the `rotate` tag; FPS from `avg_frame_rate`, `r_frame_rate` only when the average is `0/0`; HDR when `color_transfer` is `smpte2084` or `arib-std-b67`, or Dolby Vision side data is present; duration from `format.duration`, else the longest stream duration, else a second ffprobe pass over the chosen stream's packets (`-show_entries packet=pts_time,duration_time -of csv=p=0`) taking the largest `pts+duration`, else `unreadable`. Checks in spec §6's order: `no_video`/`no_audio`; video codec not `h264`, `hevc`, `vp8`, `vp9`, `av1` → `unsupported_video_codec`; audio codec not `aac`, `opus`, `vorbis`, `mp3`, `flac` or `pcm_*` → `unsupported_audio_codec`; a side over 4096 or more than 3840·2160 pixels → `source_dimensions`; FPS over 60 → `source_frame_rate`; duration over `MaxHiMS` (video above 1080p: longer side over 1920 or shorter side over 1080), else `MaxHDRMS` (HDR video; 0 is `MaxMS`, held to it; spec §11 A7) or `MaxMS` → `source_too_long`; video above 1080p with `Above1080pNeedsLong` (the short video class, A7) → `needs_long_class`; over `GrantedMS` → `needs_long_class` when `GrantedBy` is `class`, else `allowance_exceeded`; Dolby Vision profile 5 → `unsupported_hdr` only when the spike report sets `refuseDolbyVision5 = true` (spike; default false: decoded as HEVC and tone-mapped); probe failure or timeout → `unreadable`. |
| - [ ] **Step 1: Write the failing tests:** `TestSniffTable` (each family for each preset; `#EXTM3U`, `<?xml`, a PDF, 0 bytes and an MP3 under `video-720p` → `unsupported_container`); `FuzzSniff` (never panics; never answers a family whose magic is absent); `TestParseProbeFixtures` (each fixture's facts); `TestFrameRateUsesTheAverage` (Review Focus 2); `TestDurationFromPacketsWhenTheHeaderHasNone` (Review Focus 3, the second pass driven by a fake ffprobe from Task 7's helper); `TestAttachedPictureIsNotVideo` (Review Focus 4); `TestCheckOrder` (a source failing two checks reports the earlier); `TestLyingDurationIsTooLong`; `TestBombIsDimensions`; `FuzzParseProbe` (arbitrary bytes never panic and never yield facts that pass `check` with a negative size or duration); `TestRunChildKillsEscapedDescendants` (Linux: a helper child that forks a grandchild which calls `setsid` and sleeps: after `runChild` returns, neither process exists); `TestProbeTimeoutIsUnreadable` (a fake ffprobe that sleeps past a 100 ms test timeout). |
| - [ ] **Step 2:** Run `go test ./internal/mediahandler/ -run 'TestSniff|TestParseProbe|TestFrameRate|TestDurationFromPackets|TestAttachedPicture|TestCheckOrder|TestLying|TestBomb|TestRunChild|TestProbeTimeout' -count=1`. Expected: FAIL. |
| @@ -95,6 +95,8 @@ Expected; `make census-card` decides. In scope: every new file under `infra/` (` |
| ### Task 4: Handler: the encodes, the playlist and the child processes |
| +**No longer provisional** (spec §11 A7, 2026-11-21): the spike set `x264Preset` to `medium` and kept `x264CRF` 23; the muxer flags and box sequence held on arm64. The fixtures in `testdata/fmp4` were encoded at `veryfast` and kept; `TestMuxerArgsMatchTheFixtures` accepts that one recorded difference (`fixturePreset`). Only the HDR chain's colours wait on Paul's Safari check. |
| + |
| Depends on plan 1 Task 3 Step 4: the muxer rules and the parser's accepted box sequence are settled by the fixtures Debian 13's ffmpeg made there, and this task's parser tests run only against those. |
| **Files:** |
| @@ -102,7 +104,7 @@ Depends on plan 1 Task 3 Step 4: the muxer rules and the parser's accepted box s |
| **Interfaces:** |
| - Produces: `func targetSize(w, h, rotation int) (ow, oh int)` (swap for ±90/270; box `(bw, bh)` = 1280x720 when `w >= h`, else 720x1280; integer arithmetic only: inside the box unchanged; else when `w·bh > h·bw` (width-limited) `ow = bw, oh = h·bw/w`, otherwise `oh = bh, ow = w·bh/h`, with integer division; then each side rounded down to even, at least 2); `func videoArgs(cfg Config, f probeFacts, p media.Payload, demuxer string) []string`; `func posterArgs(cfg Config, f probeFacts, p media.Payload, demuxer string) []string`; `func audioArgs(cfg Config, f probeFacts, p media.Payload, demuxer string, gainDB float64) []string` (every path from `cfg.Scratch`); `type fragment struct{ Offset, Length int64; DurationS float64 }`; `func readFMP4(r io.ReaderAt, size int64) (initLen int64, frags []fragment, durationMS int64, err error)` (top-level `ftyp`, `moov` then `moof`/`mdat` pairs, which is what these arguments produce with `skip_trailer`; if plan 1's Debian-made fixtures show another top-level box (a `free`, an `mfra`), the parser accepts exactly the sequence plan 1's report records and no other; the timescale from the first video track's `mdhd`, else the first track's; each fragment's duration from consecutive `tfdt`, the last from its `trun` sample durations; any other box order, overlap, a size past the file or over 1,000,000 fragments is an error); `func writePlaylist(w io.Writer, name string, initLen int64, frags []fragment) error`. Every encode runs through Task 3's `runChild`. |
| -- `videoArgs` (in order): the Global Constraints input flags; `-map 0:<v>`, `-map 0:<a>` when there is audio; `-sn -dn -map_metadata -1 -map_chapters -1 -t <GrantedMS as seconds, 3 decimals>`; `-vf scale=<ow>:<oh>:flags=bicubic,format=yuv420p` for SDR, or `-vf scale=<ow>:<oh>:flags=bicubic,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p` for HDR (spike: the chain and operator plan 1 confirms); `-c:v libx264 -profile:v high -preset <x264Preset> -crf <x264CRF> -maxrate 2500k -bufsize 5000k -pix_fmt yuv420p -fpsmax 30 -force_key_frames expr:gte(t,n_forced*2) -sc_threshold 0`; audio `-c:a aac -b:a 128k -ac 2 -ar 48000` or `-an`; `-f mp4 -movflags +frag_keyframe+empty_moov+default_base_moof+skip_trailer -min_frag_duration 4000000 /scratch/out/video.mp4` (fragments start at the first keyframe at least 4 s on; `skip_trailer` drops the `mfra` trailer). `x264Preset = "veryfast"` and `x264CRF = 23` (spike). |
| +- `videoArgs` (in order): the Global Constraints input flags; `-map 0:<v>`, `-map 0:<a>` when there is audio; `-sn -dn -map_metadata -1 -map_chapters -1 -t <GrantedMS as seconds, 3 decimals>`; `-vf scale=<ow>:<oh>:flags=bicubic,format=yuv420p` for SDR, or `-vf scale=<ow>:<oh>:flags=bicubic,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p` for HDR (spike: the chain and operator plan 1 confirms); `-c:v libx264 -profile:v high -preset <x264Preset> -crf <x264CRF> -maxrate 2500k -bufsize 5000k -pix_fmt yuv420p -fpsmax 30 -force_key_frames expr:gte(t,n_forced*2) -sc_threshold 0`; audio `-c:a aac -b:a 128k -ac 2 -ar 48000` or `-an`; `-f mp4 -movflags +frag_keyframe+empty_moov+default_base_moof+skip_trailer -min_frag_duration 4000000 /scratch/out/video.mp4` (fragments start at the first keyframe at least 4 s on; `skip_trailer` drops the `mfra` trailer). `x264Preset = "medium"` and `x264CRF = 23` (the spike's values, spec §11 A7; `veryfast` before it). |
| - `posterArgs`: `-ss <1.000, or duration/2 when under 2 s>` before `-i`, the same input flags and video filter, `-frames:v 1 -q:v 3 /scratch/out/poster.jpg`. |
| - `audioArgs`: `-map 0:<a> -vn -sn -dn -map_metadata -1 -map_chapters -1 -t <granted>`, `-af aformat=channel_layouts=<mono|stereo>:sample_rates=48000,volume=<gain>dB`, `-c:a aac -b:a <64k|128k>`, then `-f mp4 -movflags +empty_moov+default_base_moof+skip_trailer -frag_duration 4000000 /scratch/out/audio.mp4` (audio has no video keyframe to cut at, so the fragment duration itself is the trigger). |
| - Playlist: `#EXTM3U`, `#EXT-X-VERSION:7`, `#EXT-X-TARGETDURATION:<ceil(max)>`, `#EXT-X-PLAYLIST-TYPE:VOD`, `#EXT-X-INDEPENDENT-SEGMENTS`, `#EXT-X-MAP:URI="<name>",BYTERANGE="<initLen>@0"`, per fragment `#EXTINF:<3 decimals>,`, `#EXT-X-BYTERANGE:<len>@<off>`, `<name>`, then `#EXT-X-ENDLIST`. Written by Go, never by ffmpeg. `SourceFacts.DurationMS` is `readFMP4`'s duration (what was converted). |
| @@ -132,6 +134,8 @@ Depends on plan 1 Task 3 Step 4: the muxer rules and the parser's accepted box s |
| ### Task 6: Handler: collecting and uploading outputs, and the result **[Astra: security gate]** |
| +**No longer provisional** (spec §11 A7, 2026-11-21): the spike ran the result path on every class. The result's `SourceFacts` gain `hdr` (omitted when false), which the console reads to name the HDR maximum. |
| + |
| **Files:** |
| - Create: `internal/mediahandler/collect_linux.go`, `collect_other.go`, `upload.go`, `result.go`, `collect_test.go`, `upload_test.go`, `run_test.go` |
diff --git a/docs/superpowers/specs/2026-11-16-video-conversion-design.md b/docs/superpowers/specs/2026-11-16-video-conversion-design.md| index 921be6468..c7cc97e06 100644 |
| --- a/docs/superpowers/specs/2026-11-16-video-conversion-design.md |
| +++ b/docs/superpowers/specs/2026-11-16-video-conversion-design.md |
| @@ -617,6 +617,7 @@ checks, exiting before any encoding: |
| | a side over 4096, or more pixels than 3840x2160 | `source_dimensions` | |
| | over 60 frames a second | `source_frame_rate` | |
| | longer than the preset's maximum duration (§7.1) | `source_too_long` | |
| +| short video class: a source above 1080p, whatever its length (§11 A7) | `needs_long_class` | |
| | short class: longer than the class's granted duration (§7.1). The message says to resubmit with `"class": "long"` | `needs_long_class` | |
| | longer than the allowance granted to this job (§7.3) | `allowance_exceeded` | |
| | probe fails or exceeds 60 s | `unreadable` | |
| @@ -664,16 +665,18 @@ about the source but its size **(astra R6-4)**. |
| | `audio-aac` | short | source up to 256 MiB, class not given | 1 vCPU, 2 GB | 10 min | 2 hours | |
| | `audio-aac` | long | larger source, or `"class": "long"` | 2 vCPU, 4 GB | 50 min | the audio maximum | |
| -A short job whose source turns out longer than its granted duration exits at |
| +A short job whose source turns out longer than its granted duration, or a |
| +short video job whose source is above 1080p (§11 A7), exits at |
| the probe with `needs_long_class`, and the app submits it again with |
| `"class": "long"`: a new job, since requeue was cut. Ephemeral storage is 20 |
| GiB, or the source size plus 8 GiB when that is more. |
| -**Provisional maximums (estimates; the spike sets the final values).** |
| +**Maximums (the spike's values, §11 A7; estimates before it).** |
| | | `video-720p` | `audio-aac` | |
| |---|---|---| |
| | Duration, sources up to 1080p | 2 hours | 8 hours | |
| +| Duration, HDR sources up to 1080p (A7) | 75 minutes | | |
| | Duration, sources above 1080p | 30 minutes | | |
| | Source size | 40 GiB | 10 GiB | |
| | Dimensions, frame rate | 3840x2160, 60 | | |
| @@ -710,7 +713,9 @@ uses one per-account figure from `CARLOS_MEDIA_LIMITS` in its place. |
| **What is charged.** Every figure is in allowance minutes and is a query over |
| `media_jobs`. `w` is the preset's weight: `video-720p` 1, `audio-aac` 0.1 |
| -**(paul R-A, decision 7)**. |
| +**(paul R-A, decision 7)**. Since §11 A7, video above 1080p weighs 2: a |
| +settled row is charged at the weight its probe measured, and a running long |
| +video row is reserved at 2. |
| - A `done` job: `w` times its source duration. |
| - Any other settled execution: `w` times its engine time. `charged_ms` is |
| @@ -745,7 +750,8 @@ Outputs count as the tenant's storage (roadmap ruling 6). |
| ### 7.4 Cost and the spike |
| -All figures here are **estimates** until the spike reports. |
| +All figures here are **estimates** from before the spike. Its measured |
| +values are in §11 A7 and the spike report. |
| - **Time.** A task takes 30 to 60 seconds to start. A three-minute 1080p30 |
| phone clip then converts in 30 to 90 seconds on 4 vCPUs. On 16 vCPUs, |
| @@ -1000,6 +1006,70 @@ the outputs. Store destroy gains the refusal of §5.3. |
| tracked again without a restart. Settings errors still stop the boot. A |
| settings error found only on a retry, once the console is already up, |
| leaves conversion off and is logged once. |
| +- **A7, spike values and above-1080p minutes** (spike 2026-11-20; Paul |
| + chose option A). The dev spike measured the engine on Fargate arm64: |
| + `docs/superpowers/reviews/2026-11-16-media-conversion-spike.md`, its |
| + "Values for plans 2 and 3" table and its "Spec amendments" 1 to 3. |
| + Where these values differ from §6, §7.1, §7.3, §7.4 or decision 6, they |
| + override them. |
| + - **Preset.** x264 encodes at `medium`, the slowest preset that runs at |
| + least 3 times real time on long-class 1080p (`veryfast` 10.35, |
| + `faster` 5.65, `medium` 5.85). The CRF stays 23. |
| + - **HDR maximum.** 1080p HDR converts at 2.71 times real time on the |
| + long class, against 5.85 for SDR. The plan's rule (the class's 40 |
| + minutes less a 31.7 s start and a 40 GiB download at 95.3 MB/s, times |
| + the speed) gives 86.6 minutes, so HDR video up to 1080p converts up to |
| + 75 minutes (`video_max_hdr`, held to `video_max`). SDR up to 1080p |
| + keeps 2 hours, and above 1080p keeps 30 minutes whatever the |
| + transfer. The probe already tells HDR from `color_transfer` and Dolby |
| + Vision side data. The result's source facts now carry `hdr`, so the |
| + console's `source_too_long` message names the HDR maximum. |
| + - **Short-class ceiling.** At 4 vCPU the short video class converts 4K |
| + HDR at 0.27 times real time and 4K SDR at 0.71, so not even 5 minutes |
| + of 4K HDR fits its budget. Only the long video class takes a source |
| + above 1080p. On the short class the codec answers `needs_long_class` |
| + for one, after `source_too_long` and before the granted duration, |
| + through the payload's `Above1080pNeedsLong`, and the console's message |
| + names the picture size rather than a length. Up to 1080p the short |
| + class still converts 10 minutes. |
| + - **Weights (Paul's option A, 2026-11-20).** A minute of video above |
| + 1080p counts twice against the allowance: video up to 1080p 1, above |
| + 1080p 2, audio 0.1 (in tenths 10, 20 and 1). One minute of 4K HDR costs |
| + about 1 cent of engine time (0.98 cents on the long class at `medium`, |
| + 1.07 on the short), against decision 6's 0.6. 1080p SDR costs about |
| + 0.2 cents, 1080p HDR 0.27 to 0.43, 4K SDR 0.36 to 0.46. The weight |
| + applies everywhere the allowance is read: |
| + - **Charge.** A settled row is charged at the weight of the source |
| + its probe measured, from the dimensions in a result the console |
| + parsed, and stores it as `weight_tenths` in the transaction that |
| + settles it. Above 1080p counts only on the long video class. A row |
| + that settles with no source facts read (no result, retired before |
| + its result was read, or `engine_lost`) is charged at the weight up |
| + to 1080p. |
| + - **Reservation.** Before the probe nothing is known of the picture, |
| + so a long video row is reserved, and its grant and deadline fitted, |
| + at weight 2; a short video row at 1, as it never converts a source |
| + above 1080p; audio at 0.1. A charge weight is never above its |
| + class's reservation weight, so §7.3's bound still holds: a row's |
| + reservation is the most it can cost. Near twice its limit, an |
| + account's long video job is therefore granted half the minutes it |
| + would get at weight 1. |
| + - **Door and metering.** The 402 at twice the limit, the hourly cap |
| + measure, the billing page and the notices all read the same |
| + weighted figure. |
| + - **Residual, as A2.** A tenant who compromises the codec in its own |
| + job can report its source as 1080p or less and pay weight 1 for that |
| + job. It gains nothing else, and every other bound holds. |
| + - **Unchanged by the spike:** `video_bytes` 40 GiB, `video_max_hi` 30 |
| + minutes, `audio_max` 8 hours, `audio_bytes` 10 GiB, the class rows, |
| + `codecHeadroomDB` 0.5, `refuseDolbyVision5` false (no profile 5 sample |
| + was supplied), `EngineRecordRetention` 1 hour, `MaxOverrideBytes` |
| + 8,192. |
| + - **Still open from the report:** the HDR colours and the playback |
| + matrix wait on Paul's Safari checks. ECS records a task STOPPED 23 to |
| + 35 s after its last container dies, so a charge read from `stoppedAt` |
| + can pass a row's full bound by that much; that is plan 2's to settle, |
| + not this amendment's. |
| ## 12. Decisions for Paul |
diff --git a/internal/media/media.go b/internal/media/media.go| index c3077fbc3..9f094e798 100644 |
| --- a/internal/media/media.go |
| +++ b/internal/media/media.go |
| @@ -227,9 +227,9 @@ const ( |
| ScratchHeadroom = 8 << 30 |
| ) |
| -// The source maximums the probe enforces (spec §7.1, provisional). The |
| -// deck's media.job.source_dimensions and source_frame_rate messages are |
| -// filled from MaxDimensions and MaxFPS. |
| +// The source maximums the probe enforces (spec §7.1; the spike kept them, |
| +// §11 A7). The deck's media.job.source_dimensions and source_frame_rate |
| +// messages are filled from MaxDimensions and MaxFPS. |
| const ( |
| MaxDimensions = "3840x2160" |
| MaxSide = 4096 |
diff --git a/internal/mediahandler/probe.go b/internal/mediahandler/probe.go| index 967e1af21..c2ccb1db2 100644 |
| --- a/internal/mediahandler/probe.go |
| +++ b/internal/mediahandler/probe.go |
| @@ -77,8 +77,8 @@ const grantedByClass = "class" |
| // refuseDolbyVision5 is the spike's ruling (plan 1): true refuses Dolby |
| // Vision profile 5 as unsupported_hdr; false decodes it as HEVC and |
| -// tone-maps it. Provisional: false until the spike report says |
| -// otherwise. A variable so the test can set it. |
| +// tone-maps it. False: the spike had no profile 5 sample to test (its |
| +// report; spec §11 A7). A variable so the test can set it. |
| var refuseDolbyVision5 = false |
| // maxDurationMS is where a parsed duration saturates: far over every |