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
@@ -0,0 +1,124 @@
# Browser first-turn stall repair — 2026-10-16
Follow-up: [Phase 2 accepted](phase-02-accepted-20261016.md). Required database and preservation checks are now green; delayed invoice accounting retains full reserves. The handoff descriptions below are historical; the paid engine has been stopped normally.
The user's real session `331b8eed-21ba-423a-ad21-237986846ef9` reached
`session_ready`, detected speech and delivered the recognized transcript, then
failed with `LIVE_TRANSPORT_FAILED` / close1011 before audible output. This was
not a successful Phase2 microphone acceptance. Login succeeded; the initial
identity401 was before login. The legacy dark-mode404 is separate from the voice
transport failure.
## Cause and change
The pinned native output processor calls `_observe_assistant_language()` whenever
there is a session configuration, even when `detect_llm_output_language` is false.
Its first call lazily invokes `warm_language_detector()`, whose Lingua builder
preloads models for all supported languages. Native thread snapshots captured this
work in `pipeline/language_detection.py:51` via `lm_output_processor.py:97` at the
first LLM-to-speech handoff. The expensive native initialization can hold the GIL
and prevents timely servicing of live microphone traffic. A separately running API
reaches its unchanged five-second provider-send bound; shutdown then also has
pending transport work. Same-process native-only tests had not exposed the same
cross-process deadline failure.
[The launcher](../../../services/local_s2s/engine.py) now primes **the same existing
cached language detector during construction**, before the listener is exposed.
The existing startup deadline owns this work. Automatic detection semantics and
language models are preserved. No buffer, queue capacity, speed, PCM rate, provider
send/cleanup timeout, public API or frontend source changes were made. Operational
OpenAI is untouched. The added language-prewarm step is provider-free and adds no dependency or
download. Restarting the engine still performs its usual three paid component
probes, all counted in the carried-forward budget.
## Evidence
- Actual native duplex fixture test sent580 continuous microphone frames while
a controlled LLM streamed with12 seconds of delay; normal output/close passed.
This isolated native-only success was insufficient to certify browser behavior.
- The full Angular proxy → actual authenticated API → native fixture engine path
reproduced the user's failure repeatedly with no provider fees. A single pass
during diagnosis was retained as an intermittent outcome, not acceptance.
- API coroutine traces showed an open provider socket waiting for its write buffer
to drain. Native receive queues were empty/read-enabled, and SQL connections
showed no lock wait. Plain TCP and raw-WebSocket probes between these same
containers passed. Explicit native legacy-WebSocket backend selection also
failed and was discarded; no such backend switch remains in production code.
- Native watchdog thread snapshots at the LLM/TTS boundary identified the lazy
Lingua preload. After moving it to startup, **three sequential full-path duplex
fixture sessions passed**, including the first response from a cold fixed engine.
Each delivered10752 test PCM bytes, `audio_ended`, and explicit
`closed / user_requested`. Microphone input continued during the delayed reply.
These were synthetic fixture audio/sink tests, not human listening evidence.
- **98 focused tests passed** in8.51s:
`tests/unit/test_local_s2s_phase2.py` and `tests/unit/test_local_s2s_repairs.py`.
Browser budget regression covers both original and repair ledgers. Fixture audio
testing now refuses an engine whose entrypoint is not fixture-only or which
mounts a provider credential. No broad PostgreSQL suite rerun is claimed.
The [duplex regression](check-browser-duplex.py) requires the explicit
[fixture override](phase-02-browser-fixture.override.yml), which mounts no provider
key. The [fixture engine](browser-fixture-engine.py) uses actual handlers/assets
and intercepts all component HTTP. Do not apply that override to a human quality
test; the corrected real handoff uses the repair override instead.
## Fixed image and real handoff
New COPY-only image:
`sha256:a51167d1952a8947efe1c9048311b549a1998ab8cfaf41371228b6c326781ff9`
(tag `rag-local-s2s-candidate:phase2-prewarm-fix`). Its verified base is89c7295e5219;
only the launcher file is replaced. Original images are retained. A first build
using bare `FROM sha256:...` was rejected as an invalid registry reference; the
successful build used the verified local tag with no dependency installation.
Append [repair override](phase-02-browser-repair.override.yml) after the standalone
candidate base and Linux browser override. Its fresh evidence directory is
`.local-s2s-build/browser-repair-paid`; previous ledgers remain intact. The real
engine is owned by `watch-browser-engine.py --repair`, with the same3GiB/no-swap,
two-CPU, >5GiB pre-start and2500MiB runtime headroom gates and30-minute handoff
expiry. API/Angular/test account and URL are unchanged.
Retained exposure before this restart is **$0.807118333**: every earlier unbilled
attempt, the initial failed WAV and the cancelled browser TTS reservation remain
included. The new guard permits at most two STT, two LLM and four TTS attempts,
including the three startup probes. Its **cumulative ceiling is$0.995118333** under
the original$1 authorization. This is not an actual bill. No old ledger was reset,
no failed attempt was treated as free and no operational/shared-key cap changed.
The one-greeting browser handoff below has now completed. Earlier WAV listening
approvals are retained. No complete Phase2 acceptance is claimed.
## Actual repaired handoff check
The real repaired engine reached startup in **50.411s** and its three actual
component probes returnedHTTP200. Current cumulative reservation after probes is
**$0.866118333**; ceiling remains$0.995118333. The running launcher hash matches
the reviewed source. An actual proxied API/native connection again reached
`session_ready` and persisted `closed / user_requested`; admissions remained3→3.
No additional user-audio inference was run during that final connection check.
The fixture-audio test was verified to refuse this real engine before login/audio.
[Machine-readable evidence](phase-02-browser-first-turn-repair-20261016.json)
records exact hashes, test results, budget and watchdog state.
## Actual human browser result
The user reported this real browser exchange after the repair:
> سلام چطوریم
>
> سلام ممنونم. شما چطورید چطور میتونم در زمینه امور شرکت شهرکهای صنعتی اصفهان کمکتون کنم
Session `4445c984-c56b-4269-a7a2-49556c0902d2` completed one response with
`terminal_completed=1`, `terminal_limited=0`, and `terminal_cancelled=0`.
All **350208 PCM bytes / 7.296 seconds** were sent and acknowledged as played;
final backlog, queued and reserved bytes were zero. The close endpoint returned200.
A read-only query of the isolated database confirmed **closed / user_requested**
with `error_code=null`. This verifies the single real browser greeting round trip;
it does not score transcription accuracy or certify interruption/RAG behavior.
The three new component requests all returnedHTTP200. Cumulative retained
reservation is now **$0.925118333**, against the unchanged **$0.995118333** ceiling;
these reservations are not actual billed costs. Startup plus this greeting exhaust
the current STT/LLM admission counts. Do not run another paid conversation under
this ledger. Final billing reconciliation and applicable database acceptance
checks remain before complete Phase2 acceptance. No buffer or speed was changed.