diff --git a/codex-rs/app-server/README.md b/codex-rs/app-server/README.md index 33617ad14a..88f2a22277 100644 --- a/codex-rs/app-server/README.md +++ b/codex-rs/app-server/README.md @@ -404,16 +404,28 @@ Example: When `nextCursor` is `null`, you’ve reached the final page. -To keep a paginated catalog current, call `threadCatalog/subscribe` before the initial -`thread/list`. The response only acknowledges future notifications; it does not replay existing -threads. Registration completes before the response is sent, so clients should buffer catalog -notifications until their list request completes and apply `threadCatalog/changed` summaries -idempotently. Its `upsert` variant contains the complete row, `delete` removes a row, and -`invalidate` means the client fell behind and must refetch its catalog view. Reconnects require -another subscribe and list sequence. +`threadCatalog/subscribe` is an opt-in, future-only metadata feed. Registration completes before +the response is sent, but the server does not replay existing threads or reconcile changes missed +while disconnected. Older clients receive no catalog events because only connections that call the +method are subscribed. + +To maintain a parent's subagent catalog without loading its history: + +1. Call `threadCatalog/subscribe` and buffer `threadCatalog/changed` notifications. +2. Seed the authoritative descendant set by paging `thread/list` with `ancestorThreadId`. +3. Apply buffered and future `upsert` summaries and `delete` IDs idempotently by thread ID. An + `invalidate` event means the client fell behind and must repeat the list snapshot. +4. Merge the existing global `thread/status/changed` feed by thread ID for active or idle runtime + state. + +Reconnects repeat the subscribe-and-list sequence. Codex Apps must version-gate the subscribe call +and retain its existing startup sweep when connected to older app servers. This feed alone does not +replace that sweep or recover mutations missed while disconnected. `threadCatalog/changed` contains persisted sidebar metadata only. It never contains turns, items, -messages, deltas, tool state, or loaded runtime status. +messages, deltas, tool state, or loaded runtime status. Subagent summaries include relationship and +display metadata such as `parentThreadId`, `threadSource`, `agentNickname`, and `agentRole`; clients +compose runtime state from `thread/status/changed` rather than this feed. ### Example: List descendant threads diff --git a/codex-rs/app-server/tests/suite/v2/turn_start.rs b/codex-rs/app-server/tests/suite/v2/turn_start.rs index 62b13a1e52..fb37414b0d 100644 --- a/codex-rs/app-server/tests/suite/v2/turn_start.rs +++ b/codex-rs/app-server/tests/suite/v2/turn_start.rs @@ -42,6 +42,8 @@ use codex_app_server_protocol::ServerRequest; use codex_app_server_protocol::ServerRequestResolvedNotification; use codex_app_server_protocol::SubAgentActivityKind; use codex_app_server_protocol::TextElement; +use codex_app_server_protocol::ThreadCatalogChangedNotification; +use codex_app_server_protocol::ThreadCatalogSubscribeResponse; use codex_app_server_protocol::ThreadDeleteParams; use codex_app_server_protocol::ThreadDeleteResponse; use codex_app_server_protocol::ThreadDeletedNotification; @@ -3927,6 +3929,16 @@ config_file = "./custom-role.toml" .await??; let ThreadStartResponse { thread, .. } = to_response::(thread_resp)?; + let subscribe_req = mcp + .send_raw_request("threadCatalog/subscribe", /*params*/ None) + .await?; + let subscribe_resp = timeout( + DEFAULT_READ_TIMEOUT, + mcp.read_stream_until_response_message(RequestId::Integer(subscribe_req)), + ) + .await??; + let _: ThreadCatalogSubscribeResponse = to_response(subscribe_resp)?; + let turn_req = mcp .send_turn_start_request(TurnStartParams { thread_id: thread.id.clone(), @@ -3999,6 +4011,37 @@ config_file = "./custom-role.toml" ); assert_eq!(agent_state.message, None); + let child_summary = timeout(DEFAULT_READ_TIMEOUT, async { + loop { + let changed = mcp + .read_stream_until_notification_message("threadCatalog/changed") + .await?; + let changed: ThreadCatalogChangedNotification = + serde_json::from_value(changed.params.expect("threadCatalog/changed params"))?; + if let ThreadCatalogChangedNotification::Upsert { thread: summary } = changed + && summary.id == receiver_thread_id + && summary.agent_role.as_deref() == Some("custom") + { + return Ok::<_, anyhow::Error>(summary); + } + } + }) + .await??; + assert_eq!( + ( + child_summary.parent_thread_id.as_deref(), + child_summary.thread_source.as_ref(), + child_summary.agent_nickname.as_deref().map(str::is_empty), + child_summary.agent_role.as_deref(), + ), + ( + Some(thread.id.as_str()), + Some(&ThreadSource::Subagent), + Some(false), + Some("custom"), + ) + ); + let turn_completed = timeout(DEFAULT_READ_TIMEOUT, async { loop { let turn_completed_notif = mcp diff --git a/codex-rs/tui/src/app/app_server_event_targets.rs b/codex-rs/tui/src/app/app_server_event_targets.rs index 6c55850e4d..2f770416d9 100644 --- a/codex-rs/tui/src/app/app_server_event_targets.rs +++ b/codex-rs/tui/src/app/app_server_event_targets.rs @@ -161,7 +161,8 @@ pub(super) fn server_notification_thread_target( None => return ServerNotificationThreadTarget::AppScoped, } } - ServerNotification::SkillsChanged(_) + ServerNotification::ThreadCatalogChanged(_) + | ServerNotification::SkillsChanged(_) | ServerNotification::McpServerOauthLoginCompleted(_) | ServerNotification::AccountUpdated(_) | ServerNotification::AccountRateLimitsUpdated(_) diff --git a/codex-rs/tui/src/chatwidget/protocol.rs b/codex-rs/tui/src/chatwidget/protocol.rs index f60f9c41da..56c93324e8 100644 --- a/codex-rs/tui/src/chatwidget/protocol.rs +++ b/codex-rs/tui/src/chatwidget/protocol.rs @@ -192,6 +192,7 @@ impl ChatWidget { } } ServerNotification::ServerRequestResolved(_) + | ServerNotification::ThreadCatalogChanged(_) | ServerNotification::AccountUpdated(_) | ServerNotification::AccountRateLimitsUpdated(_) | ServerNotification::ThreadStarted(_)