feat(voice): implement local S2S retained history and provider selection

Add pinned CPU engine dependencies, retained interrupted-response history, provider admission, offline evaluation and isolated browser tooling.

Record Phase 2 acceptance and Phase 3/4 preparation, bounded paid-test accounting and interruption incident findings. Human interruption acceptance, paired OpenAI evaluation and rollback remain pending.
This commit is contained in:
11linear11
2026-10-16 17:09:27 -04:00
parent 8d348f0ba1
commit a94b8cd3ea
111 changed files with 14764 additions and 58 deletions
+20 -4
View File
@@ -1,6 +1,9 @@
# Local speech-to-speech adapter: phased implementation plan
Date: 2026-10-15. Status: **Phase 1 offline implementation delivered; Phase 2 candidate prepared; build/live acceptance pending**.
Date: 2026-10-16. Status: **Phase 1 accepted for provider-boundary/OpenAI preservation;
Phase 2 accepted; Phase 3 retained-answer implementation/live pending; Phase 4 preparation including frontend selection in progress**.
[Final Phase 2 acceptance](../evaluation/local-s2s/phase-02-accepted-20261016.md) records actual browser/provider evidence, green scoped tests and retained billing uncertainty. No operational promotion or interruption acceptance.
## 1. Outcome and scope
@@ -14,7 +17,10 @@ This is a plan, not authorization to switch the running application, download
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. Phase 1 offline
evidence is in [its report](../evaluation/local-s2s/phase-01.md); no phase is accepted.
evidence is in [its report](../evaluation/local-s2s/phase-01.md); subsequent real
OpenAI listening/native cleanup acceptance is recorded in the
[Linux report](../evaluation/local-s2s/phase-01-linux-preparation.md). Phases 2-4
remain unaccepted.
## 2. Target architecture
@@ -202,6 +208,8 @@ phases. The preserved OpenAI path remains the fallback chosen by the operator.
## Phase 3 - Complete interruption, shared RAG and used sources
**User amendment (2026-10-16):** The user revoked whole-response deletion and requested retaining interrupted answers for repeated questions. Keep the original text in a bounded same-session archive and mark its model-context representation explicitly as not fully heard. Do not infer a heard prefix or claim full delivery. Document facts still require backend evidence revalidation. This supersedes the earlier unheard-text-removal criterion; live/RAG acceptance remains mandatory.
**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.
@@ -210,9 +218,9 @@ phases. The preserved OpenAI path remains the fallback chosen by the operator.
- 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.
- Inspect the next real controlled LLM request: the interrupted sentinel must remain only in explicitly marked unheard draft context, 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.
- Use the user-selected retain_unheard_draft_v1 policy: keep raw interrupted text, annotate rather than erase its context, and attest the applied mutation. Do not advertise word-level alignment, exact heard-prefix repair or delivery of the entire draft.
- 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.
@@ -236,6 +244,14 @@ phases. The preserved OpenAI path remains the fallback chosen by the operator.
## Phase 4 - Validate quality/cost and prove controlled switch/rollback
**User-authorized preparation amendment (2026-10-16):** Implement independent
Phase 4 preparation while real Phase 3 checks remain pending; run the remaining
real tests together later. Add frontend OpenAI/local_s2s selection with server-owned
allowlisting, frozen per-session provider identity and close/fresh-session switching.
This does not waive Phase 3 acceptance, measured quality/cost, or actual operational
switch/rollback authorization. [Prepared implementation](../evaluation/local-s2s/phase-04.md).
**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.
+163 -7
View File
@@ -1,22 +1,143 @@
## 2026-10-16 — interruption incident follow-up
[Evidence and scoped budget-denial repair](../evaluation/local-s2s/phase-04-interruption-incident.md): 100 focused checks passed; actual native active cancellation/retained history/next response passed offline,71.037s, zero paid calls. Browser transient error code remains unavailable; do not claim full incident or human acceptance. Exhausted engine and test API/frontend stopped. Old ledger remains exclusive; reserve$0.704504399 held. No tuning changes.
## 2026-10-16 — isolated Step 1 browser checkpoint
See [actual browser handoff](../evaluation/local-s2s/phase-04-browser-handoff.md). New retained-history engine and chooser frontend are running; proxied auth/native setup/normal close passed with no inference during connection check. Three startup requests HTTP200; carried exposure $0.420504399, current reserve $0.479504399, exclusive cumulative ceiling $0.774504399. Older ledgers unchanged. Step 1 is partial: OpenAI remains disabled until its own bounded admission is prepared; isolated real RAG/corpus/embedding preparation remains pending. No paired acceptance, human interruption test or operational switch. Engine handoff expires after30minutes; never restart the exclusive ledger.
# Local S2S adapter progress - four phases
Updated: 2026-10-15. The original eight stages were consolidated into four before
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
prepared for isolated testing, not deployed or accepted. No new paid request,
audio tuning or operational switch. Earlier checkpoints below are historical.
Current verdict (2026-10-16): **Phase 2 accepted for isolated development-only
normal Persian browser voice**. [Final evidence](../evaluation/local-s2s/phase-02-accepted-20261016.md)
and [machine-readable results](../evaluation/local-s2s/phase-02-accepted-20261016.json):
125 local + 258 preservation + 63 PostgreSQL tests passed; actual browser response
fully played and closed normally. Conservative cost exposure $0.420504399, below
the same $1 cap; final invoice details remain unresolved with full reserves held.
Paid engine stopped normally. No buffer/speed change or operational promotion.
Phase 3/4 remain not_started. Earlier checkpoints below are historical and are
superseded where they describe open Phase 2 gates.
Current incident follow-up: [first browser-turn initialization stall repaired](../evaluation/local-s2s/phase-02-browser-first-turn-repair-20261016.md).
User session failed after transcription. Native snapshots identified first-reply
Lingua model preload; same cache now warms before listener readiness. Three full
proxy/API/native continuous-input fixture sessions and98 focused tests pass.
Fixed image a51167d1952a; no buffer/speed/timeout change. Repair handoff carries all
prior attempts; cumulative reservation ceiling $0.995118333 of the same$1. Human
browser greeting passed: 7.296s fully played, closed/user_requested, no persisted error.
Current reserved exposure is $0.925118333; final billing and applicable DB gates
remain. Earlier ready checkpoints below are historical.
Current browser handoff (2026-10-16): [isolated browser is ready](../evaluation/local-s2s/phase-02-browser-ready-20261016.md).
Angular/API/login and actual proxied WebSocket session_ready/normal close passed;
no inference in connection check. Three real startup probes passed. Human microphone/
reply/transcript acceptance remains open. Same $1 authorization; reconciled prior
exposure $0.689118333, cumulative ceiling $0.901118333, startup reserve $0.748118333.
Private login file and 30-minute engine watchdog documented. No tuning/operational change.
Latest actual run (2026-10-16): [real native Persian round trip passed](../evaluation/local-s2s/phase-02-real-native-20261016.md).
Six actual requests succeeded, 2.528s reply audio, successful terminal/normal
release and clean shutdown. Cumulative reservation is $0.998 of the same $1;
final billing remains unresolved, so no further paid request. User accepted native output; browser/microphone remains open; earlier memory blocker below is historical.
No operational switch or audio tuning change.
Latest preparation (2026-10-16): [bounded real native session](../evaluation/local-s2s/phase-02-native-paid-preparation-20261016.md).
Single-sample pronunciation accepted by the user. Cumulative reservation ceiling
is $0.998 including the retained $0.56; no new paid request. Real launch awaits
>5GiB host headroom. Budget/runner checks and actual native fixture pass; browser
and real session acceptance remain open. Audio tuning and operations unchanged.
Updated: 2026-10-16. The original eight stages were consolidated into four before
implementation started. Scope and acceptance requirements are retained.
The consolidation itself changed planning only. Phase 1/2 offline implementation
and evaluation are now recorded below; no model downloads, paid validation or
operational switch was performed.
and evaluation are now recorded below. Phase 1 real OpenAI listening and native
cleanup acceptance passed on the isolated Linux candidate. The local engine image
was built and basic native/SDK checks passed on 2026-10-16. No model-weight
download, operational switch or new paid call occurred during that retry.
[Plan](local-s2s-adapter-plan.md) | [Four active prompts](local-s2s-adapter-prompts/README.md)
| Phase | Status | Evidence | Visible demo | Blockers |
| --- | --- | --- | --- | --- |
| 1 - Preserve OpenAI and introduce the provider boundary | offline_complete_live_pending | [Phase 1 report](../evaluation/local-s2s/phase-01.md); baseline 215 passed, final focused 242 passed; full suite has 5 existing failures (details in report) | Before/after controlled-clock replay; command in report | Changed-source real OpenAI interaction/listening pending; build lock/image digest required before Phase 2 build |
| 2 - Add an isolated local stack and browser voice session | in_progress | [Phase 2 report](../evaluation/local-s2s/phase-02.md); v3 repair checkpoint: 74 repair regressions (including 31 prior), 107 final combined and 242 preservation checks passed; pinned warmup constant corrected to 6; acceptance preparation: 201 local assets fingerprinted and NLTK load passed; fresh DB 2 local passed, expanded 57 passed/6 earlier baseline failures; checklist and isolated source/browser overrides prepared | Playable offline test-tone WAV and simulated native audio/transcripts; real browser demo unrun | Phase 1 acceptance; clean pinned source and reviewed Linux lock/build authorization; cached base and local assets found, Linux validation pending; actual engine/SDK/POSIX conformance and authorized real Persian/browser checks |
| 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 |
| 1 - Preserve OpenAI and introduce the provider boundary | accepted | [Phase 1 report](../evaluation/local-s2s/phase-01.md); [final Linux listening/native cleanup evidence](../evaluation/local-s2s/phase-01-linux-preparation.md); historical 242 focused passed, broader failures disclosed | Actual Persian greeting, two interruptions including completed-unplayed audio, subsequent speech and normal close; user reports no errors | Phase 2 requires complete source, reviewed dependency lock and actual engine build; rollback restoration unproved |
| 2 - Add an isolated local stack and browser voice session | accepted | [Final acceptance](../evaluation/local-s2s/phase-02-accepted-20261016.md): 125 local + 258 preservation + 63 PostgreSQL passed; actual components/native/browser evidence | Real Persian greeting/reply/transcripts; full 7.296s playback; persisted closed/user_requested without error | No open Phase 2 gate; delayed invoice accounting retains full reserves; no safe interruption or operational promotion claimed |
| 3 - Complete interruption, shared RAG and used sources | in_progress | [Retained-answer implementation](../evaluation/local-s2s/phase-03.md); controlled native context/history and canonical tool tests | Retained text is marked not fully heard; no real browser/factual acceptance yet | Bounded live barge-in/repeat/RAG and approved critical factual evidence |
| 4 - Validate quality/cost and prove controlled switch/rollback | offline_prepared_live_pending | [Provider chooser, scorecard and runbook](../evaluation/local-s2s/phase-04.md) | Angular selector and backend pinned selection prepared; no operational switch | Phase 3 live acceptance, paired quality/cost/fault/human checks and actual authorized restoration |
Real components **2026-10-16**: [actual paid-stage results and budget qualifications](../evaluation/local-s2s/phase-02-real-components-20261016.md).
User authorized $1. One WAV HTTP400, then an explicit PCM correction and successful
TTS/STT/LLM calls; four attempts total, $0.56 retained conservative reservation.
Reported STT+LLM cost $0.000338333333333; TTS/final total unverified (billing lookup404,
unchanged key usage is not proof of free calls). Real 5.16s Persian audio retained
for human review; STT returned کتاه versus source کوتاه. No heavy engine/browser
or operational changes. Do not spend again before reconciling the retained budget.
Earlier native session follow-up **2026-10-16**: [actual cases, cleanup repairs and IDE-memory incident](../evaluation/local-s2s/phase-02-native-session-20261016.md).
Normal turn/close, real SIGINT/SIGTERM and controlled provider failure passed with
actual local assets/handlers/SDK and fixture upstream I/O. Mismatch and intent
checks passed in the final normal run. 110 focused tests passed. Shutdown now
cancels provider connections before joining native workers and accepted clients
before server wait_closed. Budgets/tuning unchanged. Concurrent tests coincided
with an actual systemd-oomd IDE kill; continuation is sequential with hard memory/
swap/headroom guards. Cold one-core startup/response failures remain disclosed;
normal/failure passed with two CPUs. No paid calls, downloads or operational switch.
Earlier Queue repair **2026-10-16**: [actual corrected-image evidence](../evaluation/local-s2s/phase-02-queue-repair-20261016.md).
Type-compatible subclass replaces the lambda, preserving 256-item capacity and
owner stop on overflow. 109 targeted tests and actual asset-backed construction,
three fixture warmups, queue regression and cleanup pass. Corrected image uses a
separate tag; original image and audio tuning preserved. Native session/audio and
full-engine POSIX checks remain open; no paid calls or downloads in this repair.
Earlier authorized acquisition follow-up **2026-10-16**: [download/load evidence and discovered construction defect](../evaluation/local-s2s/phase-02-linux-assets-20261016.md).
Missing resources resolved: 14-file Linux manifest, real NLTK POS and Silero JIT
load plus 8/16 kHz silence inference passed offline. Full construction then failed
because the current Queue lambda is incompatible with upstream Queue[Any] type
annotations. No runtime fix or paid call in this download task. Repair that
factory while preserving capacity/stop behavior before further engine acceptance.
Earlier offline follow-up **2026-10-16**: [assets and actual Linux signal subset](../evaluation/local-s2s/phase-02-offline-preflight-20261016.md).
Four real SIGINT/SIGTERM cases passed using the actual lifecycle/HTTP gateway with
fixture runtime/provider I/O. Four locally cached punkt files matched prior
fingerprints and loaded in the image. NLTK POS tagger and Silero source/JIT bundle
were not found; full preflight correctly rejects the incomplete resources. Full
engine/POSIX and real-audio gates remain open. Next requires offline transfer or
authorized acquisition of those missing resources. No downloads or paid calls.
## Phase evidence template
Latest **2026-10-16** image retry passed: [actual result](../evaluation/local-s2s/phase-02-image-build-20261016.md).
Image built; basic native/SDK and 423 focused checks passed. Older not-built/disk
blockers below are historical; full asset-backed engine and Phase 2 live gates stay open.
Latest image-build checkpoint: [actual attempt](../evaluation/local-s2s/phase-02-image-build.md)
cancelled by the disk guard during dependency installation (exit 130); no final
image. Task resolver cache moved to tmpfs without deletion; root returned to about
1.8 GiB free. More Docker-disk space required (prefer at least 4 GiB free) before
retry. No voice tuning, operational changes, pruning, models or provider calls.
Latest dependency checkpoint: [Linux CPU lock review](../evaluation/local-s2s/phase-02-dependency-lock.md)
passed resolution and a wheel-only hash-required installation dry run for 134
packages. Matching CPU torch/audio 2.11.0, exact wheel URLs, verified trixie base
manifest and full license/size metadata recorded. No install/build/model download,
provider call or voice tuning. Missing lock/source prerequisites are resolved;
actual image build, native/engine/asset conformance and live gates remain open.
Latest source-only checkpoint: clean full pinned source is now available in
`tmp/local-s2s-upstream-619e3fe4`, detached at
`619e3fe4f71d1c6f35c15870d588a3638de34722`. All 17 audited SHA-256/blob identities
and Git object integrity passed; [evidence](../evaluation/local-s2s/phase-02-source-checkout.json).
This closes the missing-source prerequisite only. No dependencies/models/builds,
provider calls or voice configuration changes. Next: reviewed Linux lock inputs
and resolver environment; Phase 2 still in_progress.
- Phase/status and prerequisite evidence:
- Reviewed diff/implementation commit:
- Preserved operational and rollback identities:
@@ -41,3 +162,38 @@ DB checks used the guarded disposable target and restored stopped state. Asset
fingerprints/NLTK load are host evidence, not Linux engine or real audio evidence.
No downloads/builds/paid requests/operational switch. Phase 2 remains in_progress;
complete engine/POSIX, component audio and isolated Persian browser gates stay open.
Linux follow-up: [isolated Phase 1 environment](../evaluation/local-s2s/phase-01-linux-preparation.md)
is running on API 127.0.0.2:8091 / Angular 127.0.0.2:4201 using cached Linux
images and current read-only source. Migrations, actual candidate DB identity,
bootstrap, readiness and proxied login/Origin/CSRF checks passed. One bounded
OpenAI test authorized; no provider session or speech capture executed yet.
Human listening and native cleanup evidence remain pending; phase statuses unchanged.
First Linux browser-start follow-up: missing validation-only embedding limits
made configuration advertise voice=false before reservation. Candidate override
corrected; actual authenticated configuration now returns voice/captions=true,
transport testing true, uncalibrated. No provider session opened; speech/native
cleanup acceptance remains pending. Details in the Linux preparation report.
Real Linux OpenAI test: audible speech/interruption reported; numeric traces show
cancelled/limited terminals, matching truncation acknowledgements and normal close.
User rejected the shortened 256-token test profile. Candidate cap restored to
the established 2048; effective speed 1.30 and buffer values verified unchanged,
readiness 200, no new paid session. See Linux report; no phase accepted.
Subsequent user-run test reached the artificial 3/3 response-intent ceiling
(`RESPONSE_INTENT_CAPACITY`, public `LIVE_BUFFER_OVERFLOW`). Tool continuations
also count; this was not audio-buffer exhaustion (peak 302,704 / 5,760,000 bytes).
No tuning or provider calls during diagnosis; bounded test design must account
for tool continuations before another run. Normal-session acceptance stays open.
Follow-up correction: removed only the candidate's artificial three-intent
override; actual baseline capacity 256 verified. Generation cap 2048, speed 1.30,
all inspected buffers and 60s test expiry unchanged; readiness 200. No live call
during correction. This runtime ceiling is not an expanded paid-call budget.
Final Linux acceptance supersedes the earlier live-pending checkpoints: Phase 1
provider-boundary/OpenAI preservation accepted after the successful user-run
speech/interruption/normal-close session and matching native/DB evidence.
Phase 2 remains in progress; no engine build or local-provider acceptance claimed.
@@ -27,9 +27,9 @@ Execution rules:
Required work:
- 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.
- Inspect the next real controlled LLM request: the interrupted sentinel must be retained only as an explicitly unheard draft while valid previous user/tool/assistant context remains. The user revoked deletion on 2026-10-16. 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.
- Apply the user-selected retain_unheard_draft_v1 policy: preserve raw interrupted text in a bounded same-session archive, annotate its context as not fully heard, and attest the applied mutation. Do not infer word alignment or count the draft as delivered. Document facts still require backend revalidation.
- 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.