# Phase 7 - Controlled switch and verified rollback Paste the following into a fresh implementation session in this repository. ```text Implement Phase 7 only: Controlled switch and verified rollback. Prerequisite: All mandatory prior gates accepted; candidate configuration, evidence and rollback procedure are reviewable. Required visible outcome: Switch to local_s2s only when authorized, demonstrate a document interaction, then restore preserved OpenAI without rebuilding it. 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: 1. Finalize opt-in Compose and .env.example; OpenAI remains default until explicit switching. No UI provider selector or automatic cross-provider fallback. 2. Verify original OpenAI container/image/config remain intact. Build separate candidate tags; never remove/prune/rebuild the original rollback target. 3. Check authoritative profile, readiness, credentials, rates/bounds and DB compatibility. An old-image-incompatible migration blocks simple rollback. 4. Drain/close current sessions, stop the current API, then start candidate on operational DB. Never run both against that DB simultaneously. 5. Use fresh sessions for greeting, Persian audio, tools, sources, barge-in and close; old reservations are not repinned. 6. Actually stop candidate/start preserved OpenAI and verify health plus a fresh real session. Container rollback is not DB/filesystem rollback or seamless media resume. 7. Leave provider state as explicitly requested and record exact commands, IDs, digests, validation and limitations. Acceptance criteria: - Original OpenAI image/container remain intact and restoration has actually succeeded. - One API owns operational lifecycle at a time; users/documents/ingestion data preserved. - Fresh-session admission and profile pinning hold; no credentials exposed. - Final provider and live check results recorded; health alone is not speech/RAG acceptance. Relevant paths (verify actual locations before editing): Opt-in Compose overrides, .env.example, operator runbook and progress/evaluation evidence; app changes only for confirmed deployment defects. Validation: Config/image inspection, authorized controlled switch/rollback, health and actual fresh-session smoke. Visible demonstration: Show local RAG, execute documented OpenAI rollback without rebuilding, and repeat the same question in a fresh session. Explicit stop/narrow condition: Complete preparation first; missing explicit switch authorization, compatibility or acceptance blocks operational switching. Deliver: 1. Scoped code/configuration and necessary tests/contracts where this phase requires implementation; Phase 0 remains an audit. 2. docs/evaluation/local-s2s/phase-07.md with exact commands, results, actual/simulated/unverified evidence, fingerprints, not-run checks and risks. 3. Updated docs/plans/local-s2s-adapter-progress.md with a candid acceptance verdict. 4. Exact demo instructions and rollback relevance. Preserve the operational provider unless this phase explicitly authorizes switching and session authorization exists. Do not implement the next phase. Do not mark acceptance complete with mandatory live or human checks unrun. ```