mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Box the session startup future at its API boundary (#41853)
## What changed - Make `Session::spawn` return a `BoxFuture` while preserving lazy session initialization. - Prevent the startup wrapper from being inlined so callers do not expose its concrete future. - Await the returned future directly at session creation call sites. GitOrigin-RevId: 5432745aae1c934b16202716a8d49a8553de2018
This commit is contained in:
1 parent
305eed102d
commit
9d19c7426e
3 files changed
+11
-5
No files matched your search
@@ -111,7 +111,7 @@ pub(crate) async fn run_codex_thread_interactive(
|
|||||||
} else {
|
} else {
|
||||||
Arc::clone(&parent_session.services.extensions)
|
Arc::clone(&parent_session.services.extensions)
|
||||||
};
|
};
|
||||||
let (session, io) = Box::pin(Session::spawn(SessionSpawnArgs {
|
let (session, io) = Session::spawn(SessionSpawnArgs {
|
||||||
config,
|
config,
|
||||||
allow_provider_model_fallback: false,
|
allow_provider_model_fallback: false,
|
||||||
user_instructions,
|
user_instructions,
|
||||||
@@ -158,7 +158,7 @@ pub(crate) async fn run_codex_thread_interactive(
|
|||||||
inherited_multi_agent_version: Some(MultiAgentVersion::Disabled),
|
inherited_multi_agent_version: Some(MultiAgentVersion::Disabled),
|
||||||
git_enrichment_policy,
|
git_enrichment_policy,
|
||||||
windows_sandbox_proxy_settings_mode,
|
windows_sandbox_proxy_settings_mode,
|
||||||
}))
|
})
|
||||||
.or_cancel(&cancel_token)
|
.or_cancel(&cancel_token)
|
||||||
.await??;
|
.await??;
|
||||||
let thread_config = session.thread_config_snapshot().await;
|
let thread_config = session.thread_config_snapshot().await;
|
||||||
|
|||||||
@@ -478,7 +478,12 @@ const CYBER_SAFETY_URL: &str = "https://developers.openai.com/codex/concepts/cyb
|
|||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
/// Spawn and initialize a new session.
|
/// Spawn and initialize a new session.
|
||||||
pub(crate) async fn spawn(args: SessionSpawnArgs) -> CodexResult<(Arc<Self>, SessionIo)> {
|
/// Hide the concrete startup future from callers while keeping initialization lazy.
|
||||||
|
#[inline(never)]
|
||||||
|
pub(crate) fn spawn(
|
||||||
|
args: SessionSpawnArgs,
|
||||||
|
) -> BoxFuture<'static, CodexResult<(Arc<Self>, SessionIo)>> {
|
||||||
|
Box::pin(async move {
|
||||||
let parent_trace = match args.parent_trace {
|
let parent_trace = match args.parent_trace {
|
||||||
Some(trace) => {
|
Some(trace) => {
|
||||||
if codex_otel::context_from_w3c_trace_context(&trace).is_some() {
|
if codex_otel::context_from_w3c_trace_context(&trace).is_some() {
|
||||||
@@ -500,6 +505,7 @@ impl Session {
|
|||||||
})
|
})
|
||||||
.instrument(thread_spawn_span)
|
.instrument(thread_spawn_span)
|
||||||
.await
|
.await
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn spawn_internal(args: SessionSpawnArgs) -> CodexResult<(Arc<Self>, SessionIo)> {
|
async fn spawn_internal(args: SessionSpawnArgs) -> CodexResult<(Arc<Self>, SessionIo)> {
|
||||||
|
|||||||
@@ -1987,7 +1987,7 @@ impl ThreadManagerState {
|
|||||||
} else {
|
} else {
|
||||||
codex_sandboxing::WindowsSandboxProxySettingsMode::Reconcile
|
codex_sandboxing::WindowsSandboxProxySettingsMode::Reconcile
|
||||||
};
|
};
|
||||||
let (session, io) = Box::pin(Session::spawn(SessionSpawnArgs {
|
let (session, io) = Session::spawn(SessionSpawnArgs {
|
||||||
config,
|
config,
|
||||||
allow_provider_model_fallback,
|
allow_provider_model_fallback,
|
||||||
user_instructions,
|
user_instructions,
|
||||||
@@ -2027,7 +2027,7 @@ impl ThreadManagerState {
|
|||||||
inherited_multi_agent_version: multi_agent_version,
|
inherited_multi_agent_version: multi_agent_version,
|
||||||
git_enrichment_policy: GitEnrichmentPolicy::Fresh,
|
git_enrichment_policy: GitEnrichmentPolicy::Fresh,
|
||||||
windows_sandbox_proxy_settings_mode,
|
windows_sandbox_proxy_settings_mode,
|
||||||
}))
|
})
|
||||||
.await?;
|
.await?;
|
||||||
// Enable Full Access form input only after session startup so a required MCP server cannot
|
// Enable Full Access form input only after session startup so a required MCP server cannot
|
||||||
// block startup while waiting for form input.
|
// block startup while waiting for form input.
|
||||||
|
|||||||
Reference in new issue
Block a user