fix(voice): preserve interrupted searches and report used sources

Retain and revalidate interrupted searches, resolve abandoned provider calls, recover invalid source reports privately, and expose only declared sources. Improve Persian delivery and provider event replay capacity. Include regression coverage and contract updates.
This commit is contained in:
amirhosein mazaheri
2026-10-13 14:09:20 +03:30
parent 9cc9f0bc01
commit 18e595ac93
21 changed files with 1346 additions and 60 deletions
@@ -728,3 +728,112 @@ cleanup-ack and intent gates still apply. Limited generation alone neither creat
a new user turn nor releases a response. A later genuine user turn after fully
drained/cleaned limited output emits no fabricated turn_interrupted.
See docs/guides/openai-output-limit-repair.md for consumer and acceptance details.
## Live declared-source amendment ? 2026-10-13
`search_knowledge` and `reuse_last_evidence` still give the model the complete
eligible evidence bundle. They no longer publish every retrieval candidate as
an answer citation. Before a document answer, the model calls internal
`report_used_sources` with exactly `{"source_refs":["S1","S3"]}` (or an empty
list when no passage supports the answer). Labels must be unique, bounded and
belong to successful evidence already delivered to the same turn. Backend-owned
document/chunk identities and excerpts are resolved from those originals;
forged labels, scope/identity fields and prior-turn labels without revalidated
reuse are rejected. No source report creates a durable retrieval row.
Only declared labels are emitted through the existing `sources` event, grouped
by their real retrieval's `tool_call_id`. Revalidate original durable results
before report output, source delivery and answer continuation; interrupted or
revoked evidence must never become citations. Missing/invalid reports do not
fall back to displaying every candidate. Multiple reports add to the set of
sources declared during the turn; event/call replay remains idempotent. Polling
`recent_tool_results` remains explicitly retrieval diagnostics, not declared
answer citations. Declaration is model attribution, not independent proof of
claim-level support or which spoken words were heard. No new public endpoint,
database table or durable transcript is introduced.
New reservations pin `evidence_policy_revision=same-session-evidence-selected-v2`;
OpenAI delivery style is `iranian-persian-professional-v5`. An optional pre-tool
acknowledgement is only «یه لحظه…», at most once per turn. No acknowledgement is
needed when the answer can start directly. Suppression of longer preambles is
an instruction, not a guarantee inferred from synthetic tests. Existing pinned
reservations are never rewritten; use a new session after this deployment.
### Source-report recovery - 2026-10-13
Invalid `report_used_sources` arguments are recoverable provider-tool feedback,
not browser `error` events. Unknown-label feedback includes server-derived
`available_source_refs` for the current turn; an empty set requires revalidated
reuse or a fresh search (or an empty report after no_evidence). Invalid reports
still emit no citations, never fall back to all candidates and cannot widen
scope. Other tool/runtime errors retain their browser error behavior. Current
new reservations use evidence policy `same-session-evidence-selected-v3` and
OpenAI delivery `iranian-persian-conversational-v6`. Existing pins are preserved.
Numeric source-report traces record requested/available/rejected counts only.
### Abandoned OpenAI tool resolution - 2026-10-13
After interruption terminal confirmation and existing audio cleanup barriers,
the OpenAI adapter supplies a private function_call_output with status cancelled
and empty sources for each interrupted call whose output was never sent. These
metadata-only outputs precede the next current-turn response.create and undergo
current authority and supersession checks. They do not validate or disclose old
evidence, create retrieval rows, resume the old response or rewrite durable tool
status. Delivered tool outputs are not emitted again; late retrieval results
remain suppressed. Gemini retains its existing native interruption behavior.
Existing bounded send/correlation failures remain terminal; no blind send retry.
New sessions use evidence policy `same-session-evidence-selected-v4`.
Official wire reference:
https://developers.openai.com/api/reference/resources/realtime/client-events
(function_call_output accepts a string associated with the original call_id).
### Session provider-event replay capacity - 2026-10-13
Finite `LIVE_MAX_EVENTS` default and validated upper bound are now 32768,
replacing 4096. This counts all unique provider event IDs over the session,
including audio/transcript deltas; it is not an outstanding audio buffer.
The full ID-to-digest ledger remains retained: identical replay is ignored,
changed-payload replay fails, and cap exhaustion still closes with
LIVE_BUFFER_OVERFLOW. No eviction or duplicate audio replay is introduced.
Only this metadata capacity increases; other audio, message, identity and turn
bounds remain independent. This increases maximum replay-ledger memory eightfold;
it does not establish unlimited duration or deployment concurrency acceptance.
### Retain one same-topic search across speech interruption - 2026-10-13
This user-authorized amendment supersedes cancellation of the retained search
on ordinary speech interruption. Playback/old response cancellation remains
immediate under the existing terminal, audio cleanup and authority gates. The
latest real search has a separate cancellation token and its original deadline;
interruption of a turn or a reuse waiter does not cancel that search or reset
its time budget. Keep its result private until explicitly reused/revalidated
for a current turn. `turn_interrupted.cancelled_tool_call_ids` excludes the
retained search; other cancelled operations retain their existing semantics.
`reuse_last_evidence` still accepts only {}. For a repeated question or clear
same-topic continuation, it awaits the retained search if necessary, then
revalidates the original durable row against current identity/session, access
epoch, knowledge revision and document eligibility. It retains document/chunk
IDs and the actual public retrieval reference, and assigns source labels using
the new turn's backend execution. It creates no retrieval row. Reporting sources
still selects only current delivered labels. No old response resumes or emits
its late evidence. Technical errors do not become fabricated no-evidence answers.
A fresh search in a later turn for a different query discards/cancels the old
retained search and starts a new topic. An exactly identical validated search
argument object in a later turn can coalesce through the same revalidation path,
even if the model chooses search rather than reuse. Semantic equivalence of
differently phrased queries remains the model's explicit reuse decision; the
backend performs no fuzzy scope or question matching. Session stop, failure or
close cancels independent searches. Expiry/revocation still fails safely; this
is not cross-session caching or reuse of assistant prose. At most the latest
search is retained for continuation; existing tool/task/session bounds apply.
The OpenAI interruption function output closes the old private response's call
with empty metadata and directs same-topic continuation to reuse. Its cancelled
status does not declare cancellation of the separately retained backend search.
Gemini continues to use its native interruption transport. New reservations use
`evidence_policy_revision=same-session-evidence-retained-v5`; existing pins are
not rewritten. No schema/table migration or new public endpoint is introduced.