refactor app-server runtime storage deps

This commit is contained in:
starr-openai
2026-06-03 00:23:08 -07:00
parent 8f4d1c2ce6
commit 4bbb82b331
8 changed files with 186 additions and 34 deletions
+18 -2
View File
@@ -50,6 +50,7 @@ use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::time::Duration;
use crate::AppServerRuntimeStorageDeps;
use crate::analytics_utils::analytics_events_client_from_config;
use crate::config_manager::ConfigManager;
use crate::error_code::OVERLOADED_ERROR_CODE;
@@ -348,8 +349,19 @@ impl InProcessClientHandle {
/// the handle, so callers receive a ready-to-use runtime. If initialize fails,
/// the runtime is shut down and an `InvalidData` error is returned.
pub async fn start(args: InProcessStartArgs) -> IoResult<InProcessClientHandle> {
start_with_runtime_storage_deps(args, AppServerRuntimeStorageDeps::default()).await
}
/// Starts an in-process app-server runtime with explicit thread storage backends.
///
/// This is the embedded-host path for supplying executor-visible artifact and
/// shell snapshot stores without changing the existing start-argument shape.
pub async fn start_with_runtime_storage_deps(
args: InProcessStartArgs,
runtime_storage_deps: AppServerRuntimeStorageDeps,
) -> IoResult<InProcessClientHandle> {
let initialize = args.initialize.clone();
let client = start_uninitialized(args).await?;
let client = start_uninitialized(args, runtime_storage_deps).await?;
let initialize_response = client
.request(ClientRequest::Initialize {
@@ -369,7 +381,10 @@ pub async fn start(args: InProcessStartArgs) -> IoResult<InProcessClientHandle>
Ok(client)
}
async fn start_uninitialized(args: InProcessStartArgs) -> IoResult<InProcessClientHandle> {
async fn start_uninitialized(
args: InProcessStartArgs,
runtime_storage_deps: AppServerRuntimeStorageDeps,
) -> IoResult<InProcessClientHandle> {
let channel_capacity = args.channel_capacity.max(1);
let installation_id = resolve_installation_id(&args.config.codex_home).await?;
let (client_tx, mut client_rx) = mpsc::channel::<InProcessClientMessage>(channel_capacity);
@@ -438,6 +453,7 @@ async fn start_uninitialized(args: InProcessStartArgs) -> IoResult<InProcessClie
rpc_transport: AppServerRpcTransport::InProcess,
remote_control_handle: None,
plugin_startup_tasks: crate::PluginStartupTasks::Start,
runtime_storage_deps,
}));
let mut thread_created_rx = processor.thread_created_receiver();
let session = Arc::new(ConnectionSessionState::new());
+41
View File
@@ -6,6 +6,7 @@ use codex_config::LoaderOverrides;
use codex_config::NoopThreadConfigLoader;
use codex_config::RemoteThreadConfigLoader;
use codex_config::ThreadConfigLoader;
use codex_core::ThreadManagerStorageDeps;
use codex_core::config::Config;
use codex_core::resolve_installation_id;
use codex_login::AuthManager;
@@ -416,6 +417,16 @@ impl Default for AppServerRuntimeOptions {
}
}
/// Storage backends an app-server host can inject into managed threads.
///
/// Leaving these fields unset preserves the standard local `codex_home`
/// behavior used by the existing app-server entrypoints.
#[derive(Clone, Default)]
pub struct AppServerRuntimeStorageDeps {
/// Optional executor-visible storage backends for app-server threads.
pub thread_manager: Option<ThreadManagerStorageDeps>,
}
#[allow(clippy::too_many_arguments)]
pub async fn run_main_with_transport_options(
arg0_paths: Arg0DispatchPaths,
@@ -427,6 +438,35 @@ pub async fn run_main_with_transport_options(
session_source: SessionSource,
auth: AppServerWebsocketAuthSettings,
runtime_options: AppServerRuntimeOptions,
) -> IoResult<()> {
run_main_with_transport_options_and_storage_deps(
arg0_paths,
cli_config_overrides,
loader_overrides,
strict_config,
default_analytics_enabled,
transport,
session_source,
auth,
runtime_options,
AppServerRuntimeStorageDeps::default(),
)
.await
}
/// Runs app-server with explicit storage backends for managed threads.
#[allow(clippy::too_many_arguments)]
pub async fn run_main_with_transport_options_and_storage_deps(
arg0_paths: Arg0DispatchPaths,
cli_config_overrides: CliConfigOverrides,
loader_overrides: LoaderOverrides,
strict_config: bool,
default_analytics_enabled: bool,
transport: AppServerTransport,
session_source: SessionSource,
auth: AppServerWebsocketAuthSettings,
runtime_options: AppServerRuntimeOptions,
runtime_storage_deps: AppServerRuntimeStorageDeps,
) -> IoResult<()> {
let (transport_event_tx, mut transport_event_rx) =
mpsc::channel::<TransportEvent>(CHANNEL_CAPACITY);
@@ -815,6 +855,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,
runtime_storage_deps,
}));
let mut thread_created_rx = processor.thread_created_receiver();
let mut running_turn_count_rx = processor.subscribe_running_assistant_turn_count();
+37 -16
View File
@@ -272,6 +272,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) runtime_storage_deps: crate::AppServerRuntimeStorageDeps,
}
impl MessageProcessor {
@@ -295,6 +296,7 @@ impl MessageProcessor {
rpc_transport,
remote_control_handle,
plugin_startup_tasks,
runtime_storage_deps,
} = args;
auth_manager.set_external_auth(Arc::new(ExternalAuthRefreshBridge {
outgoing: outgoing.clone(),
@@ -305,26 +307,45 @@ impl MessageProcessor {
// resumed, or forked threads to a different persistence backend/root.
let thread_store = codex_core::thread_store_from_config(config.as_ref(), state_db.clone());
let environment_manager_for_requests = Arc::clone(&environment_manager);
let thread_manager_storage_deps = runtime_storage_deps.thread_manager;
let thread_manager = Arc::new_cyclic(|thread_manager| {
ThreadManager::new(
config.as_ref(),
let thread_manager_storage_deps = thread_manager_storage_deps.clone();
let extensions = thread_extensions(
guardian_agent_spawner(thread_manager.clone()),
app_server_extension_event_sink(outgoing.clone()),
auth_manager.clone(),
session_source,
environment_manager,
thread_extensions(
guardian_agent_spawner(thread_manager.clone()),
app_server_extension_event_sink(outgoing.clone()),
);
let attestation_provider = Some(app_server_attestation_provider(
outgoing.clone(),
thread_state_manager.clone(),
));
match thread_manager_storage_deps {
Some(storage_deps) => ThreadManager::new_with_storage_deps(
config.as_ref(),
auth_manager.clone(),
session_source,
environment_manager,
extensions,
Some(analytics_events_client.clone()),
Arc::clone(&thread_store),
storage_deps,
state_db.clone(),
installation_id,
attestation_provider,
),
Some(analytics_events_client.clone()),
Arc::clone(&thread_store),
state_db.clone(),
installation_id,
Some(app_server_attestation_provider(
outgoing.clone(),
thread_state_manager.clone(),
)),
)
None => ThreadManager::new(
config.as_ref(),
auth_manager.clone(),
session_source,
environment_manager,
extensions,
Some(analytics_events_client.clone()),
Arc::clone(&thread_store),
state_db.clone(),
installation_id,
attestation_provider,
),
}
});
thread_manager
.plugins_manager()
@@ -267,6 +267,7 @@ async fn build_test_processor(
rpc_transport: AppServerRpcTransport::Stdio,
remote_control_handle: None,
plugin_startup_tasks: crate::PluginStartupTasks::Start,
runtime_storage_deps: crate::AppServerRuntimeStorageDeps::default(),
}));
(processor, outgoing_rx)
}