diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock
index ac41b4ec75..c27f363568 100644
--- a/codex-rs/Cargo.lock
+++ b/codex-rs/Cargo.lock
@@ -2319,7 +2319,6 @@ dependencies = [
"async-trait",
"bytes",
"codex-utils-cargo-bin",
- "codex-utils-path",
"codex-utils-rustls-provider",
"eventsource-stream",
"futures",
@@ -3026,6 +3025,17 @@ dependencies = [
"uuid",
]
+[[package]]
+name = "codex-http-state"
+version = "0.0.0"
+dependencies = [
+ "codex-utils-path",
+ "pretty_assertions",
+ "serde",
+ "serde_json",
+ "tempfile",
+]
+
[[package]]
name = "codex-image-generation-extension"
version = "0.0.0"
diff --git a/codex-rs/Cargo.toml b/codex-rs/Cargo.toml
index 482951fb92..92392b9c69 100644
--- a/codex-rs/Cargo.toml
+++ b/codex-rs/Cargo.toml
@@ -37,6 +37,7 @@ members = [
"core-plugins",
"core-skills",
"hooks",
+ "http-state",
"secrets",
"exec",
"file-system",
@@ -178,6 +179,7 @@ codex-file-search = { path = "file-search" }
codex-file-watcher = { path = "file-watcher" }
codex-git-utils = { path = "git-utils" }
codex-hooks = { path = "hooks" }
+codex-http-state = { path = "http-state" }
codex-keyring-store = { path = "keyring-store" }
codex-linux-sandbox = { path = "linux-sandbox" }
codex-lmstudio = { path = "lmstudio" }
diff --git a/codex-rs/codex-client/Cargo.toml b/codex-rs/codex-client/Cargo.toml
index 6c00908a33..184505eb55 100644
--- a/codex-rs/codex-client/Cargo.toml
+++ b/codex-rs/codex-client/Cargo.toml
@@ -7,7 +7,6 @@ version.workspace = true
[dependencies]
async-trait = { workspace = true }
bytes = { workspace = true }
-codex-utils-path = { workspace = true }
eventsource-stream = { workspace = true }
futures = { workspace = true }
http = { workspace = true }
diff --git a/codex-rs/codex-client/src/lib.rs b/codex-rs/codex-client/src/lib.rs
index 785c9bc0e2..520132e0e0 100644
--- a/codex-rs/codex-client/src/lib.rs
+++ b/codex-rs/codex-client/src/lib.rs
@@ -3,7 +3,6 @@ mod chatgpt_hosts;
mod custom_ca;
mod default_client;
mod error;
-mod native_integrity;
mod request;
mod retry;
mod sse;
@@ -27,12 +26,8 @@ pub use crate::default_client::CodexHttpClient;
pub use crate::default_client::CodexRequestBuilder;
pub use crate::error::StreamError;
pub use crate::error::TransportError;
-pub use crate::native_integrity::INTEGRITY_STATE_HEADER_NAME;
-pub use crate::native_integrity::INTEGRITY_STATE_UPDATE_HEADER_NAME;
-pub use crate::native_integrity::NativeIntegrityStateContext;
-pub use crate::native_integrity::NativeIntegrityStateFile;
-pub use crate::native_integrity::NativeIntegrityStateStore;
-pub use crate::native_integrity::NativeIntegritySurface;
+pub const INTEGRITY_STATE_HEADER_NAME: &str = "X-OAI-IS";
+pub const INTEGRITY_STATE_UPDATE_HEADER_NAME: &str = "X-OAI-IS-Update";
pub use crate::request::PreparedRequestBody;
pub use crate::request::Request;
pub use crate::request::RequestBody;
diff --git a/codex-rs/codex-client/src/native_integrity_tests.rs b/codex-rs/codex-client/src/native_integrity_tests.rs
deleted file mode 100644
index 0f42a363e0..0000000000
--- a/codex-rs/codex-client/src/native_integrity_tests.rs
+++ /dev/null
@@ -1,120 +0,0 @@
-use super::*;
-use pretty_assertions::assert_eq;
-use tempfile::TempDir;
-
-const STATE_N: &str = "ois1.a.b.c";
-const STATE_N_PLUS_ONE: &str = "ois1.d.e.f";
-
-#[test]
-fn maps_app_server_client_names_to_bounded_surfaces() {
- assert_eq!(
- [
- "codex-tui",
- "codex_exec",
- "codex_vscode",
- "codex_desktop",
- "codex_desktop_ssh",
- "codex_remote_control",
- "third_party_client",
- ]
- .map(NativeIntegritySurface::from_app_server_client_name),
- [
- NativeIntegritySurface::CodexTui,
- NativeIntegritySurface::CodexExec,
- NativeIntegritySurface::CodexVscode,
- NativeIntegritySurface::CodexDesktop,
- NativeIntegritySurface::CodexDesktopSsh,
- NativeIntegritySurface::CodexRemoteControl,
- NativeIntegritySurface::CodexCli,
- ]
- );
-}
-
-#[test]
-fn stores_state_in_one_file_per_surface() {
- let codex_home = TempDir::new().expect("tempdir");
- let store = NativeIntegrityStateStore::new(codex_home.path().to_path_buf());
-
- store
- .replace(NativeIntegritySurface::CodexCli, STATE_N.to_string())
- .expect("CLI state should store");
- store
- .replace(
- NativeIntegritySurface::CodexDesktop,
- STATE_N_PLUS_ONE.to_string(),
- )
- .expect("desktop state should store");
-
- assert_eq!(
- store
- .load(NativeIntegritySurface::CodexCli)
- .expect("CLI state should load")
- .expect("CLI state should exist"),
- NativeIntegrityStateFile {
- state: STATE_N.to_string(),
- }
- );
- assert_eq!(
- store
- .load(NativeIntegritySurface::CodexDesktop)
- .expect("desktop state should load")
- .expect("desktop state should exist"),
- NativeIntegrityStateFile {
- state: STATE_N_PLUS_ONE.to_string(),
- }
- );
- assert_eq!(
- store.state_path(NativeIntegritySurface::CodexCli),
- codex_home.path().join("state/codex_cli.json")
- );
- store
- .clear(NativeIntegritySurface::CodexDesktop)
- .expect("desktop state should clear");
- assert_eq!(
- store
- .load(NativeIntegritySurface::CodexDesktop)
- .expect("desktop state should load"),
- None
- );
-}
-
-#[test]
-fn compare_and_store_rejects_a_stale_prior_value() {
- let codex_home = TempDir::new().expect("tempdir");
- let store = NativeIntegrityStateStore::new(codex_home.path().to_path_buf());
- store
- .replace(NativeIntegritySurface::CodexCli, STATE_N.to_string())
- .expect("state should store");
-
- assert!(
- !store
- .compare_and_store(
- NativeIntegritySurface::CodexCli,
- "ois1.stale.state.value",
- STATE_N_PLUS_ONE.to_string(),
- )
- .expect("compare should succeed")
- );
- assert!(
- store
- .compare_and_store(
- NativeIntegritySurface::CodexCli,
- STATE_N,
- STATE_N_PLUS_ONE.to_string(),
- )
- .expect("compare should succeed")
- );
-}
-
-#[test]
-fn validates_integrity_state_envelopes() {
- assert!(is_valid_integrity_state_envelope(STATE_N));
- assert!(!is_valid_integrity_state_envelope(""));
- assert!(!is_valid_integrity_state_envelope("state"));
- assert!(!is_valid_integrity_state_envelope(&format!(" {STATE_N}")));
- assert!(!is_valid_integrity_state_envelope("ois1.a.b"));
- assert!(!is_valid_integrity_state_envelope(&format!(
- "ois1.a.b.{}",
- "c".repeat(MAX_INTEGRITY_STATE_ENVELOPE_BYTES + 1)
- )));
-}
diff --git a/codex-rs/http-state/Cargo.toml b/codex-rs/http-state/Cargo.toml
new file mode 100644
index 0000000000..2c240904a2
--- /dev/null
+++ b/codex-rs/http-state/Cargo.toml
@@ -0,0 +1,17 @@
+[package]
+edition.workspace = true
+license.workspace = true
+name = "codex-http-state"
+version.workspace = true
+
+[dependencies]
+codex-utils-path = { workspace = true }
+serde = { workspace = true, features = ["derive"] }
+serde_json = { workspace = true }
+
+[dev-dependencies]
+pretty_assertions = { workspace = true }
+tempfile = { workspace = true }
+
+[lints]
+workspace = true
diff --git a/codex-rs/codex-client/src/native_integrity.rs b/codex-rs/http-state/src/lib.rs
similarity index 54%
rename from codex-rs/codex-client/src/native_integrity.rs
rename to codex-rs/http-state/src/lib.rs
index 63af8466a2..c045f53d97 100644
--- a/codex-rs/codex-client/src/native_integrity.rs
+++ b/codex-rs/http-state/src/lib.rs
@@ -10,19 +10,15 @@ use codex_utils_path::write_atomically;
use serde::Deserialize;
use serde::Serialize;
-pub const INTEGRITY_STATE_HEADER_NAME: &str = "X-OAI-IS";
-pub const INTEGRITY_STATE_UPDATE_HEADER_NAME: &str = "X-OAI-IS-Update";
-const MAX_INTEGRITY_STATE_ENVELOPE_BYTES: usize = 2048;
-
const STATE_DIR_NAME: &str = "state";
-/// Native Codex surface that owns one local integrity-state file.
+/// Native Codex surface that owns one local HTTP-state file.
///
/// Unknown app-server clients intentionally share the CLI state file. This
/// preserves the default classification while first-party clients opt into a
/// more specific surface by setting `clientInfo.name` during initialization.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
-pub enum NativeIntegritySurface {
+pub enum HttpStateSurface {
CodexCli,
CodexTui,
CodexExec,
@@ -32,7 +28,7 @@ pub enum NativeIntegritySurface {
CodexRemoteControl,
}
-impl NativeIntegritySurface {
+impl HttpStateSurface {
pub fn from_app_server_client_name(client_name: &str) -> Self {
match client_name {
"codex-tui" => Self::CodexTui,
@@ -58,55 +54,50 @@ impl NativeIntegritySurface {
}
}
-impl fmt::Display for NativeIntegritySurface {
+impl fmt::Display for HttpStateSurface {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
-#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
-pub struct NativeIntegrityStateFile {
- pub state: String,
+#[derive(Deserialize, Serialize)]
+struct HttpStateFile {
+ state: String,
}
#[derive(Clone, Debug)]
-pub struct NativeIntegrityStateStore {
+pub struct HttpStateStore {
codex_home: PathBuf,
}
-impl NativeIntegrityStateStore {
+impl HttpStateStore {
pub fn new(codex_home: PathBuf) -> Self {
Self { codex_home }
}
- fn state_path(&self, surface: NativeIntegritySurface) -> PathBuf {
+ fn state_path(&self, surface: HttpStateSurface) -> PathBuf {
self.codex_home
.join(STATE_DIR_NAME)
.join(format!("{surface}.json"))
}
- pub fn load(
- &self,
- surface: NativeIntegritySurface,
- ) -> io::Result