[codex-app-server] expose generic per-surface HTTP state bridge [ci changed_files]

This commit is contained in:
Cooper Gamble
2026-06-03 09:58:07 +00:00
parent bf1b28e1c1
commit 81ccd4cbf2
25 changed files with 323 additions and 336 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ codex-utils-pty = { workspace = true }
codex-backend-client = { workspace = true }
codex-file-search = { workspace = true }
codex-chatgpt = { workspace = true }
codex-client = { workspace = true }
codex-http-state = { workspace = true }
codex-login = { workspace = true }
codex-image-generation-extension = { workspace = true }
codex-memories-extension = { workspace = true }
+3 -3
View File
@@ -214,9 +214,9 @@ Example with notification opt-out:
- `remoteControl/client/list` — experimental; list controller devices granted access to an environment. Pass `environmentId` and optional `cursor`, `limit`, and `order`; returns picker-oriented client metadata plus `nextCursor`. This signed-in account-management operation works while the local relay is disabled or unenrolled.
- `remoteControl/client/revoke` — experimental; revoke one controller device's grant for an environment. Pass `environmentId` and `clientId`; returns an empty object. This signed-in account-management operation works while the local relay is disabled or unenrolled.
- `remoteControl/status/changed` — notification emitted when the remote-control status or client-visible environment id changes. `status` is one of `disabled`, `connecting`, `connected`, or `errored`; `serverName` is the local machine name used by this app-server process; `environmentId` is a string when the app-server has a current enrollment and `null` when that enrollment is cleared, invalidated, or remote control is disabled. Newly initialized app-server clients always receive the current status snapshot.
- `nativeIntegrityState/read` — read the integrity state file for the initialized client's recognized native surface. Returns `{ state }`, where `state` is `null` when no file exists.
- `nativeIntegrityState/write` — write the initialized client's recognized native-surface state file. Pass `expectedState` to write only when the file still contains that value; omit it to replace the file unconditionally. Returns `{ written }`.
- `nativeIntegrityState/clear` — delete the integrity state file for the initialized client's recognized native surface. Returns `{}`.
- `httpState/get` — read the HTTP state file for the initialized client's recognized native surface. Returns `{ state }`, where `state` is `null` when no file exists.
- `httpState/set` — write the initialized client's recognized native-surface HTTP state file. Pass `expectedState` to write only when the file still contains that value; omit it to replace the file unconditionally. Returns `{ written }`.
- `httpState/clear` — delete the HTTP state file for the initialized client's recognized native surface. Returns `{}`.
- `skills/config/write` — write user-level skill config by name or absolute path.
- `plugin/install` — install a plugin from a discovered marketplace entry, rejecting marketplace entries marked unavailable for install, install MCPs if any, and return the effective plugin auth policy plus any apps that still need auth (**under development; do not call from production clients yet**).
- `plugin/uninstall` — uninstall a local plugin by `pluginId` in `<plugin>@<marketplace>` form by removing its cached files and clearing its user-level config entry, or uninstall a remote ChatGPT plugin by backend `pluginId` by forwarding the uninstall to the ChatGPT plugin backend and removing any downloaded remote-plugin cache (**under development; do not call from production clients yet**).
+12 -13
View File
@@ -26,10 +26,10 @@ use crate::request_processors::ExternalAgentConfigRequestProcessor;
use crate::request_processors::FeedbackRequestProcessor;
use crate::request_processors::FsRequestProcessor;
use crate::request_processors::GitRequestProcessor;
use crate::request_processors::HttpStateRequestProcessor;
use crate::request_processors::InitializeRequestProcessor;
use crate::request_processors::MarketplaceRequestProcessor;
use crate::request_processors::McpRequestProcessor;
use crate::request_processors::NativeIntegrityStateRequestProcessor;
use crate::request_processors::PluginRequestProcessor;
use crate::request_processors::ProcessExecRequestProcessor;
use crate::request_processors::RemoteControlRequestProcessor;
@@ -177,7 +177,7 @@ pub(crate) struct MessageProcessor {
initialize_processor: InitializeRequestProcessor,
marketplace_processor: MarketplaceRequestProcessor,
mcp_processor: McpRequestProcessor,
native_integrity_state_processor: NativeIntegrityStateRequestProcessor,
http_state_processor: HttpStateRequestProcessor,
plugin_processor: PluginRequestProcessor,
remote_control_processor: RemoteControlRequestProcessor,
search_processor: SearchRequestProcessor,
@@ -402,8 +402,7 @@ impl MessageProcessor {
outgoing.clone(),
config_manager.clone(),
);
let native_integrity_state_processor =
NativeIntegrityStateRequestProcessor::new(config.codex_home.to_path_buf());
let http_state_processor = HttpStateRequestProcessor::new(config.codex_home.to_path_buf());
let plugin_processor = PluginRequestProcessor::new(
auth_manager.clone(),
Arc::clone(&thread_manager),
@@ -507,7 +506,7 @@ impl MessageProcessor {
initialize_processor,
marketplace_processor,
mcp_processor,
native_integrity_state_processor,
http_state_processor,
plugin_processor,
remote_control_processor,
search_processor,
@@ -937,16 +936,16 @@ impl MessageProcessor {
.clients_revoke(params)
.await
.map(|response| Some(response.into())),
ClientRequest::NativeIntegrityStateRead { .. } => self
.native_integrity_state_processor
.read(app_server_client_name.as_deref())
ClientRequest::HttpStateGet { .. } => self
.http_state_processor
.get(app_server_client_name.as_deref())
.map(|response| Some(response.into())),
ClientRequest::NativeIntegrityStateWrite { params, .. } => self
.native_integrity_state_processor
.write(app_server_client_name.as_deref(), params)
ClientRequest::HttpStateSet { params, .. } => self
.http_state_processor
.set(app_server_client_name.as_deref(), params)
.map(|response| Some(response.into())),
ClientRequest::NativeIntegrityStateClear { .. } => self
.native_integrity_state_processor
ClientRequest::HttpStateClear { .. } => self
.http_state_processor
.clear(app_server_client_name.as_deref())
.map(|response| Some(response.into())),
ClientRequest::ConfigRequirementsRead { params: _, .. } => self
@@ -463,10 +463,10 @@ mod feedback_doctor_report;
mod feedback_processor;
mod fs_processor;
mod git_processor;
mod http_state_processor;
mod initialize_processor;
mod marketplace_processor;
mod mcp_processor;
mod native_integrity_state_processor;
mod plugins;
mod process_exec_processor;
mod remote_control_processor;
@@ -486,10 +486,10 @@ pub(crate) use external_agent_config_processor::ExternalAgentConfigRequestProces
pub(crate) use feedback_processor::FeedbackRequestProcessor;
pub(crate) use fs_processor::FsRequestProcessor;
pub(crate) use git_processor::GitRequestProcessor;
pub(crate) use http_state_processor::HttpStateRequestProcessor;
pub(crate) use initialize_processor::InitializeRequestProcessor;
pub(crate) use marketplace_processor::MarketplaceRequestProcessor;
pub(crate) use mcp_processor::McpRequestProcessor;
pub(crate) use native_integrity_state_processor::NativeIntegrityStateRequestProcessor;
pub(crate) use plugins::PluginRequestProcessor;
pub(crate) use process_exec_processor::ProcessExecRequestProcessor;
pub(crate) use remote_control_processor::RemoteControlRequestProcessor;
@@ -0,0 +1,85 @@
use std::io;
use std::path::PathBuf;
use codex_app_server_protocol::HttpStateClearResponse;
use codex_app_server_protocol::HttpStateGetResponse;
use codex_app_server_protocol::HttpStateSetParams;
use codex_app_server_protocol::HttpStateSetResponse;
use codex_app_server_protocol::JSONRPCErrorError;
use codex_http_state::HttpStateStore;
use codex_http_state::HttpStateSurface;
use crate::error_code::internal_error;
use crate::error_code::invalid_request;
#[derive(Clone)]
pub(crate) struct HttpStateRequestProcessor {
store: HttpStateStore,
}
impl HttpStateRequestProcessor {
pub(crate) fn new(codex_home: PathBuf) -> Self {
Self {
store: HttpStateStore::new(codex_home),
}
}
pub(crate) fn get(
&self,
app_server_client_name: Option<&str>,
) -> Result<HttpStateGetResponse, JSONRPCErrorError> {
let surface = surface_for_client_name(app_server_client_name)?;
let state = self.store.get(surface).map_err(map_get_error)?;
Ok(HttpStateGetResponse { state })
}
pub(crate) fn set(
&self,
app_server_client_name: Option<&str>,
params: HttpStateSetParams,
) -> Result<HttpStateSetResponse, JSONRPCErrorError> {
let surface = surface_for_client_name(app_server_client_name)?;
let written = match params.expected_state {
Some(expected_state) => {
self.store
.compare_and_set(surface, &expected_state, params.state)
}
None => self.store.set(surface, params.state).map(|()| true),
}
.map_err(map_set_error)?;
Ok(HttpStateSetResponse { written })
}
pub(crate) fn clear(
&self,
app_server_client_name: Option<&str>,
) -> Result<HttpStateClearResponse, JSONRPCErrorError> {
let surface = surface_for_client_name(app_server_client_name)?;
self.store.clear(surface).map_err(map_clear_error)?;
Ok(HttpStateClearResponse {})
}
}
fn surface_for_client_name(
app_server_client_name: Option<&str>,
) -> Result<HttpStateSurface, JSONRPCErrorError> {
let client_name = app_server_client_name
.ok_or_else(|| invalid_request("HTTP state requires an initialized client"))?;
HttpStateSurface::try_from_app_server_client_name(client_name).ok_or_else(|| {
invalid_request(format!(
"HTTP state is unavailable for app-server client {client_name:?}"
))
})
}
fn map_get_error(error: io::Error) -> JSONRPCErrorError {
internal_error(format!("failed to read HTTP state: {error}"))
}
fn map_set_error(error: io::Error) -> JSONRPCErrorError {
internal_error(format!("failed to write HTTP state: {error}"))
}
fn map_clear_error(error: io::Error) -> JSONRPCErrorError {
internal_error(format!("failed to clear HTTP state: {error}"))
}
@@ -1,93 +0,0 @@
use std::io;
use std::path::PathBuf;
use codex_app_server_protocol::JSONRPCErrorError;
use codex_app_server_protocol::NativeIntegrityStateClearResponse;
use codex_app_server_protocol::NativeIntegrityStateReadResponse;
use codex_app_server_protocol::NativeIntegrityStateWriteParams;
use codex_app_server_protocol::NativeIntegrityStateWriteResponse;
use codex_client::NativeIntegrityStateStore;
use codex_client::NativeIntegritySurface;
use crate::error_code::internal_error;
use crate::error_code::invalid_request;
#[derive(Clone)]
pub(crate) struct NativeIntegrityStateRequestProcessor {
store: NativeIntegrityStateStore,
}
impl NativeIntegrityStateRequestProcessor {
pub(crate) fn new(codex_home: PathBuf) -> Self {
Self {
store: NativeIntegrityStateStore::new(codex_home),
}
}
pub(crate) fn read(
&self,
app_server_client_name: Option<&str>,
) -> Result<NativeIntegrityStateReadResponse, JSONRPCErrorError> {
let surface = surface_for_client_name(app_server_client_name)?;
let state = self
.store
.load(surface)
.map_err(map_read_error)?
.map(|state_file| state_file.state);
Ok(NativeIntegrityStateReadResponse { state })
}
pub(crate) fn write(
&self,
app_server_client_name: Option<&str>,
params: NativeIntegrityStateWriteParams,
) -> Result<NativeIntegrityStateWriteResponse, JSONRPCErrorError> {
let surface = surface_for_client_name(app_server_client_name)?;
let written = match params.expected_state {
Some(expected_state) => {
self.store
.compare_and_store(surface, &expected_state, params.state)
}
None => self.store.replace(surface, params.state).map(|()| true),
}
.map_err(map_write_error)?;
Ok(NativeIntegrityStateWriteResponse { written })
}
pub(crate) fn clear(
&self,
app_server_client_name: Option<&str>,
) -> Result<NativeIntegrityStateClearResponse, JSONRPCErrorError> {
let surface = surface_for_client_name(app_server_client_name)?;
self.store.clear(surface).map_err(map_clear_error)?;
Ok(NativeIntegrityStateClearResponse {})
}
}
fn surface_for_client_name(
app_server_client_name: Option<&str>,
) -> Result<NativeIntegritySurface, JSONRPCErrorError> {
let client_name = app_server_client_name
.ok_or_else(|| invalid_request("native integrity state requires an initialized client"))?;
NativeIntegritySurface::try_from_app_server_client_name(client_name).ok_or_else(|| {
invalid_request(format!(
"native integrity state is unavailable for app-server client {client_name:?}"
))
})
}
fn map_read_error(error: io::Error) -> JSONRPCErrorError {
internal_error(format!("failed to read native integrity state: {error}"))
}
fn map_write_error(error: io::Error) -> JSONRPCErrorError {
if error.kind() == io::ErrorKind::InvalidData {
invalid_request(error.to_string())
} else {
internal_error(format!("failed to write native integrity state: {error}"))
}
}
fn map_clear_error(error: io::Error) -> JSONRPCErrorError {
internal_error(format!("failed to clear native integrity state: {error}"))
}
@@ -4,24 +4,23 @@ use anyhow::Result;
use app_test_support::TestAppServer;
use app_test_support::to_response;
use codex_app_server_protocol::ClientInfo;
use codex_app_server_protocol::HttpStateClearResponse;
use codex_app_server_protocol::HttpStateGetResponse;
use codex_app_server_protocol::HttpStateSetParams;
use codex_app_server_protocol::HttpStateSetResponse;
use codex_app_server_protocol::JSONRPCMessage;
use codex_app_server_protocol::JSONRPCResponse;
use codex_app_server_protocol::NativeIntegrityStateClearResponse;
use codex_app_server_protocol::NativeIntegrityStateReadResponse;
use codex_app_server_protocol::NativeIntegrityStateWriteParams;
use codex_app_server_protocol::NativeIntegrityStateWriteResponse;
use codex_app_server_protocol::RequestId;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
use tokio::time::timeout;
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
const STATE_N: &str = "ois1.a.b.c";
const STATE_N_PLUS_ONE: &str = "ois1.d.e.f";
const STATE_N: &str = "state-n";
const STATE_N_PLUS_ONE: &str = "state-n-plus-one";
#[tokio::test]
async fn native_integrity_state_bridge_reads_writes_rotates_and_clears_surface_state() -> Result<()>
{
async fn http_state_bridge_reads_writes_rotates_and_clears_surface_state() -> Result<()> {
let codex_home = TempDir::new()?;
let mut mcp = TestAppServer::new(codex_home.path()).await?;
let initialized = mcp
@@ -32,63 +31,63 @@ async fn native_integrity_state_bridge_reads_writes_rotates_and_clears_surface_s
};
assert_eq!(
read_state(&mut mcp).await?,
NativeIntegrityStateReadResponse { state: None }
get_state(&mut mcp).await?,
HttpStateGetResponse { state: None }
);
assert_eq!(
write_state(
set_state(
&mut mcp,
NativeIntegrityStateWriteParams {
HttpStateSetParams {
state: STATE_N.to_string(),
expected_state: None,
},
)
.await?,
NativeIntegrityStateWriteResponse { written: true }
HttpStateSetResponse { written: true }
);
assert_eq!(
read_state(&mut mcp).await?,
NativeIntegrityStateReadResponse {
get_state(&mut mcp).await?,
HttpStateGetResponse {
state: Some(STATE_N.to_string()),
}
);
assert_eq!(
write_state(
set_state(
&mut mcp,
NativeIntegrityStateWriteParams {
HttpStateSetParams {
state: STATE_N_PLUS_ONE.to_string(),
expected_state: Some("stale-state".to_string()),
},
)
.await?,
NativeIntegrityStateWriteResponse { written: false }
HttpStateSetResponse { written: false }
);
assert_eq!(
read_state(&mut mcp).await?,
NativeIntegrityStateReadResponse {
get_state(&mut mcp).await?,
HttpStateGetResponse {
state: Some(STATE_N.to_string()),
}
);
assert_eq!(
write_state(
set_state(
&mut mcp,
NativeIntegrityStateWriteParams {
HttpStateSetParams {
state: STATE_N_PLUS_ONE.to_string(),
expected_state: Some(STATE_N.to_string()),
},
)
.await?,
NativeIntegrityStateWriteResponse { written: true }
HttpStateSetResponse { written: true }
);
assert_eq!(
read_state(&mut mcp).await?,
NativeIntegrityStateReadResponse {
get_state(&mut mcp).await?,
HttpStateGetResponse {
state: Some(STATE_N_PLUS_ONE.to_string()),
}
);
let request_id = mcp
.send_raw_request("nativeIntegrityState/clear", /*params*/ None)
.send_raw_request("httpState/clear", /*params*/ None)
.await?;
let response: JSONRPCResponse = timeout(
DEFAULT_TIMEOUT,
@@ -96,12 +95,12 @@ async fn native_integrity_state_bridge_reads_writes_rotates_and_clears_surface_s
)
.await??;
assert_eq!(
to_response::<NativeIntegrityStateClearResponse>(response)?,
NativeIntegrityStateClearResponse {}
to_response::<HttpStateClearResponse>(response)?,
HttpStateClearResponse {}
);
assert_eq!(
read_state(&mut mcp).await?,
NativeIntegrityStateReadResponse { state: None }
get_state(&mut mcp).await?,
HttpStateGetResponse { state: None }
);
assert!(
!codex_home
@@ -114,7 +113,7 @@ async fn native_integrity_state_bridge_reads_writes_rotates_and_clears_surface_s
}
#[tokio::test]
async fn native_integrity_state_bridge_rejects_unknown_client_surface() -> Result<()> {
async fn http_state_bridge_rejects_unknown_client_surface() -> Result<()> {
let codex_home = TempDir::new()?;
let mut mcp = TestAppServer::new(codex_home.path()).await?;
let initialized = mcp
@@ -125,7 +124,7 @@ async fn native_integrity_state_bridge_rejects_unknown_client_surface() -> Resul
};
let request_id = mcp
.send_raw_request("nativeIntegrityState/read", /*params*/ None)
.send_raw_request("httpState/get", /*params*/ None)
.await?;
let error = timeout(
DEFAULT_TIMEOUT,
@@ -135,16 +134,16 @@ async fn native_integrity_state_bridge_rejects_unknown_client_surface() -> Resul
assert_eq!(error.error.code, -32600);
assert_eq!(
error.error.message,
"native integrity state is unavailable for app-server client \"third_party_client\""
"HTTP state is unavailable for app-server client \"third_party_client\""
);
assert_eq!(error.error.data, None);
Ok(())
}
async fn read_state(mcp: &mut TestAppServer) -> Result<NativeIntegrityStateReadResponse> {
async fn get_state(mcp: &mut TestAppServer) -> Result<HttpStateGetResponse> {
let request_id = mcp
.send_raw_request("nativeIntegrityState/read", /*params*/ None)
.send_raw_request("httpState/get", /*params*/ None)
.await?;
let response: JSONRPCResponse = timeout(
DEFAULT_TIMEOUT,
@@ -154,15 +153,12 @@ async fn read_state(mcp: &mut TestAppServer) -> Result<NativeIntegrityStateReadR
to_response(response)
}
async fn write_state(
async fn set_state(
mcp: &mut TestAppServer,
params: NativeIntegrityStateWriteParams,
) -> Result<NativeIntegrityStateWriteResponse> {
params: HttpStateSetParams,
) -> Result<HttpStateSetResponse> {
let request_id = mcp
.send_raw_request(
"nativeIntegrityState/write",
Some(serde_json::to_value(params)?),
)
.send_raw_request("httpState/set", Some(serde_json::to_value(params)?))
.await?;
let response: JSONRPCResponse = timeout(
DEFAULT_TIMEOUT,
+1 -1
View File
@@ -18,6 +18,7 @@ mod external_agent_config;
mod fs;
mod hooks_list;
mod imagegen_extension;
mod http_state;
mod initialize;
mod marketplace_add;
mod marketplace_remove;
@@ -29,7 +30,6 @@ mod mcp_tool;
mod memory_reset;
mod model_list;
mod model_provider_capabilities_read;
mod native_integrity_state;
mod output_schema;
mod permission_profile_list;
mod plan_item;