summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/codex-0.144.1-test-disable-network-model-refresh.patch
blob: b43b2d21e55fcc64a842ae70253f21827281ef44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Author: Danny Milosavljevic <dannym@friendly-machines.com>
Date: 2026-07-11
License: ASL2.0
Subject: Disable app-server network model refresh in tests.

Codex 0.144.1 starts a background app-server model refresh worker at
startup.  That worker calls list_models with RefreshStrategy::Online, so
prewriting models_cache.json does not keep it off the network.

Tests that spawn a codex-app-server child must not depend on remote
network behavior or start unrelated background network tasks.  The
app-server integration suite already passes the hidden
--disable-plugin-startup-tasks-for-tests flag to suppress startup side
work in spawned child servers.  Extend that test-only flag to skip the
model refresh worker as well.  Production startup keeps the worker
enabled.

diff --git a/codex-rs/app-server/src/lib.rs b/codex-rs/app-server/src/lib.rs
index 32a58dba2..7935f3a91 100644
--- a/codex-rs/app-server/src/lib.rs
+++ b/codex-rs/app-server/src/lib.rs
@@ -427,18 +427,26 @@ pub enum PluginStartupTasks {
     Skip,
 }
 
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum ModelsRefreshStartup {
+    Start,
+    Skip,
+}
+
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 pub struct AppServerRuntimeOptions {
     pub plugin_startup_tasks: PluginStartupTasks,
+    pub models_refresh_startup: ModelsRefreshStartup,
     pub remote_control_startup_mode: RemoteControlStartupMode,
     pub install_shutdown_signal_handler: bool,
 }
 
 impl Default for AppServerRuntimeOptions {
     fn default() -> Self {
         Self {
             plugin_startup_tasks: PluginStartupTasks::Start,
+            models_refresh_startup: ModelsRefreshStartup::Start,
             remote_control_startup_mode: RemoteControlStartupMode::ResolvePersisted,
             install_shutdown_signal_handler: true,
         }
     }
@@ -905,6 +912,7 @@ pub async fn run_main_with_transport_options(
             rpc_transport: analytics_rpc_transport(&transport),
             remote_control_handle: Some(remote_control_handle.clone()),
             plugin_startup_tasks: runtime_options.plugin_startup_tasks,
+            models_refresh_startup: runtime_options.models_refresh_startup,
         }));
         let mut thread_created_rx = processor.thread_created_receiver();
         let mut running_turn_count_rx = processor.subscribe_running_assistant_turn_count();
diff --git a/codex-rs/app-server/src/in_process.rs b/codex-rs/app-server/src/in_process.rs
index f81c65c2a..1eb834771 100644
--- a/codex-rs/app-server/src/in_process.rs
+++ b/codex-rs/app-server/src/in_process.rs
@@ -450,6 +450,7 @@ impl InProcessAppServer {
                 rpc_transport: AppServerRpcTransport::InProcess,
                 remote_control_handle: None,
                 plugin_startup_tasks: crate::PluginStartupTasks::Start,
+                models_refresh_startup: crate::ModelsRefreshStartup::Start,
             }));
             let mut thread_created_rx = processor.thread_created_receiver();
             let session = Arc::new(ConnectionSessionState::new());
diff --git a/codex-rs/app-server/src/main.rs b/codex-rs/app-server/src/main.rs
index 874d20521..3104a2d03 100644
--- a/codex-rs/app-server/src/main.rs
+++ b/codex-rs/app-server/src/main.rs
@@ -2,6 +2,7 @@ use clap::Parser;
 use codex_app_server::AppServerRuntimeOptions;
 use codex_app_server::AppServerTransport;
 use codex_app_server::AppServerWebsocketAuthArgs;
+use codex_app_server::ModelsRefreshStartup;
 use codex_app_server::PluginStartupTasks;
 use codex_app_server::run_main_with_transport_options;
 use codex_arg0::Arg0DispatchPaths;
@@ -84,6 +85,7 @@ fn main() -> anyhow::Result<()> {
         #[cfg(debug_assertions)]
         if disable_plugin_startup_tasks_for_tests {
             runtime_options.plugin_startup_tasks = PluginStartupTasks::Skip;
+            runtime_options.models_refresh_startup = ModelsRefreshStartup::Skip;
         }
         runtime_options.remote_control_startup_mode =
             match (remote_control, remote_control_disabled) {
diff --git a/codex-rs/app-server/src/message_processor.rs b/codex-rs/app-server/src/message_processor.rs
index 7d86f872a..b2da65a2a 100644
--- a/codex-rs/app-server/src/message_processor.rs
+++ b/codex-rs/app-server/src/message_processor.rs
@@ -101,7 +101,7 @@ fn decode_request_payload(payload: JsonRpcMessagePayload) -> Result<Value, JsonR
 
 pub(crate) struct MessageProcessor {
     outgoing: Arc<OutgoingMessageSender>,
-    models_refresh_worker: ModelsRefreshWorker,
+    models_refresh_worker: Option<ModelsRefreshWorker>,
     skills_watcher: Arc<SkillsWatcher>,
     account_processor: AccountRequestProcessor,
     apps_processor: AppsRequestProcessor,
@@ -219,6 +219,7 @@ pub(crate) struct MessageProcessorArgs {
     pub(crate) rpc_transport: AppServerRpcTransport,
     pub(crate) remote_control_handle: Option<RemoteControlHandle>,
     pub(crate) plugin_startup_tasks: crate::PluginStartupTasks,
+    pub(crate) models_refresh_startup: crate::ModelsRefreshStartup,
 }
 
 impl MessageProcessor {
@@ -242,6 +243,7 @@ impl MessageProcessor {
             rpc_transport,
             remote_control_handle,
             plugin_startup_tasks,
+            models_refresh_startup,
         } = args;
         let thread_state_manager = ThreadStateManager::new();
         // The thread store is intentionally process-scoped. Config reloads can
@@ -299,8 +301,13 @@ impl MessageProcessor {
             )
         });
         let models_manager = thread_manager.get_models_manager();
-        let models_refresh_worker =
-            crate::models_refresh_worker::spawn(&models_manager, config.http_client_factory());
+        let models_refresh_worker = match models_refresh_startup {
+            crate::ModelsRefreshStartup::Start => Some(crate::models_refresh_worker::spawn(
+                &models_manager,
+                config.http_client_factory(),
+            )),
+            crate::ModelsRefreshStartup::Skip => None,
+        };
         thread_manager
             .plugins_manager()
             .set_analytics_events_client(analytics_events_client.clone());
@@ -499,7 +506,9 @@ impl MessageProcessor {
     pub(crate) fn clear_runtime_references(&self) {
         self.account_processor.clear_external_auth();
         self.apps_processor.shutdown();
-        self.models_refresh_worker.shutdown();
+        if let Some(models_refresh_worker) = &self.models_refresh_worker {
+            models_refresh_worker.shutdown();
+        }
         self.skills_watcher.shutdown();
     }
 
@@ -676,7 +685,9 @@ impl MessageProcessor {
     }
 
     pub(crate) async fn drain_background_tasks(&self) {
-        self.models_refresh_worker.shutdown();
+        if let Some(models_refresh_worker) = &self.models_refresh_worker {
+            models_refresh_worker.shutdown();
+        }
         self.thread_processor.drain_background_tasks().await;
     }
 
diff --git a/codex-rs/app-server/src/message_processor_tracing_tests.rs b/codex-rs/app-server/src/message_processor_tracing_tests.rs
index d839bd6f0..797813e35 100644
--- a/codex-rs/app-server/src/message_processor_tracing_tests.rs
+++ b/codex-rs/app-server/src/message_processor_tracing_tests.rs
@@ -267,6 +267,7 @@ fn make_processor() -> (Arc<MessageProcessor>, OutgoingMessageReceiver) {
         rpc_transport: AppServerRpcTransport::Stdio,
         remote_control_handle: None,
         plugin_startup_tasks: crate::PluginStartupTasks::Start,
+        models_refresh_startup: crate::ModelsRefreshStartup::Start,
     }));
     (processor, outgoing_rx)
 }
diff --git a/codex-rs/app-server/tests/suite/v2/remote_control.rs b/codex-rs/app-server/tests/suite/v2/remote_control.rs
index f85688ddc..66ab20e88 100644
--- a/codex-rs/app-server/tests/suite/v2/remote_control.rs
+++ b/codex-rs/app-server/tests/suite/v2/remote_control.rs
@@ -240,6 +240,7 @@ async fn explicit_remote_control_startup_fails_when_disabled_by_requirements() -
             AppServerWebsocketAuthSettings::default(),
             AppServerRuntimeOptions {
                 plugin_startup_tasks: PluginStartupTasks::Skip,
+                models_refresh_startup: codex_app_server::ModelsRefreshStartup::Skip,
                 remote_control_startup_mode: RemoteControlStartupMode::EnabledEphemeral,
                 install_shutdown_signal_handler: false,
             },