mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Defer code-mode tool catalog construction until first access (#61845)
## Why Each cell eagerly built `tools` and `ALL_TOOLS`, even when its code never accessed them. ## What changed - Initialize each catalog global lazily on its first read, preserving writable values and mutations within each cell. - Normalize tool metadata at the service boundary and share it through an `Arc`-backed catalog instead of repeatedly converting it between runtime layers. - Construct catalog properties without invoking inherited setters. ## Testing Add regression tests for cell-local catalog mutations, fresh catalogs across cells, and catalog construction with inherited setters on `Object.prototype` and `Array.prototype`. GitOrigin-RevId: 04695c24ff33d3b3a4335558e9c754844f04e9f0
This commit is contained in:
@@ -22,7 +22,7 @@ pub(crate) use self::types::NestedToolCall;
|
||||
pub(crate) use self::types::Observation;
|
||||
pub(crate) use self::types::ObserveMode;
|
||||
pub(crate) use self::types::SessionRuntimeDelegate;
|
||||
pub(crate) use self::types::ToolDefinition;
|
||||
pub(crate) use self::types::ToolCatalog;
|
||||
pub(crate) use self::types::ToolKind;
|
||||
pub(crate) use self::types::ToolName;
|
||||
use crate::TaskFailureHandler;
|
||||
|
||||
@@ -145,7 +145,7 @@ async fn termination_rejects_a_waiting_store_commit_before_the_next_cell_can_loa
|
||||
CreateCellRequest {
|
||||
output_truncation: CodeModeOutputTruncation::Client,
|
||||
tool_call_id: "reader".to_string(),
|
||||
enabled_tools: Vec::new(),
|
||||
enabled_tools: Default::default(),
|
||||
source: r#"text(String(load("candidate")));"#.to_string(),
|
||||
},
|
||||
ObserveMode::YieldAfter(Duration::from_secs(1)),
|
||||
@@ -170,7 +170,7 @@ fn execute_request(source: &str) -> CreateCellRequest {
|
||||
CreateCellRequest {
|
||||
output_truncation: CodeModeOutputTruncation::Client,
|
||||
tool_call_id: "call-1".to_string(),
|
||||
enabled_tools: Vec::new(),
|
||||
enabled_tools: Default::default(),
|
||||
source: source.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use serde_json::Value as JsonValue;
|
||||
@@ -79,24 +80,19 @@ pub(crate) enum CellEvent {
|
||||
},
|
||||
}
|
||||
|
||||
/// Tool metadata in callback slot order for the lifetime of a cell.
|
||||
pub(crate) type ToolCatalog = Arc<[codex_code_mode_protocol::EnabledToolMetadata]>;
|
||||
|
||||
/// Transport-neutral input for creating a cell.
|
||||
///
|
||||
/// The owning session assigns the cell ID when it admits the request.
|
||||
pub(crate) struct CreateCellRequest {
|
||||
pub(crate) output_truncation: codex_code_mode_protocol::CodeModeOutputTruncation,
|
||||
pub(crate) tool_call_id: String,
|
||||
pub(crate) enabled_tools: Vec<ToolDefinition>,
|
||||
pub(crate) enabled_tools: ToolCatalog,
|
||||
pub(crate) source: String,
|
||||
}
|
||||
|
||||
/// Tool metadata exposed to code running inside a cell.
|
||||
pub(crate) struct ToolDefinition {
|
||||
pub(crate) name: String,
|
||||
pub(crate) tool_name: ToolName,
|
||||
pub(crate) description: String,
|
||||
pub(crate) kind: ToolKind,
|
||||
}
|
||||
|
||||
/// A tool name with an optional namespace.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub(crate) struct ToolName {
|
||||
|
||||
Reference in New Issue
Block a user