Skip to content

Runbook: resize the forge instance for a large import

cms-ai-forge-prd is sized for its steady state, which is near-idle: a FastAPI control plane plus a beat schedule. A full-site WordPress import is a different workload entirely, and it is the only thing on this service that needs real CPU.

This runbook covers scaling the box up for such an import and back down afterwards.

When to use it

Use it for a full-site import -- POST /migrate_from_wp over a whole WordPress corpus. For scale: the prod wantskicks import (2026-08-11) was 1,081 articles and roughly 66,000 image copy tasks, and took about 40 minutes on 8 vCPUs.

Do not bother for: a handful of articles, a re-drive of a few failed tasks, or anything measured in hundreds rather than tens of thousands of tasks. The steady state box handles those fine, and a resize costs a restart.

Why the instance is small by default

CloudWatch over a representative week:

date avg CPU max CPU
2026-08-06 0.29% 24.61%
2026-08-07 0.19% 2.16%
2026-08-08 0.19% 0.61%
2026-08-09 0.20% 8.70%
2026-08-10 0.20% 8.65%
2026-08-11 (import) 4.88% 92.59%

Memory peaked at 1.7 GB of 15.6 GB, so RAM does not size this box -- only the import's CPU burst does. Running a c5.2xlarge continuously to serve a burst that happens once per site onboarding is the waste this arrangement avoids.

You do NOT need to set the concurrency

The Celery pool size is computed in the container, on every start:

--concurrency ${FORGE_WORKER_CONCURRENCY:-$(( $(nproc) * 3 ))}

So it follows the instance automatically:

instance vCPU resulting pool
t3.large 2 6
c5.xlarge 4 12
c5.2xlarge 8 24

This is deliberately computed at container start rather than written into .env by scripts/after_install: that hook is a CodeDeploy step that runs on deploy, not on boot, and the procedure below never redeploys. A value baked in at deploy time would be the old box's number exactly when the box changes size.

Set FORGE_WORKER_CONCURRENCY explicitly only to override the heuristic for a one-off -- for example to throttle the pool when the source WordPress site is rate-limiting. Add it to /opt/cms-ai-forge/.env and restart the worker, and remember to remove it afterwards, or it will outlive the reason it was set.

Scale up

Do not resize while an import is in flight -- in-flight tasks would need re-driving. Start from a quiet worker.

INSTANCE=i-0062cb6bcbc6f6c4c

aws ec2 stop-instances  --instance-ids "$INSTANCE"
aws ec2 wait instance-stopped --instance-ids "$INSTANCE"

aws ec2 modify-instance-attribute --instance-id "$INSTANCE" \
    --instance-type c5.2xlarge

aws ec2 start-instances --instance-ids "$INSTANCE"
aws ec2 wait instance-running --instance-ids "$INSTANCE"

Then run the verification below before submitting the import. A pool that came back at the old size means the containers did not restart cleanly, and importing into that is how a 40-minute job becomes a 3-hour one.

Scale back down

Once the import has settled -- confirm with zero non-terminal tasks, not a quiet log; see the note at the end -- reverse it:

aws ec2 stop-instances  --instance-ids "$INSTANCE"
aws ec2 wait instance-stopped --instance-ids "$INSTANCE"
aws ec2 modify-instance-attribute --instance-id "$INSTANCE" \
    --instance-type t3.large
aws ec2 start-instances --instance-ids "$INSTANCE"
aws ec2 wait instance-running --instance-ids "$INSTANCE"

Verify after either direction

Run all four. The pool check is the one that actually proves the resize took.

# 0. the private IP is expected to persist across stop/start (same ENI), but
#    confirm it -- the bastion hop and host checks use it.
aws ec2 describe-instances --instance-ids "$INSTANCE" \
    --query 'Reservations[].Instances[].PrivateIpAddress' --output text

# 1. all five containers up, api healthy
sudo docker ps --format '{{.Names}} {{.Status}}'
#    expect: forge-api (healthy), forge-worker, forge-beat, redis, nginx

# 2. host vCPU count
nproc

# 3. the pool matches the box (expect 3x the number from step 2)
sudo docker exec cms-ai-forge_forge-worker_1 \
    celery -A forge.workers.celery_app inspect stats
#    read pool.processes -- its length is the live pool size.
#    NOTE: the "max-concurrency" field reports the CONFIGURED value and can be
#    stale; count pool.processes instead.

# 4. the service answers through the load balancer
curl -s -o /dev/null -w '%{http_code}\n' http://cms-ai-forge-prd.skyneto.com/api/status
#    expect 200

Reach the host through the bastion (see .claude/rules/bastion-access.md):

ssh -i ~/.ssh/bastion.pem ec2-user@<bastion> \
    "ssh -i ~/.ssh/skynet-prd.pem ubuntu@<private-ip> '<command>'"

Choosing a different size

The 3x multiplier is a heuristic for a fetch/PUT-bound workload, not a benchmarked optimum. Each image task spends most of its wall-clock waiting on a source fetch and four S3 PUTs; the WebP encode is real but a minority. That is why the pool can exceed core count without contending.

Two failure modes bound it, and both have been observed:

  • Too high on a small box. Raising 4 to 8 on a 2-vCPU t3.large produced no extra throughput -- the source site serves at a roughly fixed rate, so each fetch simply got proportionally slower.
  • Too low on a large box. One process per CPU left a c5.2xlarge at 4.4-6.0 of 8 cores during an import -- real idle headroom.

If a future import saturates CPU, or the source site starts returning 429s, lower FORGE_WORKER_CONCURRENCY rather than resizing. The right number depends on the encode/fetch balance of the corpus being imported, and that moves.

Knowing when an import is actually finished

A quiet log is not completion. A chord-driven import can plateau for 25+ minutes and then resume -- this has caused a false "finished" call before. The reliable signal is zero non-terminal tasks:

SELECT COUNT(*) FROM generation_tasks t
JOIN generation_jobs j ON j.id = t.job_id
WHERE j.created_at > <import start>
  AND t.state NOT IN ('done', 'dead', 'canceled');

Jobs left at running with zero non-terminal tasks are bookkeeping stragglers, not live work.