Reuse code-mode tool catalogs across executions (#61846)

## Why

Repeated executions with the same tools resend the full catalog and duplicate tool metadata. Catalog revisions let clients reuse an acknowledged catalog within a session.

## What changed

- Negotiate catalog revision support over stdio and gRPC, retaining full requests for hosts without support.
- Send tool definitions when installing a revision, then reference that revision for matching executions. Commit client catalog state only after execution admission succeeds; concurrent admissions can send full requests.
- Keep immutable tool snapshots for each cell, reject invalid, unknown, or conflicting revisions, and share identical definitions and runtime metadata across sessions in the same process.

## Testing

Add tests for acknowledged reuse, abandoned admissions, changed definitions, revision conflicts, session isolation, snapshot lifetimes, and shared metadata.

GitOrigin-RevId: d2f29bf668bc2279715f5f1b7d24310923c57d33
This commit is contained in:
Charlie Marsh
2026-11-16 17:47:49 +00:00
committed by copyberry
parent e0241d4fae
commit fef47a6769
32 changed files with 394 additions and 43 deletions
@@ -25,6 +25,7 @@ fn rejects_missing_names_unknown_tool_kinds_and_invalid_json_schemas() {
output_schema_json: None,
};
let request = |definition| proto::ExecuteRequest {
catalog_revision: None,
session_id: "session".to_string(),
execution_id: "execution".to_string(),
tool_call_id: "call".to_string(),
+2 -1
View File
@@ -219,6 +219,7 @@ impl GrpcCodeModeHost {
validation::identifier(&request.execution_id, "execution ID")?;
let request_permit = self.state.request_permit()?;
let execution_id = request.execution_id.clone();
let catalog_revision = request.catalog_revision;
let request = conversions::execute_request(request)?;
let cell_permit = self.state.cell_permit()?;
let yield_signal = session.reserve_execution(&execution_id)?;
@@ -230,7 +231,7 @@ impl GrpcCodeModeHost {
_ = session.closed.cancelled() => {
return Err(Status::cancelled("code-mode session is closed"));
}
result = session.runtime.execute(request, Arc::new(delegate::GrpcDelegate::new(Arc::downgrade(&session))), Some(yield_signal)) => {
result = session.runtime.execute_with_catalog(request, catalog_revision, Arc::new(delegate::GrpcDelegate::new(Arc::downgrade(&session))), Some(yield_signal)) => {
result.map_err(Status::failed_precondition)?
}
};
@@ -99,6 +99,7 @@ pub(super) fn execute_request(
source: &str,
) -> proto::ExecuteRequest {
proto::ExecuteRequest {
catalog_revision: None,
session_id: session_id.to_string(),
execution_id: execution_id.to_string(),
tool_call_id: "outer-call".to_string(),
@@ -130,6 +130,7 @@ impl GrpcHostState {
.try_send(Ok(proto::SessionEvent {
event: Some(proto::session_event::Event::Opened(proto::SessionOpened {
session_id: id.to_string(),
supports_catalog_revision: true,
output_truncation: match session.runtime.output_truncation() {
CodeModeOutputTruncation::Server => {
Some(proto::OutputTruncation::Server.into())
@@ -31,6 +31,7 @@ use codex_code_mode_protocol::host::RequestId;
use codex_code_mode_protocol::host::SESSION_RESOURCE_LIMITS_CAPABILITY;
use codex_code_mode_protocol::host::SessionId;
use codex_code_mode_protocol::host::SupportedProtocolVersions;
use codex_code_mode_protocol::host::TOOL_CATALOG_CAPABILITY;
use codex_code_mode_protocol::host::WireContentItem;
use codex_code_mode_protocol::host::WireExecuteRequest;
use codex_code_mode_protocol::host::WireOutputTruncation;
@@ -98,6 +99,7 @@ async fn decode_frame(frame: EncodedFrame) -> HostToClient {
fn execute_request(source: &str) -> WireExecuteRequest {
WireExecuteRequest {
catalog_revision: None,
tool_call_id: "call-1".to_string(),
enabled_tools: Vec::new(),
source: source.to_string(),
@@ -284,6 +286,7 @@ impl AsyncWrite for BlockingWriter {
#[tokio::test]
async fn supported_capabilities_are_negotiated_when_optional_or_required() {
for capability in [
TOOL_CATALOG_CAPABILITY,
SESSION_RESOURCE_LIMITS_CAPABILITY,
BOUNDED_OUTPUT_CAPABILITY,
LARGE_DELEGATE_CAPACITY_CAPABILITY,
+6 -1
View File
@@ -36,6 +36,7 @@ use codex_code_mode_protocol::host::RequestId;
use codex_code_mode_protocol::host::SESSION_RESOURCE_LIMITS_CAPABILITY;
use codex_code_mode_protocol::host::SessionId;
use codex_code_mode_protocol::host::SupportedProtocolVersions;
use codex_code_mode_protocol::host::TOOL_CATALOG_CAPABILITY;
use codex_code_mode_protocol::host::WireWaitOutcome;
use codex_code_mode_protocol::host::YIELD_OBSERVATION_CAPABILITY;
use codex_code_mode_runtime::InProcessCodeModeSession;
@@ -294,6 +295,7 @@ async fn negotiate<R: AsyncRead + Unpin, W: AsyncWrite + Unpin>(
YIELD_OBSERVATION_CAPABILITY,
BOUNDED_OUTPUT_CAPABILITY,
LARGE_DELEGATE_CAPACITY_CAPABILITY,
TOOL_CATALOG_CAPABILITY,
]
.into_iter()
.map(Capability::new)
@@ -451,6 +453,7 @@ impl HostState {
self.respond(request_id, Err("code-mode request cancelled".to_string()));
return;
}
let catalog_revision = request.catalog_revision;
let request = match request.try_into() {
Ok(request) => request,
Err(err) => {
@@ -479,7 +482,9 @@ impl HostState {
session_id.clone(),
Arc::clone(&self.peer),
));
let result = session.execute(request, delegate, Some(yield_signal)).await;
let result = session
.execute_with_catalog(request, catalog_revision, delegate, Some(yield_signal))
.await;
match result {
Ok(started) => {
let cell_id = started.cell_id.clone();
@@ -58,6 +58,7 @@ async fn execution_timing_includes_javascript_but_excludes_delayed_reads() -> Re
let observed = Instant::now();
let mut execution = client
.execute(grpc::ExecuteRequest {
catalog_revision: None,
session_id: opened.session_id.clone(),
execution_id: format!("execution-{index}"),
tool_call_id: format!("call-{index}"),