mirror of
https://github.com/openai/codex.git
synced 2026-11-06 20:20:34 +00:00
This is PR 3 of the app-server tracing rollout. PRs https://github.com/openai/codex/pull/13285 and https://github.com/openai/codex/pull/13368 gave us inbound request spans in app-server and propagated trace context through Submission. This change finishes the next piece in core: when a request actually starts a turn, we now create a core-owned long-lived span that stays open for the real lifetime of the turn. What changed: - `Session::spawn_task` can now optionally create a long-lived turn span and run the spawned task inside it - `turn/start` uses that path, so normal turn execution stays under a single core-owned span after the async handoff - `review/start` uses the same pattern - added a unit test that verifies the spawned turn task inherits the submission dispatch trace ancestry **Why** The app-server request span is intentionally short-lived. Once work crosses into core, we still want one span that covers the actual execution window until completion or interruption. This keeps that ownership where it belongs: in the layer that owns the runtime lifecycle.
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
use std::sync::Arc;
|
|
|
|
use super::SessionTask;
|
|
use super::SessionTaskContext;
|
|
use crate::codex::TurnContext;
|
|
use crate::state::TaskKind;
|
|
use async_trait::async_trait;
|
|
use codex_protocol::user_input::UserInput;
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
#[derive(Clone, Copy, Default)]
|
|
pub(crate) struct CompactTask;
|
|
|
|
#[async_trait]
|
|
impl SessionTask for CompactTask {
|
|
fn kind(&self) -> TaskKind {
|
|
TaskKind::Compact
|
|
}
|
|
|
|
fn span_name(&self) -> &'static str {
|
|
"session_task.compact"
|
|
}
|
|
|
|
async fn run(
|
|
self: Arc<Self>,
|
|
session: Arc<SessionTaskContext>,
|
|
ctx: Arc<TurnContext>,
|
|
input: Vec<UserInput>,
|
|
_cancellation_token: CancellationToken,
|
|
) -> Option<String> {
|
|
let session = session.clone_session();
|
|
let _ = if crate::compact::should_use_remote_compact_task(&ctx.provider) {
|
|
let _ = session.services.otel_manager.counter(
|
|
"codex.task.compact",
|
|
1,
|
|
&[("type", "remote")],
|
|
);
|
|
crate::compact_remote::run_remote_compact_task(session.clone(), ctx).await
|
|
} else {
|
|
let _ = session.services.otel_manager.counter(
|
|
"codex.task.compact",
|
|
1,
|
|
&[("type", "local")],
|
|
);
|
|
crate::compact::run_compact_task(session.clone(), ctx, input).await
|
|
};
|
|
None
|
|
}
|
|
}
|