mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Preserve full MCP results in rollout traces (#57280)
## Why MCP completion events can truncate large results and omit content removed for model consumption. Rollout traces need the original response, including content and metadata, as well as results for calls denied before reaching the backend. ## What changed - Record MCP runtime results before callbacks, content filtering, and UI truncation, and record skipped calls as failures. - Stop deriving MCP runtime completion records from protocol events to avoid duplicate records. - Treat MCP runtime payloads as opaque results when reducing agent interactions. - Buffer JSON trace writes and explicitly flush them. ## Testing Extend app-server tests to verify that traces retain oversized MCP text, audio, structured content, and metadata while UI results remain truncated, and that denied calls produce exactly one failed runtime result with the denial reason. GitOrigin-RevId: 57880770545eb5869420d7dc6fa4a15e481cae9d
This commit is contained in:
committed by
copyberry
parent
6d8f311b00
commit
f2df3e3b56
@@ -5,6 +5,7 @@
|
||||
//! thread-local event methods here avoids repeatedly plumbing `thread_id`
|
||||
//! through session code.
|
||||
|
||||
use codex_protocol::mcp::CallToolResult;
|
||||
use codex_protocol::protocol::AgentStatus;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
@@ -21,6 +22,7 @@ use crate::CodeCellTraceContext;
|
||||
use crate::CodexTurnId;
|
||||
use crate::CompactionId;
|
||||
use crate::CompactionTraceContext;
|
||||
use crate::ExecutionStatus;
|
||||
use crate::InferenceTraceContext;
|
||||
use crate::McpCallTraceContext;
|
||||
use crate::RawPayloadKind;
|
||||
@@ -247,6 +249,40 @@ impl ThreadTraceContext {
|
||||
context.append_with_context_best_effort(codex_turn_id.into(), payload);
|
||||
}
|
||||
|
||||
/// Records the full MCP backend result before callbacks, sanitization, or UI truncation.
|
||||
/// The dispatch trace separately records the result returned to the caller.
|
||||
pub fn record_mcp_tool_result(
|
||||
&self,
|
||||
codex_turn_id: &str,
|
||||
tool_call_id: &str,
|
||||
result: &Result<CallToolResult, String>,
|
||||
) {
|
||||
let ThreadTraceContextState::Enabled(context) = &self.state else {
|
||||
return;
|
||||
};
|
||||
#[derive(Serialize)]
|
||||
struct Payload<'a> {
|
||||
result: &'a Result<CallToolResult, String>,
|
||||
}
|
||||
let Some(runtime_payload) = context
|
||||
.write_json_payload_best_effort(RawPayloadKind::ToolRuntimeEvent, &Payload { result })
|
||||
else {
|
||||
return;
|
||||
};
|
||||
context.append_with_context_best_effort(
|
||||
codex_turn_id.to_owned(),
|
||||
RawTraceEventPayload::ToolCallRuntimeEnded {
|
||||
tool_call_id: tool_call_id.to_owned(),
|
||||
status: if result.is_ok() {
|
||||
ExecutionStatus::Completed
|
||||
} else {
|
||||
ExecutionStatus::Failed
|
||||
},
|
||||
runtime_payload,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Records the exec actually selected by stdin, since its process handle can be reused.
|
||||
pub fn record_stdin_target(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user