Deployment Rollback Runbook
This guide covers manual rollback procedures when automatic rollback fails or when manual intervention is required.
Overview
The deployment workflow includes automatic rollback when health checks fail. However, there may be situations where manual rollback is necessary:
- Automatic rollback fails
- Issues detected after health check window
- Need to rollback to a specific version
- Debugging requires temporary rollback
Automatic Rollback Process
When a deployment health check fails, the workflow automatically:
- Detects failure - CPU usage is zero or aliveness check fails
- Finds rollback target - Queries deployment history for last validated version
- Rebuilds previous code - Checks out and builds the rollback target
- Redeploys - Uploads the previous version to Screeps
- Creates issue - Opens a GitHub issue for investigation
Deployment History Tracking
The workflow tracks validated deployments in reports/deployments/deployment-history.json:
1 | { |
Key benefits:
- Only validated deployments are recorded (failed deployments are excluded)
- Rollback skips any versions that failed validation
- History is independent of git tag ordering
- Maintains last 5 validated versions for reliable rollback
Health Check Criteria
The deployment is considered healthy if:
- CPU > 0: Bot code is executing
- Aliveness = active: Bot API confirms execution
- Creeps exist (optional): Spawning is working
A deployment fails validation if:
- CPU usage is 0 AND aliveness check fails
Rollback Target Selection
When finding a rollback target, the system:
- Checks deployment history - Looks for the most recent validated version (excluding current)
- Falls back to git tags - If history is empty, uses
git describe --tagsas fallback
This ensures that:
- Multiple consecutive failed deployments still rollback to the last working version
- Failed versions are automatically skipped
- No infinite rollback loops can occur
Manual Rollback Procedures
Option 1: Re-run Previous Deployment
The simplest approach - trigger deployment of a known-good version:
1 | # Via GitHub CLI |
Option 2: Local Rollback
Deploy directly from your local machine:
1 | # 1. Clone the repository (if needed) |
Option 3: View Deployment History
Check the deployment history to find a known-good version:
1 | npx tsx packages/utilities/scripts/manage-deployment-history.ts show |
Output:
1 | π Deployment History |
Option 4: Direct Screeps Console
For emergency situations, deploy code directly via Screeps console:
- Go to Screeps and open your game
- Open the console (bottom of screen)
- Upload code directly via the Memory/Code panel
Note: This bypasses all automation and wonβt trigger health checks.
Rollback Decision Tree
1 | Deploy fails health check |
Verification After Rollback
After rolling back, verify the bot is operational:
1. Check Bot Aliveness
1 | export SCREEPS_TOKEN="your-token" |
Expected output:
1 | β Bot is ACTIVE and executing in game |
2. Collect Bot Snapshot
1 | npx tsx packages/utilities/scripts/collect-bot-snapshot.ts |
Verify the snapshot shows:
- CPU usage > 0
- Creeps present
- Rooms controlled
3. Check Screeps Console
Log into Screeps and verify:
- No error messages in console
- Creeps are spawning and working
- No βCPU overflowβ warnings
Preventing Future Failures
After successful rollback, investigate the root cause:
- Review deployment logs - Check GitHub Actions for errors
- Test locally - Build and dry-run deploy locally
- Check code changes - Review commits since last good version
- Validate bundle - Run
yarn analyze:systemto check build
Common Causes
| Symptom | Likely Cause | Solution |
|---|---|---|
| CPU = 0 | Syntax error | Fix code, re-deploy |
| No creeps | Spawn logic broken | Check spawn priority |
| Memory errors | Invalid Memory access | Add null checks |
| API errors | Rate limiting | Add backoff logic |
Related Documentation
Emergency Contacts
For critical issues affecting production:
- Check the #screeps channel in Discord
- Review open issues on GitHub
- Check workflow run logs for detailed errors
Last updated: 2025-11-28