-
Notifications
You must be signed in to change notification settings - Fork 164
Open
Labels
Description
Describe the Bug
I'm using the OpenAI Realtime API together with Twilio and Express.js (express-ws
) in a Node.js app. When the WebSocket connection is closed, I call session.close()
as expected.
However, the OpenAI Agents SDK doesn't mark the trace as ended. The session is closed, but the trace remains open in the dashboard.
Here's a screenshot showing the trace still open:
Debug Info
- Agents SDK Version:
v0.0.7
- Runtime:
Node.js v22.16.0
Reproduction Steps
Example WebSocket route:
wsApp.ws('/media-stream/:userId', async (ws: any, req: Request) => {
const userId = req.params.userId;
if (!userId || !mongoose.Types.ObjectId.isValid(userId)) return ws.close();
const user = await User.findById(userId);
if (!user) return ws.close();
const twilioTransportLayer = new TwilioRealtimeTransportLayer({ twilioWebSocket: ws });
const userAgent = getUserAgent({ name: user.name, email: user.email });
const session = new RealtimeSession(userAgent, {
transport: twilioTransportLayer,
context: {
accessToken: user.accessToken,
calendarId: user.calendarId || user.email,
userInfo: user
}
});
try {
await session.connect({ apiKey: OPENAI_API_KEY });
console.log('Connected to the OpenAI Realtime API');
} catch (err) {
console.error('Error connecting to Realtime API:', err);
return ws.close();
}
ws.on('error', async (err) => {
console.error('WebSocket error:', err);
await session.close();
ws.close();
});
ws.on('close', async () => {
console.log('WebSocket closed');
await session.close(); // Called, but trace still not ended
});
});
Expected Behavior
The trace should end whenever session.close()
function called