8 scenarios
Resiliencev2.1
Scenarios8
Critical2
Auto-recover8/8

Resilience Layer

Failure Scenarios

RAFIQ is designed to fail gracefully. Every failure mode has a documented detection mechanism, an immediate fallback, and a recovery path. The system never enters an undefined state — every error is a known, handled scenario.

Internet / Cloud Failure

HIGH
01 Detection

HTTP timeout to Supabase health endpoint (5s timeout, 3 retries)

02 Fallback

Sync engine switches to offline queue mode. All writes continue locally. Cloud push paused.

03 Recovery

Auto-reconnect with exponential backoff. On reconnect: drain queue in priority order (Critical → Low).

04 Metrics

RTO: < 30s to detect, instant fallback RPO: 0 — no data lost

MQTT Broker Failure

HIGH
01 Detection

Client disconnect callback fired. Core engine loses MQTT connection.

02 Fallback

Core engine switches to direct API polling mode. Wearable data buffered at gateway. HA commands via direct REST.

03 Recovery

Mosquitto auto-restarts via systemd. Client reconnects with clean session. Re-subscribes all topics.

04 Metrics

RTO: < 10s (systemd auto-restart) RPO: Low — buffered at gateway

AI Inference Timeout

MEDIUM
01 Detection

AI orchestrator enforces 5s timeout per inference call. Alert if >3 consecutive timeouts.

02 Fallback

Rules engine takes over health analysis. Predefined threshold rules replace LLM reasoning. Simpler but reliable.

03 Recovery

Ollama watchdog restarts the process. Model reloaded from disk (GGUF). Inference resumes in ~30s.

04 Metrics

RTO: < 35s to restart RPO: 0 — rules engine covers the gap

SQLite Corruption

CRITICAL
01 Detection

PRAGMA integrity_check on startup and hourly. Any non-"ok" result triggers alert.

02 Fallback

Read-only mode from WAL snapshot. Writes buffered in memory. Emergency data preserved.

03 Recovery

Restore from last Supabase full dump. Apply local WAL changes on top. Re-sync from cloud.

04 Metrics

RTO: < 5min with recent cloud backup RPO: Seconds to minutes depending on last sync

Wearable BLE Disconnect

MEDIUM
01 Detection

BLE RSSI drop below -90dBm + connection timeout (5s). LWT message on MQTT.

02 Fallback

Last known vitals cached and used for 5 minutes. Emergency engine continues with cached values.

03 Recovery

BLE gateway auto-scans for device every 5s. Reconnects and re-subscribes GATT notifications.

04 Metrics

RTO: < 15s to reconnect if in range RPO: 0 — no reads lost, stale data clearly flagged

Home Assistant Crash

MEDIUM
01 Detection

WebSocket connection to HA drops. HTTP health check fails.

02 Fallback

Direct MQTT device control bypasses HA. Core publishes to device topics directly.

03 Recovery

HA service auto-restarts via systemd. Core reconnects WebSocket and re-syncs device states.

04 Metrics

RTO: < 30s (systemd restart) RPO: 0 — direct MQTT control active

ESP32 Emergency MCU Offline

CRITICAL
01 Detection

MQTT LWT message from Raqeeb MCU. No heartbeat for 30s.

02 Fallback

Core engine polls sensors directly via alternative I2C bus. Emergency engine continues with direct hardware access.

03 Recovery

ESP32 watchdog timer auto-resets the MCU (10s). MQTT LWT cleared on reconnect.

04 Metrics

RTO: < 15s (watchdog reset) RPO: 0 — direct sensor polling active

Memory Pressure (RAM > 85%)

MEDIUM
01 Detection

System monitor checks RAM every 60s. Alert at 75%, action at 85%.

02 Fallback

Evict LLM model cache. Reduce AI context window. Restart non-critical services (voice pipeline, caches).

03 Recovery

Services restart with lower memory profile. Swap space used as emergency buffer if needed.

04 Metrics

RTO: < 60s to restore headroom RPO: 0 — no data affected

Failure Matrix

All 8 scenarios are auto-recovering — no manual intervention required

FailureSeverityRTO (Recovery Time)RPO (Data Loss)
Internet / Cloud FailureHigh< 30s to detect, instant fallback0 — no data lost
MQTT Broker FailureHigh< 10s (systemd auto-restart)Low — buffered at gateway
AI Inference TimeoutMedium< 35s to restart0 — rules engine covers the gap
SQLite CorruptionCritical< 5min with recent cloud backupSeconds to minutes depending on last sync
Wearable BLE DisconnectMedium< 15s to reconnect if in range0 — no reads lost, stale data clearly flagged
Home Assistant CrashMedium< 30s (systemd restart)0 — direct MQTT control active
ESP32 Emergency MCU OfflineCritical< 15s (watchdog reset)0 — direct sensor polling active
Memory Pressure (RAM > 85%)Medium< 60s to restore headroom0 — no data affected