Files
11linear11 a94b8cd3ea 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.
2026-10-16 17:09:27 -04:00

100 lines
6.2 KiB
Markdown

# Local S2S Phase 3 — retained interrupted answers
Status: **in_progress; real listening/RAG acceptance pending**. The user revoked
whole-response deletion and asked to retain interrupted answers for repeated
questions. The implementation preserves raw text in the current session and
marks its model-context representation as **not fully heard**. It does not
estimate a heard prefix, delete the saved answer, or represent the draft as a
completed spoken answer. This is the user-selected policy, not exact word/audio
alignment. No operational provider switch or new paid call occurred.
## Implementation
- Opt-in `LOCAL_S2S_RETAIN_INTERRUPTED_ANSWERS=true`; default false preserves
existing Phase 2 identities and fail-closed interruption. Phase 3 pins patch and
private contract `rag-local-s2s-phase3-retain-v1` and a different effective
configuration digest. Old reservations are not rewritten.
- The [native extension](../../../services/local_s2s/history.py) captures
response-owned text before native cancellation rolls provisional history back.
It preserves raw copies and annotates/restores the matching assistant items at
their original response anchor in the actual Chat used by the LLM. Valid prior
user/assistant/tool context is preserved. Raw drafts remain private memory,
bounded to 64 responses / 128KiB each / 512KiB total, and clear on unregister.
- Active cancellation marks its captured output before returning the actual
native terminal, including the case where every emitted audio sample was
already heard but text generation was ahead. Completed-but-unplayed responses
are annotated through the explicit synchronization operation.
- The [local adapter](../../../app/infrastructure/local_s2s.py) translates the
existing internal cleanup command to private `s2s.history.retain`; native
`s2s.history.retained` receipts attest an actual applied annotation and history
revision. Session/engine-session/generation/response/item/operation/position and
replay/revision checks remain mandatory. The native type and distinct
provenance survive private normalization. This is not a fabricated OpenAI
truncate acknowledgement. The upstream native truncate remains a no-op.
- Shared runtime cancellation, cleanup dispatch, playback barriers and deadlines
remain intact. Next response is blocked until the required real terminal,
playback cleanup and matching history receipt. No buffer, queue capacity,
speed, rate, operational model or browser event changes were made.
- Search/reuse/source reporting still runs through the existing dispatcher,
ToolContext, DurableTools and SearchService. The engine gets no DB authority.
Saved prose is never evidence; document facts require backend reuse/search
revalidation and current-turn source labels before answering.
This saves text for a subsequent model answer; it does not implement a separate
persistent question/answer database or byte-for-byte audio replay. A new topic
still requires fresh search. Retention ends with the live session. Exact repeat
answer quality and model compliance require the real checks below.
## Checks
[Machine-readable evidence](phase-03.json) records final counts and image/source
identities. HTTP fixture evidence is explicitly separate from real inference.
- Focused local/OpenAI/context/source/reuse tests: **411 passed in 48.21s**.
- PostgreSQL profile/replay + local/OpenAI/Gemini authenticated ASGI tools and
evidence reuse/revocation: **31 passed in 50.60s**, zero skips, on a test-owned
tmpfs database ending `_local_s2s_test`; disposable container removed.
- Both adapters run the same pending-search reuse and selected-source assertions.
Same-question searches coalesce; invalid reports stay private; no-evidence and
technical error remain distinct. Local ASGI tests use actual backend search,
owner/Origin/cookie/CSRF and durable persistence with fixture provider wire I/O.
- Actual native Chat + actual SDK HTTP request checks preserve valid previous
user/tool/assistant context and explicitly retained drafts. Invalid identities
do not mutate history. These use controlled HTTP, not model quality evidence.
- Full native worker/WebSocket cases cover completed-unplayed and active
cancellation, real mutation receipts and next SDK request inspection. Obsolete
late sentinel output must not enter that next request. Provider calls are zero.
Earlier failures were investigated and retained in ignored diagnostic logs:
local ASGI tests initially lacked the required isolated DB/storage naming; a
manual response without a new user item needed an immutable response-start anchor;
a one-sentence stalled stream did not reach the native three-sentence batching
threshold and timed out. The final fixture sends enough sentences, without
changing batching/timing, before cancelling. No failed fixture result is speech
quality acceptance. No broad ordinary suite or operational deployment was run.
## Candidate and remaining gates
Final COPY-only candidate:
`sha256:02518bed03e909ce9b8324ce7772902fb427ce55a6f0cef31ec0d6282f1506bc`.
The [prepared isolated override](phase-03-candidate.override.yml) is not launched;
[the flag](../../../.env.example) remains off by default. Original images,
operational provider and user .env are preserved. Original paid ledgers remain
exclusive and cannot be restarted. A fresh bounded, reconciled Phase 3 paid-test
ledger is required before real engine startup; no new inference was run here.
The original total authorization remains $1.
Required before Phase 3 acceptance:
1. Run real browser barge-in and repeat the question; listen and inspect the
subsequent model request for marked retained text and correct context.
2. Run real document answers for hours/fees, deputy name/organization and incentive
percentage/date/exclusions, including pending-search interruption/repeat.
Correct source identities do not prove factual correctness.
3. Review the [prepared factual cases](phase-03-live-cases.json): inherited corpus
annotations are still drafts, and no approved deputy-name/organization
annotation was located. Do not invent expected facts or claim corpus quality.
No complete Phase 3 acceptance, safe production promotion, exact heard-prefix
alignment, final real-provider factual score or Phase 4 work is claimed.