docs(voice): consolidate local S2S roadmap into four phases
This commit is contained in:
@@ -2285,7 +2285,7 @@ The [phased plan](plans/local-s2s-adapter-plan.md),
|
||||
[execution ledger](plans/local-s2s-adapter-progress.md) and
|
||||
[copy-ready prompts](plans/local-s2s-adapter-prompts/README.md) describe local_s2s
|
||||
alongside OpenAI/Gemini, with initially remote OpenRouter STT/LLM/TTS stages.
|
||||
All eight phases are not_started. OpenAI preservation, actual context-repair
|
||||
The four consolidated phases are not_started; the original eight-stage plan is archived. OpenAI preservation, actual context-repair
|
||||
proof, shared RAG authority, isolated acceptance and rollback are hard gates.
|
||||
This planning record does not weaken existing browser/OpenAI contracts or claim
|
||||
implementation, live validation or deployment.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Historical eight-phase plan
|
||||
|
||||
Superseded by the active four-phase plan on 2026-10-15. These files are historical
|
||||
snapshots, not execution prompts. Relative links inside snapshots refer to their
|
||||
original locations and are not maintained here.
|
||||
|
||||
Use [the current plan](../../local-s2s-adapter-plan.md) and
|
||||
[the four active prompts](../../local-s2s-adapter-prompts/README.md).
|
||||
@@ -0,0 +1,458 @@
|
||||
# Local speech-to-speech adapter: phased implementation plan
|
||||
|
||||
Date: 2026-10-15. Status: **planned; implementation and live acceptance not started**.
|
||||
|
||||
## 1. Outcome and scope
|
||||
|
||||
Add `local_s2s` alongside OpenAI and Gemini. Keep the OpenAI implementation usable,
|
||||
preserve its behavior, and retain the original operational API container/image for
|
||||
rollback. Initially run orchestration/VAD locally and obtain STT, a tool-capable
|
||||
text LLM and TTS through OpenRouter. Local orchestration is not offline inference.
|
||||
Replacing individual stages with local models is a later independent optimization.
|
||||
|
||||
This is a plan, not authorization to switch the running application, download
|
||||
weights or perform unbounded paid evaluation. Each phase has a tangible demo,
|
||||
acceptance criteria, evidence and a copy-ready English prompt. No phase has run.
|
||||
|
||||
## 2. Target architecture
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
Browser[Existing Angular browser] <-->|Application PCM and JSON| API[FastAPI and VoiceRuntime]
|
||||
API --> Tools[Existing tools and SearchService]
|
||||
Tools --> Data[(Authorized knowledge)]
|
||||
API --> Boundary[Small internal provider boundary]
|
||||
Boundary <--> OA[Existing OpenAI adapter]
|
||||
Boundary <--> GE[Existing Gemini adapter]
|
||||
Boundary <--> LA[New local_s2s adapter]
|
||||
LA <--> Engine[Pinned speech-to-speech service]
|
||||
Engine --> VAD[Local VAD]
|
||||
Engine --> STT[OpenRouter STT]
|
||||
Engine --> LLM[OpenRouter text LLM]
|
||||
Engine --> TTS[OpenRouter TTS]
|
||||
```
|
||||
|
||||
The engine emits tool requests; our backend executes them. It receives no separate
|
||||
database authority. Browser clients continue to use our API, never a public engine
|
||||
endpoint or an OpenRouter key.
|
||||
|
||||
| Concern | Owner |
|
||||
| --- | --- |
|
||||
| Identity, organization, permissions and revisions | Existing application services |
|
||||
| Turn ownership, deadlines, playback credits, evidence lifetime, next-turn release | VoiceRuntime |
|
||||
| Native wire events/requests, error classification and configuration proof | Provider adapter |
|
||||
| Actual local cancellation/history mutation and authoritative receipt | Pinned engine plus a minimal versioned extension when necessary |
|
||||
| Recognition, text generation and synthesis | OpenRouter initially |
|
||||
| Search/reuse, document eligibility and used-source validation | Existing knowledge services and DurableTools |
|
||||
| Browser PCM and JSON contract | Existing application API contract |
|
||||
|
||||
### Boundary design
|
||||
|
||||
Normalize semantic events/operations actually required by runtime: effective
|
||||
setup, consumed input, speech boundaries, generation identity, audio/transcript,
|
||||
tool request and terminal outcome. Preserve native identity/provenance and replay
|
||||
fingerprints. Do not turn an arbitrary transcript into a fake input-commit ack.
|
||||
|
||||
Interruption has separate generation-stop and history-repair progress. Runtime
|
||||
supplies the response/item, session generation and final played coordinates; the
|
||||
adapter establishes the actual result and runtime retains authority to release
|
||||
the next turn. The receipt must identify the operation and applied state revision.
|
||||
A boolean success flag, elapsed timer or sent request is insufficient proof.
|
||||
|
||||
Keep OpenAI's cancel/terminal/truncate/ack behavior intact behind this boundary.
|
||||
Gemini's unsupported repair remains fail-closed. Prefer a small protocol/data model
|
||||
to a plugin registry, event bus or wholesale state-machine rewrite.
|
||||
|
||||
## 3. Upstream evidence and hard compatibility gaps
|
||||
|
||||
Upstream documents a cascade and a core Realtime interface, not full OpenAI API
|
||||
equivalence. Its documented conversation.item.truncate is a no-op without an ack.
|
||||
Pin a commit and inspect its actual implementation/tests; changing the endpoint
|
||||
URL alone cannot meet our cleanup contract. Sources:
|
||||
[repository](https://github.com/huggingface/speech-to-speech),
|
||||
[Realtime contract](https://github.com/huggingface/speech-to-speech/blob/main/src/speech_to_speech/api/openai_realtime/README.md).
|
||||
|
||||
HTTP STT progressive updates can repeatedly upload cumulative utterances. Remote
|
||||
TTS cancellation can stop local publication without proving remote compute stopped.
|
||||
These affect cost and late-result handling. Sources:
|
||||
[STT backend](https://github.com/huggingface/speech-to-speech/blob/main/docs/openai-compatible-stt.md),
|
||||
[TTS backend](https://github.com/huggingface/speech-to-speech/blob/main/docs/openai-compatible-tts.md).
|
||||
|
||||
OpenRouter documents separate STT/TTS endpoints and LLM tool calling. Model IDs,
|
||||
voices, Persian behavior, supported parameters and rates require actual checks:
|
||||
[STT](https://openrouter.ai/docs/guides/overview/multimodal/stt),
|
||||
[TTS](https://openrouter.ai/docs/guides/overview/multimodal/tts),
|
||||
[tools](https://openrouter.ai/docs/guides/features/tool-calling).
|
||||
|
||||
### Critical case: completed generation, unplayed audio
|
||||
|
||||
A model can finish text/audio while the browser has heard only the beginning.
|
||||
Cancel may then do nothing, leaving unheard assistant prose in engine history.
|
||||
Test the actual next LLM request, not only audio queue state or terminal flags.
|
||||
Closing HTTP, clearing playback and returning response.done do not establish repair.
|
||||
|
||||
Do not infer a text prefix from audio-duration ratios or character counts. If
|
||||
reliable heard-prefix alignment is unavailable, keep the gate open. Dropping an
|
||||
entire interrupted assistant turn or retaining only fully played segments is a
|
||||
weaker alternative policy requiring explicit acceptance and documentation; never
|
||||
silently present it as exact heard-prefix preservation.
|
||||
|
||||
## 4. Invariants
|
||||
|
||||
1. OpenAI remains available. No automatic cross-provider fallback, new UI provider
|
||||
selector or mid-session provider switch. Freeze effective configuration.
|
||||
2. Keep original API containers/images and unrelated changes. No database reset,
|
||||
pruning, compose down, rewriting old snapshots or document-content versioning.
|
||||
3. Keep browser PCM16LE mono 24 kHz in both directions and existing public events.
|
||||
4. One canonical search implementation, calibrated cutoff, document/chunk identity,
|
||||
ready/active/authorized/undeleted filtering and final delivery revalidation.
|
||||
5. Used-source membership validation is not full factual-entailment verification.
|
||||
6. Generation completion differs from playback completion. Retained searches have
|
||||
a lifetime independent of speech cancellation and retain their original deadline.
|
||||
7. Bound queues, bytes, concurrency, deadlines and retry counts across all stages.
|
||||
Do not stack automatic retries at multiple layers or conceal latency with buffers.
|
||||
8. Secrets stay server-side. Default logs contain fixed categories/numeric state,
|
||||
not complete provider payloads or real speech/document text.
|
||||
9. Separate offline tests, isolated PostgreSQL acceptance, provider smokes and human
|
||||
listening. Mock success or skipped checks do not prove live acceptance.
|
||||
10. Never start a second API against the operational database. app/main.py invokes
|
||||
lifecycle.reconcile_startup, which reconciles active sessions globally. A
|
||||
different HTTP port alone is not isolation.
|
||||
|
||||
## 5. Phase overview
|
||||
|
||||
| Phase | Visible result | Operational effect |
|
||||
| --- | --- | --- |
|
||||
| 0 | Baseline and protocol compatibility report | None |
|
||||
| 1 | Existing OpenAI interruption replay still passes through the new boundary | None; refactor only |
|
||||
| 2 | Independent Persian audio -> text -> response -> playable audio demo | Isolated engine only |
|
||||
| 3 | Existing browser greets and closes through local_s2s | Isolated test API/database only |
|
||||
| 4 | Real interruption and coherent continuation; verified repaired history | No promotion until proof |
|
||||
| 5 | Document answers, retained search and correct source subset | Isolated end-to-end RAG |
|
||||
| 6 | Paired OpenAI/local quality, latency and cost scorecard | Promotion decision evidence |
|
||||
| 7 | Authorized deployment switch and demonstrated OpenAI rollback | Controlled opt-in switch |
|
||||
|
||||
Phases run in order. Phase 2 engine preparation may proceed independently of Phase
|
||||
1 when it does not depend on application changes. Never accept a later gate merely
|
||||
because code exists. Do not combine the OpenAI refactor and operational switch.
|
||||
|
||||
## 6. Phase 0 - Baseline and immutable upstream audit
|
||||
|
||||
**Visible outcome:** Open a report showing OpenAI baseline, upstream support,
|
||||
required changes and proof tests side by side. Replay an existing offline trace.
|
||||
|
||||
**Work:**
|
||||
- Read applicable instructions, reference map and governing API/database/workflow
|
||||
sections. Inspect current source and deployment; historical defaults are stale.
|
||||
- Record active/preserved container IDs, image digests, selected profile, ports and
|
||||
storage mounts without keys/full environment dumps. Do not recreate containers.
|
||||
- Pin an upstream SHA and build inputs; record license and patch policy.
|
||||
- Audit effective session config, input acceptance, VAD/commit boundaries, manual
|
||||
response control, metadata/identity, tools, audio rates, terminal states,
|
||||
transcripts, cancellation and history repair against actual source/tests.
|
||||
- Run focused baseline tests; distinguish existing failures from new defects.
|
||||
- Prepare Persian fixture questions and expected answers against an authorized
|
||||
frozen test corpus. Record outstanding product/implementation decisions.
|
||||
|
||||
**Accept when:** baseline/rollback identities exist; each required behavior is
|
||||
verified, requires a specified patch, or is explicitly unverified; every live
|
||||
prerequisite is visible. No runtime/data changes occurred.
|
||||
|
||||
**Stop/narrow:** unknown upstream behavior remains unknown. Missing credentials
|
||||
block live checks, not read-only inspection or deterministic preparation.
|
||||
|
||||
**Prompt:** [Phase 0](local-s2s-adapter-prompts/phase-00.md).
|
||||
|
||||
## 7. Phase 1 - Small provider boundary, OpenAI preserved
|
||||
|
||||
**Visible outcome:** Replay the same interruption before/after extraction: old
|
||||
output stops, the same played position is respected and exactly one next response
|
||||
is released. OpenAI remains the selected provider.
|
||||
|
||||
**Work:**
|
||||
- Implement minimal typed operations/events; runtime keeps turn/authority/release,
|
||||
playback bounds and evidence state. Adapters own provider wire interpretation.
|
||||
- Move OpenAI native cancel/terminal/truncate mechanics behind the boundary without
|
||||
changing semantics. Do not lose raw event fingerprints/correlation on normalization.
|
||||
- Represent interruption with an operation ID, response/item/session identity,
|
||||
generation-stop and applied-history progress, and finite deadlines.
|
||||
- Do not introduce capability switches that waive cleanup. Unsupported capabilities
|
||||
reject admission or fail safely. Preserve Gemini's conservative behavior.
|
||||
- Add controlled-clock replay and regression tests. Document the internal contract
|
||||
amendment; browser wire contracts remain unchanged.
|
||||
|
||||
**Accept when:** existing OpenAI tests retain assertions and pass; terminal/error
|
||||
orderings, missing/wrong acknowledgements, duplicates, late events, incomplete
|
||||
responses and bounds remain covered. Shared control has no model/voice branches.
|
||||
Run isolated PostgreSQL cases if persisted profiles/lifecycle behavior is touched.
|
||||
|
||||
**Stop/narrow:** no full runtime rewrite or blanket provider-error suppression.
|
||||
|
||||
**Prompt:** [Phase 1](local-s2s-adapter-prompts/phase-01.md).
|
||||
|
||||
## 8. Phase 2 - Isolated engine with OpenRouter stages
|
||||
|
||||
**Visible outcome:** Submit a Persian recording to the independent smoke, inspect
|
||||
its explicitly requested test transcript, hear a WAV response and see stage usage
|
||||
and timing. The application remains untouched.
|
||||
|
||||
**Work:**
|
||||
- Build the pinned engine in a separate image/environment with local VAD, HTTP
|
||||
STT, Chat Completions LLM and HTTP TTS. No default local model downloads.
|
||||
- Discover/pin available models/voices and validate Persian hints, tool support,
|
||||
endpoint fields, rates and audio formats. Models are independently configurable.
|
||||
- Keep the key inside the engine. Custom endpoints must not accidentally receive
|
||||
another provider's credentials. Keep engine access behind the application boundary.
|
||||
- Start with final-utterance STT, not cumulative HTTP retranscription.
|
||||
- Verify actual multipart/JSON STT and TTS stream_format/PCM compatibility; add only
|
||||
a narrow observed-mismatch shim if necessary.
|
||||
- Bound and meter startup probes, generation, response sizes, retries/concurrency
|
||||
and close. Provide deterministic stubs and an opt-in bounded live smoke.
|
||||
|
||||
**Accept when:** with live prerequisites all stages complete and audio is valid;
|
||||
otherwise mark live-pending. Bad key/model/voice/rate fails setup accurately. Save
|
||||
sanitized timing/usage and consented fixture outputs, not secrets or raw user logs.
|
||||
|
||||
**Stop/narrow:** do not install every optional model/GPU dependency. Credential or
|
||||
model availability gaps do not authorize fabricated success.
|
||||
|
||||
**Prompt:** [Phase 2](local-s2s-adapter-prompts/phase-02.md).
|
||||
|
||||
## 9. Phase 3 - Local adapter and normal browser session
|
||||
|
||||
**Visible outcome:** In an isolated test app, open the existing browser, say hello,
|
||||
hear a Persian answer, see a transcript, and close cleanly. Show a local_s2s pinned
|
||||
profile. This milestone is development-only, not production parity.
|
||||
|
||||
**Work:**
|
||||
- Add local_s2s configuration/factory selection while keeping openai/gemini.
|
||||
- Freeze engine/patch revision, internal protocol revision, STT/LLM/TTS identities,
|
||||
voice, input policy, rates and effective instruction/config digest. No secrets
|
||||
or credential-derived hashes belong in database execution profiles.
|
||||
- Define the expected configuration and compare to authoritative engine state.
|
||||
A reachable socket or echoed request is insufficient setup proof.
|
||||
- Map actual consumed input, manual response identity/metadata, audio/transcript,
|
||||
terminal and tool events. No invented native commits/acknowledgements.
|
||||
- Preserve browser 24 kHz PCM; use stateful bounded conversion where required,
|
||||
including correct playback-position units.
|
||||
- Preserve owner/Origin/cookie/CSRF/replay/epoch checks. Inspect schema/DTO/provider
|
||||
constraints; use a new migration only if necessary, never edit an applied one.
|
||||
- Use disposable database/storage and isolated test browser identity/origin.
|
||||
Until Phase 4, unsupported interruption must fail safely and be labelled as such.
|
||||
|
||||
**Accept when:** ready/audio/transcript/close work; bad configuration, wrong owner,
|
||||
old epoch, mismatched profile, malformed terminal and disconnect cannot pass
|
||||
silently. Existing profiles are not rewritten; a new session pins new settings.
|
||||
|
||||
**Stop/narrow:** a second port with the same operational DB is prohibited. No
|
||||
promotion or hidden fallback before interruption and RAG gates.
|
||||
|
||||
**Prompt:** [Phase 3](local-s2s-adapter-prompts/phase-03.md).
|
||||
|
||||
## 10. Phase 4 - Verified interruption and history repair
|
||||
|
||||
**Visible outcome:** Interrupt a long answer, ask a follow-up, and get a coherent
|
||||
reply without stale audio. In a controlled test, show the actual next LLM input
|
||||
contains no unheard sentinel that was generated later in the interrupted answer.
|
||||
|
||||
**Work:**
|
||||
- Implement a real correlated engine operation/extension if the pinned version
|
||||
cannot repair history. Keep a reproducible versioned patch with independent tests.
|
||||
- Cover active generation AND completed generation with unplayed buffered audio.
|
||||
- Track item/response/segment/session identities, final consumed position and
|
||||
reliable assistant text/audio alignment. Never use character/duration ratios.
|
||||
- Keep valid prior turns/user/tool state; remove unheard assistant continuation
|
||||
from future generation input. Expose applied history revision/digest as proof.
|
||||
- If exact repair is unavailable, stop this acceptance gate. Conservative whole-turn
|
||||
rollback or fully-played-segment-only history needs explicit policy acceptance.
|
||||
- Admit a receipt only after mutation; reject stale, conflicting, wrong-identity
|
||||
or missing receipts. Runtime retains deadlines and final authority to continue.
|
||||
- Suppress late STT/LLM/TTS results even if remote computation cannot be cancelled.
|
||||
Keep latest backend retrieval independent from speech cancellation.
|
||||
- Repeat OpenAI regressions; the new local proof must not weaken native OpenAI gates.
|
||||
|
||||
**Accept when:** no next turn before generation stop, real repair and playback gates;
|
||||
active and completed-unplayed cases pass; late work cannot reach another turn;
|
||||
missing/wrong proof fails safely. No fake conversation.item.truncated event.
|
||||
|
||||
**Stop/narrow:** this is the highest-risk phase. Audio stopping or a stock-SDK
|
||||
compatibility claim does not prove our context semantics. Keep promotion blocked.
|
||||
|
||||
**Prompt:** [Phase 4](local-s2s-adapter-prompts/phase-04.md).
|
||||
|
||||
## 11. Phase 5 - Existing RAG tools and used sources
|
||||
|
||||
**Visible outcome:** Ask hours/Thursday, the planning deputy in the specific letter,
|
||||
and the incentive percentage/dates/exclusions. Interrupt a pending search and
|
||||
repeat the question; show one retrieval plus revalidation and relevant UI sources.
|
||||
|
||||
**Work:**
|
||||
- Expose search_knowledge, reuse_last_evidence and report_used_sources to the new
|
||||
LLM. Execute through existing dispatch/ToolContext/DurableTools/SearchService.
|
||||
- Preserve backend identity, calibrated retrieval, document/chunk references and
|
||||
handoff/delivery eligibility. Engine gets no independent retrieval path.
|
||||
- Validate streamed arguments after successful terminal validation; correlate
|
||||
response/item/call identities and deduplicate repeats/replays.
|
||||
- Reuse same-topic pending results within original deadline, revalidate, and discard
|
||||
changed-topic results. Never use earlier assistant prose as document evidence.
|
||||
- Validate current-turn source labels and correct invalid reports privately. Do
|
||||
not show every candidate or persist metadata reports as extra retrievals.
|
||||
- Exercise ok/no_evidence/error, token-limited tools, interrupted delivery,
|
||||
revocation/deactivation and all known Mini factual failure cases.
|
||||
|
||||
**Accept when:** all three tools retain existing authority; no stale evidence or
|
||||
extra retrieval on same-topic reuse; used subset has original document/chunk
|
||||
identity. Correct citation membership is not claimed as full factual verification.
|
||||
|
||||
**Stop/narrow:** no weakened cutoff/filter or second search implementation to hide
|
||||
model-quality problems.
|
||||
|
||||
**Prompt:** [Phase 5](local-s2s-adapter-prompts/phase-05.md).
|
||||
|
||||
## 12. Phase 6 - Persian quality, latency, cost and resilience
|
||||
|
||||
**Visible outcome:** A paired OpenAI/local scorecard and audio samples show the
|
||||
actual trade-off. Demonstrate a controlled provider failure without contamination.
|
||||
|
||||
**Work:**
|
||||
- Evaluate the same authorized frozen corpus and paired Persian audio/question
|
||||
fixtures. Keep exact baseline/candidate component profiles and sample counts.
|
||||
- Cover names/roles, numbers/dates, natural pauses, noise, self-correction,
|
||||
ambiguity, continuation, topic switch, no evidence and document conflicts.
|
||||
- Measure speech-end-to-first-audible-sample, tool time, first text/audio,
|
||||
interruption-to-stop, underruns, duplicates, disconnects and task completion.
|
||||
- Count cached/input/output usage when available, STT duration, TTS billed units,
|
||||
startup probes, failures and abandoned work. Missing usage stays unknown. Compare
|
||||
cost per successful task, not only successful API requests.
|
||||
- Fault-inject slow/down providers, quotas, stream loss, restart and saturation.
|
||||
Prove bounded queues, late-result suppression and no stacked retry storms.
|
||||
- Change one component at a time. Human listening is separate from transport tests;
|
||||
do not claim that a better LLM repairs bad transcription.
|
||||
|
||||
**Accept when:** all critical factual fixture assertions pass with zero invented
|
||||
names/numbers/dates/conditions; all intended interruption cases pass or fail safely
|
||||
as specified; results assess predeclared targets and expose all failures.
|
||||
|
||||
Provisional goals, to accept or revise explicitly BEFORE evaluation: p95 first
|
||||
audible response <= baseline + 1 second, no persistent underruns, and cost per
|
||||
successful task <= 70% of baseline for a cost-saving promotion. These are targets,
|
||||
not measurements or universal guarantees. If quality/cost goals fail, keep OpenAI.
|
||||
|
||||
**Stop/narrow:** missing actual provider/human evidence leaves the gate open. Do
|
||||
not broaden prompts/buffers or silently change thresholds after seeing results.
|
||||
|
||||
**Prompt:** [Phase 6](local-s2s-adapter-prompts/phase-06.md).
|
||||
|
||||
## 13. Phase 7 - Controlled switch and demonstrated rollback
|
||||
|
||||
**Visible outcome:** Demonstrate a local document interaction, then stop the
|
||||
candidate, start the preserved OpenAI API without rebuild, and repeat the question.
|
||||
Leave the selected provider in the final state explicitly requested by the user.
|
||||
|
||||
**Work:**
|
||||
- Finalize opt-in Compose and .env.example; OpenAI stays default until an explicit
|
||||
operational switch. No automatic fallback or UI provider selector.
|
||||
- Verify original container/image/config retention. Candidate gets separate tags;
|
||||
never prune, remove, overwrite or rebuild the original rollback target.
|
||||
- Check effective setup, health, secrets, bounds and database compatibility before
|
||||
switching. An incompatible migration blocks simple old-container rollback.
|
||||
- Drain/close current sessions, stop the existing API, then start the candidate on
|
||||
the operational DB. Never two application APIs against that DB simultaneously.
|
||||
- Test a fresh browser session: greeting, RAG, used sources, interruption and close.
|
||||
- Actually exercise rollback and verify readiness plus a fresh OpenAI session.
|
||||
Container rollback is not database/filesystem rollback or media-session resume.
|
||||
- Record commands, identities, fingerprints, checks, final state and limitations.
|
||||
|
||||
**Accept when:** preserved OpenAI restoration succeeds; user/ingestion data is
|
||||
preserved; one API owns the operational lifecycle at a time; session profiles stay
|
||||
pinned. Health readiness alone is not speech/RAG acceptance.
|
||||
|
||||
**Stop/narrow:** prepare all reviewable work first. Without the operational switch
|
||||
authorization, compatibility or live evidence, stop before changing the service.
|
||||
|
||||
**Prompt:** [Phase 7](local-s2s-adapter-prompts/phase-07.md).
|
||||
|
||||
## 14. Configuration, data and deployment contract
|
||||
|
||||
Proposed names below must be finalized before implementation and documented with
|
||||
units/defaults. Do not create unvalidated option bags or leak credentials to LLMs.
|
||||
|
||||
| Scope | Proposed configuration |
|
||||
| --- | --- |
|
||||
| Selection | VOICE_PROVIDER=openai / gemini / local_s2s |
|
||||
| Engine access | LOCAL_S2S_ENDPOINT and optional server-to-server credential |
|
||||
| Identity | LOCAL_S2S_ENGINE_REVISION, adapter contract revision, effective config digest |
|
||||
| Models | LOCAL_S2S_STT_MODEL, LOCAL_S2S_LLM_MODEL, LOCAL_S2S_TTS_MODEL, LOCAL_S2S_TTS_VOICE |
|
||||
| Policy | STT language/final-only mode, LLM limits, TTS rate/format and verified options |
|
||||
| Credentials | OpenRouter key only in engine component clients; never in database profile |
|
||||
| Bounds | Connect/request/repair/close deadlines, queue bytes/items/concurrency |
|
||||
|
||||
Start with fixed component identities per engine configuration. Reservation
|
||||
expectations must match authoritative engine state; never silently mutate shared
|
||||
global models on every session.update. Later multi-profile concurrency requires a
|
||||
separate isolation design.
|
||||
|
||||
Candidate API acceptance uses an isolated PostgreSQL/pgvector database and storage.
|
||||
Cookies are not port-isolated: use a dedicated test hostname/browser profile and
|
||||
credentials with matching trusted Origin. Do not copy production auth sessions
|
||||
into a parallel test browser. Operational switching runs only one application API.
|
||||
|
||||
No schema migration is assumed. Inspect provider constraints/DTOs/profile replay
|
||||
in Phases 0/3; use a new migration only if required and verify rollback image
|
||||
compatibility. Do not add document_versions/version_id/version_no.
|
||||
|
||||
## 15. Validation commands and evidence
|
||||
|
||||
Verify paths and side effects at execution time. Focused baseline command:
|
||||
|
||||
```powershell
|
||||
.venv/Scripts/python -m pytest tests/unit/test_live_context_sync.py tests/unit/test_realtime_repairs.py tests/unit/test_voice_retained_search.py tests/unit/test_voice_reported_sources.py tests/unit/test_openai_output_limit.py tests/unit/test_phase2_provider_selection.py tests/unit/test_openai_persian_style.py -q
|
||||
```
|
||||
|
||||
Broaden when shared behavior changes justify it:
|
||||
|
||||
```powershell
|
||||
.venv/Scripts/python -m pytest -m "not postgres"
|
||||
git diff --check
|
||||
```
|
||||
|
||||
Only with a verified disposable TEST_DATABASE_URL:
|
||||
|
||||
```powershell
|
||||
.venv/Scripts/python -m pytest -m postgres --require-postgres
|
||||
```
|
||||
|
||||
Existing timing/Windows failures must be recorded, not hidden by weakening tests.
|
||||
Ordinary-suite skips do not establish PostgreSQL acceptance. Future local smoke
|
||||
and conformance commands are phase deliverables, not existing verified commands.
|
||||
|
||||
Each phase produces docs/evaluation/local-s2s/phase-NN.md with scoped diff/commits,
|
||||
exact commands, results, counts, fingerprints, visible demo, actual vs simulated
|
||||
observations, not-run checks, blockers and rollback relevance. No keys/raw real
|
||||
conversation logs. Save audio/transcripts only as explicitly consented evaluation
|
||||
artifacts. Upstream CI success is not our runtime compatibility evidence.
|
||||
|
||||
Progress ledger: [local-s2s-adapter-progress.md](local-s2s-adapter-progress.md).
|
||||
Prompt index: [local-s2s-adapter-prompts/README.md](local-s2s-adapter-prompts/README.md).
|
||||
|
||||
States: not_started, in_progress, offline_complete_live_pending, blocked, accepted.
|
||||
Only accepted closes a required gate. Missing paid authorization blocks dependent
|
||||
live work, not independent preparation. Reuse existing bounded authorization; do
|
||||
not ask the user to approve the same action repeatedly.
|
||||
|
||||
## 16. Decisions to resolve and definition of done
|
||||
|
||||
- Upstream SHA, dependency/build lock and maintained patch provenance: Phase 0.
|
||||
- Effective profile/config attestation and concurrent engine isolation: Phase 3.
|
||||
- Real heard-prefix mapping/receipt: Phase 4 hard gate; weaker policy requires an
|
||||
explicit product decision and intentional API/workflow documentation.
|
||||
- Available OpenRouter models/voices, Persian quality, hardware footprint and
|
||||
latency/cost: measure, do not infer from default local-model examples.
|
||||
- Any future local weight licensing is checked for the chosen model separately.
|
||||
- Candidate promotion follows evidence, not an assumption that local is cheaper.
|
||||
|
||||
Done means independently selectable local_s2s, working OpenAI, unchanged trusted
|
||||
RAG authority, browser compatibility, real correlated history repair, bounded
|
||||
failure handling and recorded Persian quality/latency/cost acceptance. Restoring
|
||||
the compatible preserved OpenAI container has actually worked. Missing real or
|
||||
human acceptance remains a blocker, not a completed implementation.
|
||||
@@ -0,0 +1,36 @@
|
||||
# Local S2S adapter progress
|
||||
|
||||
Created: 2026-10-15. This ledger records execution, not a completion claim.
|
||||
Plan/prompts are written; implementation, paid calls, downloads and operational
|
||||
switches have NOT been performed as part of this planning task.
|
||||
|
||||
[Plan](local-s2s-adapter-plan.md) | [Prompts](local-s2s-adapter-prompts/README.md)
|
||||
|
||||
| Phase | Status | Evidence | Visible demo | Blockers |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 0 - Baseline and immutable upstream audit | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 1 - Small provider boundary with OpenAI preserved | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 2 - Isolated S2S engine with OpenRouter stages | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 3 - Local provider and normal browser session | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 4 - Verified interruption and history synchronization | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 5 - Shared RAG and declared-source integration | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 6 - Persian quality, latency, cost and resilience | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 7 - Controlled switch and verified rollback | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
|
||||
## Phase evidence template
|
||||
|
||||
- Phase/status and prerequisite evidence:
|
||||
- Reviewed diff/implementation commit:
|
||||
- Preserved operational and rollback identities:
|
||||
- Pinned upstream and patch revision:
|
||||
- Candidate effective profile without credentials:
|
||||
- Exact commands, counts and results:
|
||||
- Actual / simulated / unverified observations:
|
||||
- Visible demo and outcome:
|
||||
- Bounded paid-call authorization/usage when applicable:
|
||||
- Decisions, blockers, not-run checks and risks:
|
||||
- Acceptance verdict / next allowed phase:
|
||||
|
||||
States: not_started, in_progress, offline_complete_live_pending, blocked, accepted.
|
||||
Only accepted closes a mandatory gate. Inspect current deployment before each
|
||||
operational action; historical notes do not establish current provider selection.
|
||||
@@ -0,0 +1,12 @@
|
||||
# Local S2S phase prompts
|
||||
|
||||
Read [the complete plan](../local-s2s-adapter-plan.md) and [progress ledger](../local-s2s-adapter-progress.md). Each file contains one copy-ready English prompt. Run one phase at a time; never assume prerequisites passed.
|
||||
|
||||
- [Phase 0 - Baseline and immutable upstream audit](phase-00.md)
|
||||
- [Phase 1 - Small provider boundary with OpenAI preserved](phase-01.md)
|
||||
- [Phase 2 - Isolated S2S engine with OpenRouter stages](phase-02.md)
|
||||
- [Phase 3 - Local provider and normal browser session](phase-03.md)
|
||||
- [Phase 4 - Verified interruption and history synchronization](phase-04.md)
|
||||
- [Phase 5 - Shared RAG and declared-source integration](phase-05.md)
|
||||
- [Phase 6 - Persian quality, latency, cost and resilience](phase-06.md)
|
||||
- [Phase 7 - Controlled switch and verified rollback](phase-07.md)
|
||||
@@ -0,0 +1,57 @@
|
||||
# Phase 1 - Small provider boundary with OpenAI preserved
|
||||
|
||||
Paste the following into a fresh implementation session in this repository.
|
||||
|
||||
```text
|
||||
Implement Phase 1 only: Small provider boundary with OpenAI preserved.
|
||||
|
||||
Prerequisite:
|
||||
Phase 0 audit, scoped contract proposal and baseline evidence exist.
|
||||
|
||||
Required visible outcome:
|
||||
OpenAI still produces the same command/ack behavior through a provider boundary; show a deterministic before/after replay.
|
||||
|
||||
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. Implement minimal internal typed operations/events for actual runtime needs, preserving raw provider replay fingerprints and identities.
|
||||
2. Keep turn ownership, authorization, evidence, deadlines, audio credits, final played positions and next-turn release in runtime. Move native encoding/parsing and confirmation interpretation into adapters.
|
||||
3. Define interruption progress with operation/response/item/session identities and separate generation-stop/history-repair proof. Capability declarations must not waive cleanup.
|
||||
4. Adapt OpenAI using existing cancel/terminal/truncate semantics unchanged. Preserve Gemini conservative failure. No model/voice branches in shared control.
|
||||
5. Add controlled-clock regression/replay tests and document the internal responsibility amendment while keeping browser wire behavior fixed.
|
||||
|
||||
Acceptance criteria:
|
||||
- Existing OpenAI assertions remain and affected tests pass, with prior failures reported honestly.
|
||||
- Before/after trace releases exactly one next response after matching cleanup.
|
||||
- Wrong/missing/late/duplicate-conflicting events, limited tools and timeouts fail safely.
|
||||
- No deployment/default change or unnecessary persistence migration.
|
||||
|
||||
Relevant paths (verify actual locations before editing):
|
||||
runtime.py, a minimal internal provider-contract module if justified, realtime.py, Gemini adapter only where needed, diagnostics and focused tests.
|
||||
|
||||
Validation:
|
||||
Provider-free adapter/runtime conformance plus existing races, final playback, output limits and evidence tests. Isolated PostgreSQL only if persistence behavior changed.
|
||||
|
||||
Visible demonstration:
|
||||
Replay a fixture: interrupted old output stops, matching final played position is confirmed, and one new response begins.
|
||||
|
||||
Explicit stop/narrow condition:
|
||||
No wholesale state-machine rewrite or generic provider-error suppression.
|
||||
|
||||
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-01.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.
|
||||
```
|
||||
@@ -0,0 +1,57 @@
|
||||
# Phase 2 - Isolated S2S engine with OpenRouter stages
|
||||
|
||||
Paste the following into a fresh implementation session in this repository.
|
||||
|
||||
```text
|
||||
Implement Phase 2 only: Isolated S2S engine with OpenRouter stages.
|
||||
|
||||
Prerequisite:
|
||||
Pinned engine/build design from Phase 0; independent of Phase 1 where no application integration is used.
|
||||
|
||||
Required visible outcome:
|
||||
A Persian recording independently becomes a transcript, LLM response and playable WAV with stage timings and actual usage.
|
||||
|
||||
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. Build a separate pinned engine image/environment. Use local VAD and independently configured remote STT, Chat Completions LLM and TTS.
|
||||
2. Discover/pin supported model IDs/voices/parameters and test Persian language behavior. Choose a tool-capable text LLM, not an assumed universal audio endpoint.
|
||||
3. Verify explicit credential forwarding, multipart/JSON STT, TTS stream fields, raw PCM rate/endianness and startup probes. Add a narrow shim only for an observed mismatch.
|
||||
4. Use final-utterance STT initially. Bound retries, requests, response sizes, concurrency and cleanup; include startup probes in cost.
|
||||
5. Provide deterministic stub mode and opt-in live smoke with bounded requests/time/cost. Save only consented evaluation outputs; do not connect to production DB/API.
|
||||
|
||||
Acceptance criteria:
|
||||
- With authorized live prerequisites, all three stages succeed and output audio is valid; otherwise mark live-pending.
|
||||
- Invalid key/model/voice/rate cannot produce false readiness.
|
||||
- Models remain independently replaceable and keys remain server-side.
|
||||
- Existing app, worker, database and rollback container are untouched.
|
||||
|
||||
Relevant paths (verify actual locations before editing):
|
||||
An opt-in engine build/service directory, isolated Compose configuration, smoke command and evaluation fixtures. Do not vendor all upstream code into app/.
|
||||
|
||||
Validation:
|
||||
Pinned upstream relevant tests and HTTP fixtures; optional bounded actual-provider requests. Ordinary tests require no keys or weights.
|
||||
|
||||
Visible demonstration:
|
||||
Run the isolated Persian smoke, inspect its requested test transcript, hear the WAV and view per-stage timing/usage.
|
||||
|
||||
Explicit stop/narrow condition:
|
||||
Missing keys/availability blocks live proof only. Do not install unrelated local-model/GPU extras.
|
||||
|
||||
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-02.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.
|
||||
```
|
||||
@@ -0,0 +1,59 @@
|
||||
# Phase 3 - Local provider and normal browser session
|
||||
|
||||
Paste the following into a fresh implementation session in this repository.
|
||||
|
||||
```text
|
||||
Implement Phase 3 only: Local provider and normal browser session.
|
||||
|
||||
Prerequisite:
|
||||
Phases 1 and 2 have accepted prerequisite evidence. Candidate app has disposable DB/storage.
|
||||
|
||||
Required visible outcome:
|
||||
The existing browser opens a local_s2s session, greets in Persian, displays transcript and closes cleanly in isolation.
|
||||
|
||||
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. Add local_s2s to validated selection/factory/settings/readiness without removing openai/gemini or adding a UI selector.
|
||||
2. Freeze engine/patch/contract revisions, effective component models, voice, speech policy, rates and instruction/config digest. Do not store secrets or secret hashes.
|
||||
3. Compare reservation expectations with authoritative effective engine setup; do not rely on connection reachability or echoing desired values.
|
||||
4. Map real input acceptance, response intent/identity, tool frames, terminal states and audio/transcript. Do not synthesize native commit acknowledgements from timing.
|
||||
5. Keep browser PCM16LE mono24k and public events. Bound resampling and convert playback coordinates correctly.
|
||||
6. Preserve owner/Origin/cookie/CSRF/replay/epoch checks and old profiles. Audit DB/DTO constraints; new migration only if necessary.
|
||||
7. Use isolated DB/storage and separate test browser credentials/origin. Unsupported interruption fails closed until Phase 4.
|
||||
|
||||
Acceptance criteria:
|
||||
- Ready/audio/transcript/close work end to end in the isolated app.
|
||||
- Incorrect profile, configuration, ownership or epoch is rejected; no snapshot rewrites.
|
||||
- Malformed terminals/disconnects cannot cause false success.
|
||||
- This remains development-only, not operational parity or a default switch.
|
||||
|
||||
Relevant paths (verify actual locations before editing):
|
||||
configuration.py, settings.py, voice_provider.py, new local adapter, live admission/lifecycle only where required, .env.example and isolated deployment config.
|
||||
|
||||
Validation:
|
||||
Provider-free adapter contract tests, isolated PostgreSQL admission/replay/profile/revocation, then bounded browser live smoke.
|
||||
|
||||
Visible demonstration:
|
||||
Use the existing browser to greet and close. Show the local pinned profile and separate OpenAI conformance results.
|
||||
|
||||
Explicit stop/narrow condition:
|
||||
Never use a second port with the operational DB. No promotion before interruption/RAG acceptance.
|
||||
|
||||
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-03.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.
|
||||
```
|
||||
@@ -0,0 +1,59 @@
|
||||
# Phase 4 - Verified interruption and history synchronization
|
||||
|
||||
Paste the following into a fresh implementation session in this repository.
|
||||
|
||||
```text
|
||||
Implement Phase 4 only: Verified interruption and history synchronization.
|
||||
|
||||
Prerequisite:
|
||||
Phase 3 works in isolation. Upstream history/turn ownership and required patch are understood.
|
||||
|
||||
Required visible outcome:
|
||||
The user interrupts a long answer and continues coherently; inspect the next model request to prove unheard sentinel text is absent.
|
||||
|
||||
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. Add an actual correlated engine repair operation/extension if needed. Pin the patch and test it independently; do not monkey-patch installed packages as the deployment strategy.
|
||||
2. Handle both active generation and completed generation with audio still queued at the browser. Closing TTS HTTP or getting response.done does not prove history repair.
|
||||
3. Track response/item/segment/session identities, final consumed position and reliable text/audio mapping; no proportional text slicing.
|
||||
4. Preserve valid earlier user/assistant/tool state and remove unheard assistant continuation from subsequent LLM input. Verify applied history revision/digest.
|
||||
5. If exact heard-prefix repair cannot be proven, keep this gate open. Whole-turn rollback or fully-played-segment-only retention needs explicit policy acceptance and contract changes.
|
||||
6. Validate real applied receipts against operation identity; reject stale/missing/conflicting receipts with bounded safe failure. Runtime owns final release.
|
||||
7. Suppress late STT/LLM/TTS work and preserve same-topic backend search independently. Re-run all affected OpenAI interruption tests.
|
||||
|
||||
Acceptance criteria:
|
||||
- Generation stop, real context repair and application playback gates all precede next response.
|
||||
- Active and completed-unplayed cases pass controlled history inspection and actual microphone testing.
|
||||
- Wrong/missing receipts fail safely; late output cannot contaminate another turn/session.
|
||||
- No fabricated conversation.item.truncated or weakened OpenAI checks; unapproved weaker policies block promotion.
|
||||
|
||||
Relevant paths (verify actual locations before editing):
|
||||
Internal interruption contract, local adapter, pinned engine extension/patch, runtime barrier integration, diagnostics and regression tests.
|
||||
|
||||
Validation:
|
||||
Controlled clocks, ordering, races, receipt replay, mid-segment interruption, teardown/reuse, terminal-completed/unplayed audio, plus actual bounded live interruption.
|
||||
|
||||
Visible demonstration:
|
||||
Generate an answer with a late sentinel, interrupt before hearing it, inspect the following LLM context, then demonstrate real barge-in and continuation.
|
||||
|
||||
Explicit stop/narrow condition:
|
||||
This is the highest-risk gate. Stopped playback or upstream SDK compatibility does not prove the required semantics.
|
||||
|
||||
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-04.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.
|
||||
```
|
||||
@@ -11,7 +11,8 @@ text LLM and TTS through OpenRouter. Local orchestration is not offline inferenc
|
||||
Replacing individual stages with local models is a later independent optimization.
|
||||
|
||||
This is a plan, not authorization to switch the running application, download
|
||||
weights or perform unbounded paid evaluation. Each phase has a tangible demo,
|
||||
weights or perform unbounded paid evaluation. The original eight stages are consolidated into four phases without removing scope.
|
||||
Each phase has a tangible demo,
|
||||
acceptance criteria, evidence and a copy-ready English prompt. No phase has run.
|
||||
|
||||
## 2. Target architecture
|
||||
@@ -119,260 +120,152 @@ silently present it as exact heard-prefix preservation.
|
||||
lifecycle.reconcile_startup, which reconciles active sessions globally. A
|
||||
different HTTP port alone is not isolation.
|
||||
|
||||
## 5. Phase overview
|
||||
## 5. Four-phase roadmap
|
||||
|
||||
| Phase | Visible result | Operational effect |
|
||||
| Phase | Visible milestone | Previous stages combined |
|
||||
| --- | --- | --- |
|
||||
| 0 | Baseline and protocol compatibility report | None |
|
||||
| 1 | Existing OpenAI interruption replay still passes through the new boundary | None; refactor only |
|
||||
| 2 | Independent Persian audio -> text -> response -> playable audio demo | Isolated engine only |
|
||||
| 3 | Existing browser greets and closes through local_s2s | Isolated test API/database only |
|
||||
| 4 | Real interruption and coherent continuation; verified repaired history | No promotion until proof |
|
||||
| 5 | Document answers, retained search and correct source subset | Isolated end-to-end RAG |
|
||||
| 6 | Paired OpenAI/local quality, latency and cost scorecard | Promotion decision evidence |
|
||||
| 7 | Authorized deployment switch and demonstrated OpenAI rollback | Controlled opt-in switch |
|
||||
| 1 | OpenAI preserved through the provider boundary | Old 0 + 1 |
|
||||
| 2 | Local/OpenRouter voice works in the existing test browser | Old 2 + 3 |
|
||||
| 3 | Safe interruption plus full shared RAG and sources | Old 4 + 5 |
|
||||
| 4 | Quality/cost decision and verified deployment rollback | Old 6 + 7 |
|
||||
|
||||
Phases run in order. Phase 2 engine preparation may proceed independently of Phase
|
||||
1 when it does not depend on application changes. Never accept a later gate merely
|
||||
because code exists. Do not combine the OpenAI refactor and operational switch.
|
||||
Only these four phases and their four prompts are active. The original version is
|
||||
[archived](archive/local-s2s-eight-phase/README.md) for traceability. No implementation
|
||||
phase has started, so this consolidation changes planning only. Required internal
|
||||
checkpoints remain acceptance conditions inside each phase, not separate execution
|
||||
phases. The preserved OpenAI path remains the fallback chosen by the operator.
|
||||
|
||||
## 6. Phase 0 - Baseline and immutable upstream audit
|
||||
## Phase 1 - Preserve OpenAI and introduce the provider boundary
|
||||
|
||||
**Visible outcome:** Open a report showing OpenAI baseline, upstream support,
|
||||
required changes and proof tests side by side. Replay an existing offline trace.
|
||||
**Visible outcome:** An existing OpenAI session still works; an offline before/after interruption replay proves the same cleanup and next-turn behavior.
|
||||
|
||||
**Entry:** No adapter implementation has started. Inspect the current repository and deployment first.
|
||||
|
||||
**Work:**
|
||||
- Read applicable instructions, reference map and governing API/database/workflow
|
||||
sections. Inspect current source and deployment; historical defaults are stale.
|
||||
- Record active/preserved container IDs, image digests, selected profile, ports and
|
||||
storage mounts without keys/full environment dumps. Do not recreate containers.
|
||||
- Pin an upstream SHA and build inputs; record license and patch policy.
|
||||
- Audit effective session config, input acceptance, VAD/commit boundaries, manual
|
||||
response control, metadata/identity, tools, audio rates, terminal states,
|
||||
transcripts, cancellation and history repair against actual source/tests.
|
||||
- Run focused baseline tests; distinguish existing failures from new defects.
|
||||
- Prepare Persian fixture questions and expected answers against an authorized
|
||||
frozen test corpus. Record outstanding product/implementation decisions.
|
||||
|
||||
**Accept when:** baseline/rollback identities exist; each required behavior is
|
||||
verified, requires a specified patch, or is explicitly unverified; every live
|
||||
prerequisite is visible. No runtime/data changes occurred.
|
||||
- Capture current/preserved container and image identities, effective provider/profile and focused regression results. Keep the operational deployment unchanged.
|
||||
- Pin an upstream commit/build inputs and audit actual setup, input consumption, manual turn control, metadata/identities, tool events, audio rates, terminal states and history repair.
|
||||
- Record a compatibility matrix and unresolved decisions, especially the no-op truncate and completed-but-unplayed history case.
|
||||
- Extract only the small internal provider boundary needed by runtime. Runtime owns authorization, turn identity, playback credits, deadlines, evidence lifetime and next-turn release; adapters own native wire/confirmation details.
|
||||
- Keep native OpenAI cancel/terminal/truncate/ack semantics, raw replay fingerprints and correlation intact. Preserve Gemini's conservative failures.
|
||||
- Define correlated interruption progress with separate generation-stop and actual history-repair proof. Capability flags never waive safety gates.
|
||||
- Add controlled-clock replay/conformance coverage and document the internal responsibility split without changing public browser behavior.
|
||||
|
||||
**Stop/narrow:** unknown upstream behavior remains unknown. Missing credentials
|
||||
block live checks, not read-only inspection or deterministic preparation.
|
||||
**Accept when:**
|
||||
|
||||
**Prompt:** [Phase 0](local-s2s-adapter-prompts/phase-00.md).
|
||||
- Existing OpenAI regressions retain their assertions and pass; pre-existing failures are reported honestly.
|
||||
- The same fixture before/after refactoring releases exactly one new response after matching cleanup, with wrong/missing/late/conflicting acknowledgements failing safely.
|
||||
- Upstream SHA/build provenance, compatibility gaps and original rollback identities are recorded.
|
||||
- No runtime switch, production data change, wholesale rewrite or model/voice branch in shared turn control.
|
||||
|
||||
## 7. Phase 1 - Small provider boundary, OpenAI preserved
|
||||
**Show the user:** Run an existing OpenAI interaction if already authorized, and show a deterministic interruption trace through the new boundary. No new provider is enabled.
|
||||
|
||||
**Visible outcome:** Replay the same interruption before/after extraction: old
|
||||
output stops, the same played position is respected and exactly one next response
|
||||
is released. OpenAI remains the selected provider.
|
||||
**Validation:** Existing context-sync, provider-selection, retained-search, source-report, output-limit and style tests; controlled-clock replay. Isolated PostgreSQL acceptance if persisted profile/lifecycle behavior is touched.
|
||||
|
||||
**Work:**
|
||||
- Implement minimal typed operations/events; runtime keeps turn/authority/release,
|
||||
playback bounds and evidence state. Adapters own provider wire interpretation.
|
||||
- Move OpenAI native cancel/terminal/truncate mechanics behind the boundary without
|
||||
changing semantics. Do not lose raw event fingerprints/correlation on normalization.
|
||||
- Represent interruption with an operation ID, response/item/session identity,
|
||||
generation-stop and applied-history progress, and finite deadlines.
|
||||
- Do not introduce capability switches that waive cleanup. Unsupported capabilities
|
||||
reject admission or fail safely. Preserve Gemini's conservative behavior.
|
||||
- Add controlled-clock replay and regression tests. Document the internal contract
|
||||
amendment; browser wire contracts remain unchanged.
|
||||
|
||||
**Accept when:** existing OpenAI tests retain assertions and pass; terminal/error
|
||||
orderings, missing/wrong acknowledgements, duplicates, late events, incomplete
|
||||
responses and bounds remain covered. Shared control has no model/voice branches.
|
||||
Run isolated PostgreSQL cases if persisted profiles/lifecycle behavior is touched.
|
||||
|
||||
**Stop/narrow:** no full runtime rewrite or blanket provider-error suppression.
|
||||
**Stop/narrow:** Unknown upstream behavior stays unverified. Do not weaken OpenAI or start a deployment switch to make the new boundary easier.
|
||||
|
||||
**Prompt:** [Phase 1](local-s2s-adapter-prompts/phase-01.md).
|
||||
|
||||
## 8. Phase 2 - Isolated engine with OpenRouter stages
|
||||
## Phase 2 - Add an isolated local stack and browser voice session
|
||||
|
||||
**Visible outcome:** Submit a Persian recording to the independent smoke, inspect
|
||||
its explicitly requested test transcript, hear a WAV response and see stage usage
|
||||
and timing. The application remains untouched.
|
||||
**Visible outcome:** The existing browser talks in Persian through local_s2s using OpenRouter STT/LLM/TTS, displays transcripts and closes normally in a disposable environment.
|
||||
|
||||
**Entry:** Phase 1 accepted. Isolated engine and candidate API use disposable DB/storage, not the operational database.
|
||||
|
||||
**Work:**
|
||||
- Build the pinned engine in a separate image/environment with local VAD, HTTP
|
||||
STT, Chat Completions LLM and HTTP TTS. No default local model downloads.
|
||||
- Discover/pin available models/voices and validate Persian hints, tool support,
|
||||
endpoint fields, rates and audio formats. Models are independently configurable.
|
||||
- Keep the key inside the engine. Custom endpoints must not accidentally receive
|
||||
another provider's credentials. Keep engine access behind the application boundary.
|
||||
- Start with final-utterance STT, not cumulative HTTP retranscription.
|
||||
- Verify actual multipart/JSON STT and TTS stream_format/PCM compatibility; add only
|
||||
a narrow observed-mismatch shim if necessary.
|
||||
- Bound and meter startup probes, generation, response sizes, retries/concurrency
|
||||
and close. Provide deterministic stubs and an opt-in bounded live smoke.
|
||||
|
||||
**Accept when:** with live prerequisites all stages complete and audio is valid;
|
||||
otherwise mark live-pending. Bad key/model/voice/rate fails setup accurately. Save
|
||||
sanitized timing/usage and consented fixture outputs, not secrets or raw user logs.
|
||||
- Build a separate engine from the pinned SHA with local VAD and independently configured OpenRouter HTTP STT, tool-capable Chat Completions LLM and TTS. Avoid unnecessary local-model/GPU downloads.
|
||||
- Discover/pin actual model IDs, voices, Persian hints, supported fields and PCM rates. Verify multipart/JSON STT, TTS streaming/format compatibility and explicit server-side credential forwarding.
|
||||
- Begin with final-utterance STT. Bound requests/concurrency/bytes/retries/cleanup and meter startup probes. Provide stub mode plus an explicitly opt-in bounded live smoke and playable test audio.
|
||||
- Add local_s2s settings/factory/readiness alongside openai/gemini. Preserve the browser PCM16LE mono24k and existing JSON events; use bounded stateful resampling if required.
|
||||
- Freeze engine/patch/contract revision, component identities, voice/input policy and effective instruction/config digest. Compare to authoritative engine state, not request echoes or socket reachability.
|
||||
- Map actual input acceptance, manual response creation/intent, tool framing, terminal/error and transcript/audio semantics without invented native commit events.
|
||||
- Preserve owner/Origin/cookie/CSRF/replay/epoch checks and old snapshots. Audit provider DTO/DB constraints; use a forward migration only if actually needed and compatible with rollback.
|
||||
- Use a separate test hostname/browser identity and disposable DB/storage. Until Phase 3, interruptions must fail safely and be labelled development-only; do not enable unsafe continuation.
|
||||
|
||||
**Stop/narrow:** do not install every optional model/GPU dependency. Credential or
|
||||
model availability gaps do not authorize fabricated success.
|
||||
**Accept when:**
|
||||
|
||||
- A normal browser greeting/answer/transcript/close works against the isolated candidate, and independent stage probes produce valid audio.
|
||||
- Model/voice/rate/credential/effective-config mismatches fail setup accurately; keys and secret-derived hashes never enter profiles or logs.
|
||||
- Existing OpenAI remains usable; new configuration does not rewrite old reservations or change the operational provider.
|
||||
- Actual provider checks are distinguished from stubs. Missing credentials or real speech evidence leaves live acceptance pending.
|
||||
|
||||
**Show the user:** Show a recorded Persian utterance becoming a WAV response, then perform a normal greeting in the existing browser against the isolated candidate.
|
||||
|
||||
**Validation:** HTTP boundary fixtures, pinned-engine relevant tests, local adapter contract tests, isolated PostgreSQL profile/admission/replay/revocation cases and bounded actual browser/provider smoke.
|
||||
|
||||
**Stop/narrow:** A different port is not DB isolation. Do not claim safe barge-in or production parity before Phase 3; do not promote this provider.
|
||||
|
||||
**Prompt:** [Phase 2](local-s2s-adapter-prompts/phase-02.md).
|
||||
|
||||
## 9. Phase 3 - Local adapter and normal browser session
|
||||
## Phase 3 - Complete interruption, shared RAG and used sources
|
||||
|
||||
**Visible outcome:** In an isolated test app, open the existing browser, say hello,
|
||||
hear a Persian answer, see a transcript, and close cleanly. Show a local_s2s pinned
|
||||
profile. This milestone is development-only, not production parity.
|
||||
**Visible outcome:** The user interrupts and continues safely, receives correct document answers and sees only valid used sources; repeated interrupted searches are not duplicated.
|
||||
|
||||
**Entry:** Phase 2 accepted. Local engine history ownership and compatibility gaps are understood; shared SearchService remains authoritative.
|
||||
|
||||
**Work:**
|
||||
- Add local_s2s configuration/factory selection while keeping openai/gemini.
|
||||
- Freeze engine/patch revision, internal protocol revision, STT/LLM/TTS identities,
|
||||
voice, input policy, rates and effective instruction/config digest. No secrets
|
||||
or credential-derived hashes belong in database execution profiles.
|
||||
- Define the expected configuration and compare to authoritative engine state.
|
||||
A reachable socket or echoed request is insufficient setup proof.
|
||||
- Map actual consumed input, manual response identity/metadata, audio/transcript,
|
||||
terminal and tool events. No invented native commits/acknowledgements.
|
||||
- Preserve browser 24 kHz PCM; use stateful bounded conversion where required,
|
||||
including correct playback-position units.
|
||||
- Preserve owner/Origin/cookie/CSRF/replay/epoch checks. Inspect schema/DTO/provider
|
||||
constraints; use a new migration only if necessary, never edit an applied one.
|
||||
- Use disposable database/storage and isolated test browser identity/origin.
|
||||
Until Phase 4, unsupported interruption must fail safely and be labelled as such.
|
||||
|
||||
**Accept when:** ready/audio/transcript/close work; bad configuration, wrong owner,
|
||||
old epoch, mismatched profile, malformed terminal and disconnect cannot pass
|
||||
silently. Existing profiles are not rewritten; a new session pins new settings.
|
||||
- First implement/prove local interruption and history synchronization. Patch/version the pinned engine narrowly if it cannot apply the required real mutation.
|
||||
- Cover active generation AND already-completed generation with queued unplayed audio. Track operation/response/item/segment/session identities and actual played coordinates.
|
||||
- Inspect the next real controlled LLM request: unheard assistant sentinel text must be absent while valid previous user/tool/assistant context remains. Do not infer text alignment from duration/character ratios.
|
||||
- Accept only receipts emitted after the actual mutation with applied history revision/provenance. Missing, wrong, stale or conflicting receipts fail within bounded deadlines; runtime retains release authority.
|
||||
- If exact heard-prefix repair is unproven, keep the gate open. Whole-turn rollback or fully-played-segment retention is a weaker policy requiring explicit acceptance and contract documentation.
|
||||
- Suppress obsolete STT/LLM/TTS outputs even if remote inference keeps computing. Keep backend retained retrieval separate from speech cancellation and preserve original deadlines.
|
||||
- Then expose search_knowledge, reuse_last_evidence and report_used_sources through the existing backend dispatcher/ToolContext/DurableTools/SearchService; never add engine DB authority or a parallel RAG implementation.
|
||||
- Preserve successful-terminal tool validation, call/item/response dedup, backend scope, calibrated eligible retrieval, source identities and handoff/delivery revalidation.
|
||||
- Test current-turn source reports, private invalid-report correction, no_evidence versus technical error, knowledge revocation, topic switch and interrupted pending-search reuse.
|
||||
- Evaluate known hours/fees, deputy name/organization and incentive percentage/date/exclusion failures. Correct citations alone do not prove correct answer content.
|
||||
|
||||
**Stop/narrow:** a second port with the same operational DB is prohibited. No
|
||||
promotion or hidden fallback before interruption and RAG gates.
|
||||
**Accept when:**
|
||||
|
||||
- No next response before generation-stop, real context repair and playback gates. Active and completed-unplayed history tests pass without fabricated acknowledgement events.
|
||||
- Missing/wrong receipts fail safely; late output cannot contaminate a new turn or reused session; OpenAI interruption regressions remain intact.
|
||||
- All three tools execute through existing authority; no stale/revoked/inactive/deleted evidence reaches reuse/delivery.
|
||||
- Repeating an interrupted same-topic question uses one original retrieval plus revalidation, with valid used-source subset. Known critical document fixtures are answered correctly.
|
||||
|
||||
**Show the user:** Interrupt before an unheard sentinel and inspect the subsequent LLM context; then ask hours, deputy and incentive questions, including a pending-search interruption/repeat.
|
||||
|
||||
**Validation:** Controlled-clock/history-inspection/late-event tests; all affected OpenAI tests; existing retained-search/source suites extended to local; isolated DB evidence/revocation acceptance; bounded real barge-in and RAG checks.
|
||||
|
||||
**Stop/narrow:** This phase has two required checkpoints: history safety before dependent continuation tests, then shared RAG. They are not extra phases, and neither can be skipped or accepted from stopped playback alone.
|
||||
|
||||
**Prompt:** [Phase 3](local-s2s-adapter-prompts/phase-03.md).
|
||||
|
||||
## 10. Phase 4 - Verified interruption and history repair
|
||||
## Phase 4 - Validate quality/cost and prove controlled switch/rollback
|
||||
|
||||
**Visible outcome:** Interrupt a long answer, ask a follow-up, and get a coherent
|
||||
reply without stale audio. In a controlled test, show the actual next LLM input
|
||||
contains no unheard sentinel that was generated later in the interrupted answer.
|
||||
**Visible outcome:** A paired OpenAI/local scorecard supports the deployment decision, and the preserved OpenAI container is demonstrably restorable without rebuild.
|
||||
|
||||
**Entry:** Phase 3 accepted. Frozen corpus/model profiles, bounded live evaluation authorization and reviewable deployment/rollback configuration are available.
|
||||
|
||||
**Work:**
|
||||
- Implement a real correlated engine operation/extension if the pinned version
|
||||
cannot repair history. Keep a reproducible versioned patch with independent tests.
|
||||
- Cover active generation AND completed generation with unplayed buffered audio.
|
||||
- Track item/response/segment/session identities, final consumed position and
|
||||
reliable assistant text/audio alignment. Never use character/duration ratios.
|
||||
- Keep valid prior turns/user/tool state; remove unheard assistant continuation
|
||||
from future generation input. Expose applied history revision/digest as proof.
|
||||
- If exact repair is unavailable, stop this acceptance gate. Conservative whole-turn
|
||||
rollback or fully-played-segment-only history needs explicit policy acceptance.
|
||||
- Admit a receipt only after mutation; reject stale, conflicting, wrong-identity
|
||||
or missing receipts. Runtime retains deadlines and final authority to continue.
|
||||
- Suppress late STT/LLM/TTS results even if remote computation cannot be cancelled.
|
||||
Keep latest backend retrieval independent from speech cancellation.
|
||||
- Repeat OpenAI regressions; the new local proof must not weaken native OpenAI gates.
|
||||
|
||||
**Accept when:** no next turn before generation stop, real repair and playback gates;
|
||||
active and completed-unplayed cases pass; late work cannot reach another turn;
|
||||
missing/wrong proof fails safely. No fake conversation.item.truncated event.
|
||||
- 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.
|
||||
|
||||
**Stop/narrow:** this is the highest-risk phase. Audio stopping or a stock-SDK
|
||||
compatibility claim does not prove our context semantics. Keep promotion blocked.
|
||||
**Accept when:**
|
||||
|
||||
- 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.
|
||||
|
||||
**Show the user:** 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.
|
||||
|
||||
**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.
|
||||
|
||||
**Stop/narrow:** Quality/cost evidence and explicit operational switch authorization are separate gates within this phase. Prepare independent work but do not bypass either.
|
||||
|
||||
**Prompt:** [Phase 4](local-s2s-adapter-prompts/phase-04.md).
|
||||
|
||||
## 11. Phase 5 - Existing RAG tools and used sources
|
||||
|
||||
**Visible outcome:** Ask hours/Thursday, the planning deputy in the specific letter,
|
||||
and the incentive percentage/dates/exclusions. Interrupt a pending search and
|
||||
repeat the question; show one retrieval plus revalidation and relevant UI sources.
|
||||
|
||||
**Work:**
|
||||
- Expose search_knowledge, reuse_last_evidence and report_used_sources to the new
|
||||
LLM. Execute through existing dispatch/ToolContext/DurableTools/SearchService.
|
||||
- Preserve backend identity, calibrated retrieval, document/chunk references and
|
||||
handoff/delivery eligibility. Engine gets no independent retrieval path.
|
||||
- Validate streamed arguments after successful terminal validation; correlate
|
||||
response/item/call identities and deduplicate repeats/replays.
|
||||
- Reuse same-topic pending results within original deadline, revalidate, and discard
|
||||
changed-topic results. Never use earlier assistant prose as document evidence.
|
||||
- Validate current-turn source labels and correct invalid reports privately. Do
|
||||
not show every candidate or persist metadata reports as extra retrievals.
|
||||
- Exercise ok/no_evidence/error, token-limited tools, interrupted delivery,
|
||||
revocation/deactivation and all known Mini factual failure cases.
|
||||
|
||||
**Accept when:** all three tools retain existing authority; no stale evidence or
|
||||
extra retrieval on same-topic reuse; used subset has original document/chunk
|
||||
identity. Correct citation membership is not claimed as full factual verification.
|
||||
|
||||
**Stop/narrow:** no weakened cutoff/filter or second search implementation to hide
|
||||
model-quality problems.
|
||||
|
||||
**Prompt:** [Phase 5](local-s2s-adapter-prompts/phase-05.md).
|
||||
|
||||
## 12. Phase 6 - Persian quality, latency, cost and resilience
|
||||
|
||||
**Visible outcome:** A paired OpenAI/local scorecard and audio samples show the
|
||||
actual trade-off. Demonstrate a controlled provider failure without contamination.
|
||||
|
||||
**Work:**
|
||||
- Evaluate the same authorized frozen corpus and paired Persian audio/question
|
||||
fixtures. Keep exact baseline/candidate component profiles and sample counts.
|
||||
- Cover names/roles, numbers/dates, natural pauses, noise, self-correction,
|
||||
ambiguity, continuation, topic switch, no evidence and document conflicts.
|
||||
- Measure speech-end-to-first-audible-sample, tool time, first text/audio,
|
||||
interruption-to-stop, underruns, duplicates, disconnects and task completion.
|
||||
- Count cached/input/output usage when available, STT duration, TTS billed units,
|
||||
startup probes, failures and abandoned work. Missing usage stays unknown. Compare
|
||||
cost per successful task, not only successful API requests.
|
||||
- Fault-inject slow/down providers, quotas, stream loss, restart and saturation.
|
||||
Prove bounded queues, late-result suppression and no stacked retry storms.
|
||||
- Change one component at a time. Human listening is separate from transport tests;
|
||||
do not claim that a better LLM repairs bad transcription.
|
||||
|
||||
**Accept when:** all critical factual fixture assertions pass with zero invented
|
||||
names/numbers/dates/conditions; all intended interruption cases pass or fail safely
|
||||
as specified; results assess predeclared targets and expose all failures.
|
||||
|
||||
Provisional goals, to accept or revise explicitly BEFORE evaluation: p95 first
|
||||
audible response <= baseline + 1 second, no persistent underruns, and cost per
|
||||
successful task <= 70% of baseline for a cost-saving promotion. These are targets,
|
||||
not measurements or universal guarantees. If quality/cost goals fail, keep OpenAI.
|
||||
|
||||
**Stop/narrow:** missing actual provider/human evidence leaves the gate open. Do
|
||||
not broaden prompts/buffers or silently change thresholds after seeing results.
|
||||
|
||||
**Prompt:** [Phase 6](local-s2s-adapter-prompts/phase-06.md).
|
||||
|
||||
## 13. Phase 7 - Controlled switch and demonstrated rollback
|
||||
|
||||
**Visible outcome:** Demonstrate a local document interaction, then stop the
|
||||
candidate, start the preserved OpenAI API without rebuild, and repeat the question.
|
||||
Leave the selected provider in the final state explicitly requested by the user.
|
||||
|
||||
**Work:**
|
||||
- Finalize opt-in Compose and .env.example; OpenAI stays default until an explicit
|
||||
operational switch. No automatic fallback or UI provider selector.
|
||||
- Verify original container/image/config retention. Candidate gets separate tags;
|
||||
never prune, remove, overwrite or rebuild the original rollback target.
|
||||
- Check effective setup, health, secrets, bounds and database compatibility before
|
||||
switching. An incompatible migration blocks simple old-container rollback.
|
||||
- Drain/close current sessions, stop the existing API, then start the candidate on
|
||||
the operational DB. Never two application APIs against that DB simultaneously.
|
||||
- Test a fresh browser session: greeting, RAG, used sources, interruption and close.
|
||||
- Actually exercise rollback and verify readiness plus a fresh OpenAI session.
|
||||
Container rollback is not database/filesystem rollback or media-session resume.
|
||||
- Record commands, identities, fingerprints, checks, final state and limitations.
|
||||
|
||||
**Accept when:** preserved OpenAI restoration succeeds; user/ingestion data is
|
||||
preserved; one API owns the operational lifecycle at a time; session profiles stay
|
||||
pinned. Health readiness alone is not speech/RAG acceptance.
|
||||
|
||||
**Stop/narrow:** prepare all reviewable work first. Without the operational switch
|
||||
authorization, compatibility or live evidence, stop before changing the service.
|
||||
|
||||
**Prompt:** [Phase 7](local-s2s-adapter-prompts/phase-07.md).
|
||||
|
||||
## 14. Configuration, data and deployment contract
|
||||
## 6. Configuration, data and deployment contract
|
||||
|
||||
Proposed names below must be finalized before implementation and documented with
|
||||
units/defaults. Do not create unvalidated option bags or leak credentials to LLMs.
|
||||
@@ -398,10 +291,10 @@ credentials with matching trusted Origin. Do not copy production auth sessions
|
||||
into a parallel test browser. Operational switching runs only one application API.
|
||||
|
||||
No schema migration is assumed. Inspect provider constraints/DTOs/profile replay
|
||||
in Phases 0/3; use a new migration only if required and verify rollback image
|
||||
in Phases 1/2; use a new migration only if required and verify rollback image
|
||||
compatibility. Do not add document_versions/version_id/version_no.
|
||||
|
||||
## 15. Validation commands and evidence
|
||||
## 7. Validation commands and evidence
|
||||
|
||||
Verify paths and side effects at execution time. Focused baseline command:
|
||||
|
||||
@@ -440,11 +333,11 @@ Only accepted closes a required gate. Missing paid authorization blocks dependen
|
||||
live work, not independent preparation. Reuse existing bounded authorization; do
|
||||
not ask the user to approve the same action repeatedly.
|
||||
|
||||
## 16. Decisions to resolve and definition of done
|
||||
## 8. Decisions to resolve and definition of done
|
||||
|
||||
- Upstream SHA, dependency/build lock and maintained patch provenance: Phase 0.
|
||||
- Effective profile/config attestation and concurrent engine isolation: Phase 3.
|
||||
- Real heard-prefix mapping/receipt: Phase 4 hard gate; weaker policy requires an
|
||||
- Upstream SHA, dependency/build lock and maintained patch provenance: Phase 1.
|
||||
- Effective profile/config attestation and concurrent engine isolation: Phase 2.
|
||||
- Real heard-prefix mapping/receipt: Phase 3 hard gate; weaker policy requires an
|
||||
explicit product decision and intentional API/workflow documentation.
|
||||
- Available OpenRouter models/voices, Persian quality, hardware footprint and
|
||||
latency/cost: measure, do not infer from default local-model examples.
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
# Local S2S adapter progress
|
||||
# Local S2S adapter progress - four phases
|
||||
|
||||
Created: 2026-10-15. This ledger records execution, not a completion claim.
|
||||
Plan/prompts are written; implementation, paid calls, downloads and operational
|
||||
switches have NOT been performed as part of this planning task.
|
||||
Updated: 2026-10-15. The original eight stages were consolidated into four before
|
||||
implementation started. Scope and acceptance requirements are retained. Planning
|
||||
only: no implementation, model downloads, paid validation or operational switch
|
||||
was performed by this consolidation.
|
||||
|
||||
[Plan](local-s2s-adapter-plan.md) | [Prompts](local-s2s-adapter-prompts/README.md)
|
||||
[Plan](local-s2s-adapter-plan.md) | [Four active prompts](local-s2s-adapter-prompts/README.md)
|
||||
|
||||
| Phase | Status | Evidence | Visible demo | Blockers |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 0 - Baseline and immutable upstream audit | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 1 - Small provider boundary with OpenAI preserved | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 2 - Isolated S2S engine with OpenRouter stages | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 3 - Local provider and normal browser session | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 4 - Verified interruption and history synchronization | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 5 - Shared RAG and declared-source integration | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 6 - Persian quality, latency, cost and resilience | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 7 - Controlled switch and verified rollback | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 1 - Preserve OpenAI and introduce the provider boundary | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 2 - Add an isolated local stack and browser voice session | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 3 - Complete interruption, shared RAG and used sources | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
| 4 - Validate quality/cost and prove controlled switch/rollback | not_started | Not run | Not demonstrated | Resolve prerequisites |
|
||||
|
||||
## Phase evidence template
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
# Local S2S phase prompts
|
||||
# Four active local S2S implementation prompts
|
||||
|
||||
Read [the complete plan](../local-s2s-adapter-plan.md) and [progress ledger](../local-s2s-adapter-progress.md). Each file contains one copy-ready English prompt. Run one phase at a time; never assume prerequisites passed.
|
||||
Read [the plan](../local-s2s-adapter-plan.md) and [progress ledger](../local-s2s-adapter-progress.md).
|
||||
Run one prompt per phase. These four prompts supersede the eight-stage version;
|
||||
[historical prompts](../archive/local-s2s-eight-phase/README.md) are not active.
|
||||
|
||||
- [Phase 0 - Baseline and immutable upstream audit](phase-00.md)
|
||||
- [Phase 1 - Small provider boundary with OpenAI preserved](phase-01.md)
|
||||
- [Phase 2 - Isolated S2S engine with OpenRouter stages](phase-02.md)
|
||||
- [Phase 3 - Local provider and normal browser session](phase-03.md)
|
||||
- [Phase 4 - Verified interruption and history synchronization](phase-04.md)
|
||||
- [Phase 5 - Shared RAG and declared-source integration](phase-05.md)
|
||||
- [Phase 6 - Persian quality, latency, cost and resilience](phase-06.md)
|
||||
- [Phase 7 - Controlled switch and verified rollback](phase-07.md)
|
||||
- [Phase 1 - Preserve OpenAI and introduce the provider boundary](phase-01.md)
|
||||
- [Phase 2 - Add an isolated local stack and browser voice session](phase-02.md)
|
||||
- [Phase 3 - Complete interruption, shared RAG and used sources](phase-03.md)
|
||||
- [Phase 4 - Validate quality/cost and prove controlled switch/rollback](phase-04.md)
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
# Phase 1 - Small provider boundary with OpenAI preserved
|
||||
# Phase 1 - Preserve OpenAI and introduce the provider boundary
|
||||
|
||||
Paste the following into a fresh implementation session in this repository.
|
||||
Copy this prompt into a fresh implementation session in the repository.
|
||||
|
||||
```text
|
||||
Implement Phase 1 only: Small provider boundary with OpenAI preserved.
|
||||
Implement Phase 1 of the active FOUR-phase local S2S plan only: Preserve OpenAI and introduce the provider boundary.
|
||||
Do not execute the archived eight-stage prompts.
|
||||
|
||||
Prerequisite:
|
||||
Phase 0 audit, scoped contract proposal and baseline evidence exist.
|
||||
No adapter implementation has started. Inspect the current repository and deployment first.
|
||||
|
||||
Required visible outcome:
|
||||
OpenAI still produces the same command/ack behavior through a provider boundary; show a deterministic before/after replay.
|
||||
An existing OpenAI session still works; an offline before/after interruption replay proves the same cleanup and next-turn behavior.
|
||||
|
||||
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.
|
||||
@@ -24,34 +25,36 @@ Execution rules:
|
||||
- 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. Implement minimal internal typed operations/events for actual runtime needs, preserving raw provider replay fingerprints and identities.
|
||||
2. Keep turn ownership, authorization, evidence, deadlines, audio credits, final played positions and next-turn release in runtime. Move native encoding/parsing and confirmation interpretation into adapters.
|
||||
3. Define interruption progress with operation/response/item/session identities and separate generation-stop/history-repair proof. Capability declarations must not waive cleanup.
|
||||
4. Adapt OpenAI using existing cancel/terminal/truncate semantics unchanged. Preserve Gemini conservative failure. No model/voice branches in shared control.
|
||||
5. Add controlled-clock regression/replay tests and document the internal responsibility amendment while keeping browser wire behavior fixed.
|
||||
- Capture current/preserved container and image identities, effective provider/profile and focused regression results. Keep the operational deployment unchanged.
|
||||
- Pin an upstream commit/build inputs and audit actual setup, input consumption, manual turn control, metadata/identities, tool events, audio rates, terminal states and history repair.
|
||||
- Record a compatibility matrix and unresolved decisions, especially the no-op truncate and completed-but-unplayed history case.
|
||||
- Extract only the small internal provider boundary needed by runtime. Runtime owns authorization, turn identity, playback credits, deadlines, evidence lifetime and next-turn release; adapters own native wire/confirmation details.
|
||||
- Keep native OpenAI cancel/terminal/truncate/ack semantics, raw replay fingerprints and correlation intact. Preserve Gemini's conservative failures.
|
||||
- Define correlated interruption progress with separate generation-stop and actual history-repair proof. Capability flags never waive safety gates.
|
||||
- Add controlled-clock replay/conformance coverage and document the internal responsibility split without changing public browser behavior.
|
||||
|
||||
Acceptance criteria:
|
||||
- Existing OpenAI assertions remain and affected tests pass, with prior failures reported honestly.
|
||||
- Before/after trace releases exactly one next response after matching cleanup.
|
||||
- Wrong/missing/late/duplicate-conflicting events, limited tools and timeouts fail safely.
|
||||
- No deployment/default change or unnecessary persistence migration.
|
||||
- Existing OpenAI regressions retain their assertions and pass; pre-existing failures are reported honestly.
|
||||
- The same fixture before/after refactoring releases exactly one new response after matching cleanup, with wrong/missing/late/conflicting acknowledgements failing safely.
|
||||
- Upstream SHA/build provenance, compatibility gaps and original rollback identities are recorded.
|
||||
- No runtime switch, production data change, wholesale rewrite or model/voice branch in shared turn control.
|
||||
|
||||
Relevant paths (verify actual locations before editing):
|
||||
runtime.py, a minimal internal provider-contract module if justified, realtime.py, Gemini adapter only where needed, diagnostics and focused tests.
|
||||
Relevant areas; verify actual paths first:
|
||||
configuration/settings, runtime.py, realtime.py, provider factory, minimal shared contract, Gemini compatibility, focused tests and voice contract docs.
|
||||
|
||||
Validation:
|
||||
Provider-free adapter/runtime conformance plus existing races, final playback, output limits and evidence tests. Isolated PostgreSQL only if persistence behavior changed.
|
||||
Existing context-sync, provider-selection, retained-search, source-report, output-limit and style tests; controlled-clock replay. Isolated PostgreSQL acceptance if persisted profile/lifecycle behavior is touched.
|
||||
|
||||
Visible demonstration:
|
||||
Replay a fixture: interrupted old output stops, matching final played position is confirmed, and one new response begins.
|
||||
Visible demo:
|
||||
Run an existing OpenAI interaction if already authorized, and show a deterministic interruption trace through the new boundary. No new provider is enabled.
|
||||
|
||||
Explicit stop/narrow condition:
|
||||
No wholesale state-machine rewrite or generic provider-error suppression.
|
||||
Stop/narrow condition:
|
||||
Unknown upstream behavior stays unverified. Do not weaken OpenAI or start a deployment switch to make the new boundary easier.
|
||||
|
||||
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-01.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.
|
||||
Deliver scoped implementation/configuration/tests/contracts as necessary,
|
||||
docs/evaluation/local-s2s/phase-01.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.
|
||||
```
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
# Phase 2 - Isolated S2S engine with OpenRouter stages
|
||||
# Phase 2 - Add an isolated local stack and browser voice session
|
||||
|
||||
Paste the following into a fresh implementation session in this repository.
|
||||
Copy this prompt into a fresh implementation session in the repository.
|
||||
|
||||
```text
|
||||
Implement Phase 2 only: Isolated S2S engine with OpenRouter stages.
|
||||
Implement Phase 2 of the active FOUR-phase local S2S plan only: Add an isolated local stack and browser voice session.
|
||||
Do not execute the archived eight-stage prompts.
|
||||
|
||||
Prerequisite:
|
||||
Pinned engine/build design from Phase 0; independent of Phase 1 where no application integration is used.
|
||||
Phase 1 accepted. Isolated engine and candidate API use disposable DB/storage, not the operational database.
|
||||
|
||||
Required visible outcome:
|
||||
A Persian recording independently becomes a transcript, LLM response and playable WAV with stage timings and actual usage.
|
||||
The existing browser talks in Persian through local_s2s using OpenRouter STT/LLM/TTS, displays transcripts and closes normally in a disposable environment.
|
||||
|
||||
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.
|
||||
@@ -24,34 +25,37 @@ Execution rules:
|
||||
- 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. Build a separate pinned engine image/environment. Use local VAD and independently configured remote STT, Chat Completions LLM and TTS.
|
||||
2. Discover/pin supported model IDs/voices/parameters and test Persian language behavior. Choose a tool-capable text LLM, not an assumed universal audio endpoint.
|
||||
3. Verify explicit credential forwarding, multipart/JSON STT, TTS stream fields, raw PCM rate/endianness and startup probes. Add a narrow shim only for an observed mismatch.
|
||||
4. Use final-utterance STT initially. Bound retries, requests, response sizes, concurrency and cleanup; include startup probes in cost.
|
||||
5. Provide deterministic stub mode and opt-in live smoke with bounded requests/time/cost. Save only consented evaluation outputs; do not connect to production DB/API.
|
||||
- Build a separate engine from the pinned SHA with local VAD and independently configured OpenRouter HTTP STT, tool-capable Chat Completions LLM and TTS. Avoid unnecessary local-model/GPU downloads.
|
||||
- Discover/pin actual model IDs, voices, Persian hints, supported fields and PCM rates. Verify multipart/JSON STT, TTS streaming/format compatibility and explicit server-side credential forwarding.
|
||||
- Begin with final-utterance STT. Bound requests/concurrency/bytes/retries/cleanup and meter startup probes. Provide stub mode plus an explicitly opt-in bounded live smoke and playable test audio.
|
||||
- Add local_s2s settings/factory/readiness alongside openai/gemini. Preserve the browser PCM16LE mono24k and existing JSON events; use bounded stateful resampling if required.
|
||||
- Freeze engine/patch/contract revision, component identities, voice/input policy and effective instruction/config digest. Compare to authoritative engine state, not request echoes or socket reachability.
|
||||
- Map actual input acceptance, manual response creation/intent, tool framing, terminal/error and transcript/audio semantics without invented native commit events.
|
||||
- Preserve owner/Origin/cookie/CSRF/replay/epoch checks and old snapshots. Audit provider DTO/DB constraints; use a forward migration only if actually needed and compatible with rollback.
|
||||
- Use a separate test hostname/browser identity and disposable DB/storage. Until Phase 3, interruptions must fail safely and be labelled development-only; do not enable unsafe continuation.
|
||||
|
||||
Acceptance criteria:
|
||||
- With authorized live prerequisites, all three stages succeed and output audio is valid; otherwise mark live-pending.
|
||||
- Invalid key/model/voice/rate cannot produce false readiness.
|
||||
- Models remain independently replaceable and keys remain server-side.
|
||||
- Existing app, worker, database and rollback container are untouched.
|
||||
- A normal browser greeting/answer/transcript/close works against the isolated candidate, and independent stage probes produce valid audio.
|
||||
- Model/voice/rate/credential/effective-config mismatches fail setup accurately; keys and secret-derived hashes never enter profiles or logs.
|
||||
- Existing OpenAI remains usable; new configuration does not rewrite old reservations or change the operational provider.
|
||||
- Actual provider checks are distinguished from stubs. Missing credentials or real speech evidence leaves live acceptance pending.
|
||||
|
||||
Relevant paths (verify actual locations before editing):
|
||||
An opt-in engine build/service directory, isolated Compose configuration, smoke command and evaluation fixtures. Do not vendor all upstream code into app/.
|
||||
Relevant areas; verify actual paths first:
|
||||
Pinned engine service/build config, isolated Compose profile, local adapter, validated settings/profile/factory/readiness, .env.example, smoke harness and tests.
|
||||
|
||||
Validation:
|
||||
Pinned upstream relevant tests and HTTP fixtures; optional bounded actual-provider requests. Ordinary tests require no keys or weights.
|
||||
HTTP boundary fixtures, pinned-engine relevant tests, local adapter contract tests, isolated PostgreSQL profile/admission/replay/revocation cases and bounded actual browser/provider smoke.
|
||||
|
||||
Visible demonstration:
|
||||
Run the isolated Persian smoke, inspect its requested test transcript, hear the WAV and view per-stage timing/usage.
|
||||
Visible demo:
|
||||
Show a recorded Persian utterance becoming a WAV response, then perform a normal greeting in the existing browser against the isolated candidate.
|
||||
|
||||
Explicit stop/narrow condition:
|
||||
Missing keys/availability blocks live proof only. Do not install unrelated local-model/GPU extras.
|
||||
Stop/narrow condition:
|
||||
A different port is not DB isolation. Do not claim safe barge-in or production parity before Phase 3; do not promote this provider.
|
||||
|
||||
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-02.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.
|
||||
Deliver scoped implementation/configuration/tests/contracts as necessary,
|
||||
docs/evaluation/local-s2s/phase-02.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.
|
||||
```
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
# Phase 3 - Local provider and normal browser session
|
||||
# Phase 3 - Complete interruption, shared RAG and used sources
|
||||
|
||||
Paste the following into a fresh implementation session in this repository.
|
||||
Copy this prompt into a fresh implementation session in the repository.
|
||||
|
||||
```text
|
||||
Implement Phase 3 only: Local provider and normal browser session.
|
||||
Implement Phase 3 of the active FOUR-phase local S2S plan only: Complete interruption, shared RAG and used sources.
|
||||
Do not execute the archived eight-stage prompts.
|
||||
|
||||
Prerequisite:
|
||||
Phases 1 and 2 have accepted prerequisite evidence. Candidate app has disposable DB/storage.
|
||||
Phase 2 accepted. Local engine history ownership and compatibility gaps are understood; shared SearchService remains authoritative.
|
||||
|
||||
Required visible outcome:
|
||||
The existing browser opens a local_s2s session, greets in Persian, displays transcript and closes cleanly in isolation.
|
||||
The user interrupts and continues safely, receives correct document answers and sees only valid used sources; repeated interrupted searches are not duplicated.
|
||||
|
||||
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.
|
||||
@@ -24,36 +25,39 @@ Execution rules:
|
||||
- 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. Add local_s2s to validated selection/factory/settings/readiness without removing openai/gemini or adding a UI selector.
|
||||
2. Freeze engine/patch/contract revisions, effective component models, voice, speech policy, rates and instruction/config digest. Do not store secrets or secret hashes.
|
||||
3. Compare reservation expectations with authoritative effective engine setup; do not rely on connection reachability or echoing desired values.
|
||||
4. Map real input acceptance, response intent/identity, tool frames, terminal states and audio/transcript. Do not synthesize native commit acknowledgements from timing.
|
||||
5. Keep browser PCM16LE mono24k and public events. Bound resampling and convert playback coordinates correctly.
|
||||
6. Preserve owner/Origin/cookie/CSRF/replay/epoch checks and old profiles. Audit DB/DTO constraints; new migration only if necessary.
|
||||
7. Use isolated DB/storage and separate test browser credentials/origin. Unsupported interruption fails closed until Phase 4.
|
||||
- First implement/prove local interruption and history synchronization. Patch/version the pinned engine narrowly if it cannot apply the required real mutation.
|
||||
- Cover active generation AND already-completed generation with queued unplayed audio. Track operation/response/item/segment/session identities and actual played coordinates.
|
||||
- Inspect the next real controlled LLM request: unheard assistant sentinel text must be absent while valid previous user/tool/assistant context remains. Do not infer text alignment from duration/character ratios.
|
||||
- Accept only receipts emitted after the actual mutation with applied history revision/provenance. Missing, wrong, stale or conflicting receipts fail within bounded deadlines; runtime retains release authority.
|
||||
- If exact heard-prefix repair is unproven, keep the gate open. Whole-turn rollback or fully-played-segment retention is a weaker policy requiring explicit acceptance and contract documentation.
|
||||
- Suppress obsolete STT/LLM/TTS outputs even if remote inference keeps computing. Keep backend retained retrieval separate from speech cancellation and preserve original deadlines.
|
||||
- Then expose search_knowledge, reuse_last_evidence and report_used_sources through the existing backend dispatcher/ToolContext/DurableTools/SearchService; never add engine DB authority or a parallel RAG implementation.
|
||||
- Preserve successful-terminal tool validation, call/item/response dedup, backend scope, calibrated eligible retrieval, source identities and handoff/delivery revalidation.
|
||||
- Test current-turn source reports, private invalid-report correction, no_evidence versus technical error, knowledge revocation, topic switch and interrupted pending-search reuse.
|
||||
- Evaluate known hours/fees, deputy name/organization and incentive percentage/date/exclusion failures. Correct citations alone do not prove correct answer content.
|
||||
|
||||
Acceptance criteria:
|
||||
- Ready/audio/transcript/close work end to end in the isolated app.
|
||||
- Incorrect profile, configuration, ownership or epoch is rejected; no snapshot rewrites.
|
||||
- Malformed terminals/disconnects cannot cause false success.
|
||||
- This remains development-only, not operational parity or a default switch.
|
||||
- No next response before generation-stop, real context repair and playback gates. Active and completed-unplayed history tests pass without fabricated acknowledgement events.
|
||||
- Missing/wrong receipts fail safely; late output cannot contaminate a new turn or reused session; OpenAI interruption regressions remain intact.
|
||||
- All three tools execute through existing authority; no stale/revoked/inactive/deleted evidence reaches reuse/delivery.
|
||||
- Repeating an interrupted same-topic question uses one original retrieval plus revalidation, with valid used-source subset. Known critical document fixtures are answered correctly.
|
||||
|
||||
Relevant paths (verify actual locations before editing):
|
||||
configuration.py, settings.py, voice_provider.py, new local adapter, live admission/lifecycle only where required, .env.example and isolated deployment config.
|
||||
Relevant areas; verify actual paths first:
|
||||
Local adapter and minimal pinned-engine repair extension, shared interruption contract/barriers, tool event mapping, existing dispatch/DurableTools and focused conformance/evaluation tests.
|
||||
|
||||
Validation:
|
||||
Provider-free adapter contract tests, isolated PostgreSQL admission/replay/profile/revocation, then bounded browser live smoke.
|
||||
Controlled-clock/history-inspection/late-event tests; all affected OpenAI tests; existing retained-search/source suites extended to local; isolated DB evidence/revocation acceptance; bounded real barge-in and RAG checks.
|
||||
|
||||
Visible demonstration:
|
||||
Use the existing browser to greet and close. Show the local pinned profile and separate OpenAI conformance results.
|
||||
Visible demo:
|
||||
Interrupt before an unheard sentinel and inspect the subsequent LLM context; then ask hours, deputy and incentive questions, including a pending-search interruption/repeat.
|
||||
|
||||
Explicit stop/narrow condition:
|
||||
Never use a second port with the operational DB. No promotion before interruption/RAG acceptance.
|
||||
Stop/narrow condition:
|
||||
This phase has two required checkpoints: history safety before dependent continuation tests, then shared RAG. They are not extra phases, and neither can be skipped or accepted from stopped playback alone.
|
||||
|
||||
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-03.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.
|
||||
Deliver scoped implementation/configuration/tests/contracts as necessary,
|
||||
docs/evaluation/local-s2s/phase-03.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.
|
||||
```
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
# Phase 4 - Verified interruption and history synchronization
|
||||
# Phase 4 - Validate quality/cost and prove controlled switch/rollback
|
||||
|
||||
Paste the following into a fresh implementation session in this repository.
|
||||
Copy this prompt into a fresh implementation session in the repository.
|
||||
|
||||
```text
|
||||
Implement Phase 4 only: Verified interruption and history synchronization.
|
||||
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 works in isolation. Upstream history/turn ownership and required patch are understood.
|
||||
Phase 3 accepted. Frozen corpus/model profiles, bounded live evaluation authorization and reviewable deployment/rollback configuration are available.
|
||||
|
||||
Required visible outcome:
|
||||
The user interrupts a long answer and continues coherently; inspect the next model request to prove unheard sentinel text is absent.
|
||||
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.
|
||||
@@ -24,36 +25,38 @@ Execution rules:
|
||||
- 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. Add an actual correlated engine repair operation/extension if needed. Pin the patch and test it independently; do not monkey-patch installed packages as the deployment strategy.
|
||||
2. Handle both active generation and completed generation with audio still queued at the browser. Closing TTS HTTP or getting response.done does not prove history repair.
|
||||
3. Track response/item/segment/session identities, final consumed position and reliable text/audio mapping; no proportional text slicing.
|
||||
4. Preserve valid earlier user/assistant/tool state and remove unheard assistant continuation from subsequent LLM input. Verify applied history revision/digest.
|
||||
5. If exact heard-prefix repair cannot be proven, keep this gate open. Whole-turn rollback or fully-played-segment-only retention needs explicit policy acceptance and contract changes.
|
||||
6. Validate real applied receipts against operation identity; reject stale/missing/conflicting receipts with bounded safe failure. Runtime owns final release.
|
||||
7. Suppress late STT/LLM/TTS work and preserve same-topic backend search independently. Re-run all affected OpenAI interruption tests.
|
||||
- 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:
|
||||
- Generation stop, real context repair and application playback gates all precede next response.
|
||||
- Active and completed-unplayed cases pass controlled history inspection and actual microphone testing.
|
||||
- Wrong/missing receipts fail safely; late output cannot contaminate another turn/session.
|
||||
- No fabricated conversation.item.truncated or weakened OpenAI checks; unapproved weaker policies block promotion.
|
||||
- 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 paths (verify actual locations before editing):
|
||||
Internal interruption contract, local adapter, pinned engine extension/patch, runtime barrier integration, diagnostics and regression tests.
|
||||
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:
|
||||
Controlled clocks, ordering, races, receipt replay, mid-segment interruption, teardown/reuse, terminal-completed/unplayed audio, plus actual bounded live interruption.
|
||||
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 demonstration:
|
||||
Generate an answer with a late sentinel, interrupt before hearing it, inspect the following LLM context, then demonstrate real barge-in and continuation.
|
||||
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.
|
||||
|
||||
Explicit stop/narrow condition:
|
||||
This is the highest-risk gate. Stopped playback or upstream SDK compatibility does not prove the required semantics.
|
||||
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:
|
||||
1. Scoped code/configuration and necessary tests/contracts where this phase requires implementation; Phase 0 remains an audit.
|
||||
2. docs/evaluation/local-s2s/phase-04.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.
|
||||
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.
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user