mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
## 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
53 lines
1.8 KiB
Rust
53 lines
1.8 KiB
Rust
#![cfg(test)]
|
|
|
|
use super::*;
|
|
use codex_code_mode_protocol::CodeModeToolKind;
|
|
use codex_protocol::ToolName;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn references_require_an_acknowledged_matching_admission() {
|
|
let cache = Arc::new(Mutex::new(Catalog::default()));
|
|
let mut tools = [ToolDefinition {
|
|
name: "echo".to_string(),
|
|
tool_name: ToolName::plain("echo"),
|
|
description: String::new(),
|
|
kind: CodeModeToolKind::Function,
|
|
input_schema: None,
|
|
input_schema_max_bytes: None,
|
|
output_schema: None,
|
|
}];
|
|
let cancelled = CatalogAdmission::prepare(&cache, &tools).unwrap();
|
|
assert!(!cancelled.reuses_catalog());
|
|
assert!(CatalogAdmission::prepare(&cache, &tools).is_none());
|
|
let abandoned_revision = cancelled.revision();
|
|
drop(cancelled);
|
|
let registration = CatalogAdmission::prepare(&cache, &tools).unwrap();
|
|
assert!(!registration.reuses_catalog());
|
|
assert!(registration.revision() > abandoned_revision);
|
|
let revision = registration.revision();
|
|
registration.accepted();
|
|
let hit = CatalogAdmission::prepare(&cache, &tools).unwrap();
|
|
assert!(hit.reuses_catalog());
|
|
assert_eq!(hit.revision(), revision);
|
|
hit.accepted();
|
|
let other = Arc::new(Mutex::new(Catalog::default()));
|
|
let registration = CatalogAdmission::prepare(&other, &tools).unwrap();
|
|
assert!(!registration.reuses_catalog());
|
|
registration.accepted();
|
|
{
|
|
let first = cache.try_lock().unwrap();
|
|
let second = other.try_lock().unwrap();
|
|
assert!(Arc::ptr_eq(
|
|
&first.tools.as_ref().unwrap()[0],
|
|
&second.tools.as_ref().unwrap()[0],
|
|
));
|
|
}
|
|
tools[0].description = "changed".to_string();
|
|
assert!(
|
|
!CatalogAdmission::prepare(&cache, &tools)
|
|
.unwrap()
|
|
.reuses_catalog()
|
|
);
|
|
}
|