mirror of
https://github.com/openai/codex.git
synced 2026-11-13 06:45:07 +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
+29
-23
No files matched your search
@@ -478,28 +478,34 @@ const CYBER_SAFETY_URL: &str = "https://developers.openai.com/codex/concepts/cyb
|
||||
|
||||
impl Session {
|
||||
/// Spawn and initialize a new session.
|
||||
pub(crate) async fn spawn(args: SessionSpawnArgs) -> CodexResult<(Arc<Self>, SessionIo)> {
|
||||
let parent_trace = match args.parent_trace {
|
||||
Some(trace) => {
|
||||
if codex_otel::context_from_w3c_trace_context(&trace).is_some() {
|
||||
Some(trace)
|
||||
} else {
|
||||
warn!("ignoring invalid thread spawn trace carrier");
|
||||
None
|
||||
/// 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 {
|
||||
Some(trace) => {
|
||||
if codex_otel::context_from_w3c_trace_context(&trace).is_some() {
|
||||
Some(trace)
|
||||
} else {
|
||||
warn!("ignoring invalid thread spawn trace carrier");
|
||||
None
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let thread_spawn_span = info_span!("thread_spawn", otel.name = "thread_spawn");
|
||||
if let Some(trace) = parent_trace.as_ref() {
|
||||
let _ = set_parent_from_w3c_trace_context(&thread_spawn_span, trace);
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let thread_spawn_span = info_span!("thread_spawn", otel.name = "thread_spawn");
|
||||
if let Some(trace) = parent_trace.as_ref() {
|
||||
let _ = set_parent_from_w3c_trace_context(&thread_spawn_span, trace);
|
||||
}
|
||||
Self::spawn_internal(SessionSpawnArgs {
|
||||
parent_trace,
|
||||
..args
|
||||
Self::spawn_internal(SessionSpawnArgs {
|
||||
parent_trace,
|
||||
..args
|
||||
})
|
||||
.instrument(thread_spawn_span)
|
||||
.await
|
||||
})
|
||||
.instrument(thread_spawn_span)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn spawn_internal(args: SessionSpawnArgs) -> CodexResult<(Arc<Self>, SessionIo)> {
|
||||
|
||||
Reference in new issue
Block a user