| index 7e83c8694..ef45edb6d 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 |
| @@ -244,7 +244,7 @@ Depends on plan 1 Task 3 Step 4: the muxer rules and the parser's accepted box s |
| **Interfaces:** |
| - Variables (`pdf-host`'s style): `name`, `region`, `store_region`, `store_bucket_prefix`, `deployment_bucket_name`, `console_role_name`, `console_role_arn`, `image_digest` (default `""`), `image_built_at`, `image_ffmpeg`, `vpc_cidr` (default `10.98.0.0/24`), `logs` (default `true`), `log_retention_days` (default 14), `reaper_max_age_minutes` (default 70), `classes` (default: the four rows, each `{preset, class, cpu, memory}`: `video-720p/short` 4096/8192, `video-720p/long` 16384/32768, `audio-aac/short` 1024/2048, `audio-aac/long` 2048/4096; spike). |
| - Outputs: `carlos_media_engine` (`""` while `image_digest` is `""`; else `jsonencode` of plan 3 Task 9's `Config` with `v = 1`), `repository_url`, `cluster_arn`, `conversion_role_arn`. |
| -- Resources: an ECR repository (`IMMUTABLE` tags, scan on push); the VPC with DNS support and hostnames, two private `/25` subnets in two zones, one route table with no default route, no internet gateway and no NAT; a tasks security group with no ingress and egress only TCP 443 to the S3 prefix list and to the endpoints' security group; the endpoints' group admitting TCP 443 from the tasks' group only; an S3 gateway endpoint and interface endpoints `ecr.api`, `ecr.dkr` and (when `logs`) `logs`, private DNS on; their policies (below); a Route 53 Resolver DNS Firewall with an allow list (`s3.<region>.amazonaws.com`, `*.s3.<region>.amazonaws.com`, `api.ecr.<region>.amazonaws.com`, `*.dkr.ecr.<region>.amazonaws.com`, `logs.<region>.amazonaws.com`) at priority 100 `ALLOW` and `*` at 200 `BLOCK` with `NXDOMAIN`, associated with the VPC with mutation protection on, and `firewall_fail_open` `DISABLED`; a log group; the task execution role (trust `ecs-tasks.amazonaws.com` with `aws:SourceAccount`; `ecr:GetAuthorizationToken` on `*`, the three pull actions on the repository, `logs:CreateLogStream` and `logs:PutLogEvents` on the log group); the conversion role (trust: `console_role_arn` only; Allow `s3:GetObject` on `arn:aws:s3:::<prefix>*/*`, `s3:PutObject` on `arn:aws:s3:::<prefix>*/derived/*` and on `arn:aws:s3:::<deployment bucket>/media-results/*`; Deny `s3:GetObject` on `arn:aws:s3:::<prefix>*/*` when `s3:ExistingObjectTag/carlos-scan` is `infected`; Deny `s3:PutObject` on `*` when `ForAnyValue:StringEquals s3:RequestObjectTagKeys` is any of `carlos-scan`, `carlos-scan-version`, `carlos-scan-at`, `carlos-scan-sig`; max session 3600 s); the cluster (Fargate only, Container Insights off); four task definitions (one per `classes` entry, family `<name>-<preset>-<class>`, the Global Constraints' container shape, `deadline` with 64 CPU units and 64 MiB, `codec` with the rest, `codec` env `TMPDIR=/scratch/tmp`, `awslogs` on `codec` only when `logs`, `runtime_platform` `LINUX`/`ARM64`, no `task_role_arn`, no `pid_mode`, volume `scratch` with no host path; if plan 1 reports that RunTask refuses `ephemeralStorage` per run, each definition instead sets `ephemeral_storage` to its class's largest need, 48 GiB for video long and the 20 GiB default elsewhere, and `EphemeralGiB` is never sent), created only when `image_digest` is set; a role policy on `console_role_name` (`sts:AssumeRole` on the conversion role; `ecs:RunTask` on `arn:aws:ecs:<region>:<acct>:task-definition/<name>-*:*` with `ArnEquals ecs:cluster`; `ecs:DescribeTasks` and `ecs:StopTask` on `arn:aws:ecs:<region>:<acct>:task/<cluster>/*`; `ecs:ListTasks` on `*` with `ArnEquals ecs:cluster`; `ecs:DescribeTaskDefinition` on `*`; `iam:PassRole` on the execution role with `iam:PassedToService` `ecs-tasks.amazonaws.com`); the reaper (a Python 3.13 arm64 Lambda from `reaper/reaper.py`, env `CLUSTER` and `MAX_AGE_MINUTES`, timeout 50 s, its own log group, a role with `ecs:ListTasks` under the cluster condition, `ecs:DescribeTasks` and `ecs:StopTask` on the cluster's tasks and logging to its own group only, an EventBridge rule `rate(1 minute)` targeting it); a precondition that `region == store_region`. |
| +- Resources: an ECR repository (`IMMUTABLE` tags, scan on push); the VPC with DNS support and hostnames, two private `/25` subnets in two zones, one route table with no default route, no internet gateway and no NAT; a tasks security group with no ingress and egress only TCP 443 to the S3 prefix list and to the endpoints' security group; the endpoints' group admitting TCP 443 from the tasks' group only; an S3 gateway endpoint and interface endpoints `ecr.api`, `ecr.dkr` and (when `logs`) `logs`, private DNS on; their policies (below); a Route 53 Resolver DNS Firewall with an allow list (`s3.<region>.amazonaws.com`, `*.s3.<region>.amazonaws.com`, `api.ecr.<region>.amazonaws.com`, `*.dkr.ecr.<region>.amazonaws.com`, `logs.<region>.amazonaws.com`) at priority 100 `ALLOW` with `firewall_domain_redirection_action` `TRUST_REDIRECTION_DOMAIN` (AWS answers these names through its own CNAMEs; Astra round 1 of Task 11) and `*` at 200 `BLOCK` with `NXDOMAIN` and the default redirection handling, associated with the VPC with mutation protection on, and `firewall_fail_open` `DISABLED`; a log group; the task execution role (trust `ecs-tasks.amazonaws.com` with `aws:SourceAccount`; `ecr:GetAuthorizationToken` on `*`, the three pull actions on the repository, `logs:CreateLogStream` and `logs:PutLogEvents` on the log group); the conversion role (trust: `console_role_arn` only; Allow `s3:GetObject` on `arn:aws:s3:::<prefix>*/*`, `s3:PutObject` on `arn:aws:s3:::<prefix>*/derived/*` and on `arn:aws:s3:::<deployment bucket>/media-results/*`; Deny `s3:GetObject` on `arn:aws:s3:::<prefix>*/*` when `s3:ExistingObjectTag/carlos-scan` is `infected`; Deny `s3:PutObject` on `*` when `ForAnyValue:StringEquals s3:RequestObjectTagKeys` is any of `carlos-scan`, `carlos-scan-version`, `carlos-scan-at`, `carlos-scan-sig`; max session 3600 s); the cluster (Fargate only, Container Insights off); four task definitions (one per `classes` entry, family `<name>-<preset>-<class>`, the Global Constraints' container shape, `deadline` with 64 CPU units and 64 MiB, `codec` with the rest, `codec` env `TMPDIR=/scratch/tmp`, `awslogs` on `codec` only when `logs`, `runtime_platform` `LINUX`/`ARM64`, no `task_role_arn`, no `pid_mode`, volume `scratch` with no host path; if plan 1 reports that RunTask refuses `ephemeralStorage` per run, each definition instead sets `ephemeral_storage` to its class's largest need, 48 GiB for video long and the 20 GiB default elsewhere, and `EphemeralGiB` is never sent), created only when `image_digest` is set, each with `skip_destroy = true` so a new digest leaves active the revisions a running console still launches; a role policy on `console_role_name` (`sts:AssumeRole` on the conversion role; `ecs:RunTask` on `arn:aws:ecs:<region>:<acct>:task-definition/<name>-*:*` with `ArnEquals ecs:cluster`; `ecs:DescribeTasks` and `ecs:StopTask` on `arn:aws:ecs:<region>:<acct>:task/<cluster>/*`; `ecs:ListTasks` on `*` with `ArnEquals ecs:cluster`; `ecs:DescribeTaskDefinition` on `*`; `iam:PassRole` on the execution role with `iam:PassedToService` `ecs-tasks.amazonaws.com`; `s3:ListBucket` on `arn:aws:s3:::<deployment bucket>` with no `s3:prefix` condition, because `GetObject` carries no prefix and an absent result must read as not found); the reaper (a Python 3.13 arm64 Lambda from `reaper/reaper.py`, env `CLUSTER` and `MAX_AGE_MINUTES`, timeout 50 s, its own log group, a role with `ecs:ListTasks` under the cluster condition, `ecs:DescribeTasks` and `ecs:StopTask` on the cluster's tasks and logging to its own group only, an EventBridge rule `rate(1 minute)` targeting it); a precondition that `region == store_region`. |
| - Endpoint policies: S3 gateway: Allow `s3:GetObject`, `s3:PutObject` on the store prefix and `media-results/*` for principal `*` with `StringEquals aws:PrincipalArn` = the conversion role ARN; Allow `s3:GetObject` on `arn:aws:s3:::prod-<region>-starport-layer-bucket/*` for `*`. ECR API and Docker: Allow `ecr:BatchGetImage`, `ecr:GetDownloadUrlForLayer`, `ecr:BatchCheckLayerAvailability` on the repository and `ecr:GetAuthorizationToken` on `*`, each with `aws:PrincipalArn` = the execution role. Logs: Allow `logs:CreateLogStream`, `logs:PutLogEvents` on the log group with `aws:PrincipalArn` = the execution role. |
| - `reaper.py`: `handler(event, context)` lists `RUNNING` tasks (paginated), describes them in batches of 100, and stops each whose `createdAt` is older than `MAX_AGE_MINUTES` with reason `carlos media reaper: older than <n> minutes`; it reads no other input. |
| |
| @@ -256,7 +256,7 @@ Depends on plan 1 Task 3 Step 4: the muxer rules and the parser's accepted box s |
| A non-null `foreign_principal_arn` must match `^arn:aws:iam::[0-9]{12}:user/carlos-media-drill-[0-9a-f]{16}$` and must not be in the module's own account. Nothing but these five resources may depend on `drill`. |
| - [ ] **Step 1: Write the failing tests.** Besides the runs below: `drill_off_by_default` (no repository policy, the locked endpoint policies), `drill_closed_admits_only_the_user` (the endpoint policies unchanged, one repository statement), `drill_open_opens_only_the_endpoints`, `drill_refuses_another_principal` (`expect_failures`, a role ARN and an ARN in the module's account), and a Go test that no deployment root in this repository sets `media_engine_drill` to anything but `null` outside dev. `media_engine.tftest.hcl` with `mock_provider "aws" {}`, runs: `region_must_be_store_region` (`expect_failures`); `no_digest_creates_only_the_repository` (no task definitions, `carlos_media_engine == ""`); `task_definitions_pass_the_gate` (for each of four: `task_role_arn == null`, `pid_mode == null`, ARM64, and on `jsondecode(container_definitions)`: names, essential, `dependsOn` `deadline`/`START`, `stopTimeout` 30 both, read-only root, user, caps drop `ALL`, images equal `<repo>@<digest>`, `scratch` mounted in `codec` only, CPU and memory per class); `endpoint_policies_name_their_principals` (every statement of the three interface policies has the execution-role condition; the S3 policy's two statements exactly); `tasks_sg_has_no_ingress_and_only_https_egress`; `no_default_route`; `dns_firewall_allows_three_services_and_blocks_the_rest`; `conversion_role_policy_exact` (three Allows, two Denies, trust only the console role); `console_policy_exact`; `reaper_role_is_cluster_scoped`; `output_parses` (the output's JSON has `v` 1, the region, four task definitions and the image). `reaper_test.py` (stdlib `unittest`, a stub client): an old task is stopped, a young one is not, pagination across two pages, a describe failure stops nothing. |
| - [ ] **Step 2:** Run `cd infra/modules/media-engine && tofu init -backend=false && tofu test` and `python3 -I -m unittest discover -s infra/modules/media-engine/reaper`. Expected: FAIL. |
| -- [ ] **Step 3:** Implement. `tofu fmt -check` and `tofu validate` clean. Write the README in `pdf-host`'s shape (what it is, the two-phase apply: repository first, then the digest; wiring `carlos_media_engine` → `CARLOS_MEDIA_ENGINE`; the region rule; the activation gates of spec §5.5; rollback by digest); copy-review it. |
| +- [ ] **Step 3:** Implement. `tofu fmt -check` and `tofu validate` clean. Write the README in `pdf-host`'s shape (what it is, the two-phase apply: repository first, then the digest; wiring `carlos_media_engine` → `CARLOS_MEDIA_ENGINE`; the region rule; the activation gates of spec §5.5, plus that a real conversion's source and result transfers resolve and an ECR image pull succeeds, since the real CNAME chain is unproven until then; the image change procedure: old revisions stay active, a console moves to the new output at its next restart, and old revisions are retired only after every console has stopped referencing them; rollback by digest); copy-review it. |
| - [ ] **Step 4:** Rerun Step 2's commands. Expected: PASS. |
| - [ ] **Step 5:** Commit: `infra: media-engine module, one Fargate task per conversion`. |
| |