## ADDED Requirements

### Requirement: Runtime health endpoint
The system SHALL provide a health endpoint that checks both container and tunnel health.

#### Scenario: Full health check
- **GIVEN** a running web-enabled instance
- **WHEN** `GET /instances/{id}/health` is called
- **THEN** the response includes:
  - `container_status`: "running", "exited", "restarting", or "not_found"
  - `container_health`: "healthy", "unhealthy", or null (if no Docker healthcheck)
  - `tunnel_status`: "healthy", "unreachable", or "error_response"
  - `tunnel_status_code`: the HTTP status code from the tunnel URL, or null
  - `probe_status`: "passed", "failed", "pending", or "not_configured"
  - `healthy`: true only if container is running AND tunnel is healthy

#### Scenario: Health check for terminal-only instance
- **GIVEN** a running terminal-only instance
- **WHEN** `GET /instances/{id}/health` is called
- **THEN** the response includes `container_status: "running"`
- **AND** `tunnel_status: "not_applicable"`
- **AND** `healthy: true` if container is running

### Requirement: Continuous health polling
The system SHALL support periodic health checks from the frontend.

#### Scenario: Frontend health polling
- **GIVEN** active instances in the UI
- **WHEN** the frontend polls health every 30 seconds
- **THEN** the health status is displayed as a badge
- **AND** the badge shows "tunnel error" only when tunnel is unreachable
- **AND** the badge shows "app error" when tunnel returns 502/503/504
- **AND** the badge shows "starting" when container is up but probe is pending

### Requirement: Container state synchronization
The system SHALL update instance status when container state changes unexpectedly.

#### Scenario: Container crashes
- **GIVEN** an instance with status "running"
- **WHEN** the container exits (crash or OOM)
- **AND** a health check is performed
- **THEN** the instance status is updated to "error"
- **AND** the container exit code and logs are captured

#### Scenario: Container stopped externally
- **GIVEN** an instance with status "running"
- **WHEN** the container is stopped via docker command outside the system
- **AND** a health check is performed
- **THEN** the instance status is updated to "stopped"

## MODIFIED Requirements

None.

## REMOVED Requirements

None.
