carlos / platform Public

plans: media conversion plans, round 3 P2s; review closed

Drill log-stream permission restored; drill cleanup unconditional with a state file, verified deletes and a failure-path test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c644e12bce43b7b2f51fd9f17ec0de9af6a68584 parent 4fe7f39
3 files changed, +32 −12
  • docs/superpowers/plans/2026-11-16-media-conversion-plan-1-spike.md +12 −4
  • docs/superpowers/plans/2026-11-16-media-conversion-plan-2-console.md +3 −0
  • docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md +17 −8

CI passed — run details

Intent

Human

<task-notification> <task-id>afb34e431dff63a6f</task-id> <tool-use-id>toolu_01Dv19fcQdQgJdVox9daJTB4</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/8509ad95-d983-414c-9679-b3ef222618ef/tasks/afb34e431dff63a6f.output</output-file> <status>completed</status> <summary>Agent "Opus drafts three conversion plans" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>I've applied both round-3 P2s. Each plan's status line now reads "reviewed, round 3 closed (no P1)", and each review log has a round-3 entry. Nothing is committed or pushed. ## Line counts - `docs/superpowers/plans/2026-11-16-media-conversion-plan-1-spike.md`: 145 - `docs/superpowers/plans/2026-11-16-media-conversion-plan-2-console.md`: 569 - `docs/superpowers/plans/2026-11-16-media-conversion-plan-3-engine.md`: 387 ## Fixes 1. **`logs:CreateLogStream` restored.** The foreign user's policy in plan 3 Task 7 and R2's approval scope now grant `logs:CreateLogStream` and `logs:PutLogEvents`, both limited to the drill log group. Plan 1's scope already had it. 2. **Cleanup is unconditional.** - The drill script now creates every drill resource itself. Its first act installs `trap cleanup EXIT INT TERM HUP`, before anything is created. - Before each create it writes what it is about to make to a `state` file in its run directory. That file holds names only, no secrets. - On any exit (success, a failed step, a failed verdict, interruption) it: - restores the endpoint and repository policies; - deletes the drill bucket, the foreign user, its policy and key, and the log group; - removes `input.json`. - It then checks each of those before returning, prints `cleaned` or `NOT CLEANED &lt;item&gt;` per item, and exits non-zero if anything is not clean. - `cleanup &lt;run dir&gt;` repeats the job from the `state` file after a `SIGKILL`, the one exit a trap can't catch. - The failure-path test is `scripts/media_endpoint_drill_test.py`, run against a fake `aws`. It covers a failure at each setup step, a failed verdict, SIGTERM while the permissive policies are in place, a delete that won't go through, and the `cleanup` subcommand. - Plan 1's scratch copy of the script carries the same cleanup, and those tests run against it before any AWS call. Plan 1 Task 4 and plan 3 R3 require every cleanup line to read `cleaned`, and plan 3 R3's old removal checkbox is now the recovery step. The round-3 findings file is still only in `.cache`; I referred to it by name in the logs, assuming you commit it beside the earlier findings.</result> <usage><subagent_tokens>631165</subagent_tokens><tool_uses>4</tool_uses><duration_ms>90640</duration_ms></usage> </task-notification>

