Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Avoid duplicate cached app list update notifications (#33640)

acrognale-oaif722a7ebcf14
diff --git a/codex-rs/app-server/README.md b/codex-rs/app-server/README.md
index 25b52602ea..3acb1f2e85 100644
--- a/codex-rs/app-server/README.md
+++ b/codex-rs/app-server/README.md
@@ -1845,7 +1845,7 @@ When `threadId` is provided, app feature gating (`Feature::Apps`) is evaluated u
`app/list` returns after both accessible apps and directory apps are loaded. Set `forceRefetch: true` to bypass app caches and fetch fresh data from sources. Cache entries are only replaced when those refetches succeed.
-The server also emits `app/list/updated` notifications whenever either source (accessible apps or directory apps) finishes loading. Each notification includes the latest merged app list.
+The server also emits `app/list/updated` notifications when newly loaded accessible or directory apps change the merged app list. Each notification includes the latest merged app list. An initial cached `app/list` still emits one final notification so other initialized clients can refresh their app list, while reading an unchanged cached continuation page does not emit a duplicate notification; `forceRefetch: true` preserves the existing progressive notifications while fresh data loads.
```json
{
diff --git a/codex-rs/app-server/src/request_processors/apps_processor.rs b/codex-rs/app-server/src/request_processors/apps_processor.rs
index 5ff7ec40db..a84e7cc987 100644
--- a/codex-rs/app-server/src/request_processors/apps_processor.rs
+++ b/codex-rs/app-server/src/request_processors/apps_processor.rs
@@ -244,19 +244,23 @@ impl AppsRequestProcessor {
let mut all_loaded = false;
let mut codex_apps_ready = true;
let mut last_notified_apps = None;
+ let mut sent_app_list_update = false;
if accessible_connectors.is_some() || all_connectors.is_some() {
let merged = connectors::with_app_enabled_state(
merge_loaded_apps(all_connectors.as_deref(), accessible_connectors.as_deref()),
&config,
);
- if should_send_app_list_updated_notification(
+ if !force_refetch {
+ last_notified_apps = Some(merged);
+ } else if should_send_app_list_updated_notification(
merged.as_slice(),
accessible_loaded,
all_loaded,
) {
send_app_list_updated_notification(outgoing, merged.clone()).await;
last_notified_apps = Some(merged);
+ sent_app_list_update = true;
}
}
@@ -313,10 +317,16 @@ impl AppsRequestProcessor {
merged.as_slice(),
accessible_loaded,
all_loaded,
- ) && last_notified_apps.as_ref() != Some(&merged)
+ ) && (last_notified_apps.as_ref() != Some(&merged)
+ || (!force_refetch
+ && start == 0
+ && accessible_loaded
+ && all_loaded
+ && !sent_app_list_update))
{
send_app_list_updated_notification(outgoing, merged.clone()).await;
last_notified_apps = Some(merged.clone());
+ sent_app_list_update = true;
}
if accessible_loaded && all_loaded {
diff --git a/codex-rs/app-server/tests/suite/v2/app_list.rs b/codex-rs/app-server/tests/suite/v2/app_list.rs
index a5e589be42..bb76561e22 100644
--- a/codex-rs/app-server/tests/suite/v2/app_list.rs
+++ b/codex-rs/app-server/tests/suite/v2/app_list.rs
@@ -1168,6 +1168,7 @@ async fn list_apps_paginates_results() -> Result<()> {
break;
}
}
+ mcp.clear_message_buffer();
let second_request = mcp
.send_apps_list_request(AppsListParams {
@@ -1208,6 +1209,16 @@ async fn list_apps_paginates_results() -> Result<()> {
assert_eq!(second_page, expected_second);
assert!(second_cursor.is_none());
+ let duplicate_update = timeout(
+ Duration::from_millis(150),
+ read_app_list_updated_notification(&mut mcp),
+ )
+ .await;
+ assert!(
+ duplicate_update.is_err(),
+ "cached app/list page emitted a duplicate full-list update"
+ );
+
server_handle.abort();
Ok(())
}
@@ -1581,6 +1592,40 @@ async fn list_apps_force_refetch_patches_updates_from_cached_snapshots() -> Resu
assert_eq!(refetch_data, expected_final);
assert!(refetch_next_cursor.is_none());
+ mcp.clear_message_buffer();
+ let cached_request = mcp
+ .send_apps_list_request(AppsListParams {
+ limit: None,
+ cursor: None,
+ thread_id: None,
+ force_refetch: false,
+ })
+ .await?;
+ let cached_response: JSONRPCResponse = timeout(
+ DEFAULT_TIMEOUT,
+ mcp.read_stream_until_response_message(RequestId::Integer(cached_request)),
+ )
+ .await??;
+ let AppsListResponse {
+ data: cached_data,
+ next_cursor: cached_next_cursor,
+ } = to_response(cached_response)?;
+ assert_eq!(cached_data, expected_final);
+ assert!(cached_next_cursor.is_none());
+
+ let cached_update = read_app_list_updated_notification(&mut mcp).await?;
+ assert_eq!(cached_update.data, expected_final);
+
+ let duplicate_update = timeout(
+ Duration::from_millis(150),
+ read_app_list_updated_notification(&mut mcp),
+ )
+ .await;
+ assert!(
+ duplicate_update.is_err(),
+ "cached initial app/list emitted more than one full-list update"
+ );
+
server_handle.abort();
Ok(())
}