Skip to content

Response cancellation broken due to tuple assignment bug in Realtime API #1951

@gn00295120

Description

@gn00295120

Summary

Response cancellation is completely broken in the Realtime API due to trailing commas creating tuples instead of booleans.

Bug Location

src/agents/realtime/openai_realtime.py lines 434 and 619

Description

The trailing commas in the automatic_response_cancellation_enabled assignment create single-element tuples instead of booleans:

# Current (buggy) code:
automatic_response_cancellation_enabled = (
    session
    and session.audio is not None
    and session.audio.input is not None
    and session.audio.input.turn_detection is not None
    and session.audio.input.turn_detection.interrupt_response is True,  # ← Trailing comma
)

Impact

The condition if not automatic_response_cancellation_enabled: always evaluates to False because:

  • With trailing comma: type = tuple, value = (False,), not (False,) = False
  • Non-empty tuples are always truthy in Python

Result: _cancel_response() is never called, breaking response cancellation when interrupt_response=False.

Reproduction

# Demonstrates the bug:
enabled = (False,)  # tuple
print(not enabled)  # False - _cancel_response() NOT called!

# Expected behavior:
enabled = False  # bool  
print(not enabled)  # True - _cancel_response() IS called

Environment

Fix

Remove the trailing commas on lines 434 and 619.

I'll submit a PR with the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions