fix: reduce rate limit to 5s, add 10s connection timeout
All checks were successful
Build & Push / build-and-push (push) Successful in 1m56s

- Rate limit reduced from 30s to 5s for testing
- WebSocket setup times out after 10s instead of hanging forever
- Added connection logging

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-28 14:19:57 +01:00
parent 0e3c92f873
commit bbf534cf4f
2 changed files with 14 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ import { generateEphemeralToken } from '@/lib/gemini-live';
// ─── Rate Limiting ────────────────────────────────────────────────────────────
const rateLimitMap = new Map<string, number>();
const RATE_LIMIT_MS = 30_000; // 1 token per 30 seconds per IP
const RATE_LIMIT_MS = 5_000; // 1 token per 5 seconds per IP
// ─── Health Check (GET — no rate limit) ──────────────────────────────────────

View File

@@ -274,10 +274,22 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
// Open WebSocket to Gemini Live API
const wsUrl = `wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent?key=${apiKey}`;
console.log('[VoiceAgent] Connecting to WebSocket...');
const ws = new WebSocket(wsUrl);
wsRef.current = ws;
// Timeout if setup doesn't complete within 10 seconds
const setupTimeout = setTimeout(() => {
if (ws.readyState !== WebSocket.CLOSED) {
console.error('[VoiceAgent] Setup timed out after 10s');
ws.close();
setStatus('error');
setErrorMessage('Connection timed out. Please try again.');
}
}, 10_000);
ws.onopen = () => {
console.log('[VoiceAgent] WebSocket opened, sending config...');
// Send setup message — must use "config" key per Gemini Live API spec
ws.send(JSON.stringify({
config: {
@@ -314,6 +326,7 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
// Setup complete — Gemini sends back a setupComplete message
if (msg.setupComplete !== undefined) {
console.log('[VoiceAgent] Setup complete, session active');
clearTimeout(setupTimeout);
setStatus('active');
trackAmplitude();
return;