fix(voice): decouple cancellation race handling from model and voice

This commit is contained in:
amirhosein mazaheri
2026-10-14 12:04:08 +03:30
parent 15558fd850
commit 1f7c2bd195
8 changed files with 134 additions and 23 deletions
+13
View File
@@ -235,3 +235,16 @@ introduced. Real-provider attribution requires a new occurrence after deployment
Validation: 122 focused synchronization, interruption and retained-search tests
passed, including eight terminal failure/redaction cases.
### Protocol-scoped model switch (2026-10-14)
The selected-model/voice classifier restriction is superseded by the explicitly
authorized API amendment. The previously captured exact structured signature is
now OpenAI-protocol scoped. The runtime never accepts it as terminal confirmation:
event-ID correlation, response.done, heard-position cleanup and matching truncate
acknowledgement remain independent gates with finite deadlines. Unknown signatures
remain fatal. Diagnostics now record cancellation_correlated instead of a
Shimmer-specific profile flag. Synthetic race coverage includes 2.1-mini with
Marin, Shimmer and Cedar in both terminal orderings and missing-terminal timeout.
Actual Mini speech quality and live interruption acceptance require a fresh session.
@@ -0,0 +1,61 @@
# Isolated OpenAI Mini candidate and rollback
The original rag-api container is retained, with its image, environment and mounts.
The candidate rag-api-mini uses the separately built rag-api-model-switch:20261014
image and changes only OPENAI_REALTIME_MODEL to gpt-realtime-2.1-mini via
docker-compose.voice-candidate.yml. Local .env remains the original profile.
The old image is also tagged rag-api-rollback:20261014.
Both API instances share the database and startup reconciliation, so never run
both simultaneously, even on different ports. Switching ends current voice sessions;
start a fresh session. Worker, frontend, documents and database are not replaced.
Container rollback preserves code/configuration, not a database snapshot or live
session. Do not run compose down, container rm, or image pruning for this workflow.
Build the candidate without replacing the current container:
```powershell
docker build -t rag-api-model-switch:20261014 .
```
Switch after tests pass (if startup/readiness fails, stop the candidate and start
rag-api immediately):
```powershell
docker stop rag-api
docker compose -f docker-compose.yml -f docker-compose.voice-candidate.yml up -d --no-deps --no-build api_candidate
Invoke-RestMethod http://localhost:8080/health/ready
```
Rollback using the original container, without any rebuild:
```powershell
docker stop rag-api-mini
docker start rag-api
Invoke-RestMethod http://localhost:8080/health/ready
```
Switch back to the existing candidate:
```powershell
docker stop rag-api
docker start rag-api-mini
```
Do not run the ordinary compose api up while the candidate owns port 8080.
Readiness is not provider or Persian quality acceptance. Actual microphone tests
must cover interruption during response and search, repeated questions, source
reports and long-session behavior. Unknown provider failures remain failures.
## Verification checkpoint
Before the code fix, expanded regressions reproduced 15 failures (40 passed).
Afterward, 343 focused provider-free cases passed. Adding wrong-cancellation-intent
coverage then passed all 57 context-sync cases, including two additional cases.
The candidate API reports ready; frontend responds HTTP 200. Runtime inspection
confirmed 2.1-mini/Marin, speed 1.30, 2048 output tokens, gpt-transcribe and low
reasoning. No provider generation or real microphone acceptance was performed.
Original container ID remains
65c9fa765c150467bde2d6336b09fb46d5ffe451d1117eb1ab93a7bacff1037d,
with its original image and configuration; it is stopped, not removed.
The unrelated pre-existing .gitignore edit is excluded from this change.
+12 -1
View File
@@ -424,7 +424,7 @@ Require provider-confirmed cancellation/terminal generation within 5 seconds of
The backend is the sole cancellation and response-creation owner. Configure private VAD create_response=false AND interrupt_response=false and require provider configuration acknowledgement; VAD still reports speech/commit events. The proof's defaults are not evidence of this configuration. For a known active old response, send at most one response.cancel with that specific private response_id and a unique private event_id mapped to the cancellation intent; never issue a bare cancel that could hit a newer response. Record terminal response.done state by response identity. If completion or provider cancellation was already observed for that response, skip cancellation and proceed to required playback/context cleanup.
A completion/cancellation racing after the backend's active-state check can produce a no-active-response cancellation error. Only an adapter-verified no-active-response classification tied by error event_id to that one cancellation intent/response is benign by itself: it does not fail the session, retry cancellation or satisfy the terminal/cleanup barrier. Independently require a correlated terminal response.done (completed/cancelled; failed/other incomplete handled as technical failure; the validated audio-only output-token limit below is terminal but limited) within the bounded cancellation deadline, then complete all required context cleanup. A terminal event already recorded satisfies this test; missing terminal confirmation times out and fails. A response identity mismatch, generic/unrelated error, bad arguments, authentication failure or truncation error is not this exception and remains fatal under its normal policy. Official docs establish the benign behavior but not a stable named error code; an exact structured classifier must be proved with the selected provider profile before race acceptance, never infer it from a free-text substring or swallow all cancellation errors.
A completion/cancellation racing after the backend's active-state check can produce a no-active-response cancellation error. Only an adapter-verified no-active-response classification tied by error event_id to that one cancellation intent/response is benign by itself: it does not fail the session, retry cancellation or satisfy the terminal/cleanup barrier. Independently require a correlated terminal response.done (completed/cancelled; failed/other incomplete handled as technical failure; the validated audio-only output-token limit below is terminal but limited) within the bounded cancellation deadline, then complete all required context cleanup. A terminal event already recorded satisfies this test; missing terminal confirmation times out and fails. A response identity mismatch, generic/unrelated error, bad arguments, authentication failure or truncation error is not this exception and remains fatal under its normal policy. Official docs establish the benign behavior but not a stable named error code; the exact captured OpenAI structured classifier is provider-protocol scoped, independent of model and voice, and must retain cancellation event-ID correlation plus terminal/cleanup confirmation, never infer it from a free-text substring or swallow all cancellation errors.
Keep both VAD flags disabled throughout the session. Unexpected automatic generation/cancellation is an observable configuration/protocol deviation; correlate any actual terminal event for cleanup, suppress unintended output and fail if the controlled state cannot be established. The independent response-release gate in 7.1.6 applies even after all cleanup acknowledgements arrive. This is a future runtime obligation, not proof-script behavior.
@@ -870,3 +870,14 @@ It does not admit other model/voice pairs or relax event-ID correlation,
terminal confirmation, final playback positions or truncation acknowledgement.
Synthetic regressions reproduce the original rejection, cover both terminal
orderings, and retain failure when terminal confirmation is absent.
### OpenAI model-independent cancellation classification (2026-10-14)
User-authorized amendment superseding the selected-model/voice restriction:
OpenAI's captured invalid_request_error / response_cancel_not_active / null-param
signature is classified independently of model and voice. Model admission and
session setup acknowledgement remain separate. Cancellation event-ID correlation,
bounded terminal confirmation, final playback and truncation acknowledgement gates
remain mandatory; unknown errors and failed/incomplete technical terminals remain
fatal. This change does not establish live acceptance for every OpenAI model.