mirror of
https://github.com/openai/codex.git
synced 2026-12-06 01:10:58 +00:00
Preserve code cell response metadata in rollout traces (#55725)
## Why Reducing code cell lifecycle events discarded their response payload references and lost the initial response status when the runtime status changed. ## What changed Store the initial response status and separate raw payload IDs for the initial response and final result on `CodeCell`. Carry payload references through queued lifecycle events so they survive replay when the source item arrives later. ## Testing Extend lifecycle tests to verify distinct initial and final payload IDs and the preserved initial status for yielded cells that complete and failed cells whose lifecycle events precede their source item. GitOrigin-RevId: 8f49a3174ea487a5d91ebc2a6c97133aacaabfd2
This commit is contained in:
committed by
copyberry
parent
2744e8686c
commit
d571eaf1f6
@@ -43,6 +43,9 @@ pub struct CodeCell {
|
||||
pub runtime_status: CodeCellRuntimeStatus,
|
||||
pub initial_response_at_unix_ms: Option<i64>,
|
||||
pub initial_response_seq: Option<RawEventSeq>,
|
||||
pub initial_response_status: Option<CodeCellRuntimeStatus>,
|
||||
pub raw_initial_response_payload_id: Option<RawPayloadId>,
|
||||
pub raw_result_payload_id: Option<RawPayloadId>,
|
||||
pub yielded_at_unix_ms: Option<i64>,
|
||||
pub yielded_seq: Option<RawEventSeq>,
|
||||
pub source_js: String,
|
||||
|
||||
@@ -72,9 +72,11 @@ pub(super) enum PendingCodeCellLifecycleEventKind {
|
||||
InitialResponse {
|
||||
runtime_cell_id: String,
|
||||
status: CodeCellRuntimeStatus,
|
||||
response_payload: Option<RawPayloadRef>,
|
||||
},
|
||||
Ended {
|
||||
status: CodeCellRuntimeStatus,
|
||||
response_payload: Option<RawPayloadRef>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -192,6 +194,9 @@ impl TraceReducer {
|
||||
runtime_status: CodeCellRuntimeStatus::Starting,
|
||||
initial_response_at_unix_ms: None,
|
||||
initial_response_seq: None,
|
||||
initial_response_status: None,
|
||||
raw_initial_response_payload_id: None,
|
||||
raw_result_payload_id: None,
|
||||
yielded_at_unix_ms: None,
|
||||
yielded_seq: None,
|
||||
source_js: started.source_js,
|
||||
@@ -239,6 +244,7 @@ impl TraceReducer {
|
||||
code_cell_id: CodeCellId,
|
||||
runtime_cell_id: String,
|
||||
status: CodeCellRuntimeStatus,
|
||||
response_payload: Option<RawPayloadRef>,
|
||||
) -> Result<()> {
|
||||
if !self.rollout.code_cells.contains_key(&code_cell_id) {
|
||||
if self.pending_code_cell_starts.contains_key(&code_cell_id) {
|
||||
@@ -250,6 +256,7 @@ impl TraceReducer {
|
||||
kind: PendingCodeCellLifecycleEventKind::InitialResponse {
|
||||
runtime_cell_id,
|
||||
status,
|
||||
response_payload,
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -263,6 +270,7 @@ impl TraceReducer {
|
||||
code_cell_id,
|
||||
runtime_cell_id,
|
||||
status,
|
||||
response_payload,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -273,15 +281,18 @@ impl TraceReducer {
|
||||
code_cell_id: CodeCellId,
|
||||
runtime_cell_id: String,
|
||||
status: CodeCellRuntimeStatus,
|
||||
response_payload: Option<RawPayloadRef>,
|
||||
) -> Result<()> {
|
||||
let Some(cell) = self.rollout.code_cells.get_mut(&code_cell_id) else {
|
||||
bail!("code cell initial response referenced unknown cell {code_cell_id}");
|
||||
};
|
||||
|
||||
cell.runtime_cell_id = Some(runtime_cell_id);
|
||||
if cell.initial_response_at_unix_ms.is_none() {
|
||||
if cell.initial_response_status.is_none() {
|
||||
cell.initial_response_at_unix_ms = Some(wall_time_unix_ms);
|
||||
cell.initial_response_seq = Some(seq);
|
||||
cell.initial_response_status = Some(status.clone());
|
||||
cell.raw_initial_response_payload_id = response_payload.map(|p| p.raw_payload_id);
|
||||
}
|
||||
if status == CodeCellRuntimeStatus::Yielded {
|
||||
cell.yielded_at_unix_ms = Some(wall_time_unix_ms);
|
||||
@@ -303,6 +314,7 @@ impl TraceReducer {
|
||||
wall_time_unix_ms: i64,
|
||||
code_cell_id: CodeCellId,
|
||||
status: CodeCellRuntimeStatus,
|
||||
response_payload: Option<RawPayloadRef>,
|
||||
) -> Result<()> {
|
||||
if !self.rollout.code_cells.contains_key(&code_cell_id) {
|
||||
if self.pending_code_cell_starts.contains_key(&code_cell_id) {
|
||||
@@ -311,14 +323,23 @@ impl TraceReducer {
|
||||
PendingCodeCellLifecycleEvent {
|
||||
seq,
|
||||
wall_time_unix_ms,
|
||||
kind: PendingCodeCellLifecycleEventKind::Ended { status },
|
||||
kind: PendingCodeCellLifecycleEventKind::Ended {
|
||||
status,
|
||||
response_payload,
|
||||
},
|
||||
},
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
bail!("code cell end referenced unknown cell {code_cell_id}");
|
||||
}
|
||||
self.end_code_cell(seq, wall_time_unix_ms, code_cell_id, status)
|
||||
self.end_code_cell(
|
||||
seq,
|
||||
wall_time_unix_ms,
|
||||
code_cell_id,
|
||||
status,
|
||||
response_payload,
|
||||
)
|
||||
}
|
||||
|
||||
fn end_code_cell(
|
||||
@@ -327,6 +348,7 @@ impl TraceReducer {
|
||||
wall_time_unix_ms: i64,
|
||||
code_cell_id: CodeCellId,
|
||||
status: CodeCellRuntimeStatus,
|
||||
response_payload: Option<RawPayloadRef>,
|
||||
) -> Result<()> {
|
||||
let Some(cell) = self.rollout.code_cells.get_mut(&code_cell_id) else {
|
||||
bail!("code cell end referenced unknown cell {code_cell_id}");
|
||||
@@ -336,6 +358,7 @@ impl TraceReducer {
|
||||
cell.initial_response_at_unix_ms = Some(wall_time_unix_ms);
|
||||
cell.initial_response_seq = Some(seq);
|
||||
}
|
||||
cell.raw_result_payload_id = response_payload.map(|p| p.raw_payload_id);
|
||||
cell.execution.ended_at_unix_ms = Some(wall_time_unix_ms);
|
||||
cell.execution.ended_seq = Some(seq);
|
||||
cell.execution.status = execution_status_for_code_cell(&status);
|
||||
@@ -376,7 +399,13 @@ impl TraceReducer {
|
||||
.collect();
|
||||
|
||||
for code_cell_id in code_cell_ids {
|
||||
self.end_code_cell(seq, wall_time_unix_ms, code_cell_id, runtime_status.clone())?;
|
||||
self.end_code_cell(
|
||||
seq,
|
||||
wall_time_unix_ms,
|
||||
code_cell_id,
|
||||
runtime_status.clone(),
|
||||
/*response_payload*/ None,
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -403,18 +432,24 @@ impl TraceReducer {
|
||||
PendingCodeCellLifecycleEventKind::InitialResponse {
|
||||
runtime_cell_id,
|
||||
status,
|
||||
response_payload,
|
||||
} => self.record_code_cell_initial_response(
|
||||
event.seq,
|
||||
event.wall_time_unix_ms,
|
||||
code_cell_id.to_string(),
|
||||
runtime_cell_id,
|
||||
status,
|
||||
response_payload,
|
||||
)?,
|
||||
PendingCodeCellLifecycleEventKind::Ended { status } => self.end_code_cell(
|
||||
PendingCodeCellLifecycleEventKind::Ended {
|
||||
status,
|
||||
response_payload,
|
||||
} => self.end_code_cell(
|
||||
event.seq,
|
||||
event.wall_time_unix_ms,
|
||||
code_cell_id.to_string(),
|
||||
status,
|
||||
response_payload,
|
||||
)?,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,12 +67,20 @@ fn code_cell_lifecycle_links_nested_tools_waits_and_outputs() -> anyhow::Result<
|
||||
upstream_request_id: None,
|
||||
response_payload: response,
|
||||
})?;
|
||||
let initial_response = writer.write_json_payload(
|
||||
RawPayloadKind::ToolResult,
|
||||
&json!({"response": "initial caller result"}),
|
||||
)?;
|
||||
let final_response = writer.write_json_payload(
|
||||
RawPayloadKind::ToolResult,
|
||||
&json!({"response": "later runtime result"}),
|
||||
)?;
|
||||
writer.append_with_context(
|
||||
trace_context("turn-1"),
|
||||
RawTraceEventPayload::CodeCellInitialResponse {
|
||||
runtime_cell_id: "1".to_string(),
|
||||
status: CodeCellRuntimeStatus::Yielded,
|
||||
response_payload: None,
|
||||
response_payload: Some(initial_response.clone()),
|
||||
},
|
||||
)?;
|
||||
writer.append_with_context(
|
||||
@@ -156,7 +164,7 @@ fn code_cell_lifecycle_links_nested_tools_waits_and_outputs() -> anyhow::Result<
|
||||
RawTraceEventPayload::CodeCellEnded {
|
||||
runtime_cell_id: "1".to_string(),
|
||||
status: CodeCellRuntimeStatus::Completed,
|
||||
response_payload: None,
|
||||
response_payload: Some(final_response.clone()),
|
||||
},
|
||||
)?;
|
||||
|
||||
@@ -168,6 +176,18 @@ fn code_cell_lifecycle_links_nested_tools_waits_and_outputs() -> anyhow::Result<
|
||||
.last()
|
||||
.expect("exec output item");
|
||||
|
||||
assert_eq!(
|
||||
(
|
||||
&cell.initial_response_status,
|
||||
&cell.raw_initial_response_payload_id,
|
||||
&cell.raw_result_payload_id,
|
||||
),
|
||||
(
|
||||
&Some(CodeCellRuntimeStatus::Yielded),
|
||||
&Some(initial_response.raw_payload_id),
|
||||
&Some(final_response.raw_payload_id),
|
||||
)
|
||||
);
|
||||
assert_eq!(cell.thread_id, "thread-root");
|
||||
assert_eq!(cell.runtime_status, CodeCellRuntimeStatus::Completed);
|
||||
assert_eq!(cell.execution.status, ExecutionStatus::Completed);
|
||||
@@ -217,12 +237,20 @@ fn fast_code_cell_lifecycle_waits_for_source_item() -> anyhow::Result<()> {
|
||||
source_js: "not valid js".to_string(),
|
||||
},
|
||||
)?;
|
||||
let initial_response = writer.write_json_payload(
|
||||
RawPayloadKind::ToolResult,
|
||||
&json!({"response": "initial caller result"}),
|
||||
)?;
|
||||
let final_response = writer.write_json_payload(
|
||||
RawPayloadKind::ToolResult,
|
||||
&json!({"response": "later runtime result"}),
|
||||
)?;
|
||||
writer.append_with_context(
|
||||
trace_context("turn-1"),
|
||||
RawTraceEventPayload::CodeCellInitialResponse {
|
||||
runtime_cell_id: "1".to_string(),
|
||||
status: CodeCellRuntimeStatus::Failed,
|
||||
response_payload: None,
|
||||
response_payload: Some(initial_response.clone()),
|
||||
},
|
||||
)?;
|
||||
writer.append_with_context(
|
||||
@@ -230,7 +258,7 @@ fn fast_code_cell_lifecycle_waits_for_source_item() -> anyhow::Result<()> {
|
||||
RawTraceEventPayload::CodeCellEnded {
|
||||
runtime_cell_id: "1".to_string(),
|
||||
status: CodeCellRuntimeStatus::Failed,
|
||||
response_payload: None,
|
||||
response_payload: Some(final_response.clone()),
|
||||
},
|
||||
)?;
|
||||
let response = writer.write_json_payload(
|
||||
@@ -256,6 +284,18 @@ fn fast_code_cell_lifecycle_waits_for_source_item() -> anyhow::Result<()> {
|
||||
let code_cell_id = test_reduced_code_cell_id("call-code");
|
||||
let cell = &rollout.code_cells[&code_cell_id];
|
||||
|
||||
assert_eq!(
|
||||
(
|
||||
&cell.initial_response_status,
|
||||
&cell.raw_initial_response_payload_id,
|
||||
&cell.raw_result_payload_id,
|
||||
),
|
||||
(
|
||||
&Some(CodeCellRuntimeStatus::Failed),
|
||||
&Some(initial_response.raw_payload_id),
|
||||
&Some(final_response.raw_payload_id),
|
||||
)
|
||||
);
|
||||
assert_eq!(cell.thread_id, "thread-root");
|
||||
assert_eq!(cell.runtime_status, CodeCellRuntimeStatus::Failed);
|
||||
assert_eq!(cell.execution.status, ExecutionStatus::Failed);
|
||||
|
||||
@@ -338,7 +338,7 @@ impl TraceReducer {
|
||||
RawTraceEventPayload::CodeCellInitialResponse {
|
||||
runtime_cell_id,
|
||||
status,
|
||||
..
|
||||
response_payload,
|
||||
} => {
|
||||
let thread_id = self.code_cell_event_thread_id(
|
||||
event.thread_id,
|
||||
@@ -357,12 +357,13 @@ impl TraceReducer {
|
||||
code_cell_id,
|
||||
runtime_cell_id,
|
||||
status,
|
||||
response_payload,
|
||||
)?;
|
||||
}
|
||||
RawTraceEventPayload::CodeCellEnded {
|
||||
runtime_cell_id,
|
||||
status,
|
||||
..
|
||||
response_payload,
|
||||
} => {
|
||||
let thread_id = self.code_cell_event_thread_id(
|
||||
event.thread_id,
|
||||
@@ -380,6 +381,7 @@ impl TraceReducer {
|
||||
event.wall_time_unix_ms,
|
||||
code_cell_id,
|
||||
status,
|
||||
response_payload,
|
||||
)?;
|
||||
}
|
||||
RawTraceEventPayload::CompactionRequestStarted {
|
||||
|
||||
Reference in New Issue
Block a user