Skip to content

Conversation

gn00295120
Copy link
Contributor

Fixes #1951

Problem

Trailing commas on lines 434 and 619 in src/agents/realtime/openai_realtime.py create single-element tuples instead of boolean values, breaking the response cancellation logic when interrupt_response=False.

Root Cause

# Buggy (creates tuple):
automatic_response_cancellation_enabled = (..., )  # type: tuple

# Python semantics:
(False,) → tuple, not (False,) → False (truthy)

This causes _cancel_response() to never be called when automatic response cancellation is disabled.

Changes

  • Removed trailing commas on lines 434 and 619
  • Changes convert tuple assignments to proper boolean expressions

Verification

  • Created test demonstrating bug behavior
  • Verified bug exists in code (2 occurrences)
  • Applied fix and confirmed trailing commas removed
  • All 23 realtime tests pass

Impact

…ellation

The trailing commas on lines 434 and 619 were creating tuples instead of booleans for automatic_response_cancellation_enabled. This caused the condition 'if not automatic_response_cancellation_enabled' to always evaluate to False, preventing _cancel_response() from being called.

Impact: Response cancellation was completely broken when interrupt_response=False
Fix: Remove trailing commas to return bool instead of tuple

Verification:
- Before fix: type=tuple, not (False,) = False -> _cancel_response() NOT called
- After fix: type=bool, not False = True -> _cancel_response() IS called
- All 23 tests pass
@Copilot Copilot AI review requested due to automatic review settings October 21, 2025 04:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical bug where trailing commas were inadvertently creating single-element tuples instead of boolean values, breaking the response cancellation logic when interrupt_response=False. The trailing commas on lines 434 and 619 caused automatic_response_cancellation_enabled to always evaluate as truthy (a non-empty tuple), preventing _cancel_response() from being called when automatic response cancellation was disabled.

Key Changes:

  • Removed trailing commas from two boolean expressions in openai_realtime.py
  • Corrected tuple assignments to proper boolean values for automatic_response_cancellation_enabled

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@seratch seratch added bug Something isn't working feature:realtime labels Oct 21, 2025
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, this is a great catch

@seratch seratch merged commit d1abf43 into openai:main Oct 21, 2025
5 checks passed
@gn00295120 gn00295120 deleted the fix/realtime-tuple-bug branch October 21, 2025 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:realtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Response cancellation broken due to tuple assignment bug in Realtime API

2 participants