Skip to content

Live call error: Cancellation failed: no active response found #189

@Mq1989

Description

@Mq1989

Getting the error: Cancellation failed: no active response found

My live phone calls through twillio successfully connects and I'm having a conversation with the voice agent.The tools associated with the agent run successfully and call is completed as planned about 50% of the time.

In other cases The call ends before completed and I'm getting this error:

code: 'ERR_UNHANDLED_ERROR', context: { type: 'error', error: { type: 'error', event_id: 'event_BrRIisLBR9gFs1Xlx2zsL', error: { type: 'invalid_request_error', code: 'response_cancel_not_active', message: 'Cancellation failed: no active response found', param: null, event_id: null } }

This ends the call and crashes my server.

Here's my websocket

fastify.register(async (fastify) => {
  fastify.get("/test-stream", { websocket: true }, async (conn, req) => {
    console.log("Client connected to test-stream");

    const twilioTransportLayer = new TwilioRealtimeTransportLayer({
      twilioWebSocket: conn,
    });

    const session = new RealtimeSession(homeCareAgent, {
      transport: twilioTransportLayer,
      model: "gpt-4o-realtime-preview-2025-06-03",
      config: {
        turnDetection: {
          type: "server_vad",
        },
        inputAudioFormat: "g711_ulaw",
        outputAudioFormat: "g711_ulaw",
        voice: VOICE,
        inputAudioTranscription: {
          model: "gpt-4o-mini-transcribe",
        },
      },
    });

    await session.connect({
      apiKey: OPENAI_API_KEY,
    });



    session.sendMessage(
      "Great the user and ask how you can assist them today."
    );

    console.log("Connected to the OpenAI Realtime API");


    session.on("*", (event) => {
        console.log("Session event:", event.type || "null");
      if (event.type === "response.output_item.done") {
        console.log("Response output item done:", event?.item?.content || "null");
      }
    });

    twilioTransportLayer.on("*", (event) => {
      // Uncomment to log all transport layer events
      if (event?.type == "response.done"){
        console.log("Transport event:", event?.item?.content || "null")}
    });

    conn.on("close", () => {
      console.log("Client disconnected from test-stream");
      session.transport.close();
    });
  });
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions