# Phase 4 - Validate quality/cost and prove controlled switch/rollback Copy this prompt into a fresh implementation session in the repository. ```text Implement Phase 4 of the active FOUR-phase local S2S plan only: Validate quality/cost and prove controlled switch/rollback. Do not execute the archived eight-stage prompts. Prerequisite: Phase 3 accepted. Frozen corpus/model profiles, bounded live evaluation authorization and reviewable deployment/rollback configuration are available. Required visible outcome: A paired OpenAI/local scorecard supports the deployment decision, and the preserved OpenAI container is demonstrably restorable without rebuild. Execution rules: - Read docs/plans/local-s2s-adapter-plan.md and docs/plans/local-s2s-adapter-progress.md first. Read applicable AGENTS.md, repository skills and governing API/database/workflow sections. Inspect current code; historical defaults are not current evidence. - Implement only this phase. Check actual prerequisite artifacts, not just the existence of code. State observed, simulated, unverified and blocked outcomes separately. - Preserve OpenAI/Gemini behavior, original operational/rollback containers/images, frozen old profiles and unrelated working-tree changes. No database reset, compose down, pruning or implicit provider switch. - Keep existing browser PCM24k/application events, backend-derived identity, one canonical search implementation, document/chunk references and authorization/revision checks. - Make the smallest scoped change. No plugin framework, full runtime rewrite, new broker or unrelated refactor. Update intentional contracts and affected consumers coherently; never edit applied migrations. - Ordinary tests are provider-free. DB acceptance requires a verified disposable TEST_DATABASE_URL and --require-postgres; never production. Do not run a parallel application API against the operational database. - Reuse explicit authorization already present. Paid requests, downloads and operational switching need the applicable bounded authorization. Without it, finish independent offline preparation, identify the exact missing prerequisite and keep dependent live acceptance open. - Do not print keys/full environments/raw provider payloads or real user speech. Consent-controlled fixture artifacts are separate from default logs. - Never fake provider events, terminal success or history acknowledgements. Unsupported capabilities fail safely. Do not introduce automatic cross-provider fallback. - Before finishing: inspect diff, run meaningful checks, record exact commands/results and demo steps, update the progress ledger and list all not-run checks. Do not accept a phase with required live/human checks unrun. Do not begin the next phase. Required work: - Run paired Persian fixtures with the same authorized corpus and expected facts: names/roles, numbers/dates/conditions, noise/pauses/corrections, ambiguity, no evidence, follow-up and topic switch. - Measure first audible response after speech end, tool time, interruption stop, underruns, duplicates, disconnects and successful tasks. Count actual model usage, STT duration, TTS units, startup/failure/abandoned work; unknown cost stays unknown. - Fault-test quota, slow/down endpoints, partial stream loss, restart, saturation and teardown; no unbounded queues, retry storms or stale output. Use human listening separately from deterministic checks. - Set/accept thresholds before evaluation. Provisional targets: zero critical factual fixture errors, p95 first-audible latency <= baseline + 1 second, no persistent underruns and cost per successful task <= 70% baseline for cost-saving promotion. - Change one component at a time and report failures honestly. If quality/cost targets fail, keep OpenAI rather than silently changing thresholds or padding buffers. - Finalize opt-in Compose, .env.example and operator runbook. Keep original container/image/config intact and separately tag candidate. Check any schema change against the old image; incompatible schema blocks simple rollback. - Complete all reviewable preparation before operational switching. With explicit authorization, drain/close sessions, stop current API, then start candidate on operational DB. Never run both APIs against it simultaneously. - Verify fresh-session greeting, RAG, sources, interruption and close; actually stop candidate/start preserved OpenAI without rebuild and verify a fresh baseline session. - Leave final provider as explicitly requested. Record IDs/digests/commands/checks and limitations; container rollback is not DB/filesystem rollback or seamless media resume. Acceptance criteria: - Required paired factual, human-quality, failure and resource checks have actual evidence and sample counts; missing live checks block promotion. - Cost-saving claims include failed/abandoned/startup usage; model pricing alone is not measured service savings. - Original OpenAI restoration has actually succeeded and users/ingestion data are preserved. One API owns the operational lifecycle at a time. - Final provider is explicitly recorded. Without switch authorization, prepare the result and remain operationally unchanged rather than claiming deployment completion. Relevant areas; verify actual paths first: Evaluation harness/fixtures/usage diagnostics, opt-in Compose configuration, .env.example, operator runbook and phase evidence; code changes only for demonstrated defects. Validation: Focused/provider-free tests, isolated PostgreSQL acceptance, controlled faults, authorized paired real-provider checks and human listening; config/image inspection and controlled fresh-session switch/rollback. Visible demo: Play paired Persian name/date clips and show the scorecard. If authorized and accepted, demonstrate local RAG then OpenAI rollback without rebuilding the preserved container. Stop/narrow condition: Quality/cost evidence and explicit operational switch authorization are separate gates within this phase. Prepare independent work but do not bypass either. Deliver scoped implementation/configuration/tests/contracts as necessary, docs/evaluation/local-s2s/phase-04.md with exact commands and actual/simulated/ unverified outcomes, and an updated docs/plans/local-s2s-adapter-progress.md. Provide demo steps, acceptance verdict, risks, not-run checks and rollback relevance. Do not declare completion while mandatory real-provider/human checks are missing. Do not implement the next phase or switch the operational provider implicitly. ```