carlos / platform Public

review: Astra brief for media-results-cleanup, round 1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5daee236d90388072e2bf480932d48def9f3d1eb parent 25276ec
1 file changed, +155 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-media-results-cleanup.md +155 −0
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-media-results-cleanup.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-media-results-cleanup.md
new file mode 100644
index 000000000..b338ff497
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-media-results-cleanup.md
@@ -0,0 +1,155 @@
+# Review brief: branch `media-results-cleanup` (media result cleanup, drills F1 and F2), round 1 of 3
+
+Repo carlos/platform, branch `media-results-cleanup`, the commit that adds
+this brief (its parent is the tip under review). Under review: the diff
+`origin/main...HEAD` (merge base d3266e8e). Read it from the worktree you
+are started in: `git diff origin/main...HEAD`.
+
+Authorities, all on main: `docs/superpowers/specs/2026-11-16-video-conversion-design.md`
+§5.3, §5.4, §5.5 and §11 (A5 to A7); `AGENTS.md` ("Stopping rules", "The
+census"). The branch adds amendment A8 to that spec; A8 is part of what
+you review, not an authority. The evidence below comes from a drills
+report on the unmerged branch `media-conversion-dev-drills`; it is quoted
+here so you need not read that branch, and it is evidence of a defect,
+not a design to review against.
+
+You are an independent reviewer. Read the diff, then the code it touches
+and what that code reaches, and check every claim against the code.
+
+## The defect (drills R4 on dev, 2026-11-22)
+
+- **F1.** The deployment bucket is versioned, so the console's cleanup
+ `DeleteObject` of `media-results/<execution>.json` only leaves a delete
+ marker. A create-only PUT (`If-None-Match: *`) succeeds over a delete
+ marker, so a result transfer read from a stopped task's ECS overrides
+ (any principal with `ecs:DescribeTasks`), still inside the grant's hour,
+ recreated the object after cleanup, at any size, and nothing removes it.
+- **F2.** Every result stays as a noncurrent version forever: the bucket's
+ lifecycle has rules only for `control/geoip/` and `db-reads/`.
+- Invariant: a result object is gone after cleanup and never outlives its
+ job (spec §5.3, §5.4).
+
+## What the branch does
+
+1. `infra/modules/deployment-buckets/main.tf`: two lifecycle rules on
+ `media-results/` (`media-results-expire`: current objects after 1 day,
+ noncurrent versions 1 day after they become noncurrent, multipart after
+ 1 day; `media-results-delete-markers`: expired delete markers), inside
+ the one existing `aws_s3_bucket_lifecycle_configuration.deployment`,
+ always on (no variable). New `tests/media_results.tftest.hcl`.
+2. `infra/modules/media-engine/iam.tf`: the console's customer-managed
+ policy gains `s3:ListBucketVersions` on the deployment bucket with
+ `StringLike s3:prefix media-results/*`, and `s3:DeleteObjectVersion` on
+ `<deployment bucket>/media-results/*`.
+3. `internal/mediaaws/grants.go` `DeleteResult`: lists versions with the
+ exact result key as `Prefix` (URL encoding), deletes by version id every
+ version and delete marker whose key equals it, relists, up to
+ `resultDeleteRounds` (4). `S3API` gains `ListObjectVersions`;
+ `NoSuchVersion` joins `knownAPICodes`.
+4. `internal/mediajobs`: a stopped row's `cleanup_due` is
+ `MAX(observation, dispatched_at + GrantLifetime + GrantMintSlack)`
+ (`cleanupDueSQL`, `grantBound`) in `commitDone` and `failStop`; before,
+ it was the observation. `engine_lost` already used the bound.
+5. The result PUT's presign expiry is **not** shortened. Today every
+ transfer is presigned with `X-Amz-Expires` = `GrantLifetime` (1 h) on a
+ 1 h STS session, and `Launch` refuses a grant expiring after the bound.
+ The author's reasons for not shortening: `X-Amz-Expires` is one of the
+ payload's shared parameters (`internal/media/payload.go`,
+ `sharedParams`; `presignAll` refuses differing ones), the codec and the
+ `deadline` container read one expiry `e`, and `DeadlineSleep` counts the
+ deadline from task start, so a shorter grant would eat a task's PENDING
+ time; and a shorter expiry would not close the window anyway, because a
+ task that ends early leaves its transfer live until that expiry while
+ cleanup ran at the stop. Check that reasoning.
+6. Tests: a versioned fake bucket (`internal/mediaaws/versions_test.go`);
+ `TestCleanupWaitsForTheGrant` (`internal/mediajobs/jobs_test.go`); a
+ create-only `Put` through a presigned URL on `mediatest.FakeGrants`; the
+ simulation (`internal/sim/mediajobs`) gains a `leaked-put` action and
+ invariant R1 (it fails in 5 of 200 seeds with the old timing); the MinIO
+ contract (`internal/mediaaws/minio_test.go`, `.amadan/ci.d/30-minio-contract`)
+ versions the results bucket and replays F1, and grants the local
+ runner's user the version calls.
+7. Census proposal: `docs/superpowers/notes/census-proposal-media-results-cleanup.md`.
+
+## What to check
+
+1. **DeleteResult.** Exact-key matching under URL encoding; the claim that
+ the exact key sorts first among keys it prefixes, so a first page with
+ none of its entries means none exist; termination and the round bound;
+ a store that answers version id `null` or none; error mapping (a gone
+ deployment bucket must stay an error; `NoSuchKey`/`NoSuchVersion` on a
+ version delete are success); that nothing but that one key can ever be
+ deleted; `ExpectedBucketOwner` on every call.
+2. **Cleanup timing.** Is `dispatched_at + GrantLifetime + GrantMintSlack`
+ truly after every transfer of the execution expires (presign time vs
+ assume time vs `Launch`'s check; STS session expiry vs `X-Amz-Expires`;
+ console clock vs S3's)? Every path that sets `cleanup_due` or settles a
+ row: does any still clean before the bound, or leave a minted grant
+ with no cleanup? The author names one residual in A8: a task created
+ and never started (`neverStarted`) settles with no cleanup while its
+ overrides held live transfers; a result written through one lasts until
+ the lifecycle removes it, and an output under that execution's prefix
+ stays in the tenant's bucket. Say whether that residual is acceptable
+ for this branch or must be closed here.
+3. **What a later cleanup changes.** Store destroy, app purge, account
+ deletion, `Prune`, the `Summary`/status pages, the local runner, a
+ destroyed-then-recreated bucket, S3 request counts. Anything that
+ assumed cleanup happens in the pass that settles a row.
+4. **Nothing reads a result late.** The lifecycle expires results a day
+ after they are written. Confirm no path reads a result object later than
+ ECS's record retention after its task stops (only `Track` reads it).
+5. **IAM.** The two statements, their resources and the `s3:prefix`
+ condition for an exact-key `ListObjectVersions` on AWS; how they combine
+ with region-host's `AnalyticsDayVersionList` (`ListBucketVersions` on the
+ same bucket, `s3:prefix` `apps/*`) on the same role; any Deny that would
+ block them (deployment-buckets' bucket policy); the managed policy's
+ 6,144-character limit.
+6. **Lifecycle.** S3's constraints (an expired-object-delete-marker
+ expiration cannot sit beside `days` in one rule; two rules on one prefix
+ are allowed, as `db-reads/` already does); the rules join the one
+ resource and leave the existing rules byte for byte; on everywhere
+ without a variable (the author's reason: only the media engine writes
+ under the prefix, so where media is off the rules match nothing).
+7. **Rollout order.** The new console code calls `ListObjectVersions` and
+ `DeleteObjectVersion`. If a console rolls before its root applies the
+ module change, every due cleanup fails and is retried each pass
+ (`PassEvery` 5 s) until the IAM lands. Is a release note enough, or must
+ the code degrade?
+8. **Tests.** Does the versioned fake model S3 faithfully (create-only over
+ a marker succeeds; a delete without a version id adds a marker)? Does R1
+ check what it claims, deterministically, without disturbing I1 to I9?
+ Is the MinIO step correct (versioning enabled before the test, the
+ local runner's policy, `versionId=null` on an unversioned bucket)?
+9. **Census.** Give a verdict for every unit and envelope in the card,
+ under AGENTS.md "The census", citing the lines you read.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The
+ census, and review of any newly changed security, root, termination
+ or production-storage behaviour, still check the fix; see AGENTS.md,
+ "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the section or task, the problem,
+the evidence (file:line, verified), the failure scenario, a concrete
+fix and the invariant or trust boundary it breaks (that is its fault
+family). Then the census verdicts, one per unit and envelope. End with
+exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites. Leave GOCACHE unset; you need
+not run tests at all, and you must not call AWS.