feat(asr): implement transport recovery mechanism - #2322
diyuyi-agora wants to merge 1 commit into
Conversation
diyuyi-agora
commented
Sep 15, 2026
- Added DEFAULT_TRANSPORT_RECONNECT_GRACE_SEC constant for default reconnection grace period.
- Updated AzureASRConfig to include transport_reconnect_grace_sec parameter.
- Enhanced AzureASRExtension to manage transport recovery after disconnection, including handling reconnection logic and session epoch validation.
- Introduced unit tests for transport recovery lifecycle and configuration parameter handling.
This comment was marked as resolved.
This comment was marked as resolved.
058e351 to
d4b6329
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
|
Review: feat(asr): implement transport recovery mechanism Well-scoped change, and the epoch guards on the Azure callbacks are the right instinct: the SDK delivers events from its own threads, and stale callbacks arriving after a recognizer swap are a real source of double-reconnect bugs. A few notes below, one of which I think prevents the feature from firing in the scenario it targets. Verification note: I read 1.
if (
self.stopped
or self.connected
or disconnect_epoch != self._transport_disconnect_epoch
):
returnWithin this file
The new test passes only because Suggested fix: track transport state separately, e.g. add Worth adding a test that sets 2. Exceptions in the recovery task are swallowed, and recovery never retries self._transport_recovery_task = None
self._transport_recovery_in_flight = True
try:
await self.stop_connection()
await self._handle_reconnect()
finally:
self._transport_recovery_in_flight = FalseNothing holds a reference to the task and nothing awaits it, so if Suggest wrapping the body in Related: that blocking 3. A late The in-flight flag is reset in 4. The self-cancel guard in The 5. No validation on The field accepts any float, including 0 and negatives, and Minor: 6. Tests
7. Naming
CI reminder Per Summary: point 1 is the one I would want resolved before merge, since as written I believe the grace timer returns early in the common transport-drop case. Points 2 and 5 are small hardening items; the rest is polish. |
d4b6329 to
e1c8b7a
Compare
Code review (manual — Codex job failed: stream disconnected / builder error)The automated Codex review did not finish (provider reconnect exhausted). This comment follows SummarySolid direction: bounded grace before extension-level reconnect when Azure transport drops, Strengths
Issues / questions
Security / performance
Test coverage
ASR design review checklist
Merge recommendation: Approve after clarifying Azure event ordering (item 1) and ideally adding the ordering test; not blocking on docs alone. |
|
Review: transport recovery mechanism Reviewed against Good direction overall. It implements what section 5.1 asks for (bounded grace before the extension takes over from SDK-internal recovery), and the Blockers 1. Recovery task is never awaited during stop/deinit (section 9.2 MUST)
The method is async def _cancel_transport_recovery(self) -> None:
task = self._transport_recovery_task
self._transport_recovery_task = None
if task is None or task is asyncio.current_task() or task.done():
return
task.cancel()
with contextlib.suppress(asyncio.CancelledError):
await taskThen re-check the stop latch after the grace sleep and again before 2. The recovery task awaits More importantly, Should fix 3. Suppressed 4. 5. No validation on 6. Epoch is not re-checked inside the recovery task. 7. Test coverage The five tests are focused, and the SDK-reconnects-cancels-recovery case is the right core scenario. Gaps:
ASR checklist
Epoch guards (5.2) are a clear pass and a genuine improvement. Conventions Commit message follows conventional commits correctly. Please confirm Happy to re-review once findings 1, 2, and 4 are addressed — the core design is sound. |
e1c8b7a to
0c52ece
Compare
Review: changes requestedThe transport-recovery implementation has merge-blocking ASR lifecycle issues. These violate the repository ASR design-review MUST rules; they need correction before merge.
The new unit tests cover only the happy path with a default-false ASR design review
|