Files
rag-technical-docs-assistant/docs/plans/live-conversation-repair-progress.md
T
amirhosein mazaheri 9e6864ae2a fix(voice): expand speech buffer to 60s, handle 2.1 cancellation race, and bound cleanup
- Expand max_input_buffer_bytes to 3,072,000 (64s at 24kHz PCM16) with 65s fixed deadline
- Broaden response_cancel_not_active race classifier to include gpt-realtime-2.1/shimmer
- Add transport abort method and bound cleanup waits during websocket close
- Record repair progress in docs/plans/live-conversation-repair-progress.md
2026-10-12 18:51:06 +03:30

68 lines
8.7 KiB
Markdown

# Live conversation repair handoff
Date: 2026-10-12
Status: **Paused at user request.** This records the uncommitted working tree after work on [the repair plan](live-conversation-repair-plan.md). It is a progress record, not completion or release acceptance.
## Repositories and scope
- Backend: `D:\raymand\projects\rag-technical-docs-assistant`
- Frontend: `D:\raymand\projects\faq_chatbot_frontend`
- Both working trees were clean before this repair began. The changes listed below are uncommitted. No migrations, provider calls, deployment, or PostgreSQL tests were performed.
## What changed
### Backend
- **Issue 1, continuous speech:** `RuntimeSettings.max_input_buffer_bytes` is now fixed at 3,072,000 bytes (64 seconds at 24 kHz PCM16), and an independent, fixed 65-second speech-stop deadline replaces the old deadline derived from the byte bound. The 96,000-byte transport queue and input offset/commit logic remain. The API contract, operator guide, and `.env.example` were aligned. Tests now exercise 10, 30, and 60 seconds with four seconds of padding, hard-bound exhaustion, late starts, missing stop/commit, and transport saturation.
- **Issue 8, already-ended cancellation:** the exact `invalid_request_error` / `response_cancel_not_active` / null-param classifier now also accepts `gpt-realtime-2.1/shimmer`. Other model/voice pairs and signatures remain rejected. Runtime event-ID, response terminal, and truncation gates were not relaxed. A guide addendum records the observed profile and limits of that evidence.
- **Issue 12, cleanup:** route child-task and runtime worker termination waits are bounded. Runtime close retains one shared owner; provider graceful-close expiry attempts the existing transport's abort capability through each adapter. Cleanup diagnostics record pending task count and abort result. The route still attempts terminal persistence and registry release after a task timeout. A regression covers a task that resists cancellation while preserving the original failure.
- The backend edits are in `app/modules/voice/{settings,runtime,diagnostics}.py`, `app/infrastructure/{realtime,gemini_live}.py`, `app/api/v1/live.py`, `.env.example`, the API catalog and two guides, plus the three affected unit-test files.
### Frontend
- **Issue 5, premature listening:** normal completion no longer uses the 700 ms idle heuristic or a completed transcript alone. It requires a matching `audio_ended` and a worklet idle event for the audio reference. Idle while generation remains open is treated as an underrun. Duplicate final transcripts no longer re-flush playback.
- **Issue 4, accounting instrumentation:** the existing `audio_ended.sent_bytes` field is typed and validated when present. The service compares sent and received bytes at sealing, then compares sent bytes with worklet-reported consumed milliseconds at drain, allowing for the sub-millisecond reporting remainder. It logs bounded numeric discrepancies; it does not yet establish or repair the cause of the reported audio/text mismatch.
- Audio-reference tagging now passes through the playback worklet and engine. Duplicate `audio_started` events no longer reset byte accounting; stale seals and old-turn interruptions are guarded. The remaining 700 ms timer is limited to a limited response with no audio reference.
- **Issues 6 and 7** were already implemented in the clean frontend baseline: limited-answer rendering and final transcript snapshot replacement. Their existing tests were exercised; no new implementation for those items was needed in this pass.
- Frontend edits are under `src/app/services/voice-stream/` and `public/assets/worklets/pcm-playback.worklet.js`, including tests. No other frontend paths were edited.
## Plan position
| Plan item | Position at pause |
| --- | --- |
| 1. 60-second speech | Code and targeted regressions pass; real microphone/provider acceptance pending. |
| 2. Choppy audio | Open. No correlated provider-to-worklet trace or prebuffer comparison yet. |
| 3. Complete initial answers | Open. Existing style already requests concise completeness, but the 256-token budget was not changed or evaluated. |
| 4. Audio shorter than text | Instrumentation only. No measured discrepancy attribution or root-cause fix. |
| 5. Premature listening | Code and focused frontend regressions pass; browser playback acceptance pending. |
| 6. Limited answer UI | Present in baseline and focused tests pass; browser acceptance pending. |
| 7. Repeated final text | Present in baseline and focused tests pass; browser acceptance pending. |
| 8. Cancellation race | Narrow classifier change and targeted tests pass; same-connection provider acceptance pending. |
| 9. Cancellation acknowledgement deadline | Open. No timing trace or root-cause fix. |
| 10. Same-topic evidence reuse | Open. No contract amendment, reuse tool, authorization/revision recheck, or PostgreSQL tests were implemented. Current fresh-retrieval rule remains. |
| 11. Longer output capacity | Open. The 30-second bound remains; the proposed 120-second OpenAI bound and token budgets were not measured or selected. |
| 12. Cleanup timeout | Backend code and targeted tests pass; blocked-transport/ASGI and real-provider acceptance pending. |
The plan's diagnostic prerequisite is only partly met. The new audio counters and cleanup numbers do not provide a full provider-to-browser timeline, underrun duration, or cancellation enqueue/dispatch/terminal trace.
## Checks actually run
- Backend focused command: `.venv/Scripts/python -m pytest tests/unit/test_voice_input_accounting.py tests/unit/test_live_context_sync.py tests/unit/test_voice_session_incident.py tests/integration/test_voice_session_incident.py -m "not postgres" -q -p no:cacheprovider` — **69 passed, 11 PostgreSQL cases deselected**.
- Frontend focused command: `npm.cmd test -- --watch=false --include=src/app/services/voice-stream/voice-stream.service.spec.ts --include=src/app/services/voice-stream/voice-event.validator.spec.ts --include=src/app/services/voice-stream/pcm-playback.worklet.spec.ts` — **81 passed**.
- `npm.cmd run build` — passed; existing `moment-jalaali` CommonJS optimization warning.
- Backend broad suite: one parallel run reported failures and was interrupted after stalling near its end. A solo `-x` rerun stopped at the unchanged `test_transport_capacity_survives_timeout_and_recovers_without_late_results[False]` 50 ms timing case after **755 passed, 1 skipped**. Both cases of that test passed when rerun alone. **No clean broad-suite result is claimed.**
- Frontend full suite was run before the final duplicate-flush test assertion was updated: **137 passed, 6 failed**. One failure expected the removed duplicate flush and passes in the later 81-test focused run. The other five were outside edited voice paths: three `localStorage` failures in app/auth/theme tests and two call-center/chat-question rendering assertions. The full suite was not rerun after the correction.
- `git diff --check` passed in both repositories. Git printed only LF/CRLF working-copy notices.
`TEST_DATABASE_URL` was absent. PostgreSQL acceptance, actual browser/microphone playback, same-connection provider runs, and the plan's 20-question answer-quality benchmark have not been performed. Synthetic tests and the build do not establish release readiness.
## Where to resume
1. Review the uncommitted diffs in both repositories and run `git diff --check` again. Preserve these edits; do not treat the handoff as a commit or a completed rollout.
2. Finish and test the remaining cleanup and audio-accounting edge cases, especially unresponsive real transport abort, route finalization, and real worklet consumption at 24/44.1/48 kHz. Keep issue 4 open until an actual trace identifies the first loss point.
3. Instrument and reproduce issues 2 and 9 on the same live connection. Compare fixed 80/120/160/240 ms prebuffer traces; retain the five-second cancellation deadline unless internal blocking is demonstrated.
4. Implement issue 10 as an explicit contract change with session-local evidence, backend-owned eligibility/owner/access-epoch/knowledge-revision revalidation, real source identities, and isolated PostgreSQL tests. Do not infer validity from the current epoch alone.
5. Evaluate issues 3 and 11 together using the plan's fixed 20-question set and measured 512/1024/2048/4096-token candidates. Only then select the OpenAI reservoir and generation budget; keep Gemini bounds separate.
6. Run focused and broad checks again, followed by the plan's browser/provider same-connection acceptance. Record implementation, synthetic checks, and real acceptance separately for each issue.
The active work immediately before the pause was the final diff/contract check. That check returned clean whitespace results and the file inventories above; no further implementation was started.