Add app-server APIs for stored thread attachments (#44564)

## What changed

- Add `thread/attachment/add`, `thread/attachment/list`, and `thread/attachment/remove` to manage durable resource references without loading the owning thread or changing conversation history.
- Identify attachments by thread, `attachmentType`, and `identityKey`. Repeated adds return the existing attachment; repeated removals succeed without emitting another update. Listing supports cursor pagination.
- Broadcast `thread/attachment/updated` after creation or deletion, after responding to the requester. Serialize attachment mutations with thread lifecycle operations and reject stores that do not support attachments.
- Update protocol schemas, TypeScript and Python bindings, documentation, and TUI notification handling so attachment updates do not add untracked threads to the agent picker.

## Testing

Add coverage for unloaded threads, pagination, idempotent addition and removal, reattachment, invalid inputs, unsupported stores, response-before-notification ordering across clients, and TUI notification routing.

GitOrigin-RevId: 0d29cf903afd4e931a70a9cf96300475213b34aa
This commit is contained in:
joeytrasatti-openai authored and copyberry committed 2026-09-10 15:52:09 +00:00
1 parent 94697375cb
commit 3319d9b296
47 files changed
+2341 -6

No files matched your search

@@ -59,6 +59,9 @@ pub(super) fn server_notification_thread_target(
ServerNotification::ThreadNameUpdated(notification) => {
Some(notification.thread_id.as_str())
}
ServerNotification::ThreadAttachmentUpdated(notification) => {
Some(notification.thread_id.as_str())
}
ServerNotification::ThreadProjectUpdated(notification) => {
Some(notification.thread_id.as_str())
}
@@ -231,6 +234,8 @@ mod tests {
use codex_app_server_protocol::McpServerStartupState;
use codex_app_server_protocol::McpServerStatusUpdatedNotification;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ThreadAttachmentOperation;
use codex_app_server_protocol::ThreadAttachmentUpdatedNotification;
use codex_app_server_protocol::ThreadSettings;
use codex_app_server_protocol::ThreadSettingsUpdatedNotification;
use codex_app_server_protocol::WarningNotification;
@@ -352,4 +357,21 @@ mod tests {
assert_eq!(target, ServerNotificationThreadTarget::Thread(thread_id));
}
#[test]
fn thread_attachment_updated_notifications_route_to_threads() {
let thread_id = ThreadId::new();
let notification =
ServerNotification::ThreadAttachmentUpdated(ThreadAttachmentUpdatedNotification {
thread_id: thread_id.to_string(),
attachment_type: "pull_request".to_string(),
identity_key: r#"["github.com","openai","codex",123]"#.to_string(),
attachment_id: "attachment-1".to_string(),
operation: ThreadAttachmentOperation::Deleted,
});
let target = server_notification_thread_target(&notification);
assert_eq!(target, ServerNotificationThreadTarget::Thread(thread_id));
}
}
+28 -1
View File
@@ -135,6 +135,8 @@ use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ServerRequest;
use codex_app_server_protocol::Thread;
use codex_app_server_protocol::ThreadArchivedNotification;
use codex_app_server_protocol::ThreadAttachmentOperation;
use codex_app_server_protocol::ThreadAttachmentUpdatedNotification;
use codex_app_server_protocol::ThreadClosedNotification;
use codex_app_server_protocol::ThreadItem;
use codex_app_server_protocol::ThreadSettings;
@@ -1976,7 +1978,8 @@ async fn archived_untracked_threads_do_not_appear_in_agent_picker() -> Result<()
app.chat_widget.config_ref(),
))
.await?;
let primary_thread_id = ThreadId::new();
let primary_thread_id =
ThreadId::from_string("00000000-0000-0000-0000-000000000123").expect("valid thread id");
app.enqueue_primary_thread_session(
test_thread_session(primary_thread_id, test_path_buf("/tmp/project")),
Vec::new(),
@@ -1996,8 +1999,32 @@ async fn archived_untracked_threads_do_not_appear_in_agent_picker() -> Result<()
assert!(!app.thread_event_channels.contains_key(&archived_thread_id));
let attachment_thread_id = ThreadId::new();
app.handle_app_server_event(
&app_server,
codex_app_server_client::AppServerEvent::ServerNotification(Box::new(
ServerNotification::ThreadAttachmentUpdated(ThreadAttachmentUpdatedNotification {
thread_id: attachment_thread_id.to_string(),
attachment_type: "pull_request".to_string(),
identity_key: r#"["github.com","openai","codex",123]"#.to_string(),
attachment_id: "attachment-1".to_string(),
operation: ThreadAttachmentOperation::Deleted,
}),
)),
)
.await;
assert!(
!app.thread_event_channels
.contains_key(&attachment_thread_id)
);
Box::pin(app.open_agent_picker(&mut app_server)).await;
assert_app_snapshot!(
"untracked_thread_notifications_agent_picker",
render_bottom_popup(&app.chat_widget, /*width*/ 80)
);
assert_eq!(
app.agent_navigation.ordered_thread_ids(),
vec![primary_thread_id]
+12
View File
@@ -282,6 +282,7 @@ impl ThreadEventStore {
| ServerNotification::FileChangePatchUpdated(_)
| ServerNotification::ServerRequestResolved(_)
| ServerNotification::McpToolCallProgress(_)
| ServerNotification::ThreadAttachmentUpdated(_)
| ServerNotification::ThreadRealtimeItemAdded(_)
| ServerNotification::ThreadRealtimeOutputAudioDelta(_)
| ServerNotification::ThreadRealtimeSdp(_)
@@ -646,6 +647,8 @@ mod tests {
use codex_app_server_protocol::McpToolCallProgressNotification;
use codex_app_server_protocol::ReasoningSummaryTextDeltaNotification;
use codex_app_server_protocol::RequestId as AppServerRequestId;
use codex_app_server_protocol::ThreadAttachmentOperation;
use codex_app_server_protocol::ThreadAttachmentUpdatedNotification;
use codex_app_server_protocol::ThreadRealtimeAudioChunk;
use codex_app_server_protocol::ThreadRealtimeOutputAudioDeltaNotification;
use codex_app_server_protocol::TurnCompletedNotification;
@@ -902,6 +905,15 @@ mod tests {
let large_payload = "x".repeat(1024 * 1024);
for _ in 0..32 {
store.push_notification_ref(&ServerNotification::ThreadAttachmentUpdated(
ThreadAttachmentUpdatedNotification {
thread_id: thread_id.to_string(),
attachment_type: "pullRequest".to_string(),
identity_key: "openai/codex#1".to_string(),
attachment_id: "attachment-1".to_string(),
operation: ThreadAttachmentOperation::Created,
},
));
store.push_notification_ref(&ServerNotification::McpToolCallProgress(
McpToolCallProgressNotification {
thread_id: thread_id.to_string(),
+3 -1
View File
@@ -1166,7 +1166,9 @@ impl App {
}
if matches!(
notification,
ServerNotification::ThreadSettingsUpdated(_) | ServerNotification::ThreadArchived(_)
ServerNotification::ThreadSettingsUpdated(_)
| ServerNotification::ThreadArchived(_)
| ServerNotification::ThreadAttachmentUpdated(_)
) && self.primary_thread_id.is_some()
&& self.primary_thread_id != Some(thread_id)
&& !self.thread_event_channels.contains_key(&thread_id)