Repository navigation
Fix VAD gate keepalive: 20s → 5s to prevent DG 1011 disconnect - #5235
Conversation
Deepgram's idle timeout is 10s (not 30s as originally assumed). Our 20s keepalive interval left a gap where DG received nothing for 10+ seconds during initial silence, risking 1011 disconnect for users without speech profile in quiet environments. Fixes #5234 Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Add TestDG1011KeepaliveGap: reproduces the 10s gap bug and verifies keepalive fires within DG's documented 10s idle timeout - Update TestKeepaliveBoundary to use VAD_GATE_KEEPALIVE_SEC constant instead of hardcoded 19.99/20.0 values Co-Authored-By: Claude Opus 4.6 <[email protected]>
Greptile SummaryThis PR fixes a critical bug where users without speech profiles could experience Deepgram WebSocket disconnects (error 1011 / NET-0001) in quiet environments. The root cause was a mismatch between the keepalive interval (20s) and Deepgram's documented idle timeout (10s). Key Changes:
Technical Correctness: Test Coverage:
Both tests failed with the old 20s interval and pass with the new 5s interval, confirming the fix resolves the issue. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant VADGate
participant GatedDGSocket
participant Deepgram
Note over VADGate,Deepgram: Initial Silence Scenario (No Speech Profile)
Client->>GatedDGSocket: send(silence_audio, t=0s)
GatedDGSocket->>VADGate: process_audio()
VADGate-->>GatedDGSocket: audio_to_send=empty (silence gated)
Note over VADGate: last_send_time=None<br/>ref_time=first_audio_time(0s)
Client->>GatedDGSocket: send(silence_audio, t=5s)
GatedDGSocket->>VADGate: needs_keepalive(5s)?
VADGate-->>GatedDGSocket: True (5s >= 5s)
GatedDGSocket->>Deepgram: keep_alive()
Note over Deepgram: Traffic received at 5s<br/>✅ Within 10s timeout
GatedDGSocket->>VADGate: record_keepalive(5s)
Note over VADGate: last_send_time=5s
Client->>GatedDGSocket: send(silence_audio, t=10s)
GatedDGSocket->>VADGate: needs_keepalive(10s)?
VADGate-->>GatedDGSocket: True (5s elapsed)
GatedDGSocket->>Deepgram: keep_alive()
Note over Deepgram: ✅ No disconnect
Note over VADGate,Deepgram: OLD BEHAVIOR (20s interval)
rect rgb(255, 230, 230)
Note over VADGate: With 20s keepalive interval
Note over Deepgram: 10s passes with no traffic
Note over Deepgram: ❌ DG disconnects with 1011<br/>(NET-0001 idle timeout)
end
Last reviewed commit: 5f8bab5 |
Live Backend Test ResultsSetup: Local dev backend with Test flow:
Results:
Key evidence: With the old 20s keepalive, DG would have disconnected at ~10s of silence (1011 NET-0001). With the fixed 5s keepalive, the connection survived 4+ minutes of uninterrupted silence. Log excerpts: by AI for @beastoin |
Prod Deployment — ConfirmedDeploy: SUCCESS (02:55 UTC, Feb 28)
The keepalive fix eliminated the pre-existing ~50/hour 1011 error rate entirely. The old 20s interval was causing DG disconnects in production that went unnoticed — now confirmed and fixed. Bonus insight from prod metrics (100 sessions):
by AI for @beastoin |
Summary
VAD_GATE_KEEPALIVE_SECfrom 20s to 5s to match Deepgram's documented 10s idle timeoutProblem
Deepgram's WebSocket idle timeout is 10 seconds (docs), not 30s as originally assumed. Our 20s keepalive interval left a window where DG received no audio or keepalive for 10+ seconds, risking a 1011 (NET-0001) disconnect.
Affected users: Those WITHOUT speech profile in quiet environments. Gate starts in active mode, classifies initial silence, sends nothing to DG → 1011 disconnect at 10s.
Unaffected: Users WITH speech profile (gate starts in shadow mode, sends all audio for first ~15-25s).
Bug Reproduction
Two regression tests reproduce the bug with the old 20s interval:
test_reproduce_1011_gap_initial_silence— 10s of initial silence, DG gets nothingtest_keepalive_fires_within_dg_timeout_after_speech_ends— silence after speech, keepalive too lateBoth tests FAILED before the fix, PASS after.
Changes
backend/utils/stt/vad_gate.py:VAD_GATE_KEEPALIVE_SEC = 20→5, comment fixbackend/tests/unit/test_vad_gate.py: 2 new regression tests + updated boundary tests to use constantTest plan
Risk
Fixes #5234
Related: #4931 (VAD gate implementation)
🤖 Generated with Claude Code