Engineering BlueprintSecuritySQLiteFastAPIReliabilityCUDATestingOpen SourceSpeakOn

SpeakOn Phase 7: Reliability Drills, Prompt-Injection Hardening, and Aldeon Release Gates

Hardening SpeakOn across SQLite WAL SIGKILL drills, structured 503 AI failover, prompt sanitization, 0600/0700 filesystem modes, RTX 3070 1.92s voice…

Célio Vieira497 words3 min read

Key Takeaways (TL;DR)

Summary
  • Defense in Depth for a Local-First AI Tutor — Shipping a local voice and Mandarin tutor means hardening both traditional web/mobile attack surfaces and local AI failure modes.
  • Structured 503 Failover & Prompt-Injection Sanitization — Two subtle failure classes happen in local LLM applications: crashing with HTTP 500 when Ollama stops mid-session…
  • Five Automated Reliability Drills (scripts/drills/runreliabilitydrills.py) — Every drill runs deterministically in isolated temporary directories and exits non-zero on…
  • Live RTX 3070 GPU Benchmark & Cross-Repo Aldeon Gates — After warming en-core-web-sm and local HF/Ollama weights, the full RTX 3070 8 GB benchmark (scripts/bench_turn.py…

Defense in Depth for a Local-First AI Tutor#

Shipping a local voice and Mandarin tutor means hardening both traditional web/mobile attack surfaces and local AI failure modes. In Phase 7 of SpeakOn (Celio1878/speakon-services, commit a2fc8a7 on develop), we paired automated chaos/reliability drills with strict input sanitization, structured failover handlers, POSIX least-privilege file modes, and full cross-repo release gates.

Structured 503 Failover & Prompt-Injection Sanitization#

Two subtle failure classes happen in local LLM applications: crashing with HTTP 500 when Ollama stops mid-session, and leaving untrusted learner text undelimited in structured JSON prompts.

  • Zero Unhandled 500s (app/main.py): Global FastAPI exception handlers catch ProviderError, httpx.HTTPError, and TimeoutError, returning 503 Service Unavailable with JSON {"detail": ..., "error_code": "provider_unavailable"} across /api/sessions/{id}/turn and /api/mandarin/*.
  • Untrusted Input Delimiting (app/mandarin/ai_engines.py, app/mandarin/router.py): sanitize_untrusted_input strips ASCII control codes, zero-width spoofing characters (\u200b-\u200f, \ufeff), and closing tag breakouts before wrapping learner text in <untrusted_learner_input>...</untrusted_learner_input> across Dissect, Nuance, Coach, and Graded Stories, paired with 30 req/min per-user rate limits, a 5,000-character linguistics cap, and batch limits (<= 500 logs/attempts, <= 20 queued AI items per sync).
  • Host Least Privilege (app/core/db.py, app/cli/backup.py): Data directories stay 0o700, while SQLite WAL database files, backups, and SHA-256 backup manifests are chmodded 0o600 on POSIX.

Five Automated Reliability Drills (scripts/drills/run_reliability_drills.py)#

Every drill runs deterministically in isolated temporary directories and exits non-zero on regression:

  1. SQLite WAL kill -9 Survival (571.4 ms): Spawns a real writer subprocess, sends SIGKILL after committed WAL transactions, and verifies PRAGMA check_db_integrity returns sqlite:wal:ok with committed sessions intact.
  2. Online Backup -> Lock Guard -> Wipe -> Restore (49.4 ms): Verifies restore_backup refuses while hold_server_lock is active, wipes live DB and -wal/-shm files, restores from SHA-256 manifest, and validates integrity.
  3. Ollama Stopped Mid-Turn -> 503 (1,064.2 ms): Triggers ProviderError and CircuitOpenError across voice turns, sentence dissection, composition coaching, and story generation—asserting HTTP 503 and provider_unavailable on every route.
  4. GPU OOM -> CPU Piper Failover (4.7 ms): Forces RuntimeError("CUDA out of memory") inside Kokoro and confirms MultilingualTTSRouter fails over to MIT Piper with valid WAV bytes.
  5. Offline Pack SHA-256 & Idempotent Sync (231.5 ms): Builds and checksum-verifies the HSK 1–2 starter pack (integrity: "ok") and replays identical POST /api/mandarin/sync batches twice (0 duplicate ingestions).

Live RTX 3070 GPU Benchmark & Cross-Repo Aldeon Gates#

After warming en-core-web-sm and local HF/Ollama weights, the full RTX 3070 8 GB benchmark (scripts/bench_turn.py with llama3.1:latest) measured 1,922.9 ms warm end-to-end latency (158.3 ms STT + 1,664.4 ms LLM + 100.3 ms TTS first chunk; budget < 3,000 ms) with 5.501 GB VRAM delta (budget < 6.5 GB).

All 55 / 55 backend tests (46 CPU including test_phase7_hardening.py + 9 GPU golden roundtrips across en/es/zh/pt/de/it/fr + Silero VAD), mypy app (62 files), uvx pip-audit (0 vulnerabilities), Web Gate 1–2 (227 tests, 230 SSR renders, 192.3 KB gz landing JS), Mobile Gate 2 (14 tests, iOS & Android CNG prebuild), DNS Gate 3 (MX/TXT SPF/CNAME), and gitleaks (0 leaks across speakon-services and speakon-mobile full histories) passed on develop.

Célio Vieira

Célio Vieira

Founder & Architect

Engineering applied AI systems, distributed cloud platforms, and the Aldeon umbrella venture ecosystem.

Related Technical Dispatches

View all 90