Repository navigation
Docs: ops runbook (OPS.md), AGENTS.md, SETUP.md cleanup - #427
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Merging to `main` builds the `runtime` target and pushes `back-end:prod`. Staging gets the same image, so it tests exactly what prod will run. | ||
|
|
||
| A dispatch on `main` pushes `:prod`, and it also needs approval. | ||
| 1. Save the running digest for a rollback, for each service: |
There was a problem hiding this comment.
low bug, confidence medium, pass review
Rollback digest step only captures prod, not staging
The step says 'for each service' but the snippet queries only python_backend_prod. Staging's digest is not saved, so the staging rollback (which retags :staging) has no saved digest. Also, since staging is retagged to :prod's image, the staging rollback needs its own prior digest. The same snippet is also the only place that defines $C, which later steps depend on.
Model output from untrusted input. Check it before you act on it.
🟡 Clear to proceed: Claude of Duty logged 3 items to considerMission: Review the code. Protect the branch. Deploy the future. Note 3 findings to consider. They do not block this PR.
Run 45656868978, attempt 1 for head Claude of Duty never approves a PR. A human reviewer gives the final approval. 📋 Full review record: reasons, checks, signals, finding details, model summaries, token usageReviewed snapshot
Reasons the gate failed None. No reason applies. Checks (code, no model)
Signals (context only, never block)
Dependency changes None. Finding details
Blocking is decided by code from category and severity, never by the model. A finding in a blocking category blocks only at high or critical severity.
The Security pass completed and reported no findings. The Supply chain pass completed and reported no findings. Model summaries
Token usage
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hecks Step 2b implied a one-off task before the retag, but the task definition pins a tag, so that task would run the old image without the new migrations. Now: retag, run migrate in a one-off task (run-task with a command override, wait tasks-stopped, check exitCode), then deploy. Also check the rollback manifest before put-image, and set C in the JWT rotation block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each multi-step block in OPS.md now runs in a set -euo pipefail subshell with explicit "if ...; then echo STOP; exit 1; fi" checks. The digest, health, and log checks of steps 3, 3b, 4 and the rollback verify are now automatic. The JWT block no longer uses an && list that set -e ignores. AGENTS.md: a short guide for humans and agents, matching the pybot one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches pybot #474: a re-run of step 2 after a failed deploy must not replace the good rollback digest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| echo "step 4 OK" | ||
| ) | ||
| ``` | ||
| 5. Migrations on staging (the new image has the migration files, so run this after the rollout). First list the pending ones (ECS Exec, see section 5 for `$T`): |
There was a problem hiding this comment.
medium bug, confidence medium, pass review
Step 5 relies on $T/$S from step 4 or section 5 that may be unset
Step 5 uses $C, $S and $T, but the step 4 block sets T outside the subshell and S for staging only if run in the same shell. After step 4's later prod run (step 8), $S/$T point to prod, so repeating step 5 for staging in the same shell would run migrations on the wrong service. Step 5 never sets S/T itself, and the T captured in step 4 may refer to a task that has since been replaced.
Model output from untrusted input. Check it before you act on it.
| ( | ||
| set -euo pipefail | ||
| D=$HOME/back-end-deploy.env | ||
| if [ -s $D ]; then echo "STOP: $D exists. Roll back with it, or delete it after a finished deploy"; exit 1; fi |
There was a problem hiding this comment.
medium bug, confidence medium, pass review
Digest file never cleaned up by the procedure; next deploy blocks
Step 2 refuses to run if the file exists, but no step in the deploy tells the operator to delete it after a successful deploy; it is only mentioned in prose. Also the file is created empty (`: > $D`) before digests are fetched, and if a later check fails (e.g. prod has no digest) the partially written file remains, so the rerun fails with the STOP message while the file lacks a digest for prod, and rollback would source a missing PROD_DIGEST.
Model output from untrusted input. Check it before you act on it.
| # Build and push production images | ||
| ./docker-build.sh prod | ||
| C=operationcode-ecs-us-east-2 | ||
| . $HOME/back-end-deploy.env |
There was a problem hiding this comment.
low bug, confidence medium, pass review
Rollback sources file with set -u not applied; missing variable yields empty DIGEST
The rollback line `DIGEST=$PROD_DIGEST` runs outside the set -euo subshell. If the file is partial or lacks the variable, DIGEST is empty and the check catches it, but the shell is not in nounset mode so it works only by luck; if the operator's shell has `set -u`, the interactive shell may abort. Minor robustness issue.
Model output from untrusted input. Check it before you act on it.
… cleanup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| G=$(aws ecs describe-tasks --cluster $C --tasks "$T" --query 'tasks[0].containers[0].imageDigest' --output text) | ||
| P=$(aws ecr describe-images --repository-name back-end --image-ids imageTag=prod --query 'imageDetails[0].imageDigest' --output text) | ||
| echo "health $H, task $G, :prod $P" | ||
| if [ "$H" != HEALTHY ] || [ "$G" != "$P" ]; then echo "STOP: 4a failed"; exit 1; fi |
There was a problem hiding this comment.
medium bug, confidence medium, pass review
Step 4 prod check compares task digest to :prod, fails after migrate/rollback cases
Step 4 is reused for prod (step 8) and for staging. After a prod rollback or when :prod moves (a new merge to main mid-deploy), the task digest legitimately differs from the current :prod digest, so the check reports failure for a good deploy. For staging it is correct, but the 'run again for prod' reuse relies on :prod not changing between step 3 and step 8; a merge to main in that window makes it a false STOP and may push the operator into an unneeded rollback.
Model output from untrusted input. Check it before you act on it.
| export AWS_PROFILE=operationcode AWS_REGION=us-east-2 | ||
| C=operationcode-ecs-us-east-2 | ||
| D=$HOME/back-end-deploy.env | ||
| if [ -s $D ]; then echo "STOP: $D exists: a previous deploy or rollback was not finished. If it was finished, run: rm $D"; exit 1; fi |
There was a problem hiding this comment.
low bug, confidence medium, pass review
Saved-digest guard uses -s so an empty leftover file is not detected
Step 2 does `: > $D` before the loop. If the loop fails (e.g. no digest for prod), the file is left partly written or empty. An empty file passes the `-s` test on re-run, while a partial one blocks; a partially written file with only the STAGING digest then makes rollback of prod fail with an unset PROD_DIGEST under `set -u`. The failure path does not clean up the file.
Model output from untrusted input. Check it before you act on it.
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
| ``` | ||
| ECS Exec can return 0 even when the command in the container fails, so read the output. If `migrate` fails, STOP. Do not go to prod. A code rollback does not undo applied migrations. | ||
| 6. Check staging again after the migration: run the step 4 block again. | ||
| 7. Prod: `:prod` is already the image, so do not retag. On the migrate-first path, first run the step 3b block with `S=python_backend_prod`. Then deploy: |
There was a problem hiding this comment.
medium bug, confidence medium, pass review
Migrate-first on prod runs on old task def/image, order inconsistent with staging
Step 3b relies on the tag having just been moved to the new image. For prod, a one-off task started from the current task definition pulls :prod, which is fine only if no running-task digest mismatch occurs. The check at the end compares the task digest to the tag digest, which is fine, but the runbook also says the saved digest file must exist and step 2b is per deploy. Low risk, but the ordering is subtle.
Model output from untrusted input. Check it before you act on it.
| ```bash | ||
| gh run list -R OperationCode/back-end --workflow ci.yml --branch main --limit 3 | ||
| ``` | ||
| 2. Save the running digest of each service in a file, and print it. You need it for a rollback. A new terminal loses shell variables, the file does not. Run this step one time per deploy, before step 3. It refuses to overwrite a saved digest, so a failed deploy cannot replace the good digest with a bad one. Step 10 (deploy) and the end of section 4 (rollback) delete the file: |
There was a problem hiding this comment.
medium bug, confidence medium, pass review
Digest file is never cleaned after a failed staging deploy with no rollback path
Step 2 refuses to run when the digest file exists, and the file is deleted only at step 10 or after a rollback. If a deploy is aborted at a STOP before any change (e.g. step 2b says ask a maintainer), the file remains and blocks the next run until removed by hand. The error message does tell the user to rm it, so impact is minor.
Model output from untrusted input. Check it before you act on it.
| T=$(aws ecs list-tasks --cluster $C --service-name $S --query 'taskArns[0]' --output text) | ||
| G=$(aws ecs describe-tasks --cluster $C --tasks "$T" --query 'tasks[0].containers[0].imageDigest' --output text) | ||
| if [ -z "$G" ] || [ "$G" = None ]; then echo "STOP: no digest for $S"; exit 1; fi | ||
| echo "$(echo ${S#python_backend_} | tr a-z A-Z)_DIGEST=$G" >> $D |
There was a problem hiding this comment.
low bug, confidence medium, pass review
Digest file written with unquoted/untrusted value then sourced
The file is later sourced with `.` in the rollback block. If the describe-tasks output is multi-word or empty strings pass the check, sourcing could misbehave. Also, with `set -u`, if only one service line was saved (partial failure after the first loop iteration), rollback of the other env fails with an unbound variable.
Model output from untrusted input. Check it before you act on it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| S=python_backend_$ENV TAG=$ENV | ||
| case $ENV in prod) DIGEST=$PROD_DIGEST;; staging) DIGEST=$STAGING_DIGEST;; *) echo "STOP: ENV must be prod or staging"; exit 1;; esac | ||
| if [ -z "$DIGEST" ] || [ "$DIGEST" = None ]; then echo "STOP: no saved digest"; exit 1; fi | ||
| CUR=$(aws ecr describe-images --repository-name back-end --image-ids imageTag=$TAG --query 'imageDetails[0].imageDigest' --output text 2>/dev/null || echo none) |
There was a problem hiding this comment.
medium bug, confidence medium, pass review
Rollback of staging: saved digest check compares against wrong semantics
Rollback retags :prod or :staging to the saved digest. For ENV=prod the saved PROD_DIGEST is the pre-deploy digest, which is correct. But the deploy step 2 saves digests of running tasks, and step 3 of deploy retags :staging to :prod, so a staging rollback restores the old staging task digest; fine. However the step 4 check requires task digest == :prod, which will fail on a normal prod deploy if :prod moved again mid-deploy. Low impact.
Model output from untrusted input. Check it before you act on it.
| ```bash | ||
| gh run list -R OperationCode/back-end --workflow ci.yml --branch main --limit 3 | ||
| ``` | ||
| 2. Save the running digest of each service in a file, and print it. You need it for a rollback. A new terminal loses shell variables, the file does not. Run this step one time per deploy, before step 3. It refuses to overwrite a saved digest, so a failed deploy cannot replace the good digest with a bad one. Step 10 (deploy) and the end of section 4 (rollback) delete the file: |
There was a problem hiding this comment.
medium bug, confidence medium, pass review
Saved digest file blocks step 2 after early STOP
If a deploy stops before any change (e.g. step 2b says STOP and ask a maintainer, or step 1 fails), the digest file already exists and no step tells you to delete it. The next step 2 refuses to run until the operator removes it by hand. Rollback guidance deletes it only after a rollback.
Model output from untrusted input. Check it before you act on it.
| ``` | ||
| 2b. Check for a migration that must run before the rollout. List the migration files that are new since the last deploy (`<last deployed commit>` is the `main` commit of the previous deploy): | ||
| ```bash | ||
| git fetch origin && git diff --name-only <last deployed commit> origin/main -- 'src/**/migrations/*.py' |
There was a problem hiding this comment.
low bug, confidence medium, pass review
Migration diff pathspec may miss nested files
Git pathspecs treat `**` literally only with the :(glob) magic. In default mode `*` matches slashes, so it generally works. But the `<last deployed commit>` is not recorded anywhere by the runbook, so the operator cannot reliably fill it in, and the check can be skipped or wrong.
Model output from untrusted input. Check it before you act on it.
Why
OPS.mdwas out of date: wrong log groups, old procedures, and no deploy, migration, or rollback steps. The app is in maintenance mode, so humans and AI agents need one short, correct runbook and clear rules for working in a public repo.What changes
OPS.md(rewritten): a runbook with numbered, copy-paste steps. Each block sets its own variables and stops at the first failed check.mainpushes:prod; CI never deploys:stagingthemainimage, roll out, verify, then prodmanage.pythrough ECS Exec, andJWT_SECRET_KEYrotationAGENTS.md(new, 24 lines): maintenance mode, public-repo care, how to work here, and human approval before any prod action. Claude Code reads it natively; there is noCLAUDE.md..github/SETUP.md: the switch-over of the old shared AWS role is marked done (the role was deleted on 2026-11-23), and deploy steps now point toOPS.md.Checks
bash -npasses on every block.migratetask, JWT rotation, and rollback.🤖 Generated with Claude Code