FEAT: Realtime streaming session support and server-side barge-in attack#1766
Open
adrian-gavrila wants to merge 22 commits into
Open
FEAT: Realtime streaming session support and server-side barge-in attack#1766adrian-gavrila wants to merge 22 commits into
adrian-gavrila wants to merge 22 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…t API Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ardown Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nc rename, Optional→union Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tion) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…me-server-vad # Conflicts: # pyrit/prompt_target/openai/openai_realtime_target.py
| piece.converted_value = converted_text | ||
| piece.converted_value_data_type = converted_text_data_type | ||
|
|
||
| async def convert_audio_async( |
Contributor
There was a problem hiding this comment.
could we make this a message_normalizer and then the target can use this as the default normalizer if the user doesn't specify a special one ?
Contributor
Author
There was a problem hiding this comment.
I agree that this probably shouldn't live on PromptNormalizer but I am not sure it fits the shape of MessageNormalizer since this is converting from bytes to bytes instead of operating directly on messages (since they don't exist mid-stream where this would be run). I made a standalone AudioStreamNormalizer instead of forcing the shape. What do you think?
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…imitive Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… inline drive_response Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Description
Adds persistent streaming session support to
OpenAIRealtimeTargetand introducesBargeInAttack, a streaming attack that leverages server-side VAD to detect and exploit barge-in (interruption) behavior. Previously the target only supported single-turn fire-and-forget audio exchanges; this PR adds the transport primitives needed for multi-turn streaming sessions with incremental audio push, event subscription, and mid-session response requests.When the server detects new user speech while the assistant is still responding, the in-flight response is automatically interrupted and the conversation history is truncated to match what was actually delivered.
Key additions:
OpenAIRealtimeTargetstreaming primitives —connect_async,push_audio_chunk_async,insert_user_audio_async,subscribe_events_async,request_response_async,send_streaming_session_config_async. These expose transport-level operations over a persistent WebSocket connection._RealtimeEventDispatcher— ABC that owns a realtime connection's event stream, routes provider-specific events to the active turn, and fires anon_user_audio_committedcallback when server VAD finalizes a turn. Provider-specific routing is isolated to_route_event/_cancelabstract methods.BargeInAttack— streaming attack that pushes audio chunks into a persistent session, applies configured converters on each server-committed turn (convert-on-commit), requests responses, and tracks interruptions. Per-turnMessagepairs are persisted toCentralMemorywithprompt_metadata["interrupted"] = Trueon interrupted turns.ServerVadConfig/RealtimeTargetResult— shared types for configuring server VAD and representing turn results (audio, transcripts, interruption flag).PromptNormalizer.convert_audio_async— applies audio converter configurations to raw PCM bytes for streaming attacks that hold audio mid-turn rather than aMessage.The target exposes only transport primitives; all attack logic (buffering, convert-on-commit dance, interruption signaling) lives in
BargeInAttack.Tests and Documentation
realtime_audio.py, 72% onopenai_realtime_target.py(uncovered lines are pre-existing code paths, not new additions).doc/code/executor/attack/barge_in_attack.py(jupytext py:percent format) demonstrates the attack against a live OpenAI Realtime API endpoint with server VAD. Ran successfully againstgpt-4o-realtime-preview— outputs cleared for CI (requires live credentials).