Fix guardrails failing when interrupt_response=True#1949
Closed
gn00295120 wants to merge 2 commits intoopenai:mainfrom
Closed
Fix guardrails failing when interrupt_response=True#1949gn00295120 wants to merge 2 commits intoopenai:mainfrom
gn00295120 wants to merge 2 commits intoopenai:mainfrom
Conversation
3a20351 to
5d4414b
Compare
When turn_detection.interrupt_response is set to True and a guardrail triggers an interrupt, the SDK was only sending response.interrupt but not response.cancel. This caused the API to think the response was still active, leading to "Conversation already has an active response" errors on subsequent requests. Root cause: - Guardrail interrupts are SDK-side logic, but the API doesn't know about them - interrupt_response=True tells the API to auto-cancel on USER VOICE interrupts - When a guardrail triggered, the SDK would skip sending response.cancel if interrupt_response=True, assuming the API would handle it (incorrect) Solution: - Add force_cancel parameter to RealtimeModelSendInterrupt - Set force_cancel=True for guardrail interrupts - Always send response.cancel when force_cancel=True, regardless of interrupt_response setting - User voice interrupts continue to respect interrupt_response setting Changes: - src/agents/realtime/model_inputs.py: Add force_cancel parameter - src/agents/realtime/session.py: Pass force_cancel=True for guardrails - src/agents/realtime/openai_realtime.py: Check force_cancel in _send_interrupt Fixes openai#1907
5d4414b to
b1fc173
Compare
Member
|
Perhaps, I need to take time to identify the best solution for this issue, but at a glance, I am unsure if this simple fix works. |
Contributor
Author
As a beginner/newcomer, I would like to ask if I should submit the test file |
Member
|
Just having auto-generated tests does not guarantee your fix is effective for fixing the issue. I need to take time to investigate the actual behavior, but I haven't had the bandwidth for it. |
Member
|
Closing this in favor of #1952 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1907
When
turn_detection.interrupt_responseis set toTrueand a guardrail triggers an interrupt, the SDK was only sendingresponse.interruptbut notresponse.cancel. This caused the API to think the response was still active, leading to "Conversation already has an active response" errors on subsequent requests.Root Cause
interrupt_response=Truetells the API to auto-cancel on user voice interruptsresponse.cancelifinterrupt_response=True, incorrectly assuming the API would handle itSolution
force_cancelparameter toRealtimeModelSendInterruptforce_cancel=Truefor guardrail interruptsresponse.cancelwhenforce_cancel=True, regardless ofinterrupt_responsesettinginterrupt_responsesettingFiles Changed
src/agents/realtime/model_inputs.py: Addforce_cancelparameter with documentationsrc/agents/realtime/session.py: Passforce_cancel=Truefor guardrail interruptssrc/agents/realtime/openai_realtime.py: Checkforce_cancelin_send_interrupt()methodTesting
Comprehensive test suite included in branch:
tests/realtime/test_issue_1907_guardrail_interrupt.py(5 test cases)Tests verify:
interrupt_response=True(core fix)interrupt_response=False(baseline)interrupt_response=True(edge case)All existing tests pass:
Backward Compatibility
✅ Fully backward compatible
force_canceldefaults toFalse, preserving existing behavior for user voice interruptsforce_cancel=True