Maintenance Mode API
The Maintenance Mode API enables graceful deployments by pausing new duel cycles and waiting for active markets to resolve before deploying code changes.Overview
Maintenance mode prevents data loss and incomplete transactions during deployments by:- Pausing new duel cycle starts
- Allowing active duels to complete naturally
- Waiting for on-chain markets to resolve
- Providing deployment safety status
Authentication
All maintenance mode endpoints require admin authentication via thex-admin-code header:
ADMIN_CODE environment variable in packages/server/.env.
Endpoints
POST /admin/maintenance/enter
Enters maintenance mode and pauses new duel cycles. Request:reason(string, optional): Reason for entering maintenance mode (e.g., “deployment”, “emergency”)timeoutMs(number, optional): Maximum time to wait for safe deployment state (default: 300000 = 5 minutes)
maintenanceMode(boolean): Whether maintenance mode is activereason(string): Reason for maintenance modeenteredAt(string): ISO timestamp when maintenance mode was enteredsafeToDeploy(boolean): Whether it’s safe to deploy (no active markets)currentPhase(string): Current duel cycle phase (idle,betting,fighting,resolving)pendingMarkets(number): Number of active markets that need to resolveestimatedWaitMs(number): Estimated time until safe to deploy (milliseconds)
- Immediately pauses new duel cycle starts
- Waits up to
timeoutMsfor active markets to resolve - Returns
safeToDeploy: truewhen all markets are resolved - Returns
safeToDeploy: falseif timeout is reached with pending markets
GET /admin/maintenance/status
Checks current maintenance mode status. Request:POST /admin/maintenance/exit
Exits maintenance mode and resumes normal operations. Request:- Immediately exits maintenance mode
- Resumes duel cycle scheduling
- Next cycle starts according to normal schedule
Usage Examples
Manual Deployment
Automated CI/CD
The GitHub Actions workflow (.github/workflows/deploy-vast.yml) automates this process:
Emergency Maintenance
For emergency maintenance (e.g., critical bug fix):Integration with Duel System
Cycle State Machine
The maintenance mode integrates with theStreamingDuelScheduler cycle state machine:
Safe Deployment Criteria
The API returnssafeToDeploy: true when:
- No active duel is in progress
- No pending on-chain markets need resolution
- Current phase is
idle pendingMarkets === 0
Timeout Behavior
IftimeoutMs is reached before safeToDeploy: true:
- Maintenance mode remains active
safeToDeployreturnsfalsependingMarketsshows remaining marketsestimatedWaitMsshows estimated time to completion
safeToDeploy: true before deploying to avoid interrupting active markets.
Error Handling
Missing Admin Code
Request:Invalid Admin Code
Request:Server Error
If the server encounters an error during maintenance mode operations: Response:Health Endpoint Integration
The/health endpoint includes maintenance mode status:
Request:
Best Practices
Deployment Workflow
- Enter maintenance mode with sufficient timeout (5-10 minutes)
- Poll status endpoint until
safeToDeploy: true - Deploy changes (git pull, restart, etc.)
- Wait for health check to confirm server is ready
- Exit maintenance mode to resume operations
Timeout Configuration
- Development: 60000ms (1 minute) - faster iteration
- Staging: 180000ms (3 minutes) - moderate safety
- Production: 300000ms (5 minutes) - maximum safety
Error Recovery
If deployment fails after entering maintenance mode:Monitoring
Monitor maintenance mode status during deployments:Related Documentation
- docs/vast-deployment.md - Vast.ai deployment guide
- .github/workflows/deploy-vast.yml - Deployment workflow
- packages/server/src/startup/maintenance-mode.ts - Implementation
- packages/server/src/startup/routes/admin-routes.ts - Route handlers