Skip to main content

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 the x-admin-code header:
The admin code is configured via the ADMIN_CODE environment variable in packages/server/.env.

Endpoints

POST /admin/maintenance/enter

Enters maintenance mode and pauses new duel cycles. Request:
Parameters:
  • 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)
Response:
Status Fields:
  • maintenanceMode (boolean): Whether maintenance mode is active
  • reason (string): Reason for maintenance mode
  • enteredAt (string): ISO timestamp when maintenance mode was entered
  • safeToDeploy (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 resolve
  • estimatedWaitMs (number): Estimated time until safe to deploy (milliseconds)
Behavior:
  • Immediately pauses new duel cycle starts
  • Waits up to timeoutMs for active markets to resolve
  • Returns safeToDeploy: true when all markets are resolved
  • Returns safeToDeploy: false if timeout is reached with pending markets

GET /admin/maintenance/status

Checks current maintenance mode status. Request:
Response:

POST /admin/maintenance/exit

Exits maintenance mode and resumes normal operations. Request:
Response:
Behavior:
  • 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 the StreamingDuelScheduler cycle state machine:

Safe Deployment Criteria

The API returns safeToDeploy: true when:
  • No active duel is in progress
  • No pending on-chain markets need resolution
  • Current phase is idle
  • pendingMarkets === 0

Timeout Behavior

If timeoutMs is reached before safeToDeploy: true:
  • Maintenance mode remains active
  • safeToDeploy returns false
  • pendingMarkets shows remaining markets
  • estimatedWaitMs shows estimated time to completion
Recommendation: Wait for safeToDeploy: true before deploying to avoid interrupting active markets.

Error Handling

Missing Admin Code

Request:
Response:
Status Code: 401 Unauthorized

Invalid Admin Code

Request:
Response:
Status Code: 401 Unauthorized

Server Error

If the server encounters an error during maintenance mode operations: Response:
Status Code: 500 Internal Server Error

Health Endpoint Integration

The /health endpoint includes maintenance mode status: Request:
Response:
This allows monitoring systems to detect maintenance mode without admin authentication.

Best Practices

Deployment Workflow

  1. Enter maintenance mode with sufficient timeout (5-10 minutes)
  2. Poll status endpoint until safeToDeploy: true
  3. Deploy changes (git pull, restart, etc.)
  4. Wait for health check to confirm server is ready
  5. 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: