mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Encapsulate executed tool call metadata recording (#44002)
## What changed Introduce `ExecutedToolCalls` to own optional shared recorder state and centralize feature checks, call recording, and accepted result source lookup. Update session, tool runtime, MCP, and Code Mode callers to use this interface. Move prompt attachment, retry handling, and metadata budgeting into the `request_metadata` module, preserving existing recording and request behavior. ## Testing Add coverage for all session and turn feature combinations, lazy result source lookup, and unchanged prompts when recording is disabled. Retain the existing metadata budget and cell completeness tests in the new module. GitOrigin-RevId: bc19f34317232b6599c7ec71c15db4a80123ff6f
This commit is contained in:
@@ -20,7 +20,7 @@ use super::ExecContext;
|
||||
use super::PUBLIC_TOOL_NAME;
|
||||
use super::submit_nested_tool;
|
||||
use crate::session::step_context::StepContext;
|
||||
use crate::tools::ExecutedToolCallRecorder;
|
||||
use crate::tools::ExecutedToolCalls;
|
||||
use crate::tools::context::SharedTurnDiffTracker;
|
||||
use crate::tools::parallel::ToolCallRuntime;
|
||||
|
||||
@@ -28,7 +28,7 @@ pub(super) struct CodeModeDispatchBroker {
|
||||
dispatch_tx: async_channel::Sender<DispatchMessage>,
|
||||
dispatch_rx: async_channel::Receiver<DispatchMessage>,
|
||||
dispatch_gates: Arc<Mutex<HashMap<CellId, CellDispatchGate>>>,
|
||||
executed_tool_calls: Option<Arc<ExecutedToolCallRecorder>>,
|
||||
executed_tool_calls: ExecutedToolCalls,
|
||||
}
|
||||
|
||||
struct CellDispatchGate {
|
||||
@@ -38,7 +38,7 @@ struct CellDispatchGate {
|
||||
}
|
||||
|
||||
impl CodeModeDispatchBroker {
|
||||
pub(super) fn new(executed_tool_calls: Option<Arc<ExecutedToolCallRecorder>>) -> Self {
|
||||
pub(super) fn new(executed_tool_calls: ExecutedToolCalls) -> Self {
|
||||
let (dispatch_tx, dispatch_rx) = async_channel::unbounded();
|
||||
Self {
|
||||
dispatch_tx,
|
||||
@@ -84,9 +84,7 @@ impl CodeModeDispatchBroker {
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
dispatch_gates.remove(cell_id);
|
||||
if let Some(recorder) = &self.executed_tool_calls {
|
||||
recorder.finish_cell_recording(cell_id);
|
||||
}
|
||||
self.executed_tool_calls.finish_cell_recording(cell_id);
|
||||
}
|
||||
|
||||
pub(super) fn active_cell_ids(&self) -> Vec<CellId> {
|
||||
@@ -104,11 +102,7 @@ impl CodeModeDispatchBroker {
|
||||
step_context: Arc<StepContext>,
|
||||
tracker: SharedTurnDiffTracker,
|
||||
) -> CodeModeDispatchWorker {
|
||||
let track_completeness = exec
|
||||
.turn
|
||||
.config
|
||||
.features
|
||||
.enabled(codex_features::Feature::ExecutedToolCallMetadata);
|
||||
let track_completeness = ExecutedToolCalls::is_enabled(&exec.turn.config.features);
|
||||
let tool_runtime = ToolCallRuntime::new(Arc::clone(&exec.session), step_context, tracker);
|
||||
let host = Arc::new(CoreTurnHost { exec, tool_runtime });
|
||||
let dispatch_rx = self.dispatch_rx.clone();
|
||||
|
||||
@@ -116,7 +116,7 @@ async fn detached_code_mode_callback_keeps_thread_id_on_dispatch_span() -> anyho
|
||||
));
|
||||
let step = StepContext::for_test(Arc::clone(&turn)).with_tool_router_for_test(router);
|
||||
let broker = Arc::new(CodeModeDispatchBroker::new(
|
||||
/*executed_tool_calls*/ None,
|
||||
/*executed_tool_calls*/ Default::default(),
|
||||
));
|
||||
let cell_id = CellId::new("audit-cell".to_string());
|
||||
broker.mark_cell_ready_for_dispatch(&cell_id, /*originating_item_id*/ None);
|
||||
|
||||
@@ -87,9 +87,10 @@ impl CodeModeExecuteHandler {
|
||||
call_id: call_id.clone(),
|
||||
cell_id: cell_id.to_string(),
|
||||
});
|
||||
if let Some(executed_tool_calls) = exec.session.services.executed_tool_calls.as_ref() {
|
||||
executed_tool_calls.start_cell(&cell_id, &call_id);
|
||||
}
|
||||
exec.session
|
||||
.services
|
||||
.executed_tool_calls
|
||||
.start_cell(&cell_id, &call_id);
|
||||
let runtime_cell_id = cell_id.to_string();
|
||||
let code_cell_trace = exec
|
||||
.session
|
||||
|
||||
@@ -30,7 +30,7 @@ use crate::original_image_detail::sanitize_original_image_detail as sanitize_ima
|
||||
use crate::session::session::Session;
|
||||
use crate::session::step_context::StepContext;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
use crate::tools::ExecutedToolCallRecorder;
|
||||
use crate::tools::ExecutedToolCalls;
|
||||
use crate::tools::context::FunctionToolOutput;
|
||||
use crate::tools::context::SharedTurnDiffTracker;
|
||||
use crate::tools::context::ToolPayload;
|
||||
@@ -80,7 +80,7 @@ impl CodeModeService {
|
||||
pub(crate) fn new(
|
||||
session_provider: Arc<dyn CodeModeSessionProvider>,
|
||||
config: &CodeModeConfig,
|
||||
executed_tool_calls: Option<Arc<ExecutedToolCallRecorder>>,
|
||||
executed_tool_calls: ExecutedToolCalls,
|
||||
) -> Self {
|
||||
let dispatch_broker = Arc::new(CodeModeDispatchBroker::new(executed_tool_calls));
|
||||
let availability = session_provider.availability();
|
||||
|
||||
@@ -123,11 +123,10 @@ impl CodeModeWaitHandler {
|
||||
| codex_code_mode::RuntimeResponse::Result { cell_id, .. } => cell_id,
|
||||
};
|
||||
telemetry.cell_id = Some(runtime_cell_id.to_string());
|
||||
if let Some(executed_tool_calls) =
|
||||
exec.session.services.executed_tool_calls.as_ref()
|
||||
{
|
||||
executed_tool_calls.register_cell(runtime_cell_id, &call_id);
|
||||
}
|
||||
exec.session
|
||||
.services
|
||||
.executed_tool_calls
|
||||
.register_cell(runtime_cell_id, &call_id);
|
||||
if !matches!(response, codex_code_mode::RuntimeResponse::Yielded { .. }) {
|
||||
exec.session
|
||||
.services
|
||||
|
||||
Reference in New Issue
Block a user