# REVIEW.md — Code Review Notes

## ✅ Looks Good
- Health check is fast (no async work)
- WebSocket cleanup on disconnect/stop
- Conversation history bounded to 20 messages
- Chunked audio send (160-byte mulaw frames = 20ms)
- Processing guard prevents overlapping LLM calls
- Graceful error handling in pipeline (try/catch/finally)

## ⚠️ Known Limitations / Things to Watch

### 1. ElevenLabs `ulaw_8000` output format
The `output_format: 'ulaw_8000'` param is passed in the JSON body but ElevenLabs actually takes it as a **query parameter**. Fix: append `?output_format=ulaw_8000` to the URL and remove from body.
**Impact:** Audio may come back as MP3 instead of mulaw → garbled playback.

### 2. ALB WebSocket routing
ALB needs to be configured for WebSocket support. HTTP listeners handle WS upgrade automatically, but ensure the **idle timeout** is set high enough (e.g., 300s) so long calls don't get dropped.

### 3. No barge-in / interrupt handling
If user speaks while TTS is playing, we don't send a `clear` event to Twilio to stop playback. For v2, send `{"event": "clear", "streamSid": ...}` before new response.

### 4. Deepgram reconnection
If Deepgram WS drops mid-call, there's no auto-reconnect. The call goes silent. For production, add reconnect logic on the `Close` event.

### 5. TLS requirement for Twilio WebSocket
Twilio requires `wss://`. The ALB must have an HTTPS listener with a valid cert, terminating TLS and forwarding to port 80 HTTP on the container. Ensure ALB has a TLS cert attached.

### 6. Anthropic SDK import
Using `new Anthropic.default()` — this works with CommonJS require of the ESM package. Verify after `npm ci` that this resolves correctly. If not, switch to `new Anthropic()` or use dynamic import.

## 🔧 Recommended Fix (apply before deploy)

```js
// In textToSpeech(), change the URL to include output_format as query param:
url: `https://api.elevenlabs.io/v1/text-to-speech/${voiceId}?output_format=ulaw_8000`,
// And remove output_format from the data body
```
