mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
## What changed - Add `CodeModeCellTiming` notifications for yielded executions, terminal waits, and unavailable cells, with thread, call, and cell identifiers. - Measure how long completed results remain buffered before retrieval and carry `result_buffered_for` through the runtime, stdio protocol, and gRPC response metadata. Immediate delivery reports zero; waits without a completed result report no buffering measurement. - Default missing buffering data to zero for compatibility with older hosts. ## Testing Extend runtime tests to verify buffering duration with a paused clock and retrieval through termination. Add gRPC conversion tests for nanosecond precision, optional metadata, and the distinction between immediate delivery and no completed result. GitOrigin-RevId: 60c0c5a3affa69ac3779bf1812fca50f5748af76
120 lines
3.8 KiB
Rust
120 lines
3.8 KiB
Rust
use codex_code_mode_protocol::CellId;
|
|
use codex_code_mode_protocol::RuntimeResponse;
|
|
use codex_code_mode_protocol::WaitOutcome;
|
|
use codex_code_mode_protocol::WaitRequest;
|
|
use codex_code_mode_protocol::host::WireCellId;
|
|
use codex_code_mode_protocol::host::WireRuntimeResponse;
|
|
use codex_code_mode_protocol::host::WireWaitOutcome;
|
|
use codex_code_mode_protocol::host::WireWaitRequest;
|
|
|
|
use super::RemoteSession;
|
|
|
|
pub(super) fn public_cell_id(generation: u64, cell_id: &WireCellId) -> CellId {
|
|
if generation == 1 {
|
|
CellId::new(cell_id.as_str().to_string())
|
|
} else {
|
|
CellId::new(format!("g{generation}:{}", cell_id.as_str()))
|
|
}
|
|
}
|
|
|
|
pub(super) fn public_cell_id_from_protocol(generation: u64, cell_id: &CellId) -> CellId {
|
|
public_cell_id(generation, &WireCellId::new(cell_id.as_str()))
|
|
}
|
|
|
|
pub(super) fn remote_cell_id(
|
|
session: &RemoteSession,
|
|
cell_id: &CellId,
|
|
) -> Result<WireCellId, String> {
|
|
if session.generation == 1 {
|
|
if cell_id.as_str().starts_with('g') && cell_id.as_str().contains(':') {
|
|
return Err(format!(
|
|
"cell {cell_id} belongs to a stale code-mode host generation"
|
|
));
|
|
}
|
|
return Ok(WireCellId::new(cell_id.as_str()));
|
|
}
|
|
let prefix = format!("g{}:", session.generation);
|
|
let Some(remote_id) = cell_id.as_str().strip_prefix(&prefix) else {
|
|
return Err(format!(
|
|
"cell {cell_id} belongs to a stale code-mode host generation"
|
|
));
|
|
};
|
|
Ok(WireCellId::new(remote_id))
|
|
}
|
|
|
|
pub(super) fn remote_wait_request(
|
|
session: &RemoteSession,
|
|
request: WaitRequest,
|
|
) -> Result<WireWaitRequest, String> {
|
|
Ok(WireWaitRequest {
|
|
cell_id: remote_cell_id(session, &request.cell_id)?,
|
|
yield_time_ms: request.yield_time_ms,
|
|
})
|
|
}
|
|
|
|
pub(super) fn public_runtime_response(
|
|
generation: u64,
|
|
response: RuntimeResponse,
|
|
) -> RuntimeResponse {
|
|
match response {
|
|
RuntimeResponse::Yielded {
|
|
cell_id,
|
|
content_items,
|
|
code_mode_host_duration,
|
|
} => RuntimeResponse::Yielded {
|
|
cell_id: public_cell_id_from_protocol(generation, &cell_id),
|
|
content_items,
|
|
code_mode_host_duration,
|
|
},
|
|
RuntimeResponse::Terminated {
|
|
cell_id,
|
|
content_items,
|
|
code_mode_host_duration,
|
|
} => RuntimeResponse::Terminated {
|
|
cell_id: public_cell_id_from_protocol(generation, &cell_id),
|
|
content_items,
|
|
code_mode_host_duration,
|
|
},
|
|
RuntimeResponse::Result {
|
|
cell_id,
|
|
content_items,
|
|
result_buffered_for,
|
|
error_text,
|
|
code_mode_host_duration,
|
|
} => RuntimeResponse::Result {
|
|
cell_id: public_cell_id_from_protocol(generation, &cell_id),
|
|
content_items,
|
|
result_buffered_for,
|
|
error_text,
|
|
code_mode_host_duration,
|
|
},
|
|
}
|
|
}
|
|
|
|
pub(super) fn public_wait_outcome(generation: u64, outcome: WaitOutcome) -> WaitOutcome {
|
|
match outcome {
|
|
WaitOutcome::LiveCell(response) => {
|
|
WaitOutcome::LiveCell(public_runtime_response(generation, response))
|
|
}
|
|
WaitOutcome::MissingCell(response) => {
|
|
WaitOutcome::MissingCell(public_runtime_response(generation, response))
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(super) fn runtime_response_cell_id(response: &WireRuntimeResponse) -> &WireCellId {
|
|
match response {
|
|
WireRuntimeResponse::Yielded { cell_id, .. }
|
|
| WireRuntimeResponse::Terminated { cell_id, .. }
|
|
| WireRuntimeResponse::Result { cell_id, .. } => cell_id,
|
|
}
|
|
}
|
|
|
|
pub(super) fn wait_outcome_cell_id(outcome: &WireWaitOutcome) -> &WireCellId {
|
|
match outcome {
|
|
WireWaitOutcome::LiveCell(response) | WireWaitOutcome::MissingCell(response) => {
|
|
runtime_response_cell_id(response)
|
|
}
|
|
}
|
|
}
|