mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
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:
@@ -21,11 +21,15 @@ use codex_code_mode_protocol::TerminateRequest;
|
||||
use codex_code_mode_protocol::WaitOutcome;
|
||||
use codex_code_mode_protocol::WaitRequest;
|
||||
use codex_code_mode_protocol::host::SessionId;
|
||||
use codex_code_mode_protocol::host::TOOL_CATALOG_CAPABILITY;
|
||||
use codex_code_mode_protocol::host::WireExecuteRequest;
|
||||
use codex_install_context::InstallContext;
|
||||
use tokio::sync::Semaphore;
|
||||
use tokio::sync::watch;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use crate::tool_catalog::CatalogAdmission;
|
||||
|
||||
use self::connection::Connection;
|
||||
use self::connection::ConnectionError;
|
||||
use self::connection::RemoteSession;
|
||||
@@ -224,6 +228,7 @@ enum SessionState {
|
||||
|
||||
#[derive(Clone)]
|
||||
struct SessionBinding {
|
||||
catalog: Arc<tokio::sync::Mutex<crate::tool_catalog::Catalog>>,
|
||||
connection: Arc<Connection>,
|
||||
remote: RemoteSession,
|
||||
cleanup: SessionCleanup,
|
||||
@@ -292,10 +297,28 @@ impl ProcessOwnedCodeModeSession {
|
||||
request.max_output_tokens = self
|
||||
.server_output_budget(request.max_output_tokens)
|
||||
.map(|tokens| tokens.min(i32::MAX as usize));
|
||||
binding
|
||||
let admission = binding
|
||||
.connection
|
||||
.supports(TOOL_CATALOG_CAPABILITY)
|
||||
.then(|| CatalogAdmission::prepare(&binding.catalog, &request.enabled_tools))
|
||||
.flatten();
|
||||
if admission
|
||||
.as_ref()
|
||||
.is_some_and(CatalogAdmission::reuses_catalog)
|
||||
{
|
||||
request.enabled_tools.clear();
|
||||
}
|
||||
let mut request = WireExecuteRequest::try_from(request)
|
||||
.map_err(|error| format!("failed to encode code-mode execute request: {error}"))?;
|
||||
request.catalog_revision = admission.as_ref().map(CatalogAdmission::revision);
|
||||
let started = binding
|
||||
.connection
|
||||
.execute(binding.remote, request, delegate, preempt)
|
||||
.await
|
||||
.await?;
|
||||
if let Some(admission) = admission {
|
||||
admission.accepted();
|
||||
}
|
||||
Ok(started)
|
||||
}
|
||||
|
||||
pub async fn wait(
|
||||
@@ -382,6 +405,7 @@ impl SessionInner {
|
||||
)
|
||||
.await;
|
||||
cleanup.map(|cleanup| SessionBinding {
|
||||
catalog: Default::default(),
|
||||
connection,
|
||||
remote: remote.clone(),
|
||||
cleanup,
|
||||
|
||||
Reference in New Issue
Block a user