feat: retain NetworkProxy, when appropriate (#11207)

As of this PR, `SessionServices` retains a
`Option<StartedNetworkProxy>`, if appropriate.

Now the `network` field on `Config` is `Option<NetworkProxySpec>`
instead of `Option<NetworkProxy>`.

Over in `Session::new()`, we invoke `NetworkProxySpec::start_proxy()` to
create the `StartedNetworkProxy`, which is a new struct that retains the
`NetworkProxy` as well as the `NetworkProxyHandle`. (Note that `Drop` is
implemented for `NetworkProxyHandle` to ensure the proxies are shutdown
when it is dropped.)

The `NetworkProxy` from the `StartedNetworkProxy` is threaded through to
the appropriate places.


---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/11207).
* #11285
* __->__ #11207
This commit is contained in:
Michael Bolin authored and GitHub committed 2026-02-10 02:09:23 -08:00
1 parent 8e240a13be
commit 44ebf4588f
28 files changed
+577 -24

No files matched your search

@@ -887,6 +887,17 @@
"model_provider_id": { "model_provider_id": {
"type": "string" "type": "string"
}, },
"network_proxy": {
"anyOf": [
{
"$ref": "#/definitions/SessionNetworkProxyRuntime"
},
{
"type": "null"
}
],
"description": "Runtime proxy bind addresses, when the managed proxy was started for this session."
},
"reasoning_effort": { "reasoning_effort": {
"anyOf": [ "anyOf": [
{ {
@@ -4427,6 +4438,25 @@
} }
] ]
}, },
"SessionNetworkProxyRuntime": {
"properties": {
"admin_addr": {
"type": "string"
},
"http_addr": {
"type": "string"
},
"socks_addr": {
"type": "string"
}
},
"required": [
"admin_addr",
"http_addr",
"socks_addr"
],
"type": "object"
},
"SkillDependencies": { "SkillDependencies": {
"properties": { "properties": {
"tools": { "tools": {
@@ -5600,6 +5630,17 @@
"model_provider_id": { "model_provider_id": {
"type": "string" "type": "string"
}, },
"network_proxy": {
"anyOf": [
{
"$ref": "#/definitions/SessionNetworkProxyRuntime"
},
{
"type": "null"
}
],
"description": "Runtime proxy bind addresses, when the managed proxy was started for this session."
},
"reasoning_effort": { "reasoning_effort": {
"anyOf": [ "anyOf": [
{ {
@@ -1531,6 +1531,17 @@
"model_provider_id": { "model_provider_id": {
"type": "string" "type": "string"
}, },
"network_proxy": {
"anyOf": [
{
"$ref": "#/definitions/SessionNetworkProxyRuntime"
},
{
"type": "null"
}
],
"description": "Runtime proxy bind addresses, when the managed proxy was started for this session."
},
"reasoning_effort": { "reasoning_effort": {
"anyOf": [ "anyOf": [
{ {
@@ -5583,6 +5594,25 @@
], ],
"type": "object" "type": "object"
}, },
"SessionNetworkProxyRuntime": {
"properties": {
"admin_addr": {
"type": "string"
},
"http_addr": {
"type": "string"
},
"socks_addr": {
"type": "string"
}
},
"required": [
"admin_addr",
"http_addr",
"socks_addr"
],
"type": "object"
},
"SessionSource": { "SessionSource": {
"oneOf": [ "oneOf": [
{ {
@@ -2900,6 +2900,17 @@
"model_provider_id": { "model_provider_id": {
"type": "string" "type": "string"
}, },
"network_proxy": {
"anyOf": [
{
"$ref": "#/definitions/SessionNetworkProxyRuntime"
},
{
"type": "null"
}
],
"description": "Runtime proxy bind addresses, when the managed proxy was started for this session."
},
"reasoning_effort": { "reasoning_effort": {
"anyOf": [ "anyOf": [
{ {
@@ -8678,6 +8689,25 @@
"title": "SessionConfiguredNotification", "title": "SessionConfiguredNotification",
"type": "object" "type": "object"
}, },
"SessionNetworkProxyRuntime": {
"properties": {
"admin_addr": {
"type": "string"
},
"http_addr": {
"type": "string"
},
"socks_addr": {
"type": "string"
}
},
"required": [
"admin_addr",
"http_addr",
"socks_addr"
],
"type": "object"
},
"SessionSource": { "SessionSource": {
"oneOf": [ "oneOf": [
{ {
@@ -887,6 +887,17 @@
"model_provider_id": { "model_provider_id": {
"type": "string" "type": "string"
}, },
"network_proxy": {
"anyOf": [
{
"$ref": "#/definitions/SessionNetworkProxyRuntime"
},
{
"type": "null"
}
],
"description": "Runtime proxy bind addresses, when the managed proxy was started for this session."
},
"reasoning_effort": { "reasoning_effort": {
"anyOf": [ "anyOf": [
{ {
@@ -4427,6 +4438,25 @@
} }
] ]
}, },
"SessionNetworkProxyRuntime": {
"properties": {
"admin_addr": {
"type": "string"
},
"http_addr": {
"type": "string"
},
"socks_addr": {
"type": "string"
}
},
"required": [
"admin_addr",
"http_addr",
"socks_addr"
],
"type": "object"
},
"SkillDependencies": { "SkillDependencies": {
"properties": { "properties": {
"tools": { "tools": {
@@ -887,6 +887,17 @@
"model_provider_id": { "model_provider_id": {
"type": "string" "type": "string"
}, },
"network_proxy": {
"anyOf": [
{
"$ref": "#/definitions/SessionNetworkProxyRuntime"
},
{
"type": "null"
}
],
"description": "Runtime proxy bind addresses, when the managed proxy was started for this session."
},
"reasoning_effort": { "reasoning_effort": {
"anyOf": [ "anyOf": [
{ {
@@ -4427,6 +4438,25 @@
} }
] ]
}, },
"SessionNetworkProxyRuntime": {
"properties": {
"admin_addr": {
"type": "string"
},
"http_addr": {
"type": "string"
},
"socks_addr": {
"type": "string"
}
},
"required": [
"admin_addr",
"http_addr",
"socks_addr"
],
"type": "object"
},
"SkillDependencies": { "SkillDependencies": {
"properties": { "properties": {
"tools": { "tools": {
@@ -887,6 +887,17 @@
"model_provider_id": { "model_provider_id": {
"type": "string" "type": "string"
}, },
"network_proxy": {
"anyOf": [
{
"$ref": "#/definitions/SessionNetworkProxyRuntime"
},
{
"type": "null"
}
],
"description": "Runtime proxy bind addresses, when the managed proxy was started for this session."
},
"reasoning_effort": { "reasoning_effort": {
"anyOf": [ "anyOf": [
{ {
@@ -4427,6 +4438,25 @@
} }
] ]
}, },
"SessionNetworkProxyRuntime": {
"properties": {
"admin_addr": {
"type": "string"
},
"http_addr": {
"type": "string"
},
"socks_addr": {
"type": "string"
}
},
"required": [
"admin_addr",
"http_addr",
"socks_addr"
],
"type": "object"
},
"SkillDependencies": { "SkillDependencies": {
"properties": { "properties": {
"tools": { "tools": {
@@ -5,6 +5,7 @@ import type { AskForApproval } from "./AskForApproval";
import type { EventMsg } from "./EventMsg"; import type { EventMsg } from "./EventMsg";
import type { ReasoningEffort } from "./ReasoningEffort"; import type { ReasoningEffort } from "./ReasoningEffort";
import type { SandboxPolicy } from "./SandboxPolicy"; import type { SandboxPolicy } from "./SandboxPolicy";
import type { SessionNetworkProxyRuntime } from "./SessionNetworkProxyRuntime";
import type { ThreadId } from "./ThreadId"; import type { ThreadId } from "./ThreadId";
export type SessionConfiguredEvent = { session_id: ThreadId, forked_from_id: ThreadId | null, export type SessionConfiguredEvent = { session_id: ThreadId, forked_from_id: ThreadId | null,
@@ -46,6 +47,10 @@ history_entry_count: number,
* When present, UIs can use these to seed the history. * When present, UIs can use these to seed the history.
*/ */
initial_messages: Array<EventMsg> | null, initial_messages: Array<EventMsg> | null,
/**
* Runtime proxy bind addresses, when the managed proxy was started for this session.
*/
network_proxy?: SessionNetworkProxyRuntime,
/** /**
* Path in which the rollout is stored. Can be `None` for ephemeral threads * Path in which the rollout is stored. Can be `None` for ephemeral threads
*/ */
@@ -0,0 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type SessionNetworkProxyRuntime = { http_addr: string, socks_addr: string, admin_addr: string, };
@@ -175,6 +175,7 @@ export type { ServerNotification } from "./ServerNotification";
export type { ServerRequest } from "./ServerRequest"; export type { ServerRequest } from "./ServerRequest";
export type { SessionConfiguredEvent } from "./SessionConfiguredEvent"; export type { SessionConfiguredEvent } from "./SessionConfiguredEvent";
export type { SessionConfiguredNotification } from "./SessionConfiguredNotification"; export type { SessionConfiguredNotification } from "./SessionConfiguredNotification";
export type { SessionNetworkProxyRuntime } from "./SessionNetworkProxyRuntime";
export type { SessionSource } from "./SessionSource"; export type { SessionSource } from "./SessionSource";
export type { SetDefaultModelParams } from "./SetDefaultModelParams"; export type { SetDefaultModelParams } from "./SetDefaultModelParams";
export type { SetDefaultModelResponse } from "./SetDefaultModelResponse"; export type { SetDefaultModelResponse } from "./SetDefaultModelResponse";
@@ -1634,13 +1634,30 @@ impl CodexMessageProcessor {
let timeout_ms = params let timeout_ms = params
.timeout_ms .timeout_ms
.and_then(|timeout_ms| u64::try_from(timeout_ms).ok()); .and_then(|timeout_ms| u64::try_from(timeout_ms).ok());
let started_network_proxy = match self.config.network.as_ref() {
Some(spec) => match spec.start_proxy().await {
Ok(started) => Some(started),
Err(err) => {
let error = JSONRPCErrorError {
code: INTERNAL_ERROR_CODE,
message: format!("failed to start managed network proxy: {err}"),
data: None,
};
self.outgoing.send_error(request, error).await;
return;
}
},
None => None,
};
let windows_sandbox_level = WindowsSandboxLevel::from_config(&self.config); let windows_sandbox_level = WindowsSandboxLevel::from_config(&self.config);
let exec_params = ExecParams { let exec_params = ExecParams {
command: params.command, command: params.command,
cwd, cwd,
expiration: timeout_ms.into(), expiration: timeout_ms.into(),
env, env,
network: self.config.network.clone(), network: started_network_proxy
.as_ref()
.map(codex_core::config::StartedNetworkProxy::proxy),
sandbox_permissions: SandboxPermissions::UseDefault, sandbox_permissions: SandboxPermissions::UseDefault,
windows_sandbox_level, windows_sandbox_level,
justification: None, justification: None,
@@ -1668,9 +1685,11 @@ impl CodexMessageProcessor {
let outgoing = self.outgoing.clone(); let outgoing = self.outgoing.clone();
let request_for_task = request; let request_for_task = request;
let sandbox_cwd = self.config.cwd.clone(); let sandbox_cwd = self.config.cwd.clone();
let started_network_proxy_for_task = started_network_proxy;
let use_linux_sandbox_bwrap = self.config.features.enabled(Feature::UseLinuxSandboxBwrap); let use_linux_sandbox_bwrap = self.config.features.enabled(Feature::UseLinuxSandboxBwrap);
tokio::spawn(async move { tokio::spawn(async move {
let _started_network_proxy = started_network_proxy_for_task;
match codex_core::exec::process_exec_tool_call( match codex_core::exec::process_exec_tool_call(
exec_params, exec_params,
&effective_policy, &effective_policy,
+16 -6
View File
@@ -130,10 +130,7 @@ async fn run_command_under_sandbox(
let sandbox_policy_cwd = cwd.clone(); let sandbox_policy_cwd = cwd.clone();
let stdio_policy = StdioPolicy::Inherit; let stdio_policy = StdioPolicy::Inherit;
let mut env = create_env(&config.shell_environment_policy, None); let env = create_env(&config.shell_environment_policy, None);
if let Some(network) = config.network.as_ref() {
network.apply_to_env(&mut env);
}
// Special-case Windows sandbox: execute and exit the process to emulate inherited stdio. // Special-case Windows sandbox: execute and exit the process to emulate inherited stdio.
if let SandboxType::Windows = sandbox_type { if let SandboxType::Windows = sandbox_type {
@@ -216,6 +213,19 @@ async fn run_command_under_sandbox(
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
let _ = log_denials; let _ = log_denials;
// This proxy should only live for the lifetime of the child process.
let network_proxy = match config.network.as_ref() {
Some(spec) => Some(
spec.start_proxy()
.await
.map_err(|err| anyhow::anyhow!("failed to start managed network proxy: {err}"))?,
),
None => None,
};
let network = network_proxy
.as_ref()
.map(codex_core::config::StartedNetworkProxy::proxy);
let mut child = match sandbox_type { let mut child = match sandbox_type {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
SandboxType::Seatbelt => { SandboxType::Seatbelt => {
@@ -225,7 +235,7 @@ async fn run_command_under_sandbox(
config.sandbox_policy.get(), config.sandbox_policy.get(),
sandbox_policy_cwd.as_path(), sandbox_policy_cwd.as_path(),
stdio_policy, stdio_policy,
None, network.as_ref(),
env, env,
) )
.await? .await?
@@ -245,7 +255,7 @@ async fn run_command_under_sandbox(
sandbox_policy_cwd.as_path(), sandbox_policy_cwd.as_path(),
use_bwrap_sandbox, use_bwrap_sandbox,
stdio_policy, stdio_policy,
None, network.as_ref(),
env, env,
) )
.await? .await?
+32
View File
@@ -44,6 +44,7 @@ use crate::turn_metadata::resolve_turn_metadata_header_with_timeout;
use crate::util::error_or_panic; use crate::util::error_or_panic;
use async_channel::Receiver; use async_channel::Receiver;
use async_channel::Sender; use async_channel::Sender;
use codex_network_proxy::NetworkProxy;
use codex_protocol::ThreadId; use codex_protocol::ThreadId;
use codex_protocol::approvals::ExecPolicyAmendment; use codex_protocol::approvals::ExecPolicyAmendment;
use codex_protocol::config_types::ModeKind; use codex_protocol::config_types::ModeKind;
@@ -113,6 +114,7 @@ use crate::config::Config;
use crate::config::Constrained; use crate::config::Constrained;
use crate::config::ConstraintResult; use crate::config::ConstraintResult;
use crate::config::GhostSnapshotConfig; use crate::config::GhostSnapshotConfig;
use crate::config::StartedNetworkProxy;
use crate::config::resolve_web_search_mode_for_turn; use crate::config::resolve_web_search_mode_for_turn;
use crate::config::types::McpServerConfig; use crate::config::types::McpServerConfig;
use crate::config::types::ShellEnvironmentPolicy; use crate::config::types::ShellEnvironmentPolicy;
@@ -172,6 +174,7 @@ use crate::protocol::RequestUserInputEvent;
use crate::protocol::ReviewDecision; use crate::protocol::ReviewDecision;
use crate::protocol::SandboxPolicy; use crate::protocol::SandboxPolicy;
use crate::protocol::SessionConfiguredEvent; use crate::protocol::SessionConfiguredEvent;
use crate::protocol::SessionNetworkProxyRuntime;
use crate::protocol::SkillDependencies as ProtocolSkillDependencies; use crate::protocol::SkillDependencies as ProtocolSkillDependencies;
use crate::protocol::SkillErrorInfo; use crate::protocol::SkillErrorInfo;
use crate::protocol::SkillInterface as ProtocolSkillInterface; use crate::protocol::SkillInterface as ProtocolSkillInterface;
@@ -539,6 +542,7 @@ pub(crate) struct TurnContext {
pub(crate) personality: Option<Personality>, pub(crate) personality: Option<Personality>,
pub(crate) approval_policy: AskForApproval, pub(crate) approval_policy: AskForApproval,
pub(crate) sandbox_policy: SandboxPolicy, pub(crate) sandbox_policy: SandboxPolicy,
pub(crate) network: Option<NetworkProxy>,
pub(crate) windows_sandbox_level: WindowsSandboxLevel, pub(crate) windows_sandbox_level: WindowsSandboxLevel,
pub(crate) shell_environment_policy: ShellEnvironmentPolicy, pub(crate) shell_environment_policy: ShellEnvironmentPolicy,
pub(crate) tools_config: ToolsConfig, pub(crate) tools_config: ToolsConfig,
@@ -803,6 +807,7 @@ impl Session {
session_configuration: &SessionConfiguration, session_configuration: &SessionConfiguration,
per_turn_config: Config, per_turn_config: Config,
model_info: ModelInfo, model_info: ModelInfo,
network: Option<NetworkProxy>,
sub_id: String, sub_id: String,
) -> TurnContext { ) -> TurnContext {
let reasoning_effort = session_configuration.collaboration_mode.reasoning_effort(); let reasoning_effort = session_configuration.collaboration_mode.reasoning_effort();
@@ -842,6 +847,7 @@ impl Session {
personality: session_configuration.personality, personality: session_configuration.personality,
approval_policy: session_configuration.approval_policy.value(), approval_policy: session_configuration.approval_policy.value(),
sandbox_policy: session_configuration.sandbox_policy.get().clone(), sandbox_policy: session_configuration.sandbox_policy.get().clone(),
network,
windows_sandbox_level: session_configuration.windows_sandbox_level, windows_sandbox_level: session_configuration.windows_sandbox_level,
shell_environment_policy: per_turn_config.shell_environment_policy.clone(), shell_environment_policy: per_turn_config.shell_environment_policy.clone(),
tools_config, tools_config,
@@ -1064,6 +1070,21 @@ impl Session {
}; };
session_configuration.thread_name = thread_name.clone(); session_configuration.thread_name = thread_name.clone();
let mut state = SessionState::new(session_configuration.clone()); let mut state = SessionState::new(session_configuration.clone());
let network_proxy =
match config.network.as_ref() {
Some(spec) => Some(spec.start_proxy().await.map_err(|err| {
anyhow::anyhow!("failed to start managed network proxy: {err}")
})?),
None => None,
};
let session_network_proxy = network_proxy.as_ref().map(|started| {
let proxy = started.proxy();
SessionNetworkProxyRuntime {
http_addr: proxy.http_addr().to_string(),
socks_addr: proxy.socks_addr().to_string(),
admin_addr: proxy.admin_addr().to_string(),
}
});
let services = SessionServices { let services = SessionServices {
mcp_connection_manager: Arc::new(RwLock::new(McpConnectionManager::default())), mcp_connection_manager: Arc::new(RwLock::new(McpConnectionManager::default())),
@@ -1086,6 +1107,7 @@ impl Session {
skills_manager, skills_manager,
file_watcher, file_watcher,
agent_control, agent_control,
network_proxy,
state_db: state_db_ctx.clone(), state_db: state_db_ctx.clone(),
model_client: ModelClient::new( model_client: ModelClient::new(
Some(Arc::clone(&auth_manager)), Some(Arc::clone(&auth_manager)),
@@ -1144,6 +1166,7 @@ impl Session {
history_log_id, history_log_id,
history_entry_count, history_entry_count,
initial_messages, initial_messages,
network_proxy: session_network_proxy,
rollout_path, rollout_path,
}), }),
}) })
@@ -1559,6 +1582,10 @@ impl Session {
&session_configuration, &session_configuration,
per_turn_config, per_turn_config,
model_info, model_info,
self.services
.network_proxy
.as_ref()
.map(StartedNetworkProxy::proxy),
sub_id, sub_id,
); );
@@ -3702,6 +3729,7 @@ async fn spawn_review_thread(
personality: parent_turn_context.personality, personality: parent_turn_context.personality,
approval_policy: parent_turn_context.approval_policy, approval_policy: parent_turn_context.approval_policy,
sandbox_policy: parent_turn_context.sandbox_policy.clone(), sandbox_policy: parent_turn_context.sandbox_policy.clone(),
network: parent_turn_context.network.clone(),
windows_sandbox_level: parent_turn_context.windows_sandbox_level, windows_sandbox_level: parent_turn_context.windows_sandbox_level,
shell_environment_policy: parent_turn_context.shell_environment_policy.clone(), shell_environment_policy: parent_turn_context.shell_environment_policy.clone(),
cwd: parent_turn_context.cwd.clone(), cwd: parent_turn_context.cwd.clone(),
@@ -6188,6 +6216,7 @@ mod tests {
skills_manager, skills_manager,
file_watcher, file_watcher,
agent_control, agent_control,
network_proxy: None,
state_db: None, state_db: None,
model_client: ModelClient::new( model_client: ModelClient::new(
Some(auth_manager.clone()), Some(auth_manager.clone()),
@@ -6211,6 +6240,7 @@ mod tests {
&session_configuration, &session_configuration,
per_turn_config, per_turn_config,
model_info, model_info,
None,
"turn_id".to_string(), "turn_id".to_string(),
); );
@@ -6321,6 +6351,7 @@ mod tests {
skills_manager, skills_manager,
file_watcher, file_watcher,
agent_control, agent_control,
network_proxy: None,
state_db: None, state_db: None,
model_client: ModelClient::new( model_client: ModelClient::new(
Some(Arc::clone(&auth_manager)), Some(Arc::clone(&auth_manager)),
@@ -6344,6 +6375,7 @@ mod tests {
&session_configuration, &session_configuration,
per_turn_config, per_turn_config,
model_info, model_info,
None,
"turn_id".to_string(), "turn_id".to_string(),
)); ));
+20 -4
View File
@@ -47,7 +47,6 @@ use crate::protocol::SandboxPolicy;
use crate::windows_sandbox::WindowsSandboxLevelExt; use crate::windows_sandbox::WindowsSandboxLevelExt;
use codex_app_server_protocol::Tools; use codex_app_server_protocol::Tools;
use codex_app_server_protocol::UserSavedConfig; use codex_app_server_protocol::UserSavedConfig;
use codex_network_proxy::NetworkProxy;
use codex_protocol::config_types::AltScreenMode; use codex_protocol::config_types::AltScreenMode;
use codex_protocol::config_types::ForcedLoginMethod; use codex_protocol::config_types::ForcedLoginMethod;
use codex_protocol::config_types::ModeKind; use codex_protocol::config_types::ModeKind;
@@ -80,6 +79,7 @@ use toml_edit::DocumentMut;
mod constraint; mod constraint;
pub mod edit; pub mod edit;
mod network_proxy_spec;
pub mod profile; pub mod profile;
pub mod schema; pub mod schema;
pub mod service; pub mod service;
@@ -88,6 +88,8 @@ pub use constraint::Constrained;
pub use constraint::ConstraintError; pub use constraint::ConstraintError;
pub use constraint::ConstraintResult; pub use constraint::ConstraintResult;
pub use network_proxy_spec::NetworkProxySpec;
pub use network_proxy_spec::StartedNetworkProxy;
pub use service::ConfigService; pub use service::ConfigService;
pub use service::ConfigServiceError; pub use service::ConfigServiceError;
@@ -154,7 +156,7 @@ pub struct Config {
pub enforce_residency: Constrained<Option<ResidencyRequirement>>, pub enforce_residency: Constrained<Option<ResidencyRequirement>>,
/// Effective network configuration applied to all spawned processes. /// Effective network configuration applied to all spawned processes.
pub network: Option<NetworkProxy>, pub network: Option<NetworkProxySpec>,
/// True if the user passed in an override or set a value in config.toml /// True if the user passed in an override or set a value in config.toml
/// for either of approval_policy or sandbox_mode. /// for either of approval_policy or sandbox_mode.
@@ -1657,7 +1659,7 @@ impl Config {
mcp_servers, mcp_servers,
exec_policy: _, exec_policy: _,
enforce_residency, enforce_residency,
network: _network_requirements, network: network_requirements,
} = requirements; } = requirements;
apply_requirement_constrained_value( apply_requirement_constrained_value(
@@ -1682,6 +1684,20 @@ impl Config {
let mcp_servers = constrain_mcp_servers(cfg.mcp_servers.clone(), mcp_servers.as_ref()) let mcp_servers = constrain_mcp_servers(cfg.mcp_servers.clone(), mcp_servers.as_ref())
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, format!("{e}")))?; .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, format!("{e}")))?;
let network = match network_requirements {
Some(Sourced { value, source }) => {
let network = NetworkProxySpec::from_constraints(&config_layer_stack, value)
.map_err(|err| {
std::io::Error::new(
err.kind(),
format!("failed to build managed network proxy from {source}: {err}"),
)
})?;
Some(network)
}
None => None,
};
let config = Self { let config = Self {
model, model,
review_model, review_model,
@@ -1694,7 +1710,7 @@ impl Config {
approval_policy: constrained_approval_policy.value, approval_policy: constrained_approval_policy.value,
sandbox_policy: constrained_sandbox_policy.value, sandbox_policy: constrained_sandbox_policy.value,
enforce_residency: enforce_residency.value, enforce_residency: enforce_residency.value,
network: None, network,
did_user_set_custom_approval_policy_or_sandbox_mode, did_user_set_custom_approval_policy_or_sandbox_mode,
forced_auto_mode_downgraded_on_windows, forced_auto_mode_downgraded_on_windows,
shell_environment_policy, shell_environment_policy,
@@ -0,0 +1,167 @@
use crate::config;
use crate::config_loader::NetworkConstraints;
use async_trait::async_trait;
use codex_network_proxy::ConfigReloader;
use codex_network_proxy::ConfigState;
use codex_network_proxy::NetworkProxy;
use codex_network_proxy::NetworkProxyConfig;
use codex_network_proxy::NetworkProxyConstraints;
use codex_network_proxy::NetworkProxyHandle;
use codex_network_proxy::NetworkProxyState;
use codex_network_proxy::build_config_state;
use codex_network_proxy::host_and_port_from_network_addr;
use codex_network_proxy::validate_policy_against_constraints;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NetworkProxySpec {
config: NetworkProxyConfig,
constraints: NetworkProxyConstraints,
}
pub struct StartedNetworkProxy {
proxy: NetworkProxy,
_handle: NetworkProxyHandle,
}
impl StartedNetworkProxy {
fn new(proxy: NetworkProxy, handle: NetworkProxyHandle) -> Self {
Self {
proxy,
_handle: handle,
}
}
pub fn proxy(&self) -> NetworkProxy {
self.proxy.clone()
}
}
#[derive(Clone)]
struct StaticNetworkProxyReloader {
state: ConfigState,
}
impl StaticNetworkProxyReloader {
fn new(state: ConfigState) -> Self {
Self { state }
}
}
#[async_trait]
impl ConfigReloader for StaticNetworkProxyReloader {
async fn maybe_reload(&self) -> anyhow::Result<Option<ConfigState>> {
Ok(None)
}
async fn reload_now(&self) -> anyhow::Result<ConfigState> {
Ok(self.state.clone())
}
fn source_label(&self) -> String {
"StaticNetworkProxyReloader".to_string()
}
}
impl NetworkProxySpec {
pub fn proxy_host_and_port(&self) -> String {
host_and_port_from_network_addr(&self.config.network.proxy_url, 3128)
}
pub(crate) fn from_constraints(
_config_layer_stack: &config::ConfigLayerStack,
requirements: NetworkConstraints,
) -> std::io::Result<Self> {
// TODO(mbolin): Use ConfigLayerStack once we are ready to start
// honoring network configuration in config.toml.
let config = NetworkProxyConfig::default();
let (config, constraints) = Self::apply_requirements(config, &requirements);
validate_policy_against_constraints(&config, &constraints).map_err(|err| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("network proxy constraints are invalid: {err}"),
)
})?;
Ok(Self {
config,
constraints,
})
}
pub async fn start_proxy(&self) -> std::io::Result<StartedNetworkProxy> {
let state =
build_config_state(self.config.clone(), self.constraints.clone()).map_err(|err| {
std::io::Error::other(format!("failed to build network proxy state: {err}"))
})?;
let reloader = Arc::new(StaticNetworkProxyReloader::new(state.clone()));
let state = NetworkProxyState::with_reloader(state, reloader);
let proxy = NetworkProxy::builder()
.state(Arc::new(state))
.build()
.await
.map_err(|err| {
std::io::Error::other(format!("failed to build network proxy: {err}"))
})?;
let handle = proxy
.run()
.await
.map_err(|err| std::io::Error::other(format!("failed to run network proxy: {err}")))?;
Ok(StartedNetworkProxy::new(proxy, handle))
}
fn apply_requirements(
mut config: NetworkProxyConfig,
requirements: &NetworkConstraints,
) -> (NetworkProxyConfig, NetworkProxyConstraints) {
let mut constraints = NetworkProxyConstraints::default();
if let Some(enabled) = requirements.enabled {
config.network.enabled = enabled;
constraints.enabled = Some(enabled);
}
if let Some(http_port) = requirements.http_port {
config.network.proxy_url = format!("http://127.0.0.1:{http_port}");
}
if let Some(socks_port) = requirements.socks_port {
config.network.socks_url = format!("http://127.0.0.1:{socks_port}");
}
if let Some(allow_upstream_proxy) = requirements.allow_upstream_proxy {
config.network.allow_upstream_proxy = allow_upstream_proxy;
constraints.allow_upstream_proxy = Some(allow_upstream_proxy);
}
if let Some(dangerously_allow_non_loopback_proxy) =
requirements.dangerously_allow_non_loopback_proxy
{
config.network.dangerously_allow_non_loopback_proxy =
dangerously_allow_non_loopback_proxy;
constraints.dangerously_allow_non_loopback_proxy =
Some(dangerously_allow_non_loopback_proxy);
}
if let Some(dangerously_allow_non_loopback_admin) =
requirements.dangerously_allow_non_loopback_admin
{
config.network.dangerously_allow_non_loopback_admin =
dangerously_allow_non_loopback_admin;
constraints.dangerously_allow_non_loopback_admin =
Some(dangerously_allow_non_loopback_admin);
}
if let Some(allowed_domains) = requirements.allowed_domains.clone() {
config.network.allowed_domains = allowed_domains.clone();
constraints.allowed_domains = Some(allowed_domains);
}
if let Some(denied_domains) = requirements.denied_domains.clone() {
config.network.denied_domains = denied_domains.clone();
constraints.denied_domains = Some(denied_domains);
}
if let Some(allow_unix_sockets) = requirements.allow_unix_sockets.clone() {
config.network.allow_unix_sockets = allow_unix_sockets.clone();
constraints.allow_unix_sockets = Some(allow_unix_sockets);
}
if let Some(allow_local_binding) = requirements.allow_local_binding {
config.network.allow_local_binding = allow_local_binding;
constraints.allow_local_binding = Some(allow_local_binding);
}
(config, constraints)
}
}
+2
View File
@@ -5,6 +5,7 @@ use crate::RolloutRecorder;
use crate::agent::AgentControl; use crate::agent::AgentControl;
use crate::analytics_client::AnalyticsEventsClient; use crate::analytics_client::AnalyticsEventsClient;
use crate::client::ModelClient; use crate::client::ModelClient;
use crate::config::StartedNetworkProxy;
use crate::exec_policy::ExecPolicyManager; use crate::exec_policy::ExecPolicyManager;
use crate::file_watcher::FileWatcher; use crate::file_watcher::FileWatcher;
use crate::hooks::Hooks; use crate::hooks::Hooks;
@@ -38,6 +39,7 @@ pub(crate) struct SessionServices {
pub(crate) skills_manager: Arc<SkillsManager>, pub(crate) skills_manager: Arc<SkillsManager>,
pub(crate) file_watcher: Arc<FileWatcher>, pub(crate) file_watcher: Arc<FileWatcher>,
pub(crate) agent_control: AgentControl, pub(crate) agent_control: AgentControl,
pub(crate) network_proxy: Option<StartedNetworkProxy>,
pub(crate) state_db: Option<StateDbHandle>, pub(crate) state_db: Option<StateDbHandle>,
/// Session-scoped model client shared across turns. /// Session-scoped model client shared across turns.
pub(crate) model_client: ModelClient, pub(crate) model_client: ModelClient,
+1 -1
View File
@@ -147,7 +147,7 @@ pub(crate) async fn execute_user_shell_command(
&turn_context.shell_environment_policy, &turn_context.shell_environment_policy,
Some(session.conversation_id), Some(session.conversation_id),
), ),
network: turn_context.config.network.clone(), network: turn_context.network.clone(),
// TODO(zhao-oai): Now that we have ExecExpiration::Cancellation, we // TODO(zhao-oai): Now that we have ExecExpiration::Cancellation, we
// should use that instead of an "arbitrarily large" timeout here. // should use that instead of an "arbitrarily large" timeout here.
expiration: USER_SHELL_TIMEOUT_MS.into(), expiration: USER_SHELL_TIMEOUT_MS.into(),
+3 -3
View File
@@ -53,7 +53,7 @@ impl ShellHandler {
cwd: turn_context.resolve_path(params.workdir.clone()), cwd: turn_context.resolve_path(params.workdir.clone()),
expiration: params.timeout_ms.into(), expiration: params.timeout_ms.into(),
env: create_env(&turn_context.shell_environment_policy, Some(thread_id)), env: create_env(&turn_context.shell_environment_policy, Some(thread_id)),
network: turn_context.config.network.clone(), network: turn_context.network.clone(),
sandbox_permissions: params.sandbox_permissions.unwrap_or_default(), sandbox_permissions: params.sandbox_permissions.unwrap_or_default(),
windows_sandbox_level: turn_context.windows_sandbox_level, windows_sandbox_level: turn_context.windows_sandbox_level,
justification: params.justification.clone(), justification: params.justification.clone(),
@@ -82,7 +82,7 @@ impl ShellCommandHandler {
cwd: turn_context.resolve_path(params.workdir.clone()), cwd: turn_context.resolve_path(params.workdir.clone()),
expiration: params.timeout_ms.into(), expiration: params.timeout_ms.into(),
env: create_env(&turn_context.shell_environment_policy, Some(thread_id)), env: create_env(&turn_context.shell_environment_policy, Some(thread_id)),
network: turn_context.config.network.clone(), network: turn_context.network.clone(),
sandbox_permissions: params.sandbox_permissions.unwrap_or_default(), sandbox_permissions: params.sandbox_permissions.unwrap_or_default(),
windows_sandbox_level: turn_context.windows_sandbox_level, windows_sandbox_level: turn_context.windows_sandbox_level,
justification: params.justification.clone(), justification: params.justification.clone(),
@@ -444,7 +444,7 @@ mod tests {
assert_eq!(exec_params.command, expected_command); assert_eq!(exec_params.command, expected_command);
assert_eq!(exec_params.cwd, expected_cwd); assert_eq!(exec_params.cwd, expected_cwd);
assert_eq!(exec_params.env, expected_env); assert_eq!(exec_params.env, expected_env);
assert_eq!(exec_params.network, turn_context.config.network); assert_eq!(exec_params.network, turn_context.network);
assert_eq!(exec_params.expiration.timeout_ms(), timeout_ms); assert_eq!(exec_params.expiration.timeout_ms(), timeout_ms);
assert_eq!(exec_params.sandbox_permissions, sandbox_permissions); assert_eq!(exec_params.sandbox_permissions, sandbox_permissions);
assert_eq!(exec_params.justification, justification); assert_eq!(exec_params.justification, justification);
@@ -192,7 +192,7 @@ impl ToolHandler for UnifiedExecHandler {
yield_time_ms, yield_time_ms,
max_output_tokens, max_output_tokens,
workdir, workdir,
network: context.turn.config.network.clone(), network: context.turn.network.clone(),
tty, tty,
sandbox_permissions, sandbox_permissions,
justification, justification,
@@ -98,6 +98,7 @@ fn session_configured_produces_thread_started_event() {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(rollout_path), rollout_path: Some(rollout_path),
}), }),
); );
@@ -307,6 +307,7 @@ mod tests {
history_log_id: 1, history_log_id: 1,
history_entry_count: 1000, history_entry_count: 1000,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()), rollout_path: Some(rollout_file.path().to_path_buf()),
}), }),
}; };
@@ -348,6 +349,7 @@ mod tests {
history_log_id: 1, history_log_id: 1,
history_entry_count: 1000, history_entry_count: 1000,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()), rollout_path: Some(rollout_file.path().to_path_buf()),
}; };
let event = Event { let event = Event {
@@ -413,6 +415,7 @@ mod tests {
history_log_id: 1, history_log_id: 1,
history_entry_count: 1000, history_entry_count: 1000,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()), rollout_path: Some(rollout_file.path().to_path_buf()),
}; };
let event = Event { let event = Event {
+41 -5
View File
@@ -8,13 +8,13 @@ use std::net::SocketAddr;
use tracing::warn; use tracing::warn;
use url::Url; use url::Url;
#[derive(Debug, Clone, Serialize, Deserialize, Default)] #[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct NetworkProxyConfig { pub struct NetworkProxyConfig {
#[serde(default)] #[serde(default)]
pub network: NetworkProxySettings, pub network: NetworkProxySettings,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct NetworkProxySettings { pub struct NetworkProxySettings {
#[serde(default)] #[serde(default)]
pub enabled: bool, pub enabled: bool,
@@ -205,6 +205,30 @@ fn resolve_addr(url: &str, default_port: u16) -> Result<SocketAddr> {
} }
} }
pub fn host_and_port_from_network_addr(value: &str, default_port: u16) -> String {
let trimmed = value.trim();
if trimmed.is_empty() {
return "<missing>".to_string();
}
let parts = match parse_host_port(trimmed, default_port) {
Ok(parts) => parts,
Err(_) => {
return format_host_and_port(trimmed, default_port);
}
};
format_host_and_port(&parts.host, parts.port)
}
fn format_host_and_port(host: &str, port: u16) -> String {
if host.contains(':') {
format!("[{host}]:{port}")
} else {
format!("{host}:{port}")
}
}
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
struct SocketAddressParts { struct SocketAddressParts {
host: String, host: String,
@@ -280,14 +304,13 @@ fn parse_host_port_fallback(input: &str, default_port: u16) -> Result<SocketAddr
// accidentally interpreting unbracketed IPv6 addresses as `host:port`. // accidentally interpreting unbracketed IPv6 addresses as `host:port`.
if host_port.bytes().filter(|b| *b == b':').count() == 1 if host_port.bytes().filter(|b| *b == b':').count() == 1
&& let Some((host, port)) = host_port.rsplit_once(':') && let Some((host, port)) = host_port.rsplit_once(':')
&& let Ok(port) = port.parse::<u16>()
{ {
if host.is_empty() { if host.is_empty() {
bail!("missing host in network proxy address: {input}"); bail!("missing host in network proxy address: {input}");
} }
return Ok(SocketAddressParts { return Ok(SocketAddressParts {
host: host.to_string(), host: host.to_string(),
port, port: port.parse::<u16>().ok().unwrap_or(default_port),
}); });
} }
@@ -376,12 +399,25 @@ mod tests {
assert_eq!( assert_eq!(
parse_host_port("example.com:notaport", 3128).unwrap(), parse_host_port("example.com:notaport", 3128).unwrap(),
SocketAddressParts { SocketAddressParts {
host: "example.com:notaport".to_string(), host: "example.com".to_string(),
port: 3128, port: 3128,
} }
); );
} }
#[test]
fn host_and_port_from_network_addr_defaults_for_empty_string() {
assert_eq!(host_and_port_from_network_addr("", 1234), "<missing>");
}
#[test]
fn host_and_port_from_network_addr_formats_ipv6() {
assert_eq!(
host_and_port_from_network_addr("http://[::1]:8080", 3128),
"[::1]:8080"
);
}
#[test] #[test]
fn resolve_addr_maps_localhost_to_loopback() { fn resolve_addr_maps_localhost_to_loopback() {
assert_eq!( assert_eq!(
+1
View File
@@ -15,6 +15,7 @@ mod upstream;
pub use config::NetworkMode; pub use config::NetworkMode;
pub use config::NetworkProxyConfig; pub use config::NetworkProxyConfig;
pub use config::host_and_port_from_network_addr;
pub use network_policy::NetworkDecision; pub use network_policy::NetworkDecision;
pub use network_policy::NetworkPolicyDecider; pub use network_policy::NetworkPolicyDecider;
pub use network_policy::NetworkPolicyRequest; pub use network_policy::NetworkPolicyRequest;
+12
View File
@@ -363,6 +363,18 @@ impl NetworkProxy {
NetworkProxyBuilder::default() NetworkProxyBuilder::default()
} }
pub fn http_addr(&self) -> SocketAddr {
self.http_addr
}
pub fn socks_addr(&self) -> SocketAddr {
self.socks_addr
}
pub fn admin_addr(&self) -> SocketAddr {
self.admin_addr
}
pub fn apply_to_env(&self, env: &mut HashMap<String, String>) { pub fn apply_to_env(&self, env: &mut HashMap<String, String>) {
// Enforce proxying for child processes. We intentionally override existing values so // Enforce proxying for child processes. We intentionally override existing values so
// command-level environment cannot bypass the managed proxy endpoint. // command-level environment cannot bypass the managed proxy endpoint.
+13
View File
@@ -2265,6 +2265,13 @@ pub struct SkillsListEntry {
pub errors: Vec<SkillErrorInfo>, pub errors: Vec<SkillErrorInfo>,
} }
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS, PartialEq, Eq)]
pub struct SessionNetworkProxyRuntime {
pub http_addr: String,
pub socks_addr: String,
pub admin_addr: String,
}
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)] #[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
pub struct SessionConfiguredEvent { pub struct SessionConfiguredEvent {
pub session_id: ThreadId, pub session_id: ThreadId,
@@ -2306,6 +2313,11 @@ pub struct SessionConfiguredEvent {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub initial_messages: Option<Vec<EventMsg>>, pub initial_messages: Option<Vec<EventMsg>>,
/// Runtime proxy bind addresses, when the managed proxy was started for this session.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub network_proxy: Option<SessionNetworkProxyRuntime>,
/// Path in which the rollout is stored. Can be `None` for ephemeral threads /// Path in which the rollout is stored. Can be `None` for ephemeral threads
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub rollout_path: Option<PathBuf>, pub rollout_path: Option<PathBuf>,
@@ -2696,6 +2708,7 @@ mod tests {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()), rollout_path: Some(rollout_file.path().to_path_buf()),
}), }),
}; };
+4
View File
@@ -2353,6 +2353,7 @@ impl App {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: thread.rollout_path(), rollout_path: thread.rollout_path(),
}), }),
}; };
@@ -3042,6 +3043,7 @@ mod tests {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(PathBuf::new()), rollout_path: Some(PathBuf::new()),
}; };
Arc::new(new_session_info( Arc::new(new_session_info(
@@ -3096,6 +3098,7 @@ mod tests {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(PathBuf::new()), rollout_path: Some(PathBuf::new()),
}), }),
}); });
@@ -3142,6 +3145,7 @@ mod tests {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(PathBuf::new()), rollout_path: Some(PathBuf::new()),
}; };
+10 -1
View File
@@ -613,6 +613,8 @@ pub(crate) struct ChatWidget {
current_rollout_path: Option<PathBuf>, current_rollout_path: Option<PathBuf>,
// Current working directory (if known) // Current working directory (if known)
current_cwd: Option<PathBuf>, current_cwd: Option<PathBuf>,
// Runtime network proxy bind addresses from SessionConfigured.
session_network_proxy: Option<codex_core::protocol::SessionNetworkProxyRuntime>,
// Shared latch so we only warn once about invalid status-line item IDs. // Shared latch so we only warn once about invalid status-line item IDs.
status_line_invalid_items_warned: Arc<AtomicBool>, status_line_invalid_items_warned: Arc<AtomicBool>,
// Cached git branch name for the status line (None if unknown). // Cached git branch name for the status line (None if unknown).
@@ -1015,6 +1017,7 @@ impl ChatWidget {
self.bottom_pane self.bottom_pane
.set_history_metadata(event.history_log_id, event.history_entry_count); .set_history_metadata(event.history_log_id, event.history_entry_count);
self.set_skills(None); self.set_skills(None);
self.session_network_proxy = event.network_proxy.clone();
self.thread_id = Some(event.session_id); self.thread_id = Some(event.session_id);
self.thread_name = event.thread_name.clone(); self.thread_name = event.thread_name.clone();
self.forked_from = event.forked_from_id; self.forked_from = event.forked_from_id;
@@ -2658,6 +2661,7 @@ impl ChatWidget {
feedback_audience, feedback_audience,
current_rollout_path: None, current_rollout_path: None,
current_cwd, current_cwd,
session_network_proxy: None,
status_line_invalid_items_warned, status_line_invalid_items_warned,
status_line_branch: None, status_line_branch: None,
status_line_branch_cwd: None, status_line_branch_cwd: None,
@@ -2822,6 +2826,7 @@ impl ChatWidget {
feedback_audience, feedback_audience,
current_rollout_path: None, current_rollout_path: None,
current_cwd, current_cwd,
session_network_proxy: None,
status_line_invalid_items_warned, status_line_invalid_items_warned,
status_line_branch: None, status_line_branch: None,
status_line_branch_cwd: None, status_line_branch_cwd: None,
@@ -2975,6 +2980,7 @@ impl ChatWidget {
feedback_audience, feedback_audience,
current_rollout_path: None, current_rollout_path: None,
current_cwd, current_cwd,
session_network_proxy: None,
status_line_invalid_items_warned, status_line_invalid_items_warned,
status_line_branch: None, status_line_branch: None,
status_line_branch_cwd: None, status_line_branch_cwd: None,
@@ -4239,7 +4245,10 @@ impl ChatWidget {
} }
pub(crate) fn add_debug_config_output(&mut self) { pub(crate) fn add_debug_config_output(&mut self) {
self.add_to_history(crate::debug_config::new_debug_config_output(&self.config)); self.add_to_history(crate::debug_config::new_debug_config_output(
&self.config,
self.session_network_proxy.as_ref(),
));
} }
fn open_status_line_setup(&mut self) { fn open_status_line_setup(&mut self) {
+6
View File
@@ -164,6 +164,7 @@ async fn resumed_initial_messages_render_history() {
message: "assistant reply".to_string(), message: "assistant reply".to_string(),
}), }),
]), ]),
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()), rollout_path: Some(rollout_file.path().to_path_buf()),
}; };
@@ -226,6 +227,7 @@ async fn replayed_user_message_preserves_text_elements_and_local_images() {
text_elements: text_elements.clone(), text_elements: text_elements.clone(),
local_images: local_images.clone(), local_images: local_images.clone(),
})]), })]),
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()), rollout_path: Some(rollout_file.path().to_path_buf()),
}; };
@@ -338,6 +340,7 @@ async fn submission_preserves_text_elements_and_local_images() {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()), rollout_path: Some(rollout_file.path().to_path_buf()),
}; };
chat.handle_codex_event(Event { chat.handle_codex_event(Event {
@@ -417,6 +420,7 @@ async fn submission_prefers_selected_duplicate_skill_path() {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()), rollout_path: Some(rollout_file.path().to_path_buf()),
}; };
chat.handle_codex_event(Event { chat.handle_codex_event(Event {
@@ -1108,6 +1112,7 @@ async fn make_chatwidget_manual(
feedback_audience: FeedbackAudience::External, feedback_audience: FeedbackAudience::External,
current_rollout_path: None, current_rollout_path: None,
current_cwd: None, current_cwd: None,
session_network_proxy: None,
status_line_invalid_items_warned: Arc::new(AtomicBool::new(false)), status_line_invalid_items_warned: Arc::new(AtomicBool::new(false)),
status_line_branch: None, status_line_branch: None,
status_line_branch_cwd: None, status_line_branch_cwd: None,
@@ -2973,6 +2978,7 @@ async fn plan_slash_command_with_args_submits_prompt_in_plan_mode() {
history_log_id: 0, history_log_id: 0,
history_entry_count: 0, history_entry_count: 0,
initial_messages: None, initial_messages: None,
network_proxy: None,
rollout_path: None, rollout_path: None,
}; };
chat.handle_codex_event(Event { chat.handle_codex_event(Event {
+22 -2
View File
@@ -8,11 +8,31 @@ use codex_core::config_loader::RequirementSource;
use codex_core::config_loader::ResidencyRequirement; use codex_core::config_loader::ResidencyRequirement;
use codex_core::config_loader::SandboxModeRequirement; use codex_core::config_loader::SandboxModeRequirement;
use codex_core::config_loader::WebSearchModeRequirement; use codex_core::config_loader::WebSearchModeRequirement;
use codex_core::protocol::SessionNetworkProxyRuntime;
use ratatui::style::Stylize; use ratatui::style::Stylize;
use ratatui::text::Line; use ratatui::text::Line;
pub(crate) fn new_debug_config_output(config: &Config) -> PlainHistoryCell { pub(crate) fn new_debug_config_output(
PlainHistoryCell::new(render_debug_config_lines(&config.config_layer_stack)) config: &Config,
session_network_proxy: Option<&SessionNetworkProxyRuntime>,
) -> PlainHistoryCell {
let mut lines = render_debug_config_lines(&config.config_layer_stack);
if let Some(proxy) = session_network_proxy {
lines.push("".into());
lines.push("Session runtime:".bold().into());
lines.push(" - network_proxy".into());
let SessionNetworkProxyRuntime {
http_addr,
socks_addr,
admin_addr,
} = proxy;
lines.push(format!(" - HTTP_PROXY = http://{http_addr}").into());
lines.push(format!(" - ALL_PROXY = socks5h://{socks_addr}").into());
lines.push(format!(" - ADMIN_PROXY = http://{admin_addr}").into());
}
PlainHistoryCell::new(lines)
} }
fn render_debug_config_lines(stack: &ConfigLayerStack) -> Vec<Line<'static>> { fn render_debug_config_lines(stack: &ConfigLayerStack) -> Vec<Line<'static>> {