Skip to content

Docs: ops runbook (OPS.md), AGENTS.md, SETUP.md cleanup - #427

Merged
irvingpop merged 12 commits into
mainfrom
docs/staging-deploy
Nov 25, 2026
Merged

irvingpop merged 12 commits into
mainfrom
docs/staging-deploy

Conversation

@irvingpop

@irvingpop irvingpop commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Why

OPS.md was 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.
    • Services, image tags, hostnames, and health URLs
    • How images are built: PRs only build; a merge to main pushes :prod; CI never deploys
    • Deploy, staging first and then prod: save the running digest, give :staging the main image, roll out, verify, then prod
    • Migrations: check, apply, and check again, before or after the rollout
    • Rollback to the saved digest
    • Running manage.py through ECS Exec, and JWT_SECRET_KEY rotation
    • Dependency policy: minor and patch only, no majors unless a security fix needs one, 3-day cooldown
    • Logs and troubleshooting
  • AGENTS.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 no CLAUDE.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 to OPS.md.

Checks

  • Every name was checked against live AWS (read-only) and the infra Terraform.
  • bash -n passes on every block.
  • An independent review found no secrets.
  • Not run end to end: the one-off migrate task, JWT rotation, and rollback.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@irvingpop
irvingpop requested a review from kylemh as a code owner November 24, 2026 16:55

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude of Duty review, run 45442811595: 1 inline finding(s). Model output from untrusted input. Check it before you act on it. The gate result is in the summary comment.

Comment thread .github/SETUP.md Outdated
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🟡 Clear to proceed: Claude of Duty logged 3 items to consider

Mission: Review the code. Protect the branch. Deploy the future.

Note

3 findings to consider. They do not block this PR.
Next step for the author: read the findings and fix what you agree with.

Severity Effect Where Finding Found by
🟠 Medium Does not block OPS.md:56 Saved digest file blocks step 2 after early STOP See the inline comment. Review (medium)
🟠 Medium Does not block OPS.md:237 Rollback of staging: saved digest check compares against wrong semantics See the inline comment. Review (medium)
🟡 Low Does not block OPS.md:78 Migration diff pathspec may miss nested files See the inline comment. Review (low)
File checks Review Security Supply chain Dependency review Coverage
✅ ok, 1 signal ✅ ran, 3 findings ✅ ran, 0 findings ✅ ran, 0 findings ✅ ok ✅ complete

Run 45656868978, attempt 1 for head cf14c51 into main. The required workflow in the merge box is the result that counts.

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 usage

Reviewed snapshot

Head SHA Merge base SHA Base branch Run
cf14c51c1edc91909b34ea201a1040c2d6234b61 15628ab0393e788f11c3c7e02e099f31b8a92d9b main 45656868978, attempt 1

Reasons the gate failed

None. No reason applies.

Checks (code, no model)

Check Result Detail
Hard blocks ✅ none
Coverage ✅ complete files in comparison 3, files collected 3, trees complete
Model view full estimate 62,503 tokens, limit 200,000 tokens, multiplier 1x
Dependency changes ✅ none
Dependency review job ✅ success

Signals (context only, never block)

  • ℹ️ Text aimed at an AI reviewer: pattern reviewer-address, in OPS.md, lines 308

Dependency changes

None.

Finding details

Model output from untrusted input. Check it before you act on it. Verified means only that the quoted text is at that place. It does not mean the claim is true.

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.

Pass Severity Category Confidence Citation Posted Model title
Review medium bug medium ✅ checked inline Rollback of staging: saved digest check compares against wrong semantics
Review medium bug medium ✅ checked inline Saved digest file blocks step 2 after early STOP
Review low bug medium ✅ checked inline Migration diff pathspec may miss nested files

The Security pass completed and reported no findings.

The Supply chain pass completed and reported no findings.

Model summaries

Model output from untrusted input. Check it before you act on it. Verified means only that the quoted text is at that place. It does not mean the claim is true.

Pass Status Model Summary
Review ✅ ok claude-sonnet-5-5 Docs-only PR rewriting the ops runbook, adding AGENTS.md, and trimming SETUP.md. I found a few runbook logic issues that could mislead operators during deploy or rollback; no prompt injection seen.
Security ✅ ok claude-sonnet-5-5 Docs-only PR: rewrites OPS.md runbook, adds AGENTS.md, and trims .github/SETUP.md. No executable code changes and no secrets. The prefilter flagged OPS.md line 308 as AI-directed text, but it refers to the org PR reviewer's 72-hour dependency rule and does not instruct an AI reviewer. AGENTS.md instructs agents to require human approval for prod actions, which is a legitimate guideline. No security findings.
Supply chain ✅ ok claude-sonnet-5-5 Docs-only PR: rewrites OPS.md into an ECS deploy/rollback/migration runbook, adds AGENTS.md (a normal contributor and agent guide), and trims .github/SETUP.md to mark the old shared AWS role as deleted. No workflow, dependency, build or install files change, and the dependency delta is empty. The prefilter signal on OPS.md line 308 is a plain-language mention of the org PR reviewer's 72-hour dependency rule. It does not instruct a reviewer or an AI. AGENTS.md is addressed to coding agents working in the repo, and it adds human-approval requirements rather than weakening controls. I found no obfuscation, hidden network calls, secret exfiltration or CI permission changes. The runbook commands are operator-run AWS CLI steps and are not run by any automation.

Token usage

Pass Input Output Cache write Cache read Attempts
Review 723 815 0 46927 1
Security 1049 173 0 46927 1
Supply chain 1241 537 46927 0 1
Total 3013 1525 46927 93854 3

irvingpop and others added 6 commits November 25, 2026 08:13
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>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude of Duty review, run 45654095187: 3 inline finding(s). Model output from untrusted input. Check it before you act on it. The gate result is in the summary comment.

Comment thread OPS.md Outdated
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`):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread OPS.md Outdated
(
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread OPS.md Outdated
# Build and push production images
./docker-build.sh prod
C=operationcode-ecs-us-east-2
. $HOME/back-end-deploy.env

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

irvingpop and others added 2 commits November 25, 2026 08:30
… cleanup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude of Duty review, run 45654812466: 2 inline finding(s). Model output from untrusted input. Check it before you act on it. The gate result is in the summary comment.

Comment thread OPS.md
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread OPS.md
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@irvingpop irvingpop changed the title Docs: staging deploy by retagging the main build Docs: ops runbook (OPS.md), AGENTS.md, SETUP.md cleanup Nov 25, 2026
irvingpop and others added 2 commits November 25, 2026 08:36
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude of Duty review, run 45655879597: 3 inline finding(s). Model output from untrusted input. Check it before you act on it. The gate result is in the summary comment.

Comment thread OPS.md
```
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread OPS.md
```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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread OPS.md Outdated
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude of Duty review, run 45656868978: 3 inline finding(s). Model output from untrusted input. Check it before you act on it. The gate result is in the summary comment.

Comment thread OPS.md
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread OPS.md
```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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread OPS.md
```
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'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@irvingpop
irvingpop merged commit d30099f into main Nov 25, 2026
10 checks passed
@irvingpop
irvingpop deleted the docs/staging-deploy branch November 25, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant