feat(voice): implement local S2S responsiveness candidate and direct TTS routing

Add local S2S responsiveness candidate pinning ASR options and sentence-at-a-time generation. Route speech synthesis directly to OpenAI API for fluent Persian phonetics with gpt-4o-mini-tts-2025-12-15. Add responsiveness, budget carry, and browser watch unit tests along with acceptance benchmarks and evaluation evidence.
This commit is contained in:
amirhosein mazaheri
2026-10-17 13:02:41 +03:30
parent a94b8cd3ea
commit 628aec8def
40 changed files with 1568 additions and 70 deletions
+27 -9
View File
@@ -1,5 +1,23 @@
# Phase 1 agent reference map
Latest document-intake override (2026-10-17): mandatory admin review disabled for new isolated-test uploads; existing Gemini 2.5 Flash Vision configured, automatic admission with warnings enabled. Four user files independently reimported and ready (5/100/3/21 chunks), 75 relevant tests passed. Historical failed rows preserved; active knowledge selection unchanged. Details in [combined runtime evidence](evaluation/local-s2s/combined-ready-20261017.md).
Latest user override and runtime (2026-10-17): [both voice providers and calibrated RAG ready](evaluation/local-s2s/combined-ready-20261017.md). Cost admission disabled explicitly; old budget ceilings below are historical. Memory prevention remains OFF. Direct OpenAI ASR/TTS, 85 focused tests passed, both actual session_ready/normal close passed, bge-m3 calibration reproduced 6/6 supported and 0/4 false positives. Microphone acceptance and immediate provider-switch cleanup remain open.
Latest responsive candidate (2026-10-17): [sentence-at-a-time and ASR policy implemented/live](evaluation/local-s2s/responsive-candidate-20261017.md). 157 unit +3 PostgreSQL passed; actual single-sentence native active-cancel/history fixture passed; real startup and proxied setup/normal close passed. Human Persian accuracy/latency comparison pending. Reserve $0.769884452, exclusive ceiling $0.981884452. Memory prevention OFF; no old-ledger restart.
Latest human result (2026-10-17): [two real playback interruptions and continuation passed](evaluation/local-s2s/windows-live-interruption-20261017.md). User confirms intentional barge-in and no stale audio. Generation had already completed at both cuts; active cancellation and same-answer repeat untested. New12 bills total $0.006186253; reconciled exposure $0.710884452. Engine stopped after attempt caps; UI/API remain. Memory prevention OFF. Phase3/4 open.
Latest active Windows handoff (2026-10-17): [second browser test ready](evaluation/local-s2s/windows-browser-handoff-02-20261017.md). Memory prevention OFF per user; startup and proxied session_ready/normal close passed. New exclusive billed carry baseline $0.704698199, reserve $0.763698199, ceiling $0.940698199. Human test now required; RAG/OpenAI comparison pending. Never restart the ledger.
User override (2026-10-17): Windows browser memory prevention is temporarily disabled by default; monitoring continues. `--enforce-memory-floor` restores preflight/runtime RAM checks. Docker memory cap, budget/exclusive ledger and time limits remain. See [incident and override](evaluation/local-s2s/windows-browser-stop-20261017.md). No paid restart occurred.
Latest Windows incident (2026-10-17): [engine stopped on memory floor before human tests](evaluation/local-s2s/windows-browser-stop-20261017.md). Earlier browser-ready handoff is inactive. Two user setup failures made no inference calls. Exact startup bills reconcile new exposure to $0.704698199, with full older reserves retained; exclusive ledger not restarted. Memory headroom and a verified billing-linked new carry are required before another paid launch.
Latest Windows handoff (2026-10-17): [human browser test ready](evaluation/local-s2s/windows-browser-handoff-20261017.md). Actual startup and proxied session_ready/normal close passed; carried reserve $0.763504399, exclusive ceiling $0.940504399. Real microphone/interruption acceptance, RAG and bounded OpenAI comparison remain pending. Engine expires after30minutes; never restart this ledger.
Current host continuation (2026-10-17): [Windows reconstruction and budget carry](evaluation/local-s2s/windows-continuation-20261017.md). Prior tests ran on another computer. Native images/private ledgers are absent here; verified source/assets and conservative $0.704504399 carry are prepared. No new paid inference or Phase 3/4 acceptance. Windows host memory and bounded admission remain launch gates.
Current preparation (2026-10-16): [Phase 4 frontend/provider selection and paired evaluation tooling](evaluation/local-s2s/phase-04.md).
Phase 3 retains interrupted answers as explicitly unheard drafts per the user's
revised policy; real barge-in/RAG/factual acceptance remains pending. Phase 4 is
@@ -187,7 +205,7 @@ Section numbers and heading names below are verified against these files; no inf
| --- | --- | --- |
| `RAG-AI-Phase1-Delivery-Plan.md` | [Delivery plan](specifications/RAG-AI-Phase1-Delivery-Plan.md) | Scope, sequence, acceptance: 3. Included and Deferred Scope; 6. Document Lifecycle and Knowledge Changes; 8. Delivery Schedule and Checkpoints; 9. Acceptance Criteria; 10. Demonstration Script |
| `RAG-Phase1-Implementation-Guide.md` | [Implementation guide](specifications/RAG-Phase1-Implementation-Guide.md) | Modules/workflows: 3. Modules and ports; 5. Identity and request context; 6. Document upload and ingestion; 7. Selection, revisions and revocation; 8. Deferred text turn execution; 9. Live lifecycle; 10. Internal search contract; 12. Tests and handoff; 13. Decisions still requiring confirmation |
| `RAG-Phase1-API-Catalog.md` | [API catalog](specifications/RAG-Phase1-API-Catalog.md) | Routes/DTOs/permissions/errors/replay: 1. Transport and common conventions; 2. Endpoint inventory; 4. Documents and selected knowledge; 6. Conversations and deferred text; 7. Voice contract أ¢â‚¬â€‌ OpenAI Realtime; frozen application audio/events; 9. Error envelope and mapping |
| `RAG-Phase1-API-Catalog.md` | [API catalog](specifications/RAG-Phase1-API-Catalog.md) | Routes/DTOs/permissions/errors/replay: 1. Transport and common conventions; 2. Endpoint inventory; 4. Documents and selected knowledge; 6. Conversations and deferred text; 7. Voice contract ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬أ¢â‚¬إ’ OpenAI Realtime; frozen application audio/events; 9. Error envelope and mapping |
| `RAG-Phase1-Database-Design.md` | [Database design](specifications/RAG-Phase1-Database-Design.md) | Schema/constraints/transactions: 4. Knowledge tables; 5. Minimal voice conversation and evidence; deferred text tables; 6. Live and audit tables; 7. Transaction boundaries and invariant enforcement; 8. Migration plan; 9. Essential database validation |
| `RAG-Phase1-MVP-Scenarios.md` | [English MVP scenarios](specifications/RAG-Phase1-MVP-Scenarios.md) | Current journeys: 2. Examples and unseen files; 3. Upload/replay; 4-5. Exact review and factual FAQ; 6. Publication; 7-10. Voice/failure/revocation; 11-12. Restart/evaluation |
| `RAG-AI-Architecture.md` | [Architecture](specifications/RAG-AI-Architecture.md) | Context/future direction: 4. Backend Modules and Dependency Rules; 6. Search Tool Contract; 7. Dynamic Document Lifecycle; 17. Historical prototype mapping; 19. Open Decisions and Owners; 22. Current Live document MVP decisions |
@@ -446,11 +464,11 @@ Persian, ZWNJ, CJK and emoji metadata. No real provider checks were run; these
repairs introduce no provider behavior. Original-store power-loss guarantees and
unavailable Windows symlink creation remain outside the verified evidence.
## Persian document and voice MVP documentation أ¢â‚¬â€‌ 2026-10-06
## Persian document and voice MVP documentation ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬أ¢â‚¬إ’ 2026-10-06
The governing specifications now include page-level PDF quality/fallback, DOCX FAQ pairing, infographic group preservation, retained extraction artifacts, shared semantic/identifier retrieval and direct Gemini Live `search_knowledge`. The earlier proposed `search_documents` name and SDP request/answer contract are superseded; prototype `retriever_tool` remains unchanged.
[Architecture Sections 7, 8 and 21](specifications/RAG-AI-Architecture.md) cover diagrams, decisions and static implementation evidence. [Delivery plan Sections 9 and 14أ¢â‚¬â€œ15](specifications/RAG-AI-Phase1-Delivery-Plan.md) retain P1-01أ¢â‚¬â€œP1-12, add P1-13أ¢â‚¬â€œP1-17 and record budget/account/rehearsal gates. [API Section 7](specifications/RAG-Phase1-API-Catalog.md) distinguishes HTTP, application Live WSS and internal tools. [Database Section 4.4](specifications/RAG-Phase1-Database-Design.md) proposes extraction artifacts without content-version entities. [Persian scenarios Sections 18أ¢â‚¬â€œ22](specifications/RAG-Phase1-Scenario-Report-FA.md) document actual sample inspection limits and worked examples.
[Architecture Sections 7, 8 and 21](specifications/RAG-AI-Architecture.md) cover diagrams, decisions and static implementation evidence. [Delivery plan Sections 9 and 14ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬ط¥â€œ15](specifications/RAG-AI-Phase1-Delivery-Plan.md) retain P1-01ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬ط¥â€œP1-12, add P1-13ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬ط¥â€œP1-17 and record budget/account/rehearsal gates. [API Section 7](specifications/RAG-Phase1-API-Catalog.md) distinguishes HTTP, application Live WSS and internal tools. [Database Section 4.4](specifications/RAG-Phase1-Database-Design.md) proposes extraction artifacts without content-version entities. [Persian scenarios Sections 18ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬ط¥â€œ22](specifications/RAG-Phase1-Scenario-Report-FA.md) document actual sample inspection limits and worked examples.
All four supplied files exist in `data/documents/`; DOCX XML and infographic were inspected locally, and PDF structure confirms five/one pages. Full local PDF text/layout extraction was unavailable; prior word/number-order observations remain supplied context. No provider/OCR benchmark or Persian speech test was run.
@@ -902,7 +920,7 @@ Executed evidence for these four semantic repairs (2026-10-06):
An intermediate corrected targeted run had one compatibility failure:
`Decision dated 1403/01/02` was being treated as an identifier. The final parser
recognizes the explicit dated/ط¸â€¦ط¸ث†ط·آ±ط·آ® metadata qualifier; the existing control passes.
recognizes the explicit dated/ط·آ·ط¢آ¸ط£آ¢أ¢â€ڑآ¬ط¢آ¦ط·آ·ط¢آ¸ط·آ«أ¢â‚¬آ ط·آ·ط¢آ·ط·آ¢ط¢آ±ط·آ·ط¢آ·ط·آ¢ط¢آ® metadata qualifier; the existing control passes.
Real-provider extraction quality and manual Persian fidelity acceptance remain
**unverified**. These generated fixtures and fake providers do not establish
@@ -936,7 +954,7 @@ changes, immutable originals, frozen profiles, normalization and applied migrati
Active position/case/hiding semantics fail safely; resets, harmless formatting
and unused styles pass. Deeper DOCX answer headings/table continuations stay
atomic; incomplete/ambiguous/oversized groups fail. English singular/plural and
Persian ط¸â€¦ط·آ§ط·آ¯ط¸â€،/ط¸â€¦ط¸ث†ط·آ§ط·آ¯ targets support explicit conjunction/comma lists and simple
Persian ط·آ·ط¢آ¸ط£آ¢أ¢â€ڑآ¬ط¢آ¦ط·آ·ط¢آ·ط·آ¢ط¢آ§ط·آ·ط¢آ·ط·آ¢ط¢آ¯ط·آ·ط¢آ¸ط£آ¢أ¢â€ڑآ¬ط·إ’/ط·آ·ط¢آ¸ط£آ¢أ¢â€ڑآ¬ط¢آ¦ط·آ·ط¢آ¸ط·آ«أ¢â‚¬آ ط·آ·ط¢آ·ط·آ¢ط¢آ§ط·آ·ط¢آ·ط·آ¢ط¢آ¯ targets support explicit conjunction/comma lists and simple
integer ranges; unsupported malformed/complex identifiers fail. Incidental
citations and ordinary decision prose remain accepted. See the setup guide for
exact grammar and output/intake bounds. Attachment/reuse remain Phase 5 gated;
@@ -2044,8 +2062,8 @@ Exactly one API process owns media guards; ingestion runs separately. Fake tests
are not real provider/Persian speech/browser hardware or frontend readiness proof.
Verified final commands: `.venv/bin/python -m pytest -m "not postgres" -q -p no:cacheprovider --tb=short`
أ¢â‚¬â€‌ **1679 passed**, two existing Windows path skips; `.venv/bin/python -m pytest -m postgres --require-postgres -q -p no:cacheprovider --tb=short`
أ¢â‚¬â€‌ **372 passed**, zero skips, using only the isolated task-created test database.
ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬أ¢â‚¬إ’ **1679 passed**, two existing Windows path skips; `.venv/bin/python -m pytest -m postgres --require-postgres -q -p no:cacheprovider --tb=short`
ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬أ¢â‚¬إ’ **372 passed**, zero skips, using only the isolated task-created test database.
Affected PostgreSQL cases: **61 passed**. Missing TEST_DATABASE_URL produced the
required prerequisite failure. Executable JS, syntax/compile, diff and baseline
preservation checks passed. See the report for exact durations, failed/interrupted
@@ -2062,7 +2080,7 @@ intake/review/worker/selection services, with bounded streaming
prior pending-HTTP statements above. The standalone frontend developer handoff is
[Phase 3 integration](guides/realtime-agent-phase3-handoff.md), with executable
DocumentClient and a same-origin Vite proxy example. Existing VoiceClient/worklet,
Gemini/OpenAI selection, canonical search and migrations 0001أ¢â‚¬â€œ0005 are preserved.
Gemini/OpenAI selection, canonical search and migrations 0001ط·آ£ط¢آ¢ط£آ¢أ¢â‚¬ع‘ط¢آ¬ط£آ¢أ¢â€ڑآ¬ط¥â€œ0005 are preserved.
`INGEST_OCR_REVIEW_REQUIRED=true` is a deployment default frozen in new job
profiles; false admits only automatically validated OCR. Legacy profiles retain
@@ -2348,7 +2366,7 @@ current-turn labels from delivered search/reuse evidence; the existing sources
event shows that subset, not every retrieval candidate. Metadata reports do not
create retrieval rows. See `tests/unit/test_voice_reported_sources.py` and
`tests/integration/test_voice_evidence_reuse.py` for validation and revocation
coverage. Optional acknowledgement is only «یه لحظه…» once per turn, under
coverage. Optional acknowledgement is only ط¢آ«ط؛إ’ط¸â€، ط¸â€‍ط·آ­ط·آ¸ط¸â€،أ¢â‚¬آ¦ط¢آ» once per turn, under
OpenAI delivery v5. New sessions pin the selected-evidence policy revision;
existing reservations are not rewritten. Real provider adherence remains
separate from deterministic runtime tests.