Add app-server notification media filtering (#41416)

## What changed

- Add the disabled-by-default `omit_app_server_notification_media` feature.
- When enabled, remove inline image and audio content from `item/started`,
  `item/completed`, and `rawResponseItem/completed` notifications, including
  tool output and image-generation results.
- Keep the media in model input; the filter only changes app-server
  notifications.

## Testing

- Verify that image content is absent from all three notification types while
  the model request still receives it.

GitOrigin-RevId: 9a4434d18a3dac6d67c2e0c3723ff4595a9b3797
This commit is contained in:
Vivian Fang authored and copyberry committed 2026-08-28 21:06:35 +00:00
1 parent 170da98842
commit 03147407e3
6 files changed
+337 -25

No files matched your search

@@ -1,5 +1,6 @@
use crate::error_code::internal_error;
use crate::error_code::invalid_request;
use crate::notification_media::without_notification_media;
use crate::outgoing_message::ClientRequestResult;
use crate::outgoing_message::ThreadScopedOutgoingMessageSender;
use crate::request_processors::populate_thread_turns_from_history;
@@ -91,6 +92,7 @@ use codex_app_server_protocol::guardian_auto_approval_review_notification;
use codex_app_server_protocol::item_event_to_server_notification;
use codex_core::CodexThread;
use codex_core::ThreadManager;
use codex_features::Feature;
use codex_guardian_v2::StrictReviewReason;
use codex_protocol::ThreadId;
use codex_protocol::items::CollabAgentTool as CoreCollabAgentTool;
@@ -1068,11 +1070,14 @@ pub(crate) async fn apply_bespoke_event_handling(
_ => None,
};
if should_emit {
let notification = item_event_to_server_notification(
let mut notification = item_event_to_server_notification(
EventMsg::ItemStarted(event),
&conversation_id.to_string(),
&event_turn_id,
);
if conversation.enabled(Feature::OmitAppServerNotificationMedia) {
notification = without_notification_media(notification);
}
outgoing.send_server_notification(notification).await;
}
if let Some(params) = dynamic_tool_call_params {
@@ -1093,11 +1098,14 @@ pub(crate) async fn apply_bespoke_event_handling(
&event.item,
)
.await;
let notification = item_event_to_server_notification(
let mut notification = item_event_to_server_notification(
EventMsg::ItemCompleted(event),
&conversation_id.to_string(),
&event_turn_id,
);
if conversation.enabled(Feature::OmitAppServerNotificationMedia) {
notification = without_notification_media(notification);
}
outgoing.send_server_notification(notification).await;
}
msg @ (EventMsg::PatchApplyUpdated(_) | EventMsg::TerminalInteraction(_)) => {
@@ -1129,13 +1137,17 @@ pub(crate) async fn apply_bespoke_event_handling(
.await;
}
EventMsg::RawResponseItem(raw_response_item_event) => {
maybe_emit_raw_response_item_completed(
conversation_id,
&event_turn_id,
raw_response_item_event.item,
&outgoing,
)
.await;
let mut notification = ServerNotification::RawResponseItemCompleted(
RawResponseItemCompletedNotification {
thread_id: conversation_id.to_string(),
turn_id: event_turn_id,
item: raw_response_item_event.item,
},
);
if conversation.enabled(Feature::OmitAppServerNotificationMedia) {
notification = without_notification_media(notification);
}
outgoing.send_server_notification(notification).await;
}
EventMsg::RawResponseCompleted(raw_response_completed_event) => {
let notification = RawResponseCompletedNotification {
@@ -1512,22 +1524,6 @@ async fn complete_command_execution_item(
.await;
}
async fn maybe_emit_raw_response_item_completed(
conversation_id: ThreadId,
turn_id: &str,
item: codex_protocol::models::ResponseItem,
outgoing: &ThreadScopedOutgoingMessageSender,
) {
let notification = RawResponseItemCompletedNotification {
thread_id: conversation_id.to_string(),
turn_id: turn_id.to_string(),
item,
};
outgoing
.send_server_notification(ServerNotification::RawResponseItemCompleted(notification))
.await;
}
async fn find_and_remove_turn_summary(
_conversation_id: ThreadId,
thread_state: &Arc<Mutex<ThreadState>>,