Attributed to this commit: 71.4 g CO₂e (5,432,773 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-video-conversion, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/plans/2026-11-16-media-conversion-plan-1-spike.md b/docs/superpowers/plans/2026-11-16-media-conversion-plan-1-spike.md
index cff9b666b..e77588706 100644
--- a/docs/superpowers/plans/2026-11-16-media-conversion-plan-1-spike.md
+++ b/docs/superpowers/plans/2026-11-16-media-conversion-plan-1-spike.md
@@ -6,6 +6,7 @@
**Architecture:** A scratch OpenTofu root builds the engine's network, endpoints, DNS firewall, roles, cluster and reaper as plan 3 Task 11 specifies, around a scratch image (Debian 13, its ffmpeg, and one scratch Go program, `mediaspike`). `mediaspike` is both the driver on docs-t1 (assume, presign, run, watch, time) and the probe inside the task (credentials, DNS, network, timer attacks, encodes). Nothing is committed but the report and its fixtures; everything is destroyed at the end.
**Tech Stack:** Go 1.26 (scratch module), OpenTofu, `aws` CLI with profile `kass`, podman on an arm64 builder, Debian 13 `ffmpeg`, Safari (iOS and macOS), Chrome, Firefox, hls.js.
**Spec:** docs/superpowers/specs/2026-11-16-video-conversion-design.md (rev 8, approved)
+**Status:** reviewed, round 3 closed (no P1)
## Global Constraints
@@ -34,10 +35,10 @@
**Interfaces (scratch):** `mediaspike` subcommands. Driver: `grant --bucket <b> --key <k> --etag <e> --session <minutes>` (AssumeRole of the spike conversion role with plan 3 Task 9's session policy, prints the five transfers in plan 2 Task 1's `media.Transfers` JSON, its struct copied into the scratch module since plan 2 is not built yet, and the token length); `run --class <preset/class> [--command …] [--env K=V]… [--storage <GiB>] [--cpu <units> --memory <MiB>] [--token <t>]` (RunTask as plan 3 Task 9 builds it; prints the ARN and the override byte length); `watch <arn>` (DescribeTasks every 5 s; prints created, pull start/stop, started, each container's start from the codec's metadata log, stopped, stop code, exits); `retention <arn>…` (DescribeTasks every 5 min until `MISSING`). Probe (in the task): `creds`, `dns <name>…`, `net <host:port>…`, `endpoints` (and the driver's `endpoints-verdict`), built to plan 3 Task 7's definition of the endpoint drill and nothing else, `marker`, `hostile-timer`, `deadline` (plan 2's `media.DeadlineSleep` rule, copied), `clock`, `encode --preset <x264> --profile video|audio|poster|hdr` (downloads the transfer's source with resume, runs the plan 3 arguments, reads `memory.peak` of its cgroup, uploads, prints wall times per phase), `playlist <mp4>` (a scratch copy of plan 3's `readFMP4` and `writePlaylist`), `reconnect --cut-at <bytes> --pause-until <unix>`.
-- [ ] **Step 1:** Write `mediaspike`, and a scratch copy of `scripts/media-endpoint-drill.sh` to plan 3 Task 7's definition (the drill is defined only there; plan 3 builds the committed version); `go vet` and `CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build`. Expected: clean.
+- [ ] **Step 1:** Write `mediaspike`, and a scratch copy of `scripts/media-endpoint-drill.sh` to plan 3 Task 7's definition (the drill is defined only there; plan 3 builds the committed version), including its unconditional cleanup: the trap installed before the first create, the `state` file, the restore, delete and verify steps, and the `cleanup <run dir>` subcommand; run plan 3's `media_endpoint_drill_test.py` failure-path cases against the scratch copy with the fake `aws` before Task 2 (no AWS call); `go vet` and `CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build`. Expected: clean.
- [ ] **Step 2:** Write the tofu root (plan 3 Task 11's resources, `name = "mediaspike"`, the bucket `<dev store prefix>mediaspike-<6 hex>` with SSE-S3, versioning off, public access blocked; drill task definitions `late-deadline` (the deadline container on a separate image tag padded with a 2 GB layer), `no-deadline` (the deadline container on a digest that does not exist), `no-start-dep` and `stop-20`). `tofu init -backend=false && tofu validate`. Expected: valid. Read the dev store prefix from the dev root (read-only).
- [ ] **Step 3:** Write the Containerfile: `FROM docker.io/library/debian:13-slim@sha256:<digest>`, `apt-get install --no-install-recommends ffmpeg`, `COPY mediaspike /usr/local/bin/`, `RUN mkdir /scratch && chown 65534:65534 /scratch && chmod 0700 /scratch`, `VOLUME ["/scratch"]` (plan 3's image does the same), `USER 65534:65534`, `ENTRYPOINT ["/usr/local/bin/mediaspike"]`. Record the digest.
-- [ ] **Step 4:** Write `scope.md`, the approval request, with: account and region; every resource of Step 2 by type and name, plus one throwaway `t4g.medium` Debian 13 arm64 builder (SSM only, no inbound, 40 GB gp3; or the existing dev root runner if one is up), one dev app `mediaspike` for the playback page; for the foreign-credential gate, in an unrelated account Paul names, one IAM user and access key whose identity policy allows `s3:GetObject` on one object of the spike bucket, `ecr:GetAuthorizationToken` and the pull actions on the spike repository, and `logs:CreateLogStream`/`logs:PutLogEvents` on one log group in that account, plus that log group, named `mediaspike-endpoint-drill` in `eu-west-1`; a spike-bucket policy and a spike-repository policy admitting that user; and, for minutes inside Task 4 Step 3, each of the four endpoint policies replaced by AWS's default full-access policy as a positive control and then restored; what each permits (the conversion role trusts only the operator's `kass` principal); traffic effects (none on tenants or the dev console); cost at most 100 US dollars (endpoints about 1 dollar a day, Fargate runs, the builder, about 150 GB of S3 for a week); duration at most 7 days; Task 8's cleanup and its verification. List the files needed from Paul (spec decision 1): 4K60 HDR in Dolby Vision or HLG, a portrait clip with rotation, a variable-frame-rate clip, an ordinary 1080p clip, an hour or more of video, a browser voice recording; and the Safari checks on his iPhone or the tito-studio Mac.
+- [ ] **Step 4:** Write `scope.md`, the approval request, with: account and region; every resource of Step 2 by type and name, plus one throwaway `t4g.medium` Debian 13 arm64 builder (SSM only, no inbound, 40 GB gp3; or the existing dev root runner if one is up), one dev app `mediaspike` for the playback page; for the foreign-credential gate, in an unrelated account Paul names, one IAM user and access key whose identity policy allows `s3:GetObject` on one object of the spike bucket, `ecr:GetAuthorizationToken` and the pull actions on the spike repository, and `logs:CreateLogStream`/`logs:PutLogEvents` on one log group in that account, plus that log group, named `mediaspike-endpoint-drill` in `eu-west-1`, all of it created and removed by the drill script's one run in Task 4 Step 3 (Paul gives a profile in that account allowed to create them); a spike-bucket policy and a spike-repository policy admitting that user; and, for minutes inside Task 4 Step 3, each of the four endpoint policies replaced by AWS's default full-access policy as a positive control and then restored; what each permits (the conversion role trusts only the operator's `kass` principal); traffic effects (none on tenants or the dev console); cost at most 100 US dollars (endpoints about 1 dollar a day, Fargate runs, the builder, about 150 GB of S3 for a week); duration at most 7 days; Task 8's cleanup and its verification. List the files needed from Paul (spec decision 1): 4K60 HDR in Dolby Vision or HLG, a portrait clip with rotation, a variable-frame-rate clip, an ordinary 1080p clip, an hour or more of video, a browser voice recording; and the Safari checks on his iPhone or the tito-studio Mac.
---
@@ -64,7 +65,7 @@ Each step runs one or more tasks through `mediaspike run` and records the probe'
- [ ] **Step 1: Credentials.** `--command creds` on each class. Expected: none of the credential-bearing variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_SECURITY_TOKEN`, `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`, `AWS_CONTAINER_CREDENTIALS_FULL_URI`, `AWS_CONTAINER_AUTHORIZATION_TOKEN`, `AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE`, `AWS_WEB_IDENTITY_TOKEN_FILE`, `AWS_ROLE_ARN`); `AWS_EXECUTION_ENV` and the region variables are recorded and allowed; `169.254.170.2` serves no credential; `169.254.169.254` unreachable; the v4 task metadata answers but holds no credential.
- [ ] **Step 2: Names and routes.** `dns` for the five allowed names and for `example.com`, `amazonaws.com`, `sts.eu-west-1.amazonaws.com`, `ecs.eu-west-1.amazonaws.com`; `net` to `1.1.1.1:443`, the dev console's private IP on 443 and another dev box's private IP on 22. Expected: only the allowed names resolve; every connection fails. An unsigned `GET` of a spike-bucket object: refused at the S3 endpoint.
-- [ ] **Step 3: The endpoint drill.** Run the endpoint drill exactly as plan 3 Task 7 defines it (registry token minted outside the VPC and passed in; the same four authenticated requests under the restrictive policies, AWS's full-access policy, and the restored policies) with the foreign user, on the video-short task definition. Expected: `endpoints-verdict` exits 0 (A refused, B ok, C refused at all four endpoints) and the saved policies are back. Record the table and the policy swap's start and end times. Causality comes from phase B, not from error text.
+- [ ] **Step 3: The endpoint drill.** Run the endpoint drill exactly as plan 3 Task 7 defines it (registry token minted outside the VPC and passed in; the same four authenticated requests under the restrictive policies, AWS's full-access policy, and the restored policies) with the foreign user, on the video-short task definition. Expected: `endpoints-verdict` exits 0 (A refused, B ok, C refused at all four endpoints) and the saved policies are back. Record the table, the policy swap's start and end times, and the cleanup lines; every one must read `cleaned`. If any reads `NOT CLEANED`, or the run was killed, run `cleanup <run dir>` until all are clean and tell Paul before Task 5. Causality comes from phase B, not from error text.
- [ ] **Step 4: Non-reuse and isolation.** Two tasks in sequence and two side by side with `--command marker` (writes its task ARN under `/scratch` and `/tmp`, reads for any other ARN, lists `/proc` for foreign PIDs). Expected: each sees only itself; distinct task ARNs and ENIs; and the codec, as `65534`, can create `/scratch/in`, `/scratch/out` and `/scratch/tmp` on the bind mount (record `stat /scratch`: owner, mode).
- [ ] **Step 5: Overrides, size, storage.** Twenty `grant` calls: record the longest token. A `run` with that token and a 512-byte key of 3-byte runes: record the override byte length and whether RunTask accepts it. `--storage 48`: accepted, and `df /scratch` in the task shows it. `--cpu 16384 --memory 32768` on the audio-short definition: accepted or refused (whether size can be set per run). A video-long run at 16 vCPU ARM64: placed, or the capacity error.
- [ ] **Step 6: Idempotency.** RunTask twice with one `clientToken` and the same body: the same task ARN. The same token with a different environment value: record the error code.
@@ -111,7 +112,7 @@ Each step runs one or more tasks through `mediaspike run` and records the probe'
- [ ] **Step 1: Also establish the image route.** Whether amadan CI runs on a schedule (amadan CLI help and `.amadan/README.md`); whether `snapshot.debian.org` is reachable from docs-t1 (`curl -sI`, with that host declared). Record which weekly refresh plan 3 Task 8 uses: an amadan schedule, or a Paseo schedule on docs-t1.
- [ ] **Step 2: Write the report:** Paul's approval; environment and image; Paul's files' facts (tags removed); every Task 4 to 7 result as a table; then **Values for plans 2 and 3**, one row each with provisional and measured: `media.EngineRecordRetention` (1 h), `media.MaxOverrideBytes` (8,192) and the worst token length (1,400 in plan 2's test), `video_max` (2 h), `video_max_hi` (30 min), `video_bytes` (40 GiB), `audio_max` (8 h), `audio_bytes` (10 GiB), the four class rows' CPU and memory and whether 16 vCPU ARM64 places, the short classes' granted durations (10 min, 2 h), `x264Preset` (`veryfast`), `x264CRF` (23), the HDR chain and `refuseDolbyVision5` (false), the muxer flags and the top-level box sequence of the fixtures (plan 3 expects `ftyp`, `moov`, then `moof`/`mdat` pairs with `skip_trailer`), whether `/scratch` is writable by 65534, `codecHeadroomDB` (0.5), whether `ephemeralStorage` and task size are accepted per run, platform version (1.4.0), clock skew, the playback matrix and the acceptance time, the weekly image refresh, and the cost table. Then **Spec amendments**: one per failed proof, with the evidence; or "none".
- [ ] **Step 3:** Commit the report and fixtures on the design branch: `docs: media conversion spike report and fixtures`. Paul confirms the report before plan 3 Task 4 starts.
-- [ ] **Step 4: Clean up**, then verify each: `tofu destroy` (bucket emptied first) and an `aws resourcegroupstaggingapi get-resources` for the spike's tag showing nothing; the builder terminated (or the root runner's `/var/tmp/mediaspike` removed); the foreign user's key and user deleted, and its log group `mediaspike-endpoint-drill` deleted (`aws logs delete-log-group`), each verified absent in that account (`aws iam get-user` answers `NoSuchEntity`; `aws logs describe-log-groups --log-group-name-prefix mediaspike-endpoint-drill` lists nothing), by Paul or with his credentials; dev app `mediaspike` deleted; `~/.cache/mediaspike/` and `$TMPDIR/mediaspike/` removed by exact path. Tell Paul it is done, with the report's path.
+- [ ] **Step 4: Clean up**, then verify each: `tofu destroy` (bucket emptied first) and an `aws resourcegroupstaggingapi get-resources` for the spike's tag showing nothing; the builder terminated (or the root runner's `/var/tmp/mediaspike` removed); the drill's foreign user, key and log group `mediaspike-endpoint-drill` and its bucket and repository grants, already removed and verified by the drill script's own cleanup (re-run `cleanup <run dir>` if its directory remains), checked absent once more in that account (`aws iam get-user` answers `NoSuchEntity`; `aws logs describe-log-groups --log-group-name-prefix mediaspike-endpoint-drill` lists nothing), by Paul or with his credentials; dev app `mediaspike` deleted; `~/.cache/mediaspike/` and `$TMPDIR/mediaspike/` removed by exact path. Tell Paul it is done, with the report's path.
---
@@ -135,3 +136,10 @@ Round 2: Astra (`docs/superpowers/plans/CODEX-FINDINGS-MEDIA-PLANS-R2.md`), revi
| R2-1 P1 endpoint proof | Accepted, as Paul's pick: Task 4 Step 3 runs the one endpoint drill defined in plan 3 Task 7 (token minted outside the VPC; restrictive, permissive, restored; no error-text assertions). The scope request already holds the permissive swap. |
| R2-4 P2 foreign log group cleanup | Accepted. The log group is named `mediaspike-endpoint-drill`; Task 8 deletes it and verifies its absence, with the user. |
| R2-2, R2-3 | Plan 2. |
+
+Round 3, the last: Astra (`CODEX-FINDINGS-MEDIA-PLANS-R3.md`), no P1, so review is closed; its two P2s are applied without another round.
+
+| Finding | Handling in this plan |
+|---|---|
+| R3-1 P2 `logs:CreateLogStream` | Plan 3's definition; this plan's scope already granted it. |
+| R3-2 P2 cleanup only on success | Accepted. The spike's scratch drill script carries plan 3's unconditional cleanup (trap before the first create, `state` file, restore, delete and verify on every exit, `cleanup <run dir>` for a kill), and plan 3's failure-path test runs against it before any AWS call; Task 4 Step 3 requires every cleanup line to read `cleaned`, and Task 8 checks once more. |
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 d03b58225..8653fb5b9 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
@@ -6,6 +6,7 @@
**Architecture:** `internal/media` is a stdlib-only leaf holding every shared name: presets, classes, limits, the job id, the codec's payload and result schema, exit codes, error codes and the `Engine` and `Grants` interfaces (with fakes in `internal/media/mediatest`). `internal/mediajobs` owns the `media_jobs` table and every transition as one SQL transaction, driven by a single-goroutine pass; `internal/sim/mediajobs` runs it under randomized interleavings and checks I1 to I8. The console adds the door, the store-provenance check (`internal/storecfg`), retirement at every store teardown, the `media_minutes_month` cap, `carlos store uploads`, the CLI verbs and the docs; AWS adapters arrive in plan 3.
**Tech Stack:** Go 1.26, `database/sql` over `modernc.org/sqlite` (the console store), `net/http`, the console's existing gates (`apiAccountApp`, `storeWalks`, plan caps), `clireg`.
**Spec:** docs/superpowers/specs/2026-11-16-video-conversion-design.md (rev 8, approved)
+**Status:** reviewed, round 3 closed (no P1)
## Global Constraints
@@ -564,3 +565,5 @@ Round 2: Astra (`docs/superpowers/plans/CODEX-FINDINGS-MEDIA-PLANS-R2.md`), plan
| R2-2 P2 charging changed the approved policy | Accepted. A `done` job is charged `w × source_ms` again (A2); the 0 to `granted_s·1000` bound and the hostile-result witnesses stay, with a duration far below runtime now accepted and charged by its duration. A2 states the residual risk (a tenant who compromises the codec in their own job can under-report within the bound). `max(duration, runtime)` is gone from Global Constraints, metering and the tests. |
| R2-3 P2 host-claim unresolved | Accepted. The refusal is now the exception spec §11 A1 authorises; Global Constraints point there and "Paul has to rule" is gone. |
| R2-4 P2 foreign log group cleanup | Plan 1. |
+
+Round 3, the last: Astra (`CODEX-FINDINGS-MEDIA-PLANS-R3.md`), no P1, review closed; plan 2 accepted, and its two P2s (the drill's log permission and cleanup) concern plans 1 and 3 only.
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 1162002b3..6105526ac 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
@@ -6,6 +6,7 @@
**Architecture:** One pure-Go binary, `cmd/carlos-media`, is the image's entrypoint: `deadline` sleeps and exits, `codec` runs `internal/mediahandler` (download, sniff, probe, ffmpeg, loudness, peaks, collect, upload, result), `selftest` and `drill` serve the rollout. `internal/mediaaws` implements plan 2's `media.Engine`, `media.Grants` and `storecfg.Buckets` with ECS, STS and S3; `internal/medialocal` runs the same handler as a local process, which is the provider boundary's non-AWS runner and the end-to-end harness. `infra/modules/media-engine` holds the cluster, four task definitions, the closed VPC, its endpoints and DNS firewall, the roles and the reaper.
**Tech Stack:** Go 1.26 (`CGO_ENABLED=0`, linux/arm64 for the image), Debian 13 `ffmpeg`, `aws-sdk-go-v2` (`service/ecs` added, `sts`, `s3`), OpenTofu with `mock_provider` tests, Python 3 stdlib for the reaper.
**Spec:** docs/superpowers/specs/2026-11-16-video-conversion-design.md (rev 8, approved)
+**Status:** reviewed, round 3 closed (no P1)
## Global Constraints
@@ -157,19 +158,20 @@ Depends on plan 1 Task 3 Step 4: the muxer rules and the parser's accepted box s
**Files:**
- Modify: `internal/mediahandler/fakeffmpeg_test.go` (Task 3's helper; the scenarios below)
-- Create: `cmd/carlos-media/sigv4.go` (a stdlib SigV4 signer for the drill's two signed API calls; the provider boundary keeps the SDK out), `scripts/media-endpoint-drill.sh`, `internal/mediahandler/hostile_test.go`, `internal/mediahandler/selftest.go`, `cmd/carlos-media/drill.go`, `cmd/carlos-media/drill_test.go`, `internal/mediahandler/testdata/corpus/*` (playlist-style files naming `http://169.254.169.254/` and `file:///etc/passwd`, a truncated MP4, an MP4 whose `dref` names `/etc/passwd`, a 0-byte file, 4 KiB of random bytes, an HTML file, a ZIP)
+- Create: `cmd/carlos-media/sigv4.go` (a stdlib SigV4 signer for the drill's two signed API calls; the provider boundary keeps the SDK out), `scripts/media-endpoint-drill.sh`, `scripts/media_endpoint_drill_test.py` (stdlib `unittest`, the shape of `scripts/*_test.py`), `internal/mediahandler/hostile_test.go`, `internal/mediahandler/selftest.go`, `cmd/carlos-media/drill.go`, `cmd/carlos-media/drill_test.go`, `internal/mediahandler/testdata/corpus/*` (playlist-style files naming `http://169.254.169.254/` and `file:///etc/passwd`, a truncated MP4, an MP4 whose `dref` names `/etc/passwd`, a 0-byte file, 4 KiB of random bytes, an HTML file, a ZIP)
**Interfaces:**
- Produces: fake-ffmpeg scenarios `fail`, `fill-scratch` (writes until `ENOSPC` on a small tmpfs, Linux only, skipped elsewhere), `many-files` (100,000 empty files in the output directory), `symlink-out`, `hardlink-out`, `fifo-out`, `oversize-out`, `fork-setsid`, `ignore-term`; `func Selftest(ctx context.Context, cfg Config) error` (generates inputs with the image's real ffmpeg via `lavfi` (`testsrc2` 1080p 10 s with a 440 Hz tone; the same at 1080x1920 with `-display_rotation 90`; a PQ-tagged 10-bit 4K 5 s; a `-live 1` WebM Opus voice clip; a silent mono WAV; an MP3 with an attached picture), serves them from an in-process presigned-style server, runs `Run` for each, and checks: exit 0, output sizes, `readFMP4` and the playlist, the video output size from `targetSize`, the voice clip's output loudness within 1 LU of -16 or its true peak at most -1.5 dBTP and never above, its loudness range at least the source's less 0.5 LU, 1,000 peaks, the silent file's peaks all 0); `carlos-media selftest` prints one `PASS`/`FAIL <case>: <reason>` line per case and exits 0 or 1; `carlos-media drill <name>` with `creds` (none of the credential-bearing variables `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_SECURITY_TOKEN`, `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`, `AWS_CONTAINER_CREDENTIALS_FULL_URI`, `AWS_CONTAINER_AUTHORIZATION_TOKEN`, `AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE`, `AWS_WEB_IDENTITY_TOKEN_FILE`, `AWS_ROLE_ARN` is set; ordinary metadata such as `AWS_EXECUTION_ENV`, `AWS_REGION` and `AWS_DEFAULT_REGION` is allowed; `169.254.170.2/v2/credentials` and `169.254.169.254` unreachable; the v4 task metadata endpoint yields no credential), `dns` (only the allowed names resolve; `example.com`, `amazonaws.com`, `sts.eu-west-1.amazonaws.com` do not), `net` (TCP to 1.1.1.1:443 and to a private address given as an argument fails), `endpoints` (one pass of the endpoint drill defined below), `hostile-timer` (ignores SIGTERM and SIGINT, sends `SIGKILL` to every PID it can see and to `-1`, then loops), `fill-scratch`, `many-files`, `bad-outputs` (creates the hostile files of Task 6 under the output names, then calls `collect` and `upload` with the payload from `CARLOS_MEDIA_JOB`; prints how many PUTs were attempted, expected 0); each prints `PASS`/`FAIL` lines and never prints a credential, a URL or a header.
**The endpoint drill (the one definition; plan 1 Task 4 Step 3 and rollout R3 both run it).** It proves that foreign credentials cannot use any of the four endpoints, by controls, never by error text.
-- **The principal and its four requests.** A user in an unrelated account whose identity policy allows, and whose target resources admit: `s3:GetObject` on one object of a drill bucket; `ecr:GetAuthorizationToken`; the image pull actions on the engine's repository; `logs:PutLogEvents` to a log stream in a log group of its own account in the same region. Before any task runs, outside the engine VPC (docs-t1, with that user's profile), the driver presigns the S3 GET (expiry 1 h), mints the user's ECR registry token with `GetAuthorizationToken`, creates the log stream, and writes the drill input: `{"s3_get_url", "ecr_token", "ecr_manifest_url" (the engine image's manifest by digest on the `*.dkr.ecr` host), "region", "access_key_id", "secret_access_key", "log_group", "log_stream"}`, passed to the task in `CARLOS_MEDIA_DRILL` (never logged).
+- **The principal and its four requests.** A user in an unrelated account whose identity policy allows, and whose target resources admit: `s3:GetObject` on one object of a drill bucket; `ecr:GetAuthorizationToken`; the image pull actions on the engine's repository; `logs:CreateLogStream` and `logs:PutLogEvents` on the drill log group only (`arn:aws:logs:<region>:<foreign account>:log-group:<name>:*`), a group of its own account in the same region. The script provisions all of it (below). Then, outside the engine VPC (docs-t1, with that user's new key), it presigns the S3 GET (expiry 1 h), mints the user's ECR registry token with `GetAuthorizationToken`, creates the log stream, and writes the drill input `{"s3_get_url", "ecr_token", "ecr_manifest_url" (the engine image's manifest by digest on the `*.dkr.ecr` host), "region", "access_key_id", "secret_access_key", "log_group", "log_stream"}` to `<run dir>/input.json` (mode 0600), passed to the task in `CARLOS_MEDIA_DRILL` (never logged).
- **One pass** (`carlos-media drill endpoints`, inside a task on a media task definition with `command ["drill", "endpoints"]` on `codec`): the same four authenticated requests, each with a 20 s timeout: S3 gateway, `GET` of the presigned URL; ECR API, `GetAuthorizationToken` SigV4-signed in the task with the passed key; ECR Docker, `HEAD` of the manifest with `Authorization: Basic <ecr_token>`; Logs, `PutLogEvents` SigV4-signed with the passed key. It prints one line per endpoint, `<endpoint> ok` for a 2xx and `<endpoint> refused <status or "conn">` for anything else, and nothing else: no error text, no URL, no header.
-- **Three phases** (`scripts/media-endpoint-drill.sh <profile> <cluster> <task-definition> <drill-input>`, the operator's AWS CLI): save the four endpoints' policies; phase A, one pass under them: every endpoint must be `refused`; replace all four with AWS's default full-access policy, then one pass every 60 s, at most 5: phase B passes when every endpoint is `ok`; restore the saved policies byte for byte (compared with `aws ec2 describe-vpc-endpoints`), then one pass every 60 s, at most 5: phase C passes when every endpoint is `refused`. `carlos-media drill endpoints-verdict A B C` prints a table of endpoint by phase and exits 0 only when A and C are all `refused` and B all `ok`; anything else fails the drill, and the script restores the saved policies on every exit path. A refusal is causal for an endpoint only because the identical request succeeded in phase B.
+- **Provisioning, the three phases and cleanup are one script run.** `scripts/media-endpoint-drill.sh run --profile <dev profile> --foreign-profile <unrelated account's admin profile> --cluster <arn> --task-definition <arn> --repository <name> --bucket <drill bucket name>`, the operator's AWS CLI, every call through `${AWS:-aws}`. Its first act makes a run directory with `mktemp -d "$TMPDIR/media-endpoint-drill.XXXXXX"` and installs `trap cleanup EXIT INT TERM HUP`; only then does it create anything. Before each create it appends what it is about to create to `<run dir>/state` (names only, never a secret), so cleanup covers a create that half-happened. Steps: save the four endpoints' policies to the run directory; save the repository's existing policy (or note none); create the drill bucket, its one object and its bucket policy admitting the user; add the user's grant to the repository policy; in the foreign account create the log group, the user, its policy and its key; write `input.json`. Phase A, one pass under the saved policies: every endpoint must be `refused`. Replace all four with AWS's default full-access policy (`aws ec2 modify-vpc-endpoint --reset-policy`), then one pass every 60 s, at most 5: phase B passes when every endpoint is `ok`. Restore the saved policies, then one pass every 60 s, at most 5: phase C passes when every endpoint is `refused`. `carlos-media drill endpoints-verdict A B C` prints a table of endpoint by phase and exits 0 only when A and C are all `refused` and B all `ok`. A refusal is causal for an endpoint only because the identical request succeeded in phase B.
+- **`cleanup` runs on every exit** (success, a failed step, a failed verdict, a signal, an interrupted setup), each step idempotent, in this order: restore the four saved endpoint policies; put back the saved repository policy (or delete it if there was none); delete the bucket policy, the object and the bucket; in the foreign account delete the user's key, policy and user, then the log group; `rm -f <run dir>/input.json`. It then verifies, before returning: the four endpoint policies equal the saved ones byte for byte (`aws ec2 describe-vpc-endpoints`); the repository policy equals the saved one or is absent as it was; `aws s3api head-bucket` answers 404; `aws iam get-user` answers `NoSuchEntity`; `aws logs describe-log-groups --log-group-name-prefix <group>` lists nothing; `input.json` does not exist. It prints one line per obligation, `cleaned` or `NOT CLEANED <obligation>`, exits non-zero if any is not clean (whatever the drill's verdict), and removes the run directory only when all are clean. `scripts/media-endpoint-drill.sh cleanup <run dir>` runs the same cleanup from a kept `state` file, for the one exit a trap cannot catch (`SIGKILL`, a lost machine).
- **Conversion stays off** until this drill passes: `CARLOS_MEDIA_ENGINE` is not set on a console of that deployment before then.
-- [ ] **Step 1: Write the failing tests:** `TestCorpusEndsInNamedErrors` (each corpus file through `Run` with the fake ffprobe answering as the real one would for it: a named code from `HandlerCodes`, never a panic, never exit 0, and no request other than the source GET and the result PUT); `TestPlaylistStyleFileMakesNoRequest` (the `169.254.169.254` file: `unsupported_container`, ffmpeg never started, the test server saw one GET); `TestHostileChildrenFailOnlyTheirJob` (`fill-scratch`, `many-files`, `fork-setsid`, `ignore-term`: exit 1 with a named error within the test's 30 s, no stray process left); `TestBadOutputsUploadNothing`; `TestDrillCredsReportsAnEnvCredential` (a fake environment with `AWS_SECRET_ACCESS_KEY` set: `FAIL`; one with only `AWS_EXECUTION_ENV=AWS_ECS_FARGATE` and `AWS_REGION`: `PASS`); `TestDrillOutputHasNoSecrets`; `TestDrillEndpointsOnePass` (four `httptest` endpoints answering 403, 200, a closed port and 200: exactly the four lines `s3 refused 403`, `ecr-api ok`, `ecr-docker refused conn`, `logs ok`, and the ECR Docker request carried `Authorization: Basic <the passed token>` unchanged); `TestSigV4Vector` (AWS's published SigV4 test vector `get-vanilla`); `TestEndpointsVerdict` (A all refused, B all ok, C all refused: exit 0; any one cell otherwise: exit 1, naming the cell).
-- [ ] **Step 2:** Run `go test ./internal/mediahandler/ ./cmd/carlos-media/ -run 'TestCorpus|TestPlaylistStyle|TestHostileChildren|TestBadOutputs|TestDrill|TestSigV4|TestEndpointsVerdict' -count=1`. Expected: FAIL.
+- [ ] **Step 1: Write the failing tests:** `TestCorpusEndsInNamedErrors` (each corpus file through `Run` with the fake ffprobe answering as the real one would for it: a named code from `HandlerCodes`, never a panic, never exit 0, and no request other than the source GET and the result PUT); `TestPlaylistStyleFileMakesNoRequest` (the `169.254.169.254` file: `unsupported_container`, ffmpeg never started, the test server saw one GET); `TestHostileChildrenFailOnlyTheirJob` (`fill-scratch`, `many-files`, `fork-setsid`, `ignore-term`: exit 1 with a named error within the test's 30 s, no stray process left); `TestBadOutputsUploadNothing`; `TestDrillCredsReportsAnEnvCredential` (a fake environment with `AWS_SECRET_ACCESS_KEY` set: `FAIL`; one with only `AWS_EXECUTION_ENV=AWS_ECS_FARGATE` and `AWS_REGION`: `PASS`); `TestDrillOutputHasNoSecrets`; `TestDrillEndpointsOnePass` (four `httptest` endpoints answering 403, 200, a closed port and 200: exactly the four lines `s3 refused 403`, `ecr-api ok`, `ecr-docker refused conn`, `logs ok`, and the ECR Docker request carried `Authorization: Basic <the passed token>` unchanged); `TestSigV4Vector` (AWS's published SigV4 test vector `get-vanilla`); `TestEndpointsVerdict` (A all refused, B all ok, C all refused: exit 0; any one cell otherwise: exit 1, naming the cell). `media_endpoint_drill_test.py` runs the script with `AWS` pointing at a fake `aws` (a Python script under the test's temporary directory that logs each call, keeps a fake state of endpoints, policies, bucket, user and log group, and fails on demand): `test_cleanup_after_each_failed_setup_step` (a failure injected at each create in turn: every obligation already begun is undone, the verification calls run, the script exits non-zero, `input.json` is gone and the endpoint policies equal the saved ones); `test_cleanup_after_failed_verdict` (phase B never `ok`: same obligations, non-zero exit); `test_cleanup_on_sigterm_mid_phase_b` (SIGTERM while the full-access policies are in place: they are restored and every resource deleted); `test_cleanup_reports_what_it_could_not_clean` (the fake refuses one delete: `NOT CLEANED` for that obligation, non-zero exit, the run directory and `state` kept); `test_cleanup_subcommand_from_state` (a `state` file from a killed run: `cleanup <run dir>` finishes the job).
+- [ ] **Step 2:** Run `go test ./internal/mediahandler/ ./cmd/carlos-media/ -run 'TestCorpus|TestPlaylistStyle|TestHostileChildren|TestBadOutputs|TestDrill|TestSigV4|TestEndpointsVerdict' -count=1` and `python3 -I -m unittest discover -s scripts -p 'media_endpoint_drill_test.py'`. Expected: FAIL.
- [ ] **Step 3:** Implement.
- [ ] **Step 4:** Rerun. Expected: PASS. Then each fuzz target for 60 s. Expected: no crashers; add any found input to `testdata/fuzz/`.
- [ ] **Step 5:** Commit: `media: hostile-input corpus, fuzzing, selftest and drills`.
@@ -307,7 +309,7 @@ Ask each time with the account, region, resources, cost, duration, traffic effec
### R2: Dev infrastructure, with the door still off
-- [ ] Ask Paul (profile `kass`, `eu-west-1`), including the endpoint drill's scope (Task 7): in an unrelated account he names, one IAM user and key with the drill's identity policy, and one log group with a log stream; in dev, a drill bucket with one object and a bucket policy admitting that user, and a repository policy on the engine repository admitting it; and, for minutes during R3, the four endpoint policies replaced by AWS's default full-access policy and then restored. All removed in R3. In the dev root: `store_conversion = true` on the console's region-host; `media-engine` with `image_digest = ""`; apply. Push the image (`mediaimage push`), set `image_digest`, `image_built_at`, `image_ffmpeg`; apply. Do not set `CARLOS_MEDIA_ENGINE` yet.
+- [ ] Ask Paul (profile `kass`, `eu-west-1`), including the endpoint drill's scope (Task 7), all of it created and removed by the drill script's one run in R3: in an unrelated account he names (with a profile of his allowed to create them), one IAM user and key whose policy allows `s3:GetObject` on the drill object, `ecr:GetAuthorizationToken`, the pull actions on the engine repository, and `logs:CreateLogStream` and `logs:PutLogEvents` on the drill log group only, plus that log group; in dev, a drill bucket with one object and a bucket policy admitting that user, and a grant in the engine repository's policy; and, for minutes, the four endpoint policies replaced by AWS's default full-access policy and then restored. In the dev root: `store_conversion = true` on the console's region-host; `media-engine` with `image_digest = ""`; apply. Push the image (`mediaimage push`), set `image_digest`, `image_built_at`, `image_ffmpeg`; apply. Do not set `CARLOS_MEDIA_ENGINE` yet.
- [ ] Run `carlos-media selftest` once per class as a one-off task (`aws ecs run-task` with the class's task definition and `command ["selftest"]` on `codec`). Expected: every case `PASS`.
### R3: Dev activation gates (spec §5.5), before the door is on
@@ -315,10 +317,10 @@ Ask each time with the account, region, resources, cost, duration, traffic effec
Each drill names its tool; record every result in `docs/superpowers/reviews/2026-11-16-media-conversion-dev-drills.md`. Every task here is started with `aws ecs run-task`; no console is involved.
- [ ] `drill creds`, `drill dns`, `drill net <console private IP>` and `drill net <another box's private IP>`: all `PASS`. An unsigned S3 request from inside a task: refused at the endpoint.
-- [ ] The endpoint drill (Task 7's definition) with R2's foreign user: `scripts/media-endpoint-drill.sh kass <cluster> <video-720p/short revision> <drill input>`. Expected: `endpoints-verdict` exits 0 (A refused, B ok, C refused at all four endpoints) and the saved policies are back. Record the table.
+- [ ] The endpoint drill (Task 7's definition): `scripts/media-endpoint-drill.sh run --profile kass --foreign-profile <Paul's> --cluster <arn> --task-definition <video-720p/short revision> --repository <name> --bucket <drill bucket>`. Expected: `endpoints-verdict` exits 0 (A refused, B ok, C refused at all four endpoints) and every cleanup line reads `cleaned`. Record the table and the cleanup lines.
- [ ] A revision with `deadline` made to start late (its image padded so its pull is slow): `codec` starts only after it. A revision whose `deadline` image digest does not exist: `codec` never runs.
- [ ] A task running `drill hostile-timer` with `CARLOS_MEDIA_DEADLINE_S=180`: gone within 210 s, deadline exit 0, codec 137.
-- [ ] Remove R2's foreign user and key, its log group, the drill bucket and its policy, and the repository policy; verify each is gone (`aws iam get-user`, `aws logs describe-log-groups --log-group-name-prefix`, `aws s3api head-bucket`, `aws ecr get-repository-policy`), and that the four endpoint policies equal the saved ones.
+- [ ] If the drill's run printed any `NOT CLEANED` line or was killed, run `scripts/media-endpoint-drill.sh cleanup <run dir>` until every line reads `cleaned`, and tell Paul before going on.
- [ ] Only when every line above passed: set `CARLOS_STORE_CONVERSION=1` and `CARLOS_MEDIA_ENGINE=<output>` on the dev console through the roll restart. Check `carlos system media status`: configured, four gates `ok`, image age. A failure here stops the rollout and goes to Paul.
### R4: Dev drills with the door on (spec §9)
@@ -376,3 +378,10 @@ Round 2: Astra (`docs/superpowers/plans/CODEX-FINDINGS-MEDIA-PLANS-R2.md`), revi
| R2-1 P1 endpoint proof | Accepted, as Paul's pick: one shared drill with independent controls, defined once in Task 7. The registry token is minted outside the VPC and passed in; the same four authenticated requests run under the restrictive policies (must fail), AWS's full-access policy (must succeed) and the restored policies (must fail); causality comes from those controls, never error text. R2 adds the policy swap to the rollout's scope; R3 runs the drill and keeps the door unset until it passes. `drill foreign` is gone. |
| R2-2, R2-3 | Plan 2 (spec §11 A2 and A1). |
| R2-4 | Plan 1; R3 here also deletes and verifies the drill's log group. |
+
+Round 3, the last: Astra (`CODEX-FINDINGS-MEDIA-PLANS-R3.md`), no P1, so review is closed; its two P2s are applied without another round.
+
+| Finding | Handling in this plan |
+|---|---|
+| R3-1 P2 `logs:CreateLogStream` missing | Accepted. The shared foreign-user policy in Task 7 and R2's scope grant `logs:CreateLogStream` and `logs:PutLogEvents` on the drill log group only. |
+| R3-2 P2 cleanup only on success | Accepted. The drill script provisions everything itself under a `trap cleanup EXIT INT TERM HUP` installed before the first create, records each create in a `state` file, and on every exit restores the endpoint and repository policies, deletes the bucket, user, key and log group, removes `input.json`, verifies each before returning, and exits non-zero if any is not clean; `cleanup <run dir>` covers `SIGKILL`. `media_endpoint_drill_test.py` covers failed setup steps, a failed verdict, SIGTERM in phase B, an undeletable resource and the `cleanup` subcommand. R3's separate removal checkbox is now the recovery step. |