From f3037cafd32b2097dae718eb86bcc9182dc0a5d1 Mon Sep 17 00:00:00 2001 From: Anthony Tafoya Date: Mon, 21 Sep 2026 17:13:18 +0000 Subject: [PATCH] Refresh host-supplied cloud skills at turn startup (#47074) ## What changed - Replace the built-in orchestrator skill provider with a host-supplied cloud provider, using `cloud` authority and `c` root aliases in skill tools and prompts. - Add `cloud.skills.enabled`, defaulting to true but requiring a supplied provider. Keep `orchestrator.skills` accepted as a legacy no-op setting, and remove the app server's automatic orchestrator provider registration. - Discover cloud skills once per turn during cancellable startup. Serve catalog snapshots to prompts and tools without triggering discovery or retries. - Scope cached catalogs and resources to authentication state. Preserve them on refresh failures within the same scope, invalidate them when that scope changes, and reject late discovery or read results from replaced cache generations. - Reuse executor discovery catalogs only when successful discovery inputs and bundled-skill settings match. ## Testing Add coverage for per-turn refresh, skill removal, same-account failures and reconnects, authentication changes, and stale in-flight results. Update configuration and tool tests for cloud authority, provider gating, and resource reads without an executor. GitOrigin-RevId: c57e38ec7dcc880c0d4c8a2995adfd3e28301079 --- codex-rs/Cargo.lock | 1 - codex-rs/app-server/src/extensions.rs | 5 +- .../app-server/tests/suite/v2/mcp_resource.rs | 295 +------ .../mcp_resource/plugin_metadata_refresh.rs | 210 +++-- codex-rs/cli/src/main.rs | 2 +- codex-rs/config/src/config_toml.rs | 20 +- codex-rs/core/config.schema.json | 52 +- codex-rs/core/src/config/config_tests.rs | 50 +- codex-rs/core/src/config/mod.rs | 20 +- .../core/tests/suite/model_visible_layout.rs | 2 +- codex-rs/core/tests/suite/plugins.rs | 2 +- codex-rs/core/tests/suite/scenarios.rs | 6 +- codex-rs/core/tests/suite/skills.rs | 2 +- codex-rs/core/tests/suite/skills_extension.rs | 697 +-------------- .../skills_extension/cloud_lifecycle_tests.rs | 319 +++++++ .../skills_extension/cloud_skill_tests.rs | 835 ++++++++++++++++++ ...arios__astra_disabled_executor_skills.snap | 4 +- codex-rs/core/tests/suite/token_budget.rs | 2 +- codex-rs/ext/skills/Cargo.toml | 1 - codex-rs/ext/skills/src/aliases_tests.rs | 2 +- codex-rs/ext/skills/src/catalog.rs | 12 +- codex-rs/ext/skills/src/catalog_prompt.rs | 19 +- codex-rs/ext/skills/src/cloud_cache_tests.rs | 163 ++++ codex-rs/ext/skills/src/cloud_skill.rs | 67 ++ codex-rs/ext/skills/src/config.rs | 4 +- codex-rs/ext/skills/src/extension.rs | 36 +- codex-rs/ext/skills/src/host_prompt.rs | 2 +- codex-rs/ext/skills/src/lib.rs | 4 +- codex-rs/ext/skills/src/provider.rs | 4 +- .../ext/skills/src/provider/orchestrator.rs | 380 -------- codex-rs/ext/skills/src/render.rs | 114 ++- .../ext/skills/src/render_observability.rs | 4 +- codex-rs/ext/skills/src/render_tests.rs | 63 +- .../src/shadow_selection_experiment/mod.rs | 6 +- .../ext/skills/src/skills_extension_state.rs | 168 ++++ codex-rs/ext/skills/src/sources.rs | 18 +- codex-rs/ext/skills/src/state.rs | 504 ++++++----- codex-rs/ext/skills/src/tools/mod.rs | 48 +- codex-rs/ext/skills/src/tools/read.rs | 4 +- codex-rs/ext/skills/src/world_state.rs | 18 +- .../ext/skills/src/world_state_catalogs.rs | 51 +- .../tests/executor_file_system_authority.rs | 12 +- codex-rs/ext/skills/tests/skills_extension.rs | 448 +++++----- codex-rs/thread-manager-sample/src/main.rs | 2 +- .../tui/src/temporary_structured_request.rs | 2 +- 45 files changed, 2505 insertions(+), 2175 deletions(-) create mode 100644 codex-rs/core/tests/suite/skills_extension/cloud_lifecycle_tests.rs create mode 100644 codex-rs/core/tests/suite/skills_extension/cloud_skill_tests.rs create mode 100644 codex-rs/ext/skills/src/cloud_cache_tests.rs create mode 100644 codex-rs/ext/skills/src/cloud_skill.rs delete mode 100644 codex-rs/ext/skills/src/provider/orchestrator.rs create mode 100644 codex-rs/ext/skills/src/skills_extension_state.rs diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 52bb0e3578..641848377e 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -4658,7 +4658,6 @@ dependencies = [ "tokio", "toml 0.9.11+spec-1.1.0", "tracing", - "url", ] [[package]] diff --git a/codex-rs/app-server/src/extensions.rs b/codex-rs/app-server/src/extensions.rs index 34adaff2f2..c2d6d6d0a2 100644 --- a/codex-rs/app-server/src/extensions.rs +++ b/codex-rs/app-server/src/extensions.rs @@ -103,9 +103,6 @@ pub(crate) fn thread_extensions( }); let skill_providers = codex_skills_extension::SkillProviders::new() .with_executor_provider(executor_skill_provider) - .with_orchestrator_provider(Arc::new( - codex_skills_extension::OrchestratorSkillProvider::new(), - )) .with_host_provider(Arc::new(codex_skills_extension::HostSkillProvider::new())); codex_skills_extension::install_with_providers_and_metrics( &mut builder, @@ -115,7 +112,7 @@ pub(crate) fn thread_extensions( include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: config.bundled_skills_enabled(), - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: config .features .enabled(codex_features::Feature::SkillSearch), diff --git a/codex-rs/app-server/tests/suite/v2/mcp_resource.rs b/codex-rs/app-server/tests/suite/v2/mcp_resource.rs index 426e5b051c..c2b21c336a 100644 --- a/codex-rs/app-server/tests/suite/v2/mcp_resource.rs +++ b/codex-rs/app-server/tests/suite/v2/mcp_resource.rs @@ -131,7 +131,6 @@ const TEST_ELICITATION_RESOURCE_URI: &str = "test://codex/elicitation"; const TEST_ELICITATION_RESOURCE_TEXT: &str = "Threadless elicitation was declined."; const SKILL_NAME: &str = "demo-plugin:deploy"; const RAW_SKILL_DESCRIPTION: &str = "Deploy\nthrough the orchestrator."; -const SKILL_DESCRIPTION: &str = "Deploy through the <hosted> orchestrator."; const SKILL_RESOURCE_URI: &str = "skill://plugin_demo/deploy"; const SKILL_MAIN_PROMPT_URI: &str = "skill://plugin_demo/deploy/SKILL.md"; const SKILL_REFERENCE_URI: &str = "skill://plugin_demo/deploy/references/deploy.md"; @@ -147,10 +146,6 @@ const SKILL_CONTENTS: &str = concat!( ); const SKILL_REFERENCE_CONTENTS: &str = "# Deploy reference\n\nUse the orchestrator deployment API.\n"; -const SKILLS_LIST_CALL_ID: &str = "skills-list"; -const SKILLS_READ_MAIN_CALL_ID: &str = "skills-read-main"; -const SKILLS_READ_CALL_ID: &str = "skills-read"; -const SKILLS_READ_AGAIN_CALL_ID: &str = "skills-read-again"; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn mcp_resource_read_returns_resource_contents() -> Result<()> { @@ -262,282 +257,7 @@ async fn mcp_resource_read_preserves_protocol_errors(protocol: ProtocolVersion) } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn orchestrator_skill_can_read_referenced_resource_without_an_executor() -> Result<()> { - let responses_server = responses::start_mock_server().await; - let (apps_server_url, apps_server_calls, apps_server_handle) = - start_resource_apps_mcp_server().await?; - let responses_server_uri = responses_server.uri(); - let (_codex_home, mut mcp) = start_resource_test_app_server( - &apps_server_url, - &responses_server_uri, - ResourceTestEnvironment::Auto, - ) - .await?; - - let thread_start_id = mcp - .send_thread_start_request(ThreadStartParams { - model: Some("gpt-5.5".to_string()), - environments: Some(Vec::new()), - ..Default::default() - }) - .await?; - let ThreadStartResponse { thread, .. } = - timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(thread_start_id)).await??; - - let response_mock = responses::mount_sse_sequence( - &responses_server, - vec![ - responses::sse(vec![ - responses::ev_response_created("resp-skills-read-main"), - responses::ev_function_call_with_namespace( - SKILLS_READ_MAIN_CALL_ID, - "skills", - "read", - &json!({ - "package": SKILL_RESOURCE_URI, - }) - .to_string(), - ), - responses::ev_completed("resp-skills-read-main"), - ]), - responses::sse(vec![ - responses::ev_response_created("resp-skills-list"), - responses::ev_function_call_with_namespace( - SKILLS_LIST_CALL_ID, - "skills", - "list", - &json!({ - "authority": { - "kind": "orchestrator", - }, - }) - .to_string(), - ), - responses::ev_completed("resp-skills-list"), - ]), - responses::sse(vec![ - responses::ev_response_created("resp-skills-read"), - responses::ev_function_call_with_namespace( - SKILLS_READ_CALL_ID, - "skills", - "read", - &json!({ - "package": SKILL_RESOURCE_URI, - "authority": { - "kind": "orchestrator", - }, - "resource": SKILL_REFERENCE_URI, - }) - .to_string(), - ), - responses::ev_completed("resp-skills-read"), - ]), - responses::sse(vec![ - responses::ev_response_created("resp-skills-read-again"), - responses::ev_function_call_with_namespace( - SKILLS_READ_AGAIN_CALL_ID, - "skills", - "read", - &json!({ - "package": SKILL_RESOURCE_URI, - "resource": SKILL_REFERENCE_URI, - }) - .to_string(), - ), - responses::ev_completed("resp-skills-read-again"), - ]), - responses::sse(vec![ - responses::ev_response_created("resp-orchestrator-skill"), - responses::ev_assistant_message("msg-orchestrator-skill", "Done"), - responses::ev_completed("resp-orchestrator-skill"), - ]), - responses::sse(vec![ - responses::ev_response_created("resp-orchestrator-skill-after-refresh"), - responses::ev_assistant_message("msg-orchestrator-skill-after-refresh", "Done"), - responses::ev_completed("resp-orchestrator-skill-after-refresh"), - ]), - ], - ) - .await; - let turn_start_id = mcp - .send_turn_start_request(TurnStartParams { - thread_id: thread.id.clone(), - input: vec![UserInput::Text { - text: "Use the deployment capability.".to_string(), - text_elements: Vec::new(), - }], - ..Default::default() - }) - .await?; - let _: TurnStartResponse = - timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(turn_start_id)).await??; - timeout( - DEFAULT_READ_TIMEOUT, - mcp.read_stream_until_notification_message("turn/completed"), - ) - .await??; - - let requests = response_mock.requests(); - assert_eq!(requests.len(), 5); - let first_request = &requests[0]; - assert!(first_request.tool_by_name("skills", "list").is_some()); - let read_tool = first_request - .tool_by_name("skills", "read") - .ok_or_else(|| anyhow::anyhow!("skills.read should be available"))?; - assert_eq!(read_tool["parameters"]["required"], json!(["package"])); - assert!( - read_tool["parameters"]["properties"] - .get("authority") - .is_none() - ); - assert!(first_request.tool_by_name("skills", "search").is_none()); - - let developer_messages = first_request.message_input_texts("developer"); - let catalog_line = - format!("- {SKILL_NAME}: {SKILL_DESCRIPTION} (orchestrator package: o0/deploy)"); - assert!( - developer_messages - .iter() - .any(|text| text.contains("- `o0` = `skill://plugin_demo`")) - ); - assert_eq!( - 1, - developer_messages - .iter() - .filter(|text| text.contains(&catalog_line)) - .count() - ); - assert!( - developer_messages - .iter() - .all(|text| !text.contains("ignored-plugin:ignored")) - ); - assert!( - developer_messages - .iter() - .any(|text| text.contains("do not treat `skill://` identifiers as filesystem paths")) - ); - assert!( - first_request - .message_input_texts("user") - .into_iter() - .all(|text| !text.starts_with("")) - ); - - let main_read_output = requests[1] - .function_call_output_text(SKILLS_READ_MAIN_CALL_ID) - .ok_or_else(|| anyhow::anyhow!("skills.read output should be sent to the model"))?; - assert_eq!( - serde_json::from_str::(&main_read_output)?, - json!({ - "resource": SKILL_MAIN_PROMPT_URI, - "contents": SKILL_CONTENTS, - "next_cursor": null, - }) - ); - - let list_output = requests[2] - .function_call_output_text(SKILLS_LIST_CALL_ID) - .ok_or_else(|| anyhow::anyhow!("skills.list output should be sent to the model"))?; - assert_eq!( - serde_json::from_str::(&list_output)?, - json!({ - "skills": [{ - "authority": { - "kind": "orchestrator", - }, - "package": SKILL_RESOURCE_URI, - "name": SKILL_NAME, - "description": SKILL_DESCRIPTION, - "main_resource": SKILL_MAIN_PROMPT_URI, - }], - "warnings": ["Orchestrator skill discovery stopped after 2 resource pages: failed to list orchestrator skill resources: resources/list failed for `codex_apps`: Mcp error: -32603: simulated later-page failure"], - "next_cursor": null, - }) - ); - - let read_output = requests[3] - .function_call_output_text(SKILLS_READ_CALL_ID) - .ok_or_else(|| anyhow::anyhow!("skills.read output should be sent to the model"))?; - assert_eq!( - serde_json::from_str::(&read_output)?, - json!({ - "resource": SKILL_REFERENCE_URI, - "contents": SKILL_REFERENCE_CONTENTS, - "next_cursor": null, - }) - ); - let repeated_read_output = requests[4] - .function_call_output_text(SKILLS_READ_AGAIN_CALL_ID) - .ok_or_else(|| { - anyhow::anyhow!("repeated skills.read output should be sent to the model") - })?; - assert_eq!(read_output, repeated_read_output); - assert_eq!( - ResourceAppsMcpCallCounts { - list_resources: 3, - main_prompt_reads: 1, - reference_reads: 1, - }, - apps_server_calls.snapshot() - ); - - let refresh_request_id = mcp - .send_raw_request("config/mcpServer/reload", /*params*/ None) - .await?; - timeout( - DEFAULT_READ_TIMEOUT, - mcp.read_stream_until_response_message(RequestId::Integer(refresh_request_id)), - ) - .await??; - - let refreshed_turn_start_id = mcp - .send_turn_start_request(TurnStartParams { - thread_id: thread.id, - input: vec![UserInput::Text { - text: format!("Use ${SKILL_NAME} after refreshing MCP"), - text_elements: Vec::new(), - }], - ..Default::default() - }) - .await?; - let _: TurnStartResponse = timeout( - DEFAULT_READ_TIMEOUT, - mcp.read_response(refreshed_turn_start_id), - ) - .await??; - timeout( - DEFAULT_READ_TIMEOUT, - mcp.read_stream_until_notification_message("turn/completed"), - ) - .await??; - - let requests = response_mock.requests(); - assert_eq!(requests.len(), 6); - let skill_fragments = requests[5] - .message_input_texts("user") - .into_iter() - .filter(|text| text.starts_with("")) - .collect::>(); - assert_eq!(1, skill_fragments.len()); - assert!(skill_fragments[0].contains(&format!("{SKILL_NAME}"))); - assert!(skill_fragments[0].contains(SKILL_MARKER)); - assert!(skill_fragments[0].contains(SKILL_REFERENCE_URI)); - assert_eq!( - ResourceAppsMcpCallCounts { - list_resources: 6, - main_prompt_reads: 2, - reference_reads: 1, - }, - apps_server_calls.snapshot() - ); - apps_server_handle.abort(); - let _ = apps_server_handle.await; - Ok(()) -} - -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn local_executor_does_not_expose_orchestrator_skills() -> Result<()> { +async fn local_executor_does_not_expose_cloud_skills() -> Result<()> { let responses_server = responses::start_mock_server().await; let (apps_server_url, _apps_server_calls, apps_server_handle) = start_resource_apps_mcp_server().await?; @@ -607,8 +327,12 @@ async fn local_executor_does_not_expose_orchestrator_skills() -> Result<()> { Ok(()) } +#[test_case(""; "default_off")] +#[test_case("[cloud.skills]\nenabled = false"; "explicitly_disabled")] +#[test_case("[orchestrator.skills]\nenabled = true"; "legacy_setting_ignored")] +#[test_case("[cloud.skills]\nenabled = true"; "enabled_without_provider")] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn disabled_orchestrator_skills_do_not_expose_skills_namespace() -> Result<()> { +async fn missing_cloud_provider_does_not_expose_skills_namespace(extra_config: &str) -> Result<()> { let responses_server = responses::start_mock_server().await; let (apps_server_url, apps_server_calls, apps_server_handle) = start_resource_apps_mcp_server().await?; @@ -616,10 +340,7 @@ async fn disabled_orchestrator_skills_do_not_expose_skills_namespace() -> Result let (_codex_home, mut mcp) = start_resource_test_app_server_with_extra_config( &apps_server_url, &responses_server_uri, - r#" -[orchestrator.skills] -enabled = false -"#, + extra_config, ResourceTestEnvironment::Auto, ) .await?; @@ -1485,7 +1206,7 @@ pub(super) async fn start_resource_test_app_server( start_resource_test_app_server_with_extra_config( apps_server_url, responses_server_uri, - "", + "[cloud.skills]\nenabled = true", environment, ) .await diff --git a/codex-rs/app-server/tests/suite/v2/mcp_resource/plugin_metadata_refresh.rs b/codex-rs/app-server/tests/suite/v2/mcp_resource/plugin_metadata_refresh.rs index ee8b4d52c0..77ea32a5f9 100644 --- a/codex-rs/app-server/tests/suite/v2/mcp_resource/plugin_metadata_refresh.rs +++ b/codex-rs/app-server/tests/suite/v2/mcp_resource/plugin_metadata_refresh.rs @@ -1,17 +1,20 @@ -//! Exercises installed-metadata refreshes against live MCP and skill caches. +//! Exercises installed-metadata refreshes against live MCP and bundled plugin skills. use super::*; use axum::Json; use axum::routing::get; use codex_app_server_protocol::PluginInstalledResponse; use codex_app_server_protocol::PluginReconcileResponse; +use codex_app_server_protocol::SkillMetadata; +use codex_app_server_protocol::SkillsListParams; +use codex_app_server_protocol::SkillsListResponse; use flate2::Compression; use flate2::write::GzEncoder; use pretty_assertions::assert_eq; use tokio::sync::RwLock; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn signed_image_renewal_preserves_live_mcp_and_skills() -> Result<()> { +async fn signed_image_renewal_preserves_live_mcp_and_plugin_skills() -> Result<()> { let responses_server = responses::start_mock_server().await; let listener = TcpListener::bind("127.0.0.1:0").await?; let base_url = format!("http://{}", listener.local_addr()?); @@ -33,13 +36,17 @@ async fn signed_image_renewal_preserves_live_mcp_and_skills() -> Result<()> { }, "enabled": true, }))); - let manifest = br#"{"name":"demo-plugin"}"#; let mut archive = tar::Builder::new(GzEncoder::new(Vec::new(), Compression::default())); - let mut header = tar::Header::new_gnu(); - header.set_size(manifest.len() as u64); - header.set_mode(/*mode*/ 0o644); - header.set_cksum(); - archive.append_data(&mut header, ".codex-plugin/plugin.json", &manifest[..])?; + for (path, contents) in [ + (".codex-plugin/plugin.json", r#"{"name":"demo-plugin"}"#), + ("skills/deploy/SKILL.md", SKILL_CONTENTS), + ] { + let mut header = tar::Header::new_gnu(); + header.set_size(contents.len() as u64); + header.set_mode(/*mode*/ 0o644); + header.set_cksum(); + archive.append_data(&mut header, path, contents.as_bytes())?; + } let bundle = archive.into_inner()?.finish()?; let calls = Arc::new(ResourceAppsMcpCalls::default()); @@ -49,9 +56,9 @@ async fn signed_image_renewal_preserves_live_mcp_and_skills() -> Result<()> { let mcp_service = StreamableHttpService::new( move || { server_sessions.fetch_add(1, Ordering::SeqCst); - Ok(MetadataMcpServer(ResourceAppsMcpServer { + Ok(ResourceAppsMcpServer { calls: Arc::clone(&server_calls), - })) + }) }, Arc::new(LocalSessionManager::default()), StreamableHttpServerConfig::default(), @@ -103,7 +110,7 @@ async fn signed_image_renewal_preserves_live_mcp_and_skills() -> Result<()> { .build_initialized() .await?; refresh_and_expect_logo(&mut app_server, original_logo).await?; - // Hosted skills are exposed without a local executor, as in the other resource tests. + // MCP resource reads do not require an executor or a registered cloud-skill provider. let request_id = app_server .send_thread_start_request(ThreadStartParams { model: Some("gpt-5.5".to_string()), @@ -114,39 +121,56 @@ async fn signed_image_renewal_preserves_live_mcp_and_skills() -> Result<()> { let ThreadStartResponse { thread, .. } = timeout(DEFAULT_READ_TIMEOUT, app_server.read_response(request_id)).await??; - read_skill_in_turn(&mut app_server, &responses_server, &thread.id).await?; + read_mcp_skill_resource(&mut app_server, &thread.id).await?; let warm_sessions = sessions.load(Ordering::SeqCst); assert!(warm_sessions > 0); - let warm_calls = calls.snapshot(); - assert_eq!(warm_calls.list_resources, 1); - assert_eq!(warm_calls.main_prompt_reads, 1); + let warm_skills = list_plugin_skills(&mut app_server, codex_home.path()).await?; + assert_eq!(warm_skills.len(), 1); + assert_eq!(warm_skills[0].name, SKILL_NAME); + assert_eq!( + warm_skills[0].description, + "Deploy through the orchestrator." + ); + assert!(warm_skills[0].enabled); + assert_eq!( + std::fs::read_to_string(warm_skills[0].path.as_path())?, + SKILL_CONTENTS + ); installed.write().await["release"]["interface"]["logo_url"] = json!(renewed_logo); refresh_and_expect_logo(&mut app_server, renewed_logo).await?; - read_skill_in_turn(&mut app_server, &responses_server, &thread.id).await?; + read_mcp_skill_resource(&mut app_server, &thread.id).await?; assert_eq!(sessions.load(Ordering::SeqCst), warm_sessions); - assert_eq!(calls.snapshot(), warm_calls); + assert_eq!( + list_plugin_skills(&mut app_server, codex_home.path()).await?, + warm_skills + ); installed.write().await["release"]["interface"]["capabilities"] = json!(["Updated store badge"]); refresh_and_expect_logo(&mut app_server, renewed_logo).await?; - read_skill_in_turn(&mut app_server, &responses_server, &thread.id).await?; + read_mcp_skill_resource(&mut app_server, &thread.id).await?; assert_eq!(sessions.load(Ordering::SeqCst), warm_sessions); - assert_eq!(calls.snapshot(), warm_calls); - - // A policy change must invalidate both caches without rewriting any bundle files. - installed.write().await["release"]["interface"]["logo_url"] = json!(changed_logo); - installed.write().await["authentication_policy"] = json!("ON_INSTALL"); - refresh_and_expect_logo(&mut app_server, changed_logo).await?; - read_skill_in_turn(&mut app_server, &responses_server, &thread.id).await?; - // Core may retain the HTTP connection, but the callback must invalidate resources. assert_eq!( - calls.snapshot(), - ResourceAppsMcpCallCounts { - list_resources: 2, - main_prompt_reads: 2, - reference_reads: 0, - } + list_plugin_skills(&mut app_server, codex_home.path()).await?, + warm_skills + ); + + // Runtime metadata must update the cached skill catalog without changing the bundle. + installed.write().await["release"]["interface"]["logo_url"] = json!(changed_logo); + installed.write().await["enabled"] = json!(false); + refresh_and_expect_logo(&mut app_server, changed_logo).await?; + assert!( + list_plugin_skills(&mut app_server, codex_home.path()) + .await? + .is_empty() + ); + read_mcp_skill_resource(&mut app_server, &thread.id).await?; + assert_eq!(sessions.load(Ordering::SeqCst), warm_sessions); + assert_eq!(calls.snapshot().main_prompt_reads, 4); + assert_eq!( + std::fs::read_to_string(warm_skills[0].path.as_path())?, + SKILL_CONTENTS ); server_handle.abort(); Ok(()) @@ -198,87 +222,51 @@ async fn refresh_and_expect_logo(app_server: &mut TestAppServer, logo: &str) -> Ok(()) } -async fn read_skill_in_turn( +async fn list_plugin_skills( app_server: &mut TestAppServer, - responses_server: &wiremock::MockServer, - thread_id: &str, -) -> Result<()> { - let response_mock = responses::mount_sse_sequence( - responses_server, - vec![ - responses::sse(vec![ - responses::ev_function_call_with_namespace( - "read-main", - "skills", - "read", - &json!({"package": SKILL_RESOURCE_URI}).to_string(), - ), - responses::ev_completed("read"), - ]), - responses::sse(vec![responses::ev_completed("done")]), - ], - ) - .await; - let completed = timeout( - DEFAULT_READ_TIMEOUT, - app_server.start_turn_and_wait_for_completion(TurnStartParams { - thread_id: thread_id.to_string(), - input: vec![UserInput::Text { - text: "Read the deployment skill.".to_string(), - text_elements: Vec::new(), - }], - ..Default::default() - }), - ) - .await??; - assert_eq!(completed.turn.status, TurnStatus::Completed); - let requests = response_mock.requests(); - assert_eq!(requests.len(), 2); - assert!( - requests[0] - .message_input_texts("developer") - .iter() - .any(|text| text.contains(SKILL_NAME)) - ); - let output = requests[1] - .function_call_output_text("read-main") - .context("skill read should reach the model")?; + cwd: &Path, +) -> Result> { + let request = app_server + .send_skills_list_request(SkillsListParams { + cwds: vec![cwd.to_path_buf()], + force_reload: false, + }) + .await?; + let response: SkillsListResponse = + timeout(DEFAULT_READ_TIMEOUT, app_server.read_response(request)).await??; + assert_eq!(response.data.len(), 1); + assert!(response.data[0].errors.is_empty()); + Ok(response + .data + .into_iter() + .flat_map(|entry| entry.skills) + .filter(|skill| skill.plugin_id.as_deref() == Some("demo-plugin@openai-curated-remote")) + .collect()) +} + +async fn read_mcp_skill_resource(app_server: &mut TestAppServer, thread_id: &str) -> Result<()> { + let request = app_server + .send_mcp_resource_read_request(McpResourceReadParams { + thread_id: Some(thread_id.to_string()), + origin_call_id: None, + server: "codex_apps".to_string(), + uri: SKILL_MAIN_PROMPT_URI.to_string(), + connector_id: None, + }) + .await?; + let response: McpResourceReadResponse = + timeout(DEFAULT_READ_TIMEOUT, app_server.read_response(request)).await??; assert_eq!( - serde_json::from_str::(&output)?, - json!({"resource": SKILL_MAIN_PROMPT_URI, "contents": SKILL_CONTENTS, "next_cursor": null}) + response, + McpResourceReadResponse { + contents: vec![McpResourceContent::Text { + uri: SKILL_MAIN_PROMPT_URI.to_string(), + mime_type: Some("text/markdown".to_string()), + text: SKILL_CONTENTS.to_string(), + meta: None, + }], + origin_call_id: None, + } ); Ok(()) } - -// Reuse the resource-read fixture with a healthy, single-page skills catalog. -struct MetadataMcpServer(ResourceAppsMcpServer); - -impl ServerHandler for MetadataMcpServer { - fn get_info(&self) -> ServerInfo { - self.0.get_info() - } - - async fn list_resources( - &self, - _request: Option, - _context: RequestContext, - ) -> Result { - self.0.calls.list_resources.fetch_add(1, Ordering::Relaxed); - Ok(ListResourcesResult::with_all_items(vec![skill_resource( - SKILL_RESOURCE_URI, - "plugin_demo/deploy", - RAW_SKILL_DESCRIPTION, - "mcp/skill", - "demo-plugin", - "deploy", - )])) - } - - async fn read_resource( - &self, - request: ReadResourceRequestParams, - context: RequestContext, - ) -> Result { - self.0.read_resource(request, context).await - } -} diff --git a/codex-rs/cli/src/main.rs b/codex-rs/cli/src/main.rs index 2d9e7ed7f5..b6fc71e830 100644 --- a/codex-rs/cli/src/main.rs +++ b/codex-rs/cli/src/main.rs @@ -2487,7 +2487,7 @@ async fn run_debug_prompt_input_command( include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: config.bundled_skills_enabled(), - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: config .features .enabled(codex_features::Feature::SkillSearch), diff --git a/codex-rs/config/src/config_toml.rs b/codex-rs/config/src/config_toml.rs index bdaee87179..8fe472fb56 100644 --- a/codex-rs/config/src/config_toml.rs +++ b/codex-rs/config/src/config_toml.rs @@ -140,14 +140,23 @@ of strings; comma-separated strings are not supported. Use \ #[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)] #[schemars(deny_unknown_fields)] pub struct OrchestratorToml { - pub skills: Option, - pub mcp: Option, + /// Legacy no-op setting retained for compatibility. Use `cloud.skills` to configure cloud skills. + pub skills: Option, + pub mcp: Option, } -/// Settings for a feature owned by the orchestrator. +/// Cloud-owned feature settings. #[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)] #[schemars(deny_unknown_fields)] -pub struct OrchestratorFeatureToml { +pub struct CloudToml { + /// Cloud skills are permitted by default; the host must supply a cloud provider. + pub skills: Option, +} + +/// Optional enablement of a configured feature. +#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)] +#[schemars(deny_unknown_fields)] +pub struct FeatureToggleToml { pub enabled: Option, } @@ -409,6 +418,9 @@ pub struct ConfigToml { /// Orchestrator-owned feature settings. pub orchestrator: Option, + /// Cloud-owned feature settings. + pub cloud: Option, + /// Base URL override for the built-in `openai` model provider. pub openai_base_url: Option, diff --git a/codex-rs/core/config.schema.json b/codex-rs/core/config.schema.json index 9dffbb207f..4d0ca6ad1d 100644 --- a/codex-rs/core/config.schema.json +++ b/codex-rs/core/config.schema.json @@ -505,6 +505,21 @@ }, "type": "object" }, + "CloudToml": { + "additionalProperties": false, + "description": "Cloud-owned feature settings.", + "properties": { + "skills": { + "allOf": [ + { + "$ref": "#/definitions/FeatureToggleToml" + } + ], + "description": "Cloud skills are permitted by default; the host must supply a cloud provider." + } + }, + "type": "object" + }, "CodeModeConfigToml": { "additionalProperties": false, "properties": { @@ -1389,6 +1404,16 @@ }, "type": "object" }, + "FeatureToggleToml": { + "additionalProperties": false, + "description": "Optional enablement of a configured feature.", + "properties": { + "enabled": { + "type": "boolean" + } + }, + "type": "object" + }, "FeatureToml_for_CodeModeConfigToml": { "anyOf": [ { @@ -3091,25 +3116,20 @@ } ] }, - "OrchestratorFeatureToml": { - "additionalProperties": false, - "description": "Settings for a feature owned by the orchestrator.", - "properties": { - "enabled": { - "type": "boolean" - } - }, - "type": "object" - }, "OrchestratorToml": { "additionalProperties": false, "description": "Orchestrator-owned feature settings.", "properties": { "mcp": { - "$ref": "#/definitions/OrchestratorFeatureToml" + "$ref": "#/definitions/FeatureToggleToml" }, "skills": { - "$ref": "#/definitions/OrchestratorFeatureToml" + "allOf": [ + { + "$ref": "#/definitions/FeatureToggleToml" + } + ], + "description": "Legacy no-op setting retained for compatibility. Use `cloud.skills` to configure cloud skills." } }, "type": "object" @@ -6454,6 +6474,14 @@ "default": null, "description": "Preferred backend for storing CLI auth credentials. file (default): Use a file in the Codex home directory. keyring: Use an OS-specific keyring service. auto: Use the keyring if available, otherwise use a file." }, + "cloud": { + "allOf": [ + { + "$ref": "#/definitions/CloudToml" + } + ], + "description": "Cloud-owned feature settings." + }, "compact_prompt": { "description": "Compact prompt used for history compaction.", "type": "string" diff --git a/codex-rs/core/src/config/config_tests.rs b/codex-rs/core/src/config/config_tests.rs index 0bf3dcf638..8a873cdf35 100644 --- a/codex-rs/core/src/config/config_tests.rs +++ b/codex-rs/core/src/config/config_tests.rs @@ -10734,6 +10734,49 @@ apps_mcp_product_sku = "tpp" Ok(()) } +#[tokio::test] +async fn config_loads_cloud_skills_with_legacy_noop() -> std::io::Result<()> { + let codex_home = TempDir::new()?; + for (settings, expected) in [ + ("", true), + ("[cloud.skills]", true), + ("[cloud.skills]\nenabled = false", false), + ("[cloud.skills]\nenabled = true", true), + ("[orchestrator.skills]\nenabled = false", true), + ("[orchestrator.skills]\nenabled = true", true), + ( + "[orchestrator.skills]\nenabled = false\n[cloud.skills]", + true, + ), + ( + "[orchestrator.skills]\nenabled = true\n[cloud.skills]\nenabled = false", + false, + ), + ( + "[orchestrator.skills]\nenabled = false\n[cloud.skills]\nenabled = true", + true, + ), + ] { + let cfg: ConfigToml = toml::from_str(&format!( + "model = \"gpt-5.4\"\n{settings}\n[orchestrator.mcp]\nenabled = false" + )) + .expect("cloud skill settings should deserialize"); + let config = Config::load_from_base_config_with_overrides( + cfg, + ConfigOverrides::default(), + codex_home.abs(), + ) + .await?; + + assert_eq!( + (config.cloud_skill_enabled, config.orchestrator_mcp_enabled), + (expected, false), + "{settings}" + ); + } + Ok(()) +} + #[tokio::test] async fn config_loads_orchestrator_settings_from_toml() -> std::io::Result<()> { let codex_home = TempDir::new()?; @@ -10758,11 +10801,8 @@ enabled = false .await?; assert_eq!( - ( - config.orchestrator_skills_enabled, - config.orchestrator_mcp_enabled - ), - (false, false) + (config.cloud_skill_enabled, config.orchestrator_mcp_enabled), + (true, false) ); Ok(()) } diff --git a/codex-rs/core/src/config/mod.rs b/codex-rs/core/src/config/mod.rs index e71ad88dde..1a26e6a504 100644 --- a/codex-rs/core/src/config/mod.rs +++ b/codex-rs/core/src/config/mod.rs @@ -708,8 +708,8 @@ pub struct Config { /// Optional token budget override for the available-skills catalog. pub skill_max_context_tokens: Option, - /// Whether orchestrator-owned skills are exposed to the model. - pub orchestrator_skills_enabled: bool, + /// Whether cloud skills are discovered and exposed to the model. + pub cloud_skill_enabled: bool, /// Whether orchestrator-owned MCP tools are exposed to the model. pub orchestrator_mcp_enabled: bool, @@ -2672,9 +2672,7 @@ fn resolve_update_plan_enabled(config_toml: &ConfigToml) -> bool { .is_some_and(|config| config.enabled) } -fn resolve_orchestrator_feature_enabled( - feature: Option<&codex_config::config_toml::OrchestratorFeatureToml>, -) -> bool { +fn resolve_feature_enabled(feature: Option<&codex_config::config_toml::FeatureToggleToml>) -> bool { feature.and_then(|feature| feature.enabled).unwrap_or(true) } @@ -3208,10 +3206,14 @@ impl Config { .as_ref(), )?; let orchestrator = cfg.orchestrator.as_ref(); - let orchestrator_skills_enabled = - resolve_orchestrator_feature_enabled(orchestrator.and_then(|value| value.skills.as_ref())); + let cloud_skill_enabled = cfg + .cloud + .as_ref() + .and_then(|cloud| cloud.skills.as_ref()) + .and_then(|skills| skills.enabled) + .unwrap_or(true); let orchestrator_mcp_enabled = - resolve_orchestrator_feature_enabled(orchestrator.and_then(|value| value.mcp.as_ref())); + resolve_feature_enabled(orchestrator.and_then(|value| value.mcp.as_ref())); let mut startup_warnings = config_layer_stack .startup_warnings() .unwrap_or_default() @@ -4224,7 +4226,7 @@ impl Config { include_collaboration_mode_instructions, include_skill_instructions, skill_max_context_tokens, - orchestrator_skills_enabled, + cloud_skill_enabled, orchestrator_mcp_enabled, include_environment_context, // The config.toml omits "_mode" because it's a config file. However, "_mode" diff --git a/codex-rs/core/tests/suite/model_visible_layout.rs b/codex-rs/core/tests/suite/model_visible_layout.rs index bcc0601ff2..75b4aa8e5f 100644 --- a/codex-rs/core/tests/suite/model_visible_layout.rs +++ b/codex-rs/core/tests/suite/model_visible_layout.rs @@ -90,7 +90,7 @@ fn skills_extensions() -> Arc> { include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: config.bundled_skills_enabled(), - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: config.features.enabled(Feature::SkillSearch), }); Arc::new(extensions.build()) diff --git a/codex-rs/core/tests/suite/plugins.rs b/codex-rs/core/tests/suite/plugins.rs index a6498c7a66..17059ac861 100644 --- a/codex-rs/core/tests/suite/plugins.rs +++ b/codex-rs/core/tests/suite/plugins.rs @@ -88,7 +88,7 @@ fn skills_extensions() -> Arc> { include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: config.bundled_skills_enabled(), - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: config.features.enabled(Feature::SkillSearch), }); Arc::new(extensions.build()) diff --git a/codex-rs/core/tests/suite/scenarios.rs b/codex-rs/core/tests/suite/scenarios.rs index 892c319a66..06d5b4f74e 100644 --- a/codex-rs/core/tests/suite/scenarios.rs +++ b/codex-rs/core/tests/suite/scenarios.rs @@ -80,7 +80,7 @@ fn skills_extensions() -> Arc> { include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: config.bundled_skills_enabled(), - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: config.features.enabled(Feature::SkillSearch), }); Arc::new(extensions.build()) @@ -186,7 +186,7 @@ fn configure_scenario_catalog(config: &mut Config) { ) .expect("fixture config layers"); config.model_catalog = Some(bundled_models_response().expect("bundled model catalog")); - config.orchestrator_skills_enabled = false; + config.cloud_skill_enabled = false; } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -463,7 +463,7 @@ async fn astra_omits_disabled_executor_skills_from_model_context() -> Result<()> include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); diff --git a/codex-rs/core/tests/suite/skills.rs b/codex-rs/core/tests/suite/skills.rs index d44f29b6b8..07b3c35763 100644 --- a/codex-rs/core/tests/suite/skills.rs +++ b/codex-rs/core/tests/suite/skills.rs @@ -325,7 +325,7 @@ async fn user_turn_selects_symlinked_skill_by_advertised_discovery_path() -> Res include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }); let mut builder = test_codex() diff --git a/codex-rs/core/tests/suite/skills_extension.rs b/codex-rs/core/tests/suite/skills_extension.rs index 204afccffd..d2cd7e22b4 100644 --- a/codex-rs/core/tests/suite/skills_extension.rs +++ b/codex-rs/core/tests/suite/skills_extension.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use std::sync::Mutex; use std::sync::atomic::AtomicBool; -use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use anyhow::Result; @@ -44,7 +43,6 @@ use codex_protocol::permissions::FileSystemSandboxEntry; use codex_protocol::permissions::FileSystemSandboxPolicy; use codex_protocol::permissions::FileSystemSpecialPath; use codex_protocol::permissions::NetworkSandboxPolicy; -use codex_protocol::protocol::AskForApproval; use codex_protocol::protocol::Event; use codex_protocol::protocol::EventMsg; use codex_protocol::protocol::Op; @@ -54,7 +52,6 @@ use codex_protocol::protocol::TurnSettingsUpdateOutcome; use codex_protocol::user_input::UserInput; use codex_skills_extension::ExecutorSkillProvider; use codex_skills_extension::HostSkillProvider; -use codex_skills_extension::OrchestratorSkillProvider; use codex_skills_extension::SkillProvider; use codex_skills_extension::SkillProviderSource; use codex_skills_extension::SkillProviders; @@ -108,12 +105,13 @@ use toml::toml; use tracing::Level; use tracing_subscriber::fmt::format::FmtSpan; use tracing_test::internal::MockWriter; -use wiremock::Mock; use wiremock::MockServer; -use wiremock::Request; -use wiremock::ResponseTemplate; -use wiremock::matchers::method; -use wiremock::matchers::path_regex; + +#[path = "skills_extension/cloud_skill_tests.rs"] +mod cloud_skill_tests; + +#[path = "skills_extension/cloud_lifecycle_tests.rs"] +mod cloud_lifecycle_tests; struct StaticSkillProvider { catalog: SkillCatalog, @@ -349,7 +347,7 @@ fn catalog_extensions( include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, } }); @@ -626,7 +624,7 @@ async fn capability_sections_render_in_order_with_host_repo_and_plugin_skills() include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: config.bundled_skills_enabled(), - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: config.features.enabled(Feature::SkillSearch), }); let mut builder = test_codex() @@ -905,617 +903,6 @@ async fn explicit_skill_prompt_precedes_plugin_instructions() -> Result<()> { Ok(()) } -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn explicit_only_orchestrator_skill_is_hidden_but_can_be_invoked() -> Result<()> { - skip_if_no_network!(Ok(())); - - const SKILL_PACKAGE: &str = "skill://demo/explicit-only"; - const MAIN_RESOURCE: &str = "skill://demo/explicit-only/SKILL.md"; - const REFERENCED_RESOURCE: &str = "skill://demo/explicit-only/references/guide.md"; - const READ_CALL_ID: &str = "read-explicit-only-resource"; - const LIST_CALL_ID: &str = "list-model-visible-skills"; - const CODE_MODE_LIST_CALL_ID: &str = "list-skills-through-code-mode"; - const CONTINUATION_CALL_ID: &str = "read-explicit-only-resource-continuation"; - const MAIN_READ_CALL_ID: &str = "read-explicit-only-main"; - const REPEATED_MAIN_READ_CALL_ID: &str = "read-explicit-only-main-again"; - const INVALID_CURSOR_CALL_ID: &str = "read-explicit-only-invalid-cursor"; - const MISSING_PACKAGE_CALL_ID: &str = "read-missing-package"; - const CODE_MODE_CALL_ID: &str = "code-mode-skill-read"; - - // Fill the shared 300-byte page through the emoji; ignoring escaping would fit everything. - let read_prefix = "a".repeat(184); - let referenced_contents = format!("{read_prefix}😀\"\\\nabcdefghijklm"); - let read_contents = referenced_contents.clone(); - let server = responses::start_mock_server().await; - let apps_server = AppsTestServer::mount(&server).await?; - let response = responses::mount_sse_sequence( - &server, - vec![ - sse(vec![ - ev_response_created("resp-1"), - responses::ev_function_call_with_namespace( - READ_CALL_ID, - "skills", - "read", - &json!({ - "package": SKILL_PACKAGE, - "authority": { - "kind": "orchestrator", - }, - "resource": REFERENCED_RESOURCE, - }) - .to_string(), - ), - responses::ev_function_call_with_namespace( - LIST_CALL_ID, - "skills", - "list", - &json!({ "authority": { "kind": "orchestrator" } }).to_string(), - ), - responses::ev_custom_tool_call( - CODE_MODE_LIST_CALL_ID, - "exec", - r#"const result = await tools.skills__list({ authority: { kind: "orchestrator" } }); -text({ names: result.skills.map(skill => skill.name), warnings: result.warnings, next_cursor: result.next_cursor });"#, - ), - ev_completed("resp-1"), - ]), - sse(vec![ev_response_created("resp-2"), ev_completed("resp-2")]), - ], - ) - .await; - - Mock::given(method("POST")) - .and(path_regex("^/api/codex/ps/mcp/?$")) - .and(|request: &Request| { - serde_json::from_slice::(&request.body).is_ok_and(|body| { - matches!( - body["method"].as_str(), - Some("resources/list" | "resources/read") - ) - }) - }) - .respond_with(move |request: &Request| { - let body: Value = serde_json::from_slice(&request.body) - .expect("MCP resource request should be valid JSON"); - let result = match body["method"].as_str() { - Some("resources/list") => { - let resources = [ - ("visible", Some(json!(true))), - ("explicit-only", Some(json!(false))), - ("missing-policy", None), - ("non-boolean-policy", Some(json!("false"))), - ] - .map(|(name, allow_implicit_invocation)| { - let mut metadata = json!({ - "plugin_name": "demo", - "skill_name": name, - }); - if let Some(allow_implicit_invocation) = allow_implicit_invocation { - metadata["allow_implicit_invocation"] = allow_implicit_invocation; - } - json!({ - "name": name, - "uri": format!("skill://demo/{name}"), - "mimeType": "mcp/skill", - "_meta": metadata, - }) - }); - json!({ "resources": resources }) - } - Some("resources/read") => { - let uri = body["params"]["uri"] - .as_str() - .expect("MCP resource read should include a resource URI"); - let contents = match uri { - MAIN_RESOURCE => { - format!("# Explicit-only instructions\nRead {REFERENCED_RESOURCE}.") - } - REFERENCED_RESOURCE => read_contents.clone(), - _ => unreachable!("unexpected MCP resource URI: {uri}"), - }; - json!({ - "contents": [{ - "uri": uri, - "mimeType": "text/markdown", - "text": contents, - }], - }) - } - method => unreachable!("unexpected MCP resource method: {method:?}"), - }; - ResponseTemplate::new(/*status*/ 200).set_body_json(json!({ - "jsonrpc": "2.0", - "id": body["id"], - "result": result, - })) - }) - .with_priority(/*p*/ 1) - .mount(&server) - .await; - - let mut extensions = ExtensionRegistryBuilder::new(); - install_with_providers( - &mut extensions, - SkillProviders::new() - .with_orchestrator_provider(Arc::new(OrchestratorSkillProvider::new())), - |config: &Config| SkillsExtensionConfig { - include_instructions: config.include_skill_instructions, - max_context_tokens: config.skill_max_context_tokens, - bundled_skills_enabled: false, - orchestrator_skills_enabled: true, - shadow_selection_enabled: false, - }, - ); - let mut builder = apps_enabled_builder(apps_server.chatgpt_base_url) - // Local executors disable orchestrator skill discovery. - .with_exec_server_url("none") - .with_extensions(Arc::new(extensions.build())) - .with_model_info_override("gpt-5.5", |model_info| { - model_info.truncation_policy = TruncationPolicyConfig::bytes(/*limit*/ 250); - }) - .with_config(|config| { - config.include_skill_instructions = true; - config.orchestrator_skills_enabled = true; - config - .features - .enable(Feature::CodeMode) - .expect("code mode should be configurable in tests"); - }); - let test = builder.build_with_auto_env(&server).await?; - wait_for_mcp_server(&test.codex, CODEX_APPS_MCP_SERVER_NAME).await?; - - test.submit_turn("Use $demo:explicit-only.").await?; - - let requests = response.requests(); - assert_eq!(requests.len(), 2); - let request = &requests[0]; - let developer_messages = request.message_input_texts("developer"); - for name in ["visible", "missing-policy", "non-boolean-policy"] { - let catalog_entry = format!("- demo:{name}:"); - assert!( - developer_messages - .iter() - .any(|message| message.contains(&catalog_entry)), - "model-visible skills should include `{name}`: {developer_messages:?}" - ); - } - assert!( - developer_messages - .iter() - .all(|message| !message.contains("- demo:explicit-only:")), - "model-visible skills should omit the explicit-only skill: {developer_messages:?}" - ); - let user_messages = request.message_input_texts("user"); - let skill_instructions = user_messages - .iter() - .find(|message| { - message.contains("demo:explicit-only") - && message.contains("# Explicit-only instructions") - && message.contains(REFERENCED_RESOURCE) - }) - .expect("explicit invocation should inject the hidden skill instructions and reference"); - let resource_access = skill_instructions - .split_once("") - .and_then(|(_, remainder)| remainder.split_once("")) - .map(|(metadata, _)| metadata) - .expect("hidden orchestrator skills should include resource-access metadata"); - assert_eq!( - serde_json::from_str::(resource_access)?, - json!({ - "authority": { "kind": "orchestrator" }, - "package": SKILL_PACKAGE, - "main_resource": MAIN_RESOURCE, - }) - ); - let first_output = requests[1] - .function_call_output_text(READ_CALL_ID) - .expect("skills.read should return the referenced resource"); - assert!(first_output.len() <= 300); - let first_page = serde_json::from_str::(&first_output)?; - let cursor = first_page["next_cursor"] - .as_str() - .ok_or_else(|| anyhow::anyhow!("skills.read should return a continuation cursor"))? - .to_string(); - assert_eq!( - first_page, - json!({ - "resource": REFERENCED_RESOURCE, - "contents": format!("{read_prefix}😀"), - "next_cursor": cursor, - }) - ); - let mut list_output = requests[1] - .function_call_output_text(LIST_CALL_ID) - .expect("skills.list should return the model-visible catalog"); - let code_mode_output = requests[1].custom_tool_call_output(CODE_MODE_LIST_CALL_ID); - let code_mode_text = code_mode_output["output"] - .as_array() - .and_then(|items| items.last()) - .and_then(|item| item["text"].as_str()) - .ok_or_else(|| { - anyhow::anyhow!("Code Mode should return its skills.list result: {code_mode_output}") - })?; - assert_eq!( - serde_json::from_str::(code_mode_text)?, - json!({ - "names": ["demo:visible", "demo:missing-policy", "demo:non-boolean-policy"], - "warnings": [], - "next_cursor": null, - }) - ); - let events = wait_for_analytics_events(&server, "skill_invocation", /*expected_count*/ 1).await; - assert_eq!(events.len(), 1); - assert_eq!(events[0]["skill_name"], "demo:explicit-only"); - assert_eq!(events[0]["event_params"]["invoke_type"], "explicit"); - - let response = responses::mount_sse_sequence( - &server, - vec![ - sse(vec![ - ev_response_created("resp-3"), - responses::ev_function_call_with_namespace( - CONTINUATION_CALL_ID, - "skills", - "read", - &json!({ - "package": SKILL_PACKAGE, - "resource": REFERENCED_RESOURCE, - "cursor": cursor, - }) - .to_string(), - ), - responses::ev_function_call_with_namespace( - MAIN_READ_CALL_ID, - "skills", - "read", - &json!({ "package": SKILL_PACKAGE }).to_string(), - ), - responses::ev_function_call_with_namespace( - REPEATED_MAIN_READ_CALL_ID, - "skills", - "read", - &json!({ "package": SKILL_PACKAGE, "resource": MAIN_RESOURCE }).to_string(), - ), - responses::ev_function_call_with_namespace( - INVALID_CURSOR_CALL_ID, - "skills", - "read", - &json!({ "package": SKILL_PACKAGE, "cursor": "invalid" }).to_string(), - ), - responses::ev_function_call_with_namespace( - MISSING_PACKAGE_CALL_ID, - "skills", - "read", - &json!({ "package": "skill://demo/missing" }).to_string(), - ), - ev_completed("resp-3"), - ]), - sse(vec![ev_response_created("resp-4"), ev_completed("resp-4")]), - ], - ) - .await; - - test.submit_turn("Continue without explicitly selecting a skill.") - .await?; - let requests = response.requests(); - assert_eq!(requests.len(), 2); - let continuation_output = requests[1] - .function_call_output_text(CONTINUATION_CALL_ID) - .expect("skills.read should return the next referenced-resource page"); - assert!(continuation_output.len() <= 300); - let continuation_page = serde_json::from_str::(&continuation_output)?; - assert_eq!( - continuation_page, - json!({ - "resource": REFERENCED_RESOURCE, - "contents": "\"\\\nabcdefghijklm", - "next_cursor": null, - }) - ); - assert_eq!( - format!( - "{}{}", - first_page["contents"].as_str().unwrap_or_default(), - continuation_page["contents"].as_str().unwrap_or_default() - ), - referenced_contents - ); - for call_id in [MAIN_READ_CALL_ID, REPEATED_MAIN_READ_CALL_ID] { - let output = requests[1] - .function_call_output_text(call_id) - .expect("skills.read should return the main resource"); - assert_eq!( - serde_json::from_str::(&output)?["resource"], - MAIN_RESOURCE - ); - } - for call_id in [INVALID_CURSOR_CALL_ID, MISSING_PACKAGE_CALL_ID] { - assert!( - requests[1].function_call_output_text(call_id).is_some(), - "failed skills.read should return a tool error for {call_id}" - ); - } - - let events = wait_for_analytics_events(&server, "skill_invocation", /*expected_count*/ 2).await; - assert_eq!(events.len(), 2, "repeated main reads must be deduplicated"); - assert_eq!(events[1]["skill_name"], "demo:explicit-only"); - assert_eq!( - events[1]["skill_id"], - format!("{:x}", sha1::Sha1::digest(MAIN_RESOURCE.as_bytes())) - ); - assert_eq!(events[1]["event_params"]["invoke_type"], "implicit"); - - for (name, has_more) in [ - ("visible", true), - ("missing-policy", true), - ("non-boolean-policy", false), - ] { - assert!(list_output.len() <= 300); - let list_response = serde_json::from_str::(&list_output)?; - let next_cursor = list_response["next_cursor"].as_str(); - assert_eq!(next_cursor.is_some(), has_more); - assert_eq!( - list_response, - json!({ - "skills": [{ - "authority": {"kind": "orchestrator"}, - "package": format!("skill://demo/{name}"), - "name": format!("demo:{name}"), - "description": "", - "main_resource": format!("skill://demo/{name}/SKILL.md"), - }], - "warnings": [], - "next_cursor": next_cursor, - }) - ); - if let Some(cursor) = next_cursor { - let call_id = format!("list-after-{name}"); - let page = responses::mount_sse_sequence( - &server, - vec![ - sse(vec![ - ev_response_created(&call_id), - responses::ev_function_call_with_namespace( - &call_id, - "skills", - "list", - &json!({ - "authority": { "kind": "orchestrator" }, - "cursor": cursor, - }) - .to_string(), - ), - ev_completed(&call_id), - ]), - sse(vec![ev_response_created("listed"), ev_completed("listed")]), - ], - ) - .await; - test.submit_turn("Continue listing skills.").await?; - list_output = page.requests()[1] - .function_call_output_text(&call_id) - .expect("skills.list should return the next page"); - } - } - - let response = responses::mount_sse_sequence( - &server, - vec![ - sse(vec![ - ev_response_created("resp-5"), - responses::ev_custom_tool_call( - CODE_MODE_CALL_ID, - "exec", - &format!( - "const result = await tools.skills__read({{package: {SKILL_PACKAGE:?}, resource: {REFERENCED_RESOURCE:?}}}); text(JSON.stringify({{contents: result.contents, next_cursor: result.next_cursor}}));" - ), - ), - ev_completed("resp-5"), - ]), - sse(vec![ev_response_created("resp-6"), ev_completed("resp-6")]), - ], - ) - .await; - test.submit_turn("Read the complete skill resource using code mode.") - .await?; - let requests = response.requests(); - assert_eq!(requests.len(), 2); - let output = requests[1].custom_tool_call_output(CODE_MODE_CALL_ID); - let nested_result = output["output"] - .as_array() - .and_then(|items| items.last()) - .and_then(|item| item["text"].as_str()) - .ok_or_else(|| anyhow::anyhow!("code mode should return the nested skill result"))?; - assert_eq!( - serde_json::from_str::(nested_result)?, - json!({"contents": referenced_contents, "next_cursor": null}) - ); - - Ok(()) -} - -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn production_turn_reuses_orchestrator_skills_until_mcp_invalidation() -> Result<()> { - skip_if_no_network!(Ok(())); - - const SKILL_ROOT: &str = "skill://plugin_connector_1p_2330815c823c8191941e5dc465bb899f"; - const SKILL_BODY: &str = "ORCHESTRATOR_SKILL_REMAINS_AVAILABLE_WITHOUT_HOST_DISCOVERY"; - const UPDATED_SKILL_BODY: &str = "UPDATED_ORCHESTRATOR_SKILL"; - - let server = responses::start_mock_server().await; - let (apps_server, startup) = AppsTestServer::mount_with_startup_control(&server).await?; - let response = responses::mount_sse_sequence( - &server, - (1..=5) - .map(|index| { - let id = format!("resp-{index}"); - sse(vec![ev_response_created(&id), ev_completed(&id)]) - }) - .collect(), - ) - .await; - let list_calls = Arc::new(AtomicUsize::new(0)); - let read_calls = Arc::new(AtomicUsize::new(0)); - let updated = Arc::new(AtomicBool::new(false)); - let resource_list_calls = Arc::clone(&list_calls); - let resource_read_calls = Arc::clone(&read_calls); - let resource_updated = Arc::clone(&updated); - - Mock::given(method("POST")) - .and(path_regex("^/api/codex/ps/mcp/?$")) - .and(|request: &Request| { - serde_json::from_slice::(&request.body).is_ok_and(|body| { - matches!( - body["method"].as_str(), - Some("resources/list" | "resources/read") - ) - }) - }) - .respond_with(move |request: &Request| { - let body: Value = serde_json::from_slice(&request.body) - .expect("MCP resource request should be valid JSON"); - let result = if body["method"] == "resources/read" { - resource_read_calls.fetch_add(1, Ordering::SeqCst); - let uri = format!("{SKILL_ROOT}/search/SKILL.md"); - assert_eq!(body["params"]["uri"], uri); - let contents = if resource_updated.load(Ordering::SeqCst) { - UPDATED_SKILL_BODY - } else { - SKILL_BODY - }; - json!({ - "contents": [{ - "uri": uri, - "mimeType": "text/markdown", - "text": contents, - }], - }) - } else { - resource_list_calls.fetch_add(1, Ordering::SeqCst); - json!({ - "resources": [{ - "name": "search", - "uri": format!("{SKILL_ROOT}/search"), - "description": "Search company knowledge.", - "mimeType": "mcp/skill", - "_meta": { - "plugin_name": "demo", - "skill_name": "search", - "allow_implicit_invocation": true, - }, - }], - }) - }; - ResponseTemplate::new(/*status*/ 200).set_body_json(json!({ - "jsonrpc": "2.0", - "id": body["id"], - "result": result, - })) - }) - .with_priority(/*p*/ 1) - .mount(&server) - .await; - - let mut extensions = ExtensionRegistryBuilder::new(); - install_with_providers( - &mut extensions, - SkillProviders::new() - .with_orchestrator_provider(Arc::new(OrchestratorSkillProvider::new())), - |config: &Config| SkillsExtensionConfig { - include_instructions: config.include_skill_instructions, - max_context_tokens: config.skill_max_context_tokens, - bundled_skills_enabled: false, - orchestrator_skills_enabled: true, - shadow_selection_enabled: false, - }, - ); - let mut builder = apps_enabled_builder(apps_server.chatgpt_base_url) - .with_exec_server_url("none") - .with_extensions(Arc::new(extensions.build())) - .with_model_info_override("gpt-5.5", |model_info| { - model_info.context_window = Some(1_000); - model_info.max_context_window = None; - }) - .with_config(|config| { - config.include_skill_instructions = true; - config.orchestrator_skills_enabled = true; - config - .features - .enable(Feature::SkipHostSkillDiscovery) - .expect("orchestrator skills must not depend on host discovery"); - }); - let test = builder.build_with_auto_env(&server).await?; - wait_for_mcp_server(&test.codex, CODEX_APPS_MCP_SERVER_NAME).await?; - - test.submit_turn("Use $demo:search.").await?; - - let request = response.single_request(); - let developer_text = request.message_input_texts("developer").join("\n"); - assert!( - developer_text.contains(&format!("- `o0` = `{SKILL_ROOT}`")), - "model request should include the discovered orchestrator root: {developer_text}" - ); - assert!( - developer_text.lines().any(|line| { - line.starts_with("- demo:search:") - && line.ends_with("(orchestrator package: o0/search)") - }), - "model request should include the aliased orchestrator skill: {developer_text}" - ); - assert!( - developer_text.contains("- Root aliases: Pass short package locators directly"), - "model request should explain how to read aliased packages: {developer_text}" - ); - let user_text = request.message_input_texts("user").join("\n"); - assert!( - user_text.contains("\ndemo:search") && user_text.contains(SKILL_BODY), - "orchestrator instruction reads must remain available without host discovery: {user_text}" - ); - - // A normal turn and a policy change must reuse the same Apps skill snapshot. - test.submit_text_turn("Use $demo:search again.").await?; - test.submit_turn_with_approval_and_permission_profile( - "Use $demo:search after updating approval policy.", - AskForApproval::OnRequest, - PermissionProfile::Disabled, - ) - .await?; - assert_eq!( - startup.initialize_attempts(), - 1, - "Apps connection was reused" - ); - assert_eq!(list_calls.load(Ordering::SeqCst), 1); - assert_eq!(read_calls.load(Ordering::SeqCst), 1); - - // Plugin invalidation must refresh both the catalog and contents, even when - // the underlying Apps connection is reused. - updated.store(true, Ordering::SeqCst); - test.thread_manager.invalidate_mcp_runtimes().await; - test.submit_text_turn("Use $demo:search after its plugin changed.") - .await?; - assert_eq!(startup.initialize_attempts(), 1); - assert_eq!(list_calls.load(Ordering::SeqCst), 2); - assert_eq!(read_calls.load(Ordering::SeqCst), 2); - assert!( - response.requests()[3] - .message_input_texts("user") - .join("\n") - .contains(UPDATED_SKILL_BODY) - ); - - // A forced reconnect must also refresh the skills snapshot. - test.codex.submit(Op::RefreshMcpServers).await?; - test.submit_text_turn("Use $demo:search after reconnecting.") - .await?; - assert_eq!(startup.initialize_attempts(), 2); - assert_eq!(list_calls.load(Ordering::SeqCst), 3); - assert_eq!(read_calls.load(Ordering::SeqCst), 3); - - Ok(()) -} - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn production_turn_aliases_executor_skill_roots() -> Result<()> { const SKILL_ROOT: &str = @@ -1646,7 +1033,7 @@ async fn opted_in_executor_provider_skips_host_discovery_but_injects_discovered_ include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); @@ -1827,7 +1214,7 @@ async fn opted_in_executor_provider_skips_host_discovery_but_injects_discovered_ "startup_prewarm", "turn_context.build", "capability_roots.snapshot_for_step", - "skills.executor.catalog_snapshot", + "skills.executor.refresh_executor_catalog", ] { assert!( logs.contains(span), @@ -1872,7 +1259,7 @@ async fn executor_only_provider_preserves_structured_repo_skill_without_discover include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); @@ -2016,7 +1403,7 @@ async fn executor_skill_tool_reads_references_under_current_permissions( include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); @@ -2318,7 +1705,7 @@ async fn explicit_executor_skill_prompt_rejects_oversized_resource() -> Result<( include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); @@ -2480,7 +1867,7 @@ async fn executor_skill_invocation_is_environment_scoped_and_deduplicated() -> R async fn production_turn_aliases_combined_skill_catalogs_under_shared_budget() -> Result<()> { const EXECUTOR_ROOT: &str = "skill://integration-executor/workspace/plugins/cache/executor-plugin/1.0.0/skills"; - const ORCHESTRATOR_ROOT: &str = "skill://plugin_connector_1p_2330815c823c8191941e5dc465bb899f"; + const CLOUD_ROOT: &str = "skill://plugin_connector_1p_2330815c823c8191941e5dc465bb899f"; let server = responses::start_mock_server().await; let response = mount_sse_once( @@ -2535,12 +1922,12 @@ async fn production_turn_aliases_combined_skill_catalogs_under_shared_budget() - "executor", ), })) - .with_orchestrator_provider(Arc::new(CatalogSkillProvider { + .with_cloud_provider(Arc::new(CatalogSkillProvider { catalog: resource_catalog( - SkillSourceKind::Orchestrator, - "integration-orchestrator", - ORCHESTRATOR_ROOT, - "orchestrator", + SkillSourceKind::Cloud, + "integration-cloud", + CLOUD_ROOT, + "cloud", ), })) .with_host_provider(Arc::new(HostSkillProvider::new())), @@ -2548,7 +1935,7 @@ async fn production_turn_aliases_combined_skill_catalogs_under_shared_budget() - include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: true, + cloud_skill_enabled: true, shadow_selection_enabled: false, }, ); @@ -2562,7 +1949,7 @@ async fn production_turn_aliases_combined_skill_catalogs_under_shared_budget() - }) .with_config(|config| { configure_catalog_test(config); - config.orchestrator_skills_enabled = true; + config.cloud_skill_enabled = true; }); let test = builder.build_with_auto_env(&server).await?; @@ -2577,7 +1964,7 @@ async fn production_turn_aliases_combined_skill_catalogs_under_shared_budget() - .replace('\\', "/"); for (alias, root) in [ ("e0", EXECUTOR_ROOT), - ("o0", ORCHESTRATOR_ROOT), + ("c0", CLOUD_ROOT), ("r0", host_root.as_str()), ] { assert!( @@ -2587,7 +1974,7 @@ async fn production_turn_aliases_combined_skill_catalogs_under_shared_budget() - } for (source, alias, prefix, suffix) in [ ("executor package", "e0", "executor", ""), - ("orchestrator package", "o0", "orchestrator", ""), + ("cloud package", "c0", "cloud", ""), ("file", "r0", "host", "/SKILL.md"), ] { for name in ["search", "review", "summarize"] { @@ -2685,7 +2072,7 @@ async fn assert_catalog_model_switch(max_context_tokens: Option) -> Resul include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); @@ -3123,7 +2510,7 @@ async fn production_turn_uses_provider_host_catalog_and_core_snapshot_injection( include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); @@ -3243,7 +2630,7 @@ async fn production_turn_suppresses_only_the_superseded_host_skill_prompt() -> R include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); @@ -3465,7 +2852,7 @@ async fn production_turn_keeps_full_executor_only_catalog_when_it_fits() -> Resu } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn production_turn_keeps_orchestrator_world_state_incremental_across_turns() -> Result<()> { +async fn production_turn_keeps_cloud_world_state_incremental_across_turns() -> Result<()> { let server = responses::start_mock_server().await; let response = responses::mount_sse_sequence( &server, @@ -3480,14 +2867,14 @@ async fn production_turn_keeps_orchestrator_world_state_incremental_across_turns .collect(), ) .await; - let skill_name = "orchestrator-search"; + let skill_name = "cloud-search"; let skill_description = "Search available company knowledge."; - let skill_resource = "skill://codex_apps/orchestrator-search/SKILL.md"; + let skill_resource = "skill://codex_apps/cloud-search/SKILL.md"; let catalog = SkillCatalog { entries: vec![ SkillCatalogEntry::new( - SkillPackageId("orchestrator/orchestrator-search".to_string()), - SkillAuthority::new(SkillSourceKind::Orchestrator, CODEX_APPS_MCP_SERVER_NAME), + SkillPackageId("cloud/cloud-search".to_string()), + SkillAuthority::new(SkillSourceKind::Cloud, CODEX_APPS_MCP_SERVER_NAME), skill_name, skill_description, SkillResourceId::new(skill_resource), @@ -3499,13 +2886,12 @@ async fn production_turn_keeps_orchestrator_world_state_incremental_across_turns let mut extensions = ExtensionRegistryBuilder::::new(); install_with_providers( &mut extensions, - SkillProviders::new() - .with_orchestrator_provider(Arc::new(CatalogSkillProvider { catalog })), + SkillProviders::new().with_cloud_provider(Arc::new(CatalogSkillProvider { catalog })), |config: &Config| SkillsExtensionConfig { include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: false, }, ); @@ -3513,10 +2899,10 @@ async fn production_turn_keeps_orchestrator_world_state_incremental_across_turns .with_extensions(Arc::new(extensions.build())) .with_config(|config| { configure_catalog_test(config); - config.orchestrator_skills_enabled = true; + config.cloud_skill_enabled = true; }); let test = builder.build_with_auto_env(&server).await?; - let orchestrator_thread = test + let cloud_thread = test .thread_manager .start_thread(StartThreadOptions { environments: Some(Vec::new()), @@ -3528,14 +2914,14 @@ async fn production_turn_keeps_orchestrator_world_state_incremental_across_turns "Inspect the available skills.", "Inspect the available skills again.", ] { - orchestrator_thread + cloud_thread .thread .start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text { text: prompt.to_string(), text_elements: Vec::new(), }])) .await?; - core_test_support::wait_for_event(&orchestrator_thread.thread, |event| { + core_test_support::wait_for_event(&cloud_thread.thread, |event| { matches!(event, EventMsg::TurnComplete(_)) }) .await; @@ -3543,9 +2929,8 @@ async fn production_turn_keeps_orchestrator_world_state_incremental_across_turns let requests = response.requests(); assert_eq!(requests.len(), 2); - let expected_line = format!( - "- {skill_name}: {skill_description} (orchestrator package: orchestrator/orchestrator-search)" - ); + let expected_line = + format!("- {skill_name}: {skill_description} (cloud package: cloud/cloud-search)"); for (index, request) in requests.iter().enumerate() { let developer_texts = request.message_input_texts("developer"); let occurrences = developer_texts @@ -3554,7 +2939,7 @@ async fn production_turn_keeps_orchestrator_world_state_incremental_across_turns .sum::(); assert_eq!( occurrences, 1, - "request {index} should contain the orchestrator catalog exactly once: {developer_texts:?}" + "request {index} should contain the cloud catalog exactly once: {developer_texts:?}" ); assert!( developer_texts @@ -3769,7 +3154,7 @@ async fn production_turn_fairly_shortens_extension_catalog_descriptions() -> Res include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: false, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, shadow_selection_enabled: false, }, ); diff --git a/codex-rs/core/tests/suite/skills_extension/cloud_lifecycle_tests.rs b/codex-rs/core/tests/suite/skills_extension/cloud_lifecycle_tests.rs new file mode 100644 index 0000000000..dc5d925fe5 --- /dev/null +++ b/codex-rs/core/tests/suite/skills_extension/cloud_lifecycle_tests.rs @@ -0,0 +1,319 @@ +//! Cloud catalog refresh and auth-scoped retention through real Core turns. + +use super::*; +use codex_extension_api::ThreadLifecycleContributor; +use codex_extension_api::ThreadStartInput; +use codex_mcp::McpResourceClient; +use pretty_assertions::assert_eq; +use std::sync::atomic::AtomicUsize; + +struct CloudTurnProvider { + reply: Mutex, ()>>, + lists: AtomicUsize, + reads: AtomicUsize, + resource_key: Mutex>, +} + +impl SkillProvider for CloudTurnProvider { + fn list(&self, query: SkillListQuery) -> SkillProviderFuture<'_, SkillCatalog> { + Box::pin(async move { + self.lists.fetch_add(1, Ordering::SeqCst); + *self.resource_key.lock().expect("resource key lock") = query + .mcp_resources + .as_ref() + .and_then(|client| client.server_cache_key(CODEX_APPS_MCP_SERVER_NAME)); + let reply = *self.reply.lock().expect("cloud reply lock"); + let selected = + reply.map_err(|()| SkillProviderError::new("cloud skill unavailable"))?; + let entries = selected + .into_iter() + .map(|(plugin, revision)| { + let package = format!("skill://{plugin}/demo"); + SkillCatalogEntry::new( + SkillPackageId(package.clone()), + SkillAuthority::new(SkillSourceKind::Cloud, CODEX_APPS_MCP_SERVER_NAME), + format!("{plugin}:demo"), + format!("Cloud {plugin} revision {revision}"), + SkillResourceId::new(format!("{package}/SKILL.md")), + ) + .with_display_path(&package) + .with_alias_root(format!("skill://{plugin}")) + }) + .collect(); + Ok(SkillCatalog { + entries, + warnings: Vec::new(), + }) + }) + } + + fn read<'a>( + &'a self, + request: SkillReadRequest<'a>, + ) -> SkillProviderFuture<'a, SkillReadResult> { + Box::pin(async move { + self.reads.fetch_add(1, Ordering::SeqCst); + let selected = *self.reply.lock().expect("cloud reply lock"); + let (plugin, revision) = selected + .ok() + .flatten() + .ok_or_else(|| SkillProviderError::new("cloud skill unavailable"))?; + assert_eq!( + request.resource.as_str(), + format!("skill://{plugin}/demo/SKILL.md") + ); + Ok(SkillReadResult { + resource: request.resource, + contents: format!("{plugin} instructions {revision}"), + }) + }) + } + + fn search(&self, _request: SkillSearchRequest) -> SkillProviderFuture<'_, SkillSearchResult> { + Box::pin(async { Ok(SkillSearchResult::default()) }) + } +} + +#[derive(Default)] +struct SessionResources(Mutex>>); + +impl ThreadLifecycleContributor for SessionResources { + fn on_thread_start<'a>( + &'a self, + input: ThreadStartInput<'a, Config>, + ) -> ExtensionFuture<'a, ()> { + Box::pin(async move { + *self.0.lock().expect("session resources lock") = input.mcp_resource_client.clone(); + }) + } +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn cloud_skills_refresh_per_turn_and_invalidate_on_auth_change() -> Result<()> { + let server = responses::start_mock_server().await; + let apps = AppsTestServer::mount(&server).await?; + let calendar = ("calendar", 1); + let updated_calendar = ("calendar", 2); + let gmail = ("gmail", 1); + let provider = Arc::new(CloudTurnProvider { + reply: Mutex::new(Ok(Some(calendar))), + lists: AtomicUsize::new(0), + reads: AtomicUsize::new(0), + resource_key: Mutex::new(None), + }); + let resources = Arc::new(SessionResources::default()); + let mut extensions = ExtensionRegistryBuilder::new(); + extensions.thread_lifecycle_contributor(resources.clone()); + install_with_providers( + &mut extensions, + SkillProviders::new().with_cloud_provider(provider.clone()), + |_config: &Config| SkillsExtensionConfig { + include_instructions: true, + max_context_tokens: None, + bundled_skills_enabled: false, + cloud_skill_enabled: true, + shadow_selection_enabled: false, + }, + ); + let mut builder = apps_enabled_builder(apps.chatgpt_base_url) + .with_exec_server_url("none") + .with_extensions(Arc::new(extensions.build())) + .with_auth(CodexAuth::from_external_chatgpt_tokens( + "header.e30.initial", + "account-a", + /*chatgpt_plan_type*/ None, + )?) + .with_config(move |config| { + config.include_skill_instructions = true; + config.cloud_skill_enabled = true; + }); + let test = builder.build_with_auto_env(&server).await?; + let mut last_available_skill = calendar; + for (turn, next_reply, expected_skill, new_account, expected_reads) in [ + ("discovered", Ok(Some(calendar)), Some(calendar), None, 1), + ( + "refreshed", + Ok(Some(updated_calendar)), + Some(updated_calendar), + None, + 1, + ), + ( + "same-account-failure", + Err(()), + Some(updated_calendar), + None, + 0, + ), + ("removed", Ok(None), None, None, 0), + ( + "restored", + Ok(Some(updated_calendar)), + Some(updated_calendar), + None, + 1, + ), + ("auth-changed-failure", Err(()), None, Some("account-b"), 0), + ( + "new-account-discovered", + Ok(Some(gmail)), + Some(gmail), + None, + 1, + ), + ("connection-replaced-failure", Err(()), Some(gmail), None, 0), + ( + "replacement-connection-discovered", + Ok(Some(gmail)), + Some(gmail), + None, + 1, + ), + ] { + let previous_lists = provider.lists.load(Ordering::SeqCst); + let previous_reads = provider.reads.load(Ordering::SeqCst); + *provider.reply.lock().expect("cloud reply lock") = next_reply; + let previous_connection_scope = if turn == "connection-replaced-failure" { + let client = resources + .0 + .lock() + .expect("session resources lock") + .clone() + .expect("thread MCP resource client"); + let auth = client.auth_cache_key_for_server(CODEX_APPS_MCP_SERVER_NAME); + let connection = client.server_cache_key(CODEX_APPS_MCP_SERVER_NAME); + // Turn-start preparation must consume the pending reconnect before discovery. + test.codex.submit(Op::RefreshMcpServers).await?; + Some((client, auth, connection)) + } else { + None + }; + if let Some(account) = new_account { + let client = resources + .0 + .lock() + .expect("session resources lock") + .clone() + .expect("thread MCP resource client"); + let previous_auth = client.auth_cache_key_for_server(CODEX_APPS_MCP_SERVER_NAME); + codex_login::auth::login_with_chatgpt_auth_tokens( + test.codex_home_path(), + "header.e30.changed", + account, + /*chatgpt_plan_type*/ None, + )?; + test.thread_manager.auth_manager().reload().await; + // Wait for the real auth transition, without manually refreshing MCP. + tokio::time::timeout(Duration::from_secs(10), async { + while client.auth_cache_key_for_server(CODEX_APPS_MCP_SERVER_NAME) == previous_auth + { + tokio::task::yield_now().await; + } + }) + .await?; + assert_eq!(provider.lists.load(Ordering::SeqCst), previous_lists); + } + // Empty catalogs must also reject reads of the previously cached skill. + let (plugin, _) = expected_skill.unwrap_or(last_available_skill); + let package = format!("skill://{plugin}/demo"); + let list_id = format!("list-{turn}"); + let read_id = format!("read-{turn}"); + let response = responses::mount_sse_sequence( + &server, + vec![ + sse(vec![ + ev_response_created("tools"), + responses::ev_function_call_with_namespace( + &list_id, + "skills", + "list", + &json!({"authority":{"kind":"cloud"}}).to_string(), + ), + responses::ev_function_call_with_namespace( + &read_id, + "skills", + "read", + &json!({"package": package}).to_string(), + ), + ev_completed("tools"), + ]), + sse(vec![ev_response_created("done"), ev_completed("done")]), + ], + ) + .await; + test.submit_turn("Inspect the cloud skill and read its instructions.") + .await?; + let client = resources + .0 + .lock() + .expect("session resources lock") + .clone() + .expect("thread MCP resource client"); + assert!( + client.server_cache_key(CODEX_APPS_MCP_SERVER_NAME) + == *provider.resource_key.lock().expect("resource key lock"), + "turn-start reprojection must not invalidate resource caches: {turn}" + ); + if let Some((client, scope, connection)) = previous_connection_scope { + assert!(client.server_cache_key(CODEX_APPS_MCP_SERVER_NAME) != connection); + assert!( + client.auth_cache_key_for_server(CODEX_APPS_MCP_SERVER_NAME) == scope, + "same-auth reconnect must preserve the cloud cache scope" + ); + } + let requests = response.requests(); + assert_eq!(requests.len(), 2, "turn {turn}"); + assert_eq!( + provider.lists.load(Ordering::SeqCst), + previous_lists + 1, + "turn {turn}" + ); + assert_eq!( + provider.reads.load(Ordering::SeqCst), + previous_reads + expected_reads, + "turn {turn}" + ); + let listed: Value = serde_json::from_str( + &requests[1] + .function_call_output_text(&list_id) + .expect("skills.list result"), + )?; + let read = requests[1] + .function_call_output_text(&read_id) + .expect("skills.read result"); + if let Some((plugin, revision)) = expected_skill { + last_available_skill = (plugin, revision); + let description = format!("Cloud {plugin} revision {revision}"); + assert_eq!( + listed["skills"].as_array().expect("listed skills").len(), + 1, + "turn {turn}" + ); + assert_eq!(listed["skills"][0]["package"], package, "turn {turn}"); + assert_eq!( + listed["skills"][0]["description"], description, + "turn {turn}" + ); + assert!( + requests[0] + .message_input_texts("developer") + .join("\n") + .contains(&description), + "turn {turn}" + ); + let read: Value = serde_json::from_str(&read)?; + assert_eq!( + read["contents"], + format!("{plugin} instructions {revision}"), + "turn {turn}" + ); + } else { + assert_eq!(listed["skills"], json!([]), "turn {turn}"); + assert!( + read.contains("skill package is not available"), + "turn {turn}: {read}" + ); + } + } + Ok(()) +} diff --git a/codex-rs/core/tests/suite/skills_extension/cloud_skill_tests.rs b/codex-rs/core/tests/suite/skills_extension/cloud_skill_tests.rs new file mode 100644 index 0000000000..2963f4fc8c --- /dev/null +++ b/codex-rs/core/tests/suite/skills_extension/cloud_skill_tests.rs @@ -0,0 +1,835 @@ +//! Core cloud-skill behavior exercised without the concrete MCP-backed provider. + +use super::*; +use pretty_assertions::assert_eq; +use tokio::sync::Mutex; + +struct FakeCloudSkillProvider { + catalog: SkillCatalog, + resources: std::collections::HashMap, + reads: Mutex>, +} + +impl SkillProvider for FakeCloudSkillProvider { + fn list(&self, _query: SkillListQuery) -> SkillProviderFuture<'_, SkillCatalog> { + Box::pin(async { Ok(self.catalog.clone()) }) + } + + fn read<'a>( + &'a self, + request: SkillReadRequest<'a>, + ) -> SkillProviderFuture<'a, SkillReadResult> { + Box::pin(async move { + assert_eq!( + request.authority, + SkillAuthority::new(SkillSourceKind::Cloud, CODEX_APPS_MCP_SERVER_NAME) + ); + assert!( + self.catalog + .entries + .iter() + .any(|entry| entry.id == request.package) + ); + self.reads + .lock() + .await + .push(request.resource.as_str().to_string()); + let contents = self + .resources + .get(request.resource.as_str()) + .cloned() + .ok_or_else(|| SkillProviderError::new("unknown fake skill resource"))?; + Ok(SkillReadResult { + resource: request.resource, + contents, + }) + }) + } + + fn search(&self, _request: SkillSearchRequest) -> SkillProviderFuture<'_, SkillSearchResult> { + Box::pin(async { Ok(SkillSearchResult::default()) }) + } +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn explicit_only_cloud_skill_is_hidden_but_can_be_invoked() -> Result<()> { + skip_if_no_network!(Ok(())); + + const SKILL_PACKAGE: &str = "skill://demo/explicit-only"; + const MAIN_RESOURCE: &str = "skill://demo/explicit-only/SKILL.md"; + const REFERENCED_RESOURCE: &str = "skill://demo/explicit-only/references/guide.md"; + const READ_CALL_ID: &str = "read-explicit-only-resource"; + const LIST_CALL_ID: &str = "list-model-visible-skills"; + const CODE_MODE_LIST_CALL_ID: &str = "list-skills-through-code-mode"; + const CONTINUATION_CALL_ID: &str = "read-explicit-only-resource-continuation"; + const MAIN_READ_CALL_ID: &str = "read-explicit-only-main"; + const REPEATED_MAIN_READ_CALL_ID: &str = "read-explicit-only-main-again"; + const INVALID_CURSOR_CALL_ID: &str = "read-explicit-only-invalid-cursor"; + const MISSING_PACKAGE_CALL_ID: &str = "read-missing-package"; + const CODE_MODE_CALL_ID: &str = "code-mode-skill-read"; + + // Fill the shared 300-byte page through the emoji; ignoring escaping would fit everything. + let read_prefix = "a".repeat(184); + let referenced_contents = format!("{read_prefix}😀\"\\\nabcdefghijklm"); + let server = responses::start_mock_server().await; + let response = responses::mount_sse_sequence( + &server, + vec![ + sse(vec![ + ev_response_created("resp-1"), + responses::ev_function_call_with_namespace( + READ_CALL_ID, + "skills", + "read", + &json!({ + "package": SKILL_PACKAGE, + "authority": { + "kind": "cloud", + }, + "resource": REFERENCED_RESOURCE, + }) + .to_string(), + ), + responses::ev_function_call_with_namespace( + LIST_CALL_ID, + "skills", + "list", + &json!({ "authority": { "kind": "cloud" } }).to_string(), + ), + responses::ev_custom_tool_call( + CODE_MODE_LIST_CALL_ID, + "exec", + r#"const result = await tools.skills__list({ authority: { kind: "cloud" } }); +text({ names: result.skills.map(skill => skill.name), warnings: result.warnings, next_cursor: result.next_cursor });"#, + ), + ev_completed("resp-1"), + ]), + sse(vec![ev_response_created("resp-2"), ev_completed("resp-2")]), + ], + ) + .await; + + let mut extensions = ExtensionRegistryBuilder::new(); + install_with_providers( + &mut extensions, + SkillProviders::new().with_cloud_provider(Arc::new(FakeCloudSkillProvider { + catalog: SkillCatalog { + entries: [ + "alpha-visible", + "bravo-visible-skill", + "explicit-only", + "visible", + ] + .into_iter() + .map(|name| { + let package = format!("skill://demo/{name}"); + let entry = SkillCatalogEntry::new( + SkillPackageId(package.clone()), + SkillAuthority::new(SkillSourceKind::Cloud, CODEX_APPS_MCP_SERVER_NAME), + format!("demo:{name}"), + "", + SkillResourceId::new(format!("{package}/SKILL.md")), + ) + .with_display_path(&package) + .with_alias_root("skill://demo"); + if name == "explicit-only" { + entry.hidden_from_prompt() + } else { + entry + } + }) + .collect(), + warnings: Vec::new(), + }, + reads: Mutex::default(), + resources: std::collections::HashMap::from([ + ( + MAIN_RESOURCE.to_string(), + format!("# Explicit-only instructions\nRead {REFERENCED_RESOURCE}."), + ), + (REFERENCED_RESOURCE.to_string(), referenced_contents.clone()), + ]), + })), + |config: &Config| SkillsExtensionConfig { + include_instructions: config.include_skill_instructions, + max_context_tokens: config.skill_max_context_tokens, + bundled_skills_enabled: false, + cloud_skill_enabled: true, + shadow_selection_enabled: false, + }, + ); + let chatgpt_base_url = server.uri(); + let mut builder = test_codex() + .with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing()) + .with_config(move |config| config.chatgpt_base_url = chatgpt_base_url) + // Local executors disable cloud skill discovery. + .with_exec_server_url("none") + .with_extensions(Arc::new(extensions.build())) + .with_model_info_override("gpt-5.5", |model_info| { + model_info.truncation_policy = TruncationPolicyConfig::bytes(/*limit*/ 250); + }) + .with_config(|config| { + config.include_skill_instructions = true; + config.cloud_skill_enabled = true; + config + .features + .enable(Feature::CodeMode) + .expect("code mode should be configurable in tests"); + config + .features + .enable(Feature::CodeModeHost) + .expect("code mode host should be configurable in tests"); + }) + .with_code_mode_host_program(codex_utils_cargo_bin::cargo_bin("codex-code-mode-host")?); + let test = builder.build_with_auto_env(&server).await?; + + test.submit_turn("Use $demo:explicit-only.").await?; + + let requests = response.requests(); + assert_eq!(requests.len(), 2); + let request = &requests[0]; + let developer_messages = request.message_input_texts("developer"); + for name in ["visible", "alpha-visible", "bravo-visible-skill"] { + let catalog_entry = format!("- demo:{name}:"); + assert!( + developer_messages + .iter() + .any(|message| message.contains(&catalog_entry)), + "model-visible skills should include `{name}`: {developer_messages:?}" + ); + } + assert!( + developer_messages + .iter() + .all(|message| !message.contains("- demo:explicit-only:")), + "model-visible skills should omit the explicit-only skill: {developer_messages:?}" + ); + let user_messages = request.message_input_texts("user"); + let skill_instructions = user_messages + .iter() + .find(|message| { + message.contains("demo:explicit-only") + && message.contains("# Explicit-only instructions") + && message.contains(REFERENCED_RESOURCE) + }) + .expect("explicit invocation should inject the hidden skill instructions and reference"); + let resource_access = skill_instructions + .split_once("") + .and_then(|(_, remainder)| remainder.split_once("")) + .map(|(metadata, _)| metadata) + .expect("hidden cloud skills should include resource-access metadata"); + assert_eq!( + serde_json::from_str::(resource_access)?, + json!({ + "authority": { "kind": "cloud" }, + "package": SKILL_PACKAGE, + "main_resource": MAIN_RESOURCE, + }) + ); + let first_output = requests[1] + .function_call_output_text(READ_CALL_ID) + .expect("skills.read should return the referenced resource"); + assert!(first_output.len() <= 300); + let first_page = serde_json::from_str::(&first_output)?; + let cursor = first_page["next_cursor"] + .as_str() + .ok_or_else(|| anyhow::anyhow!("skills.read should return a continuation cursor"))? + .to_string(); + assert_eq!( + first_page, + json!({ + "resource": REFERENCED_RESOURCE, + "contents": format!("{read_prefix}😀"), + "next_cursor": cursor, + }) + ); + let mut list_output = requests[1] + .function_call_output_text(LIST_CALL_ID) + .expect("skills.list should return the model-visible catalog"); + let code_mode_output = requests[1].custom_tool_call_output(CODE_MODE_LIST_CALL_ID); + let code_mode_text = code_mode_output["output"] + .as_array() + .and_then(|items| items.last()) + .and_then(|item| item["text"].as_str()) + .ok_or_else(|| { + anyhow::anyhow!("Code Mode should return its skills.list result: {code_mode_output}") + })?; + assert_eq!( + serde_json::from_str::(code_mode_text)?, + json!({ + "names": ["demo:alpha-visible", "demo:bravo-visible-skill", "demo:visible"], + "warnings": [], + "next_cursor": null, + }) + ); + let events = wait_for_analytics_events(&server, "skill_invocation", /*expected_count*/ 1).await; + assert_eq!(events.len(), 1); + assert_eq!(events[0]["skill_name"], "demo:explicit-only"); + assert_eq!(events[0]["event_params"]["invoke_type"], "explicit"); + + let response = responses::mount_sse_sequence( + &server, + vec![ + sse(vec![ + ev_response_created("resp-3"), + responses::ev_function_call_with_namespace( + CONTINUATION_CALL_ID, + "skills", + "read", + &json!({ + "package": SKILL_PACKAGE, + "resource": REFERENCED_RESOURCE, + "cursor": cursor, + }) + .to_string(), + ), + responses::ev_function_call_with_namespace( + MAIN_READ_CALL_ID, + "skills", + "read", + &json!({ "package": SKILL_PACKAGE }).to_string(), + ), + responses::ev_function_call_with_namespace( + REPEATED_MAIN_READ_CALL_ID, + "skills", + "read", + &json!({ "package": SKILL_PACKAGE, "resource": MAIN_RESOURCE }).to_string(), + ), + responses::ev_function_call_with_namespace( + INVALID_CURSOR_CALL_ID, + "skills", + "read", + &json!({ "package": SKILL_PACKAGE, "cursor": "invalid" }).to_string(), + ), + responses::ev_function_call_with_namespace( + MISSING_PACKAGE_CALL_ID, + "skills", + "read", + &json!({ "package": "skill://demo/missing" }).to_string(), + ), + ev_completed("resp-3"), + ]), + sse(vec![ev_response_created("resp-4"), ev_completed("resp-4")]), + ], + ) + .await; + + test.submit_turn("Continue without explicitly selecting a skill.") + .await?; + let requests = response.requests(); + assert_eq!(requests.len(), 2); + let continuation_output = requests[1] + .function_call_output_text(CONTINUATION_CALL_ID) + .expect("skills.read should return the next referenced-resource page"); + assert!(continuation_output.len() <= 300); + let continuation_page = serde_json::from_str::(&continuation_output)?; + assert_eq!( + continuation_page, + json!({ + "resource": REFERENCED_RESOURCE, + "contents": "\"\\\nabcdefghijklm", + "next_cursor": null, + }) + ); + assert_eq!( + format!( + "{}{}", + first_page["contents"].as_str().unwrap_or_default(), + continuation_page["contents"].as_str().unwrap_or_default() + ), + referenced_contents + ); + for call_id in [MAIN_READ_CALL_ID, REPEATED_MAIN_READ_CALL_ID] { + let output = requests[1] + .function_call_output_text(call_id) + .expect("skills.read should return the main resource"); + assert_eq!( + serde_json::from_str::(&output)?["resource"], + MAIN_RESOURCE + ); + } + for call_id in [INVALID_CURSOR_CALL_ID, MISSING_PACKAGE_CALL_ID] { + assert!( + requests[1].function_call_output_text(call_id).is_some(), + "failed skills.read should return a tool error for {call_id}" + ); + } + + let events = wait_for_analytics_events(&server, "skill_invocation", /*expected_count*/ 2).await; + assert_eq!(events.len(), 2, "repeated main reads must be deduplicated"); + assert_eq!(events[1]["skill_name"], "demo:explicit-only"); + assert_eq!( + events[1]["skill_id"], + format!("{:x}", sha1::Sha1::digest(MAIN_RESOURCE.as_bytes())) + ); + assert_eq!(events[1]["event_params"]["invoke_type"], "implicit"); + + for (name, has_more) in [ + ("alpha-visible", true), + ("bravo-visible-skill", true), + ("visible", false), + ] { + assert!(list_output.len() <= 300); + let list_response = serde_json::from_str::(&list_output)?; + let next_cursor = list_response["next_cursor"].as_str(); + assert_eq!(next_cursor.is_some(), has_more); + assert_eq!( + list_response, + json!({ + "skills": [{ + "authority": {"kind": "cloud"}, + "package": format!("skill://demo/{name}"), + "name": format!("demo:{name}"), + "description": "", + "main_resource": format!("skill://demo/{name}/SKILL.md"), + }], + "warnings": [], + "next_cursor": next_cursor, + }) + ); + if let Some(cursor) = next_cursor { + let call_id = format!("list-after-{name}"); + let page = responses::mount_sse_sequence( + &server, + vec![ + sse(vec![ + ev_response_created(&call_id), + responses::ev_function_call_with_namespace( + &call_id, + "skills", + "list", + &json!({ + "authority": { "kind": "cloud" }, + "cursor": cursor, + }) + .to_string(), + ), + ev_completed(&call_id), + ]), + sse(vec![ev_response_created("listed"), ev_completed("listed")]), + ], + ) + .await; + test.submit_turn("Continue listing skills.").await?; + list_output = page.requests()[1] + .function_call_output_text(&call_id) + .expect("skills.list should return the next page"); + } + } + + let response = responses::mount_sse_sequence( + &server, + vec![ + sse(vec![ + ev_response_created("resp-5"), + responses::ev_custom_tool_call( + CODE_MODE_CALL_ID, + "exec", + &format!( + "const result = await tools.skills__read({{package: {SKILL_PACKAGE:?}, resource: {REFERENCED_RESOURCE:?}}}); text(JSON.stringify({{contents: result.contents, next_cursor: result.next_cursor}}));" + ), + ), + ev_completed("resp-5"), + ]), + sse(vec![ev_response_created("resp-6"), ev_completed("resp-6")]), + ], + ) + .await; + test.submit_turn("Read the complete skill resource using code mode.") + .await?; + let requests = response.requests(); + assert_eq!(requests.len(), 2); + let output = requests[1].custom_tool_call_output(CODE_MODE_CALL_ID); + let nested_result = output["output"] + .as_array() + .and_then(|items| items.last()) + .and_then(|item| item["text"].as_str()) + .ok_or_else(|| anyhow::anyhow!("code mode should return the nested skill result"))?; + assert_eq!( + serde_json::from_str::(nested_result)?, + json!({"contents": referenced_contents, "next_cursor": null}) + ); + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn production_turn_aliases_discovered_singleton_cloud_root() -> Result<()> { + skip_if_no_network!(Ok(())); + + const SKILL_ROOT: &str = "skill://plugin_connector_1p_2330815c823c8191941e5dc465bb899f"; + const SKILL_BODY: &str = "CLOUD_SKILL_REMAINS_AVAILABLE_WITHOUT_HOST_DISCOVERY"; + + let server = responses::start_mock_server().await; + let response = mount_sse_once( + &server, + sse(vec![ev_response_created("resp-1"), ev_completed("resp-1")]), + ) + .await; + + let mut extensions = ExtensionRegistryBuilder::new(); + install_with_providers( + &mut extensions, + SkillProviders::new().with_cloud_provider(Arc::new(FakeCloudSkillProvider { + catalog: SkillCatalog { + entries: vec![ + SkillCatalogEntry::new( + SkillPackageId(format!("{SKILL_ROOT}/search")), + SkillAuthority::new(SkillSourceKind::Cloud, CODEX_APPS_MCP_SERVER_NAME), + "demo:search", + "Search company knowledge.", + SkillResourceId::new(format!("{SKILL_ROOT}/search/SKILL.md")), + ) + .with_display_path(format!("{SKILL_ROOT}/search")) + .with_alias_root(SKILL_ROOT), + ], + warnings: Vec::new(), + }, + resources: std::collections::HashMap::from([( + format!("{SKILL_ROOT}/search/SKILL.md"), + SKILL_BODY.to_string(), + )]), + reads: Mutex::default(), + })), + |config: &Config| SkillsExtensionConfig { + include_instructions: config.include_skill_instructions, + max_context_tokens: config.skill_max_context_tokens, + bundled_skills_enabled: false, + cloud_skill_enabled: true, + shadow_selection_enabled: false, + }, + ); + let chatgpt_base_url = server.uri(); + let mut builder = test_codex() + .with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing()) + .with_config(move |config| config.chatgpt_base_url = chatgpt_base_url) + .with_exec_server_url("none") + .with_extensions(Arc::new(extensions.build())) + .with_model_info_override("gpt-5.5", |model_info| { + model_info.context_window = Some(1_000); + model_info.max_context_window = None; + }) + .with_config(|config| { + config.include_skill_instructions = true; + config.cloud_skill_enabled = true; + config + .features + .enable(Feature::SkipHostSkillDiscovery) + .expect("cloud skills must not depend on host discovery"); + }); + let test = builder.build_with_auto_env(&server).await?; + + test.submit_turn("Use $demo:search.").await?; + + let request = response.single_request(); + let developer_text = request.message_input_texts("developer").join("\n"); + assert!( + developer_text.contains(&format!("- `c0` = `{SKILL_ROOT}`")), + "model request should include the discovered cloud root: {developer_text}" + ); + assert!( + developer_text.lines().any(|line| { + line.starts_with("- demo:search:") && line.ends_with("(cloud package: c0/search)") + }), + "model request should include the aliased cloud skill: {developer_text}" + ); + assert!( + developer_text.contains("- Root aliases: Pass short package locators directly"), + "model request should explain how to read aliased packages: {developer_text}" + ); + let user_text = request.message_input_texts("user").join("\n"); + assert!( + user_text.contains("\ndemo:search") && user_text.contains(SKILL_BODY), + "cloud instruction reads must remain available without host discovery: {user_text}" + ); + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn cloud_skill_can_read_referenced_resource_without_an_executor() -> Result<()> { + skip_if_no_network!(Ok(())); + const SKILL_NAME: &str = "demo-plugin:deploy"; + + const SKILL_DESCRIPTION: &str = "Deploy through the <hosted> orchestrator."; + + const SKILL_RESOURCE_URI: &str = "skill://plugin_demo/deploy"; + + const SKILL_MAIN_PROMPT_URI: &str = "skill://plugin_demo/deploy/SKILL.md"; + + const SKILL_REFERENCE_URI: &str = "skill://plugin_demo/deploy/references/deploy.md"; + + const SKILL_MARKER: &str = "ORCHESTRATOR_SKILL_BODY_MARKER"; + + const SKILL_CONTENTS: &str = concat!( + "---\n", + "name: deploy\n", + "description: Deploy through the orchestrator.\n", + "---\n\n", + "# Deploy\n\n", + "ORCHESTRATOR_SKILL_BODY_MARKER\n\n", + "Read the [deployment reference](skill://plugin_demo/deploy/references/deploy.md).\n", + ); + + const SKILL_REFERENCE_CONTENTS: &str = + "# Deploy reference\n\nUse the orchestrator deployment API.\n"; + + const SKILLS_LIST_CALL_ID: &str = "skills-list"; + + const SKILLS_READ_MAIN_CALL_ID: &str = "skills-read-main"; + + const SKILLS_READ_CALL_ID: &str = "skills-read"; + + const SKILLS_READ_AGAIN_CALL_ID: &str = "skills-read-again"; + + let responses_server = responses::start_mock_server().await; + let provider = Arc::new(FakeCloudSkillProvider { + catalog: SkillCatalog { + entries: vec![ + SkillCatalogEntry::new( + SkillPackageId(SKILL_RESOURCE_URI.to_string()), + SkillAuthority::new(SkillSourceKind::Cloud, CODEX_APPS_MCP_SERVER_NAME), + SKILL_NAME, + SKILL_DESCRIPTION, + SkillResourceId::new(SKILL_MAIN_PROMPT_URI), + ) + .with_display_path(SKILL_RESOURCE_URI) + .with_alias_root("skill://plugin_demo"), + ], + warnings: vec!["Cloud discovery returned a partial catalog.".to_string()], + }, + resources: std::collections::HashMap::from([ + ( + SKILL_MAIN_PROMPT_URI.to_string(), + SKILL_CONTENTS.to_string(), + ), + ( + SKILL_REFERENCE_URI.to_string(), + SKILL_REFERENCE_CONTENTS.to_string(), + ), + ]), + reads: Mutex::default(), + }); + let mut extensions = ExtensionRegistryBuilder::new(); + install_with_providers( + &mut extensions, + SkillProviders::new().with_cloud_provider(provider.clone()), + |config: &Config| SkillsExtensionConfig { + include_instructions: config.include_skill_instructions, + max_context_tokens: config.skill_max_context_tokens, + bundled_skills_enabled: false, + cloud_skill_enabled: true, + shadow_selection_enabled: false, + }, + ); + let chatgpt_base_url = responses_server.uri(); + let mut builder = test_codex() + .with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing()) + .with_config(move |config| config.chatgpt_base_url = chatgpt_base_url) + .with_exec_server_url("none") + .with_extensions(Arc::new(extensions.build())) + .with_config(|config| { + config.include_skill_instructions = true; + config.cloud_skill_enabled = true; + }); + let test = builder.build_with_auto_env(&responses_server).await?; + let response_mock = responses::mount_sse_sequence( + &responses_server, + vec![ + responses::sse(vec![ + responses::ev_response_created("resp-skills-read-main"), + responses::ev_function_call_with_namespace( + SKILLS_READ_MAIN_CALL_ID, + "skills", + "read", + &json!({ + "package": SKILL_RESOURCE_URI, + }) + .to_string(), + ), + responses::ev_completed("resp-skills-read-main"), + ]), + responses::sse(vec![ + responses::ev_response_created("resp-skills-list"), + responses::ev_function_call_with_namespace( + SKILLS_LIST_CALL_ID, + "skills", + "list", + &json!({ + "authority": { + "kind": "cloud", + }, + }) + .to_string(), + ), + responses::ev_completed("resp-skills-list"), + ]), + responses::sse(vec![ + responses::ev_response_created("resp-skills-read"), + responses::ev_function_call_with_namespace( + SKILLS_READ_CALL_ID, + "skills", + "read", + &json!({ + "package": SKILL_RESOURCE_URI, + "authority": { + "kind": "cloud", + }, + "resource": SKILL_REFERENCE_URI, + }) + .to_string(), + ), + responses::ev_completed("resp-skills-read"), + ]), + responses::sse(vec![ + responses::ev_response_created("resp-skills-read-again"), + responses::ev_function_call_with_namespace( + SKILLS_READ_AGAIN_CALL_ID, + "skills", + "read", + &json!({ + "package": SKILL_RESOURCE_URI, + "resource": SKILL_REFERENCE_URI, + }) + .to_string(), + ), + responses::ev_completed("resp-skills-read-again"), + ]), + responses::sse(vec![ + responses::ev_response_created("resp-orchestrator-skill"), + responses::ev_assistant_message("msg-orchestrator-skill", "Done"), + responses::ev_completed("resp-orchestrator-skill"), + ]), + responses::sse(vec![ + responses::ev_response_created("resp-orchestrator-skill-after-refresh"), + responses::ev_assistant_message("msg-orchestrator-skill-after-refresh", "Done"), + responses::ev_completed("resp-orchestrator-skill-after-refresh"), + ]), + ], + ) + .await; + test.submit_turn("Use the deployment capability.").await?; + let requests = response_mock.requests(); + assert_eq!(requests.len(), 5); + let first_request = &requests[0]; + assert!(first_request.tool_by_name("skills", "list").is_some()); + let read_tool = first_request + .tool_by_name("skills", "read") + .ok_or_else(|| anyhow::anyhow!("skills.read should be available"))?; + assert_eq!(read_tool["parameters"]["required"], json!(["package"])); + assert!( + read_tool["parameters"]["properties"] + .get("authority") + .is_none() + ); + assert!(first_request.tool_by_name("skills", "search").is_none()); + + let developer_messages = first_request.message_input_texts("developer"); + let catalog_line = format!("- {SKILL_NAME}: {SKILL_DESCRIPTION} (cloud package: c0/deploy)"); + assert!( + developer_messages + .iter() + .any(|text| text.contains("- `c0` = `skill://plugin_demo`")) + ); + assert_eq!( + 1, + developer_messages + .iter() + .filter(|text| text.contains(&catalog_line)) + .count() + ); + assert!( + developer_messages + .iter() + .all(|text| !text.contains("ignored-plugin:ignored")) + ); + assert!( + developer_messages + .iter() + .any(|text| text.contains("do not treat `skill://` identifiers as filesystem paths")) + ); + assert!( + first_request + .message_input_texts("user") + .into_iter() + .all(|text| !text.starts_with("")) + ); + + let main_read_output = requests[1] + .function_call_output_text(SKILLS_READ_MAIN_CALL_ID) + .ok_or_else(|| anyhow::anyhow!("skills.read output should be sent to the model"))?; + assert_eq!( + serde_json::from_str::(&main_read_output)?, + json!({ + "resource": SKILL_MAIN_PROMPT_URI, + "contents": SKILL_CONTENTS, + "next_cursor": null, + }) + ); + + let list_output = requests[2] + .function_call_output_text(SKILLS_LIST_CALL_ID) + .ok_or_else(|| anyhow::anyhow!("skills.list output should be sent to the model"))?; + assert_eq!( + serde_json::from_str::(&list_output)?, + json!({ + "skills": [{ + "authority": { + "kind": "cloud", + }, + "package": SKILL_RESOURCE_URI, + "name": SKILL_NAME, + "description": SKILL_DESCRIPTION, + "main_resource": SKILL_MAIN_PROMPT_URI, + }], + "warnings": ["Cloud discovery returned a partial catalog."], + "next_cursor": null, + }) + ); + + let read_output = requests[3] + .function_call_output_text(SKILLS_READ_CALL_ID) + .ok_or_else(|| anyhow::anyhow!("skills.read output should be sent to the model"))?; + assert_eq!( + serde_json::from_str::(&read_output)?, + json!({ + "resource": SKILL_REFERENCE_URI, + "contents": SKILL_REFERENCE_CONTENTS, + "next_cursor": null, + }) + ); + let repeated_read_output = requests[4] + .function_call_output_text(SKILLS_READ_AGAIN_CALL_ID) + .ok_or_else(|| { + anyhow::anyhow!("repeated skills.read output should be sent to the model") + })?; + assert_eq!(read_output, repeated_read_output); + assert_eq!( + *provider.reads.lock().await, + vec![SKILL_MAIN_PROMPT_URI, SKILL_REFERENCE_URI] + ); + + test.codex.submit(Op::RefreshMcpServers).await?; + test.submit_turn(&format!("Use ${SKILL_NAME} after refreshing MCP")) + .await?; + let requests = response_mock.requests(); + assert_eq!(requests.len(), 6); + let skill_fragments = requests[5] + .message_input_texts("user") + .into_iter() + .filter(|text| text.starts_with("")) + .collect::>(); + assert_eq!(1, skill_fragments.len()); + assert!(skill_fragments[0].contains(&format!("{SKILL_NAME}"))); + assert!(skill_fragments[0].contains(SKILL_MARKER)); + assert!(skill_fragments[0].contains(SKILL_REFERENCE_URI)); + assert_eq!( + *provider.reads.lock().await, + vec![ + SKILL_MAIN_PROMPT_URI, + SKILL_REFERENCE_URI, + SKILL_MAIN_PROMPT_URI + ] + ); + Ok(()) +} diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__astra_disabled_executor_skills.snap b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__astra_disabled_executor_skills.snap index 68292b03bb..ff076513c6 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__astra_disabled_executor_skills.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__astra_disabled_executor_skills.snap @@ -16,8 +16,8 @@ Settings: text: {"verbosity":"low"} tool_choice: "auto" -- request 1 (request) -- -00:additional_tools/developer (3; hash=d78b689d87e8c03e): - - namespace/functions; hash=97852c93915dad58 +00:additional_tools/developer (3; hash=1a25ddd32492d564): + - namespace/functions; hash=99a630cff25563aa - custom/exec - function/wait - function/request_user_input diff --git a/codex-rs/core/tests/suite/token_budget.rs b/codex-rs/core/tests/suite/token_budget.rs index fd85da9098..b4eb97390d 100644 --- a/codex-rs/core/tests/suite/token_budget.rs +++ b/codex-rs/core/tests/suite/token_budget.rs @@ -1609,7 +1609,7 @@ async fn new_context_tool_skips_auto_compact_fallback() -> Result<()> { include_instructions: config.include_skill_instructions, max_context_tokens: config.skill_max_context_tokens, bundled_skills_enabled: config.bundled_skills_enabled(), - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: config.features.enabled(Feature::SkillSearch), }); let test = test_codex() diff --git a/codex-rs/ext/skills/Cargo.toml b/codex-rs/ext/skills/Cargo.toml index 59af40c035..2b7b1f4032 100644 --- a/codex-rs/ext/skills/Cargo.toml +++ b/codex-rs/ext/skills/Cargo.toml @@ -35,7 +35,6 @@ serde_yaml = { workspace = true } tokio = { workspace = true, features = ["sync", "time"] } toml = { workspace = true } tracing = { workspace = true } -url = { workspace = true } [dev-dependencies] assert_matches = { workspace = true } diff --git a/codex-rs/ext/skills/src/aliases_tests.rs b/codex-rs/ext/skills/src/aliases_tests.rs index a4f41adc1f..814abef22c 100644 --- a/codex-rs/ext/skills/src/aliases_tests.rs +++ b/codex-rs/ext/skills/src/aliases_tests.rs @@ -49,7 +49,7 @@ fn shortens_filesystem_and_skill_resource_locators() { "skill://executor/workspace/skills/alpha/SKILL.md", "e0/alpha/SKILL.md", ), - ("o", "skill://plugin", "skill://plugin/alpha", "o0/alpha"), + ("c", "skill://plugin", "skill://plugin/alpha", "c0/alpha"), ] { let plan = AliasPlan::build(prefix, &[root, root]).expect("alias plan should build"); diff --git a/codex-rs/ext/skills/src/catalog.rs b/codex-rs/ext/skills/src/catalog.rs index 1877f8fc21..5783a7039d 100644 --- a/codex-rs/ext/skills/src/catalog.rs +++ b/codex-rs/ext/skills/src/catalog.rs @@ -11,8 +11,8 @@ pub enum SkillSourceKind { Host, /// Skills owned by an execution environment. Executor, - /// Skills owned by the orchestrator rather than an execution environment. - Orchestrator, + /// Skills owned by the cloud rather than an execution environment. + Cloud, /// Extension-private source kind for future providers that do not fit an /// existing transport category. Custom(String), @@ -27,7 +27,7 @@ impl SkillSourceKind { match self { Self::Host => "host", Self::Executor => "executor", - Self::Orchestrator => "orchestrator", + Self::Cloud => "cloud", Self::Custom(kind) => kind, } } @@ -178,9 +178,9 @@ pub struct SkillCatalogEntry { pub short_description: Option, pub main_prompt: SkillResourceId, pub display_path: Option, - pub(crate) canonical_skill_id: Option, - pub(crate) plugin_id: Option, - pub(crate) analytics_scope: Option, + pub canonical_skill_id: Option, + pub plugin_id: Option, + pub analytics_scope: Option, alias_root: Option, alias_root_order: Option, prompt_scope: Option, diff --git a/codex-rs/ext/skills/src/catalog_prompt.rs b/codex-rs/ext/skills/src/catalog_prompt.rs index cfd3eec158..826fee869a 100644 --- a/codex-rs/ext/skills/src/catalog_prompt.rs +++ b/codex-rs/ext/skills/src/catalog_prompt.rs @@ -1,17 +1,17 @@ use crate::catalog::SkillSourceKind; -const SKILLS_INTRO_WITH_SOURCE_LOCATORS: &str = "A skill is a set of instructions provided through a `SKILL.md` source. Below is the list of skills that can be used. Each entry includes a name, description, and source locator. `file` locators are on the host filesystem, `executor package` locators are owned by their execution environment, `orchestrator package` locators are opaque package identifiers, and `custom resource` locators use their provider's access mechanism."; +const SKILLS_INTRO_WITH_SOURCE_LOCATORS: &str = "A skill is a set of instructions provided through a `SKILL.md` source. Below is the list of skills that can be used. Each entry includes a name, description, and source locator. `file` locators are on the host filesystem, `executor package` locators are owned by their execution environment, `cloud package` locators are opaque package identifiers, and `custom resource` locators use their provider's access mechanism."; const SKILLS_INTRO_WITH_HOST_ALIASES: &str = "A skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and a short path that can be expanded into an absolute path using the skill roots table."; const SKILLS_INTRO_WITH_RESOURCE_ALIASES: &str = "A skill is a set of instructions provided through a `SKILL.md` source. Below is the list of skills that can be used. Each entry includes a name, description, and source locator. Short locators can be expanded using the skill roots table."; const RESOURCE_ALIAS_INSTRUCTIONS: &str = "- Root aliases: Pass short package locators directly to `skills.read`; it resolves their matching alias from `### Skill roots`."; -const SKILLS_HOW_TO_USE_WITH_SOURCE_LOCATORS: &str = r###"- Discovery: The list above is the skills available in this session (name + description + source locator). `file` entries live on the host filesystem, `executor package` and `orchestrator package` entries are accessed directly through `skills.read`, and `custom resource` entries use their provider's access mechanism. +const SKILLS_HOW_TO_USE_WITH_SOURCE_LOCATORS: &str = r###"- Discovery: The list above is the skills available in this session (name + description + source locator). `file` entries live on the host filesystem, `executor package` and `cloud package` entries are accessed directly through `skills.read`, and `custom resource` entries use their provider's access mechanism. - Trigger rules: If the user names a skill (with `$SkillName` or plain text) OR the task clearly matches a skill's description shown above, you must use that skill for that turn. Multiple mentions mean use them all. Do not carry skills across turns unless re-mentioned. - Missing/blocked: If a named skill isn't in the list or its source can't be read, say so briefly and continue with the best fallback. - How to use a skill (progressive disclosure): - 1) After deciding to use a skill, the main agent must read its `SKILL.md` completely before taking task actions. For a `file` entry, open the listed path. For an `executor package` or `orchestrator package`, pass the listed locator directly to `skills.read` as `package`; root aliases are resolved automatically. Omit `resource` to read `SKILL.md` directly without calling `skills.list`. If a read is paginated, follow `next_cursor` until EOF. - 2) When `SKILL.md` references another resource, use the same access mechanism. For executor and orchestrator skills, pass the complete package-contained resource identifier with the same package to `skills.read`; do not treat `skill://` identifiers as filesystem paths. + 1) After deciding to use a skill, the main agent must read its `SKILL.md` completely before taking task actions. For a `file` entry, open the listed path. For an `executor package` or `cloud package`, pass the listed locator directly to `skills.read` as `package`; root aliases are resolved automatically. Omit `resource` to read `SKILL.md` directly without calling `skills.list`. If a read is paginated, follow `next_cursor` until EOF. + 2) When `SKILL.md` references another resource, use the same access mechanism. For executor and cloud skills, pass the complete package-contained resource identifier with the same package to `skills.read`; do not treat `skill://` identifiers as filesystem paths. 3) If `SKILL.md` points to extra folders such as `references/`, use its routing instructions to identify the resources required for the task. The main agent must read each required instruction or reference file itself before acting on it. Do not delegate reading, summarizing, or interpreting skill instructions to a subagent. Subagents may still perform task work when the selected skill allows it. - 4) For filesystem-backed skills, prefer running or patching provided scripts instead of retyping large code blocks. For executor and orchestrator skills, use `skills.read` and the available tools; do not invent a local path. + 4) For filesystem-backed skills, prefer running or patching provided scripts instead of retyping large code blocks. For executor and cloud skills, use `skills.read` and the available tools; do not invent a local path. 5) Reuse provided assets or templates through the same source access mechanism instead of recreating them. - Coordination and sequencing: - If multiple skills apply, choose the minimal set that covers the request and state the order you'll use them. @@ -50,7 +50,7 @@ impl SkillPromptKind { pub(crate) fn for_aliased_source(source: &SkillSourceKind) -> Self { match source { SkillSourceKind::Host => Self::HostAliases, - SkillSourceKind::Executor | SkillSourceKind::Orchestrator => Self::ResourceAliases, + SkillSourceKind::Executor | SkillSourceKind::Cloud => Self::ResourceAliases, SkillSourceKind::Custom(_) => Self::Unaliased, } } @@ -90,9 +90,10 @@ pub(crate) fn render_available_skills_body( lines.push("### Skill roots".to_string()); lines.extend(skill_root_lines.iter().cloned()); } - if skill_lines.iter().any(|line| { - line.contains("(executor package: ") || line.contains("(orchestrator package: ") - }) { + if skill_lines + .iter() + .any(|line| line.contains("(executor package: ") || line.contains("(cloud package: ")) + { lines.push( "Read a skill package directly with `skills.read({\"package\":\"\"})` to read its `SKILL.md`; root aliases are resolved automatically. To read another file from that skill, use the same `package` and pass the file's complete `skill://` identifier as `resource`. If the package is not provided, use `skills.list` to find it." .to_string(), diff --git a/codex-rs/ext/skills/src/cloud_cache_tests.rs b/codex-rs/ext/skills/src/cloud_cache_tests.rs new file mode 100644 index 0000000000..7a001ca1c5 --- /dev/null +++ b/codex-rs/ext/skills/src/cloud_cache_tests.rs @@ -0,0 +1,163 @@ +//! Regression tests for cloud cache generation isolation and late completion. + +use super::*; +use crate::catalog::SkillResourceId; +use crate::catalog::SkillSearchResult; +use crate::provider::SkillProvider; +use crate::provider::SkillProviderFuture; +use crate::provider::SkillSearchRequest; +use codex_mcp::McpRuntime; +use pretty_assertions::assert_eq; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; +use tokio::sync::Notify; + +#[derive(Default)] +struct Provider { + reads: AtomicUsize, + pause_read: AtomicBool, + pause_list: AtomicBool, + entered: Notify, + resume: Notify, +} + +impl SkillProvider for Provider { + fn list(&self, _query: SkillListQuery) -> SkillProviderFuture<'_, SkillCatalog> { + Box::pin(async move { + if self.pause_list.swap(false, Ordering::SeqCst) { + self.entered.notify_one(); + self.resume.notified().await; + } + Ok(SkillCatalog { + warnings: vec!["account catalog".into()], + ..Default::default() + }) + }) + } + + fn read<'a>( + &'a self, + request: SkillReadRequest<'a>, + ) -> SkillProviderFuture<'a, SkillReadResult> { + let revision = self.reads.fetch_add(1, Ordering::SeqCst); + Box::pin(async move { + if self.pause_read.swap(false, Ordering::SeqCst) { + self.entered.notify_one(); + self.resume.notified().await; + } + Ok(SkillReadResult { + resource: request.resource, + contents: format!("contents {revision}"), + }) + }) + } + + fn search(&self, _request: SkillSearchRequest) -> SkillProviderFuture<'_, SkillSearchResult> { + Box::pin(async { Ok(SkillSearchResult::default()) }) + } +} + +fn state() -> SkillsThreadState { + SkillsThreadState::new( + SkillsExtensionConfig { + include_instructions: true, + max_context_tokens: None, + bundled_skills_enabled: false, + cloud_skill_enabled: true, + shadow_selection_enabled: false, + }, + /*cloud_skills_available*/ true, + ) +} + +fn client() -> Arc { + Arc::new(McpResourceClient::new(Arc::new(McpRuntime::empty( + /*prefix_mcp_tool_names*/ false, + )))) +} + +fn query(client: Option>) -> SkillListQuery { + SkillListQuery { + turn_id: "turn".into(), + executor_roots: Vec::new(), + resolved_executor_roots: Vec::new(), + host_snapshot: None, + include_host_skills: false, + include_bundled_skills: false, + include_cloud_skills: true, + mcp_resources: client, + executor_capability_discovery: None, + } +} + +fn request(client: Option>) -> SkillReadRequest<'static> { + SkillReadRequest { + _lifetime: Default::default(), + authority: SkillAuthority::new(SkillSourceKind::Cloud, "codex_apps"), + package: SkillPackageId("skill://demo".into()), + resource: SkillResourceId::new("skill://demo/SKILL.md"), + resolved_executor_roots: Vec::new(), + sandbox: None, + host_snapshot: None, + mcp_resources: client, + } +} + +#[tokio::test] +async fn late_read_cannot_return_or_populate_a_replaced_cache() { + for replacement in [Some(client()), None] { + let state = state(); + let provider = Arc::new(Provider::default()); + let providers = SkillProviders::new().with_cloud_provider(provider.clone()); + let original = Some(client()); + // None here exercises a successful per-turn refresh on the SAME generation. + let replacement = replacement.or_else(|| original.clone()); + provider.pause_read.store(true, Ordering::SeqCst); + let (late, ()) = tokio::join!(state.read_skill(&providers, request(original)), async { + provider.entered.notified().await; + state + .refresh_cloud_catalog(&providers, query(replacement.clone())) + .await + .unwrap(); + provider.resume.notify_one(); + }); + assert!(late.is_err()); + assert_eq!( + state + .read_skill(&providers, request(replacement)) + .await + .unwrap() + .contents, + "contents 1" + ); + } +} + +#[tokio::test] +async fn late_discovery_cannot_publish_into_a_new_generation() { + let state = state(); + let provider = Arc::new(Provider::default()); + let providers = SkillProviders::new().with_cloud_provider(provider.clone()); + provider.pause_list.store(true, Ordering::SeqCst); + let (late, ()) = tokio::join!( + state.refresh_cloud_catalog(&providers, query(Some(client()))), + async { + provider.entered.notified().await; + state.cloud_cache(Some(&client())); + provider.resume.notify_one(); + } + ); + assert!(late.is_err()); + assert!( + state + .skills_extension_state + .lock() + .unwrap() + .cloud_cache + .as_ref() + .unwrap() + .catalog + .is_none() + ); +} diff --git a/codex-rs/ext/skills/src/cloud_skill.rs b/codex-rs/ext/skills/src/cloud_skill.rs new file mode 100644 index 0000000000..74e5bc61ad --- /dev/null +++ b/codex-rs/ext/skills/src/cloud_skill.rs @@ -0,0 +1,67 @@ +//! Attempts cloud discovery once during cancellable regular-turn startup. +//! Snapshot readers never discover or retry. Failures may retain a same-auth-scope +//! catalog; missing or invalidated catalogs remain empty until the next turn. + +use codex_extension_api::ExtensionData; +use codex_extension_api::ExtensionFuture; +use codex_extension_api::TurnLifecycleContributor; +use codex_extension_api::TurnStartInput; +use codex_extension_api::TurnStartPhase; + +use super::SkillsExtension; +use crate::provider::SkillListQuery; +use crate::state::SkillsSessionState; +use crate::state::SkillsThreadState; + +impl TurnLifecycleContributor for SkillsExtension { + fn turn_start_phase(&self, thread_store: &ExtensionData) -> TurnStartPhase { + if self.providers.has_cloud_provider() + && thread_store + .get::() + .is_some_and(|state| state.cloud_skill_enabled()) + { + TurnStartPhase::RegularTaskStart + } else { + TurnStartPhase::BeforeTaskRegistration + } + } + + fn requires_mcp_runtime(&self, thread_store: &ExtensionData) -> bool { + self.turn_start_phase(thread_store) == TurnStartPhase::RegularTaskStart + } + + fn on_turn_start<'a>(&'a self, input: TurnStartInput<'a>) -> ExtensionFuture<'a, ()> { + Box::pin(async move { + let Some(state) = input.thread_store.get::() else { + return; + }; + if !state.cloud_skill_enabled() || !self.providers.has_cloud_provider() { + return; + } + let config = state.config(); + let query = SkillListQuery { + turn_id: input.turn_id.to_string(), + executor_roots: Vec::new(), + resolved_executor_roots: Vec::new(), + host_snapshot: None, + include_host_skills: false, + include_bundled_skills: config.bundled_skills_enabled, + include_cloud_skills: true, + mcp_resources: input + .session_store + .get::() + .and_then(|state| state.mcp_resources.clone()), + executor_capability_discovery: None, + }; + if let Err(error) = state.refresh_cloud_catalog(&self.providers, query).await { + self.emit_warning( + input.thread_store.level_id(), + Some(input.turn_id), + format!( + "Cloud skill discovery failed; retaining any catalog from the same cloud auth scope: {error}" + ), + ); + } + }) + } +} diff --git a/codex-rs/ext/skills/src/config.rs b/codex-rs/ext/skills/src/config.rs index fe98df93bd..563bcb55dd 100644 --- a/codex-rs/ext/skills/src/config.rs +++ b/codex-rs/ext/skills/src/config.rs @@ -9,8 +9,8 @@ pub struct SkillsExtensionConfig { pub max_context_tokens: Option, /// Whether bundled skills are eligible for discovery. pub bundled_skills_enabled: bool, - /// Whether orchestrator-owned skills are eligible for discovery. - pub orchestrator_skills_enabled: bool, + /// Whether cloud skills are discovered and exposed to the model. + pub cloud_skill_enabled: bool, /// Whether cheap skill selectors run in shadow mode without changing prompt contents. pub shadow_selection_enabled: bool, } diff --git a/codex-rs/ext/skills/src/extension.rs b/codex-rs/ext/skills/src/extension.rs index e2400b9db4..c49e3d929c 100644 --- a/codex-rs/ext/skills/src/extension.rs +++ b/codex-rs/ext/skills/src/extension.rs @@ -76,6 +76,9 @@ use crate::warnings::bounded_warnings; use crate::world_state_catalogs::CatalogContext; use crate::world_state_catalogs::CatalogStatus; +#[path = "cloud_skill.rs"] +mod cloud_skill; + struct SkillsExtension { providers: SkillProviders, event_sink: Arc, @@ -145,13 +148,13 @@ where mcp_resources: input.mcp_resource_client.clone(), extension_metrics: input.extension_metrics.clone(), }); - let orchestrator_skills_available = !input + let cloud_skills_available = !input .environments .iter() .any(|environment| environment.environment_id == LOCAL_ENVIRONMENT_ID); input.thread_store.insert(SkillsThreadState::new( (self.config_from_host)(input.config), - orchestrator_skills_available, + cloud_skills_available, )); }) } @@ -172,11 +175,8 @@ where if let Some(state) = thread_store.get::() { state.set_config(next_config); } else { - let orchestrator_skills_available = true; - thread_store.insert(SkillsThreadState::new( - next_config, - orchestrator_skills_available, - )); + let cloud_skills_available = true; + thread_store.insert(SkillsThreadState::new(next_config, cloud_skills_available)); } } } @@ -207,7 +207,7 @@ where host_snapshot: None, include_host_skills: false, include_bundled_skills: config.bundled_skills_enabled, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: session_store .get::() .and_then(|state| state.mcp_resources.clone()), @@ -306,7 +306,7 @@ where host_snapshot: None, include_host_skills: false, include_bundled_skills: false, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery: step_store .get::() @@ -384,7 +384,7 @@ where host_snapshot: host_snapshot.clone(), include_host_skills: host_skills.is_none() && !host_catalog_in_world_state, include_bundled_skills: config.bundled_skills_enabled, - include_orchestrator_skills: thread_state.orchestrator_skills_enabled(), + include_cloud_skills: thread_state.cloud_skill_enabled(), mcp_resources: mcp_resources.clone(), executor_capability_discovery: None, }; @@ -423,7 +423,7 @@ where let mut turn_catalog = catalog.clone(); turn_catalog.entries.retain(|entry| { entry.authority.kind != SkillSourceKind::Executor - && entry.authority.kind != SkillSourceKind::Orchestrator + && entry.authority.kind != SkillSourceKind::Cloud }); let model_info = thread_store.get::(); let include_usage = model_info @@ -581,16 +581,13 @@ impl SkillsExtension { mut query: SkillListQuery, thread_state: &SkillsThreadState, ) -> SkillCatalog { - let include_orchestrator_skills = query.include_orchestrator_skills; - let orchestrator_query = query.clone(); - query.include_orchestrator_skills = false; + let include_cloud_skills = query.include_cloud_skills; + query.include_cloud_skills = false; let mut catalog = self.providers.list_for_turn(query).await; - if include_orchestrator_skills { - let orchestrator_catalog = thread_state - .orchestrator_catalog_snapshot(&self.providers, orchestrator_query) - .await; - catalog.extend(orchestrator_catalog); + if include_cloud_skills { + let cloud_catalog = thread_state.cloud_catalog_snapshot(); + catalog.extend(cloud_catalog); } catalog } @@ -674,6 +671,7 @@ pub fn install_with_providers_and_metrics( }); registry.thread_lifecycle_contributor(extension.clone()); registry.turn_lifecycle_contributor(Arc::new(SkillTelemetry)); + registry.turn_lifecycle_contributor(extension.clone()); registry.config_contributor(extension.clone()); registry.prompt_contributor(extension.clone()); registry.turn_input_contributor(extension.clone()); diff --git a/codex-rs/ext/skills/src/host_prompt.rs b/codex-rs/ext/skills/src/host_prompt.rs index 28dc95d8d0..8e59720eda 100644 --- a/codex-rs/ext/skills/src/host_prompt.rs +++ b/codex-rs/ext/skills/src/host_prompt.rs @@ -11,7 +11,7 @@ use crate::render::truncate_main_prompt_contents; /// Host skill prompts already supplied or superseded by an extension. /// /// Core preserves its host skill invocation lifecycle while avoiding duplicate -/// prompts and retaining executor/orchestrator skill precedence. +/// prompts and retaining executor/cloud skill precedence. #[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct InjectedHostSkillPrompts { paths: HashSet, diff --git a/codex-rs/ext/skills/src/lib.rs b/codex-rs/ext/skills/src/lib.rs index b3fdc291b9..8f0a7e2c3a 100644 --- a/codex-rs/ext/skills/src/lib.rs +++ b/codex-rs/ext/skills/src/lib.rs @@ -18,6 +18,7 @@ mod render; mod render_observability; mod selection; mod shadow_selection_experiment; +mod skills_extension_state; mod sources; mod state; mod telemetry; @@ -40,10 +41,11 @@ pub use host_snapshot::HostSkillsSnapshot; pub use invocation::detect_implicit_skill_invocation; pub use provider::ExecutorSkillProvider; pub use provider::HostSkillProvider; -pub use provider::OrchestratorSkillProvider; pub use provider::SkillProvider; +pub(crate) use skills_extension_state::SkillsExtensionState; pub use sources::SkillProviderSource; pub use sources::SkillProviders; +pub use state::SkillsThreadState; pub use telemetry::record_plugin_turn_usage; /// Recognizes persisted explicit skill prompts without exposing their fragment implementation. diff --git a/codex-rs/ext/skills/src/provider.rs b/codex-rs/ext/skills/src/provider.rs index 8922506b3d..0802cb43cf 100644 --- a/codex-rs/ext/skills/src/provider.rs +++ b/codex-rs/ext/skills/src/provider.rs @@ -5,7 +5,6 @@ use std::sync::Arc; mod executor; mod host; -mod orchestrator; use crate::HostSkillsSnapshot; use codex_exec_server::ExecutorCapabilityDiscoverySnapshot; @@ -25,7 +24,6 @@ use crate::catalog::SkillSearchResult; pub use executor::ExecutorSkillProvider; pub(crate) use executor::attribute_executor_plugins; pub use host::HostSkillProvider; -pub use orchestrator::OrchestratorSkillProvider; pub(crate) const MAX_SKILL_RESOURCE_CONTENT_BYTES: usize = 1024 * 1024; @@ -37,7 +35,7 @@ pub struct SkillListQuery { pub host_snapshot: Option>, pub include_host_skills: bool, pub include_bundled_skills: bool, - pub include_orchestrator_skills: bool, + pub include_cloud_skills: bool, pub mcp_resources: Option>, /// Present only when the opt-in high-level executor discovery path is selected. pub executor_capability_discovery: Option, diff --git a/codex-rs/ext/skills/src/provider/orchestrator.rs b/codex-rs/ext/skills/src/provider/orchestrator.rs deleted file mode 100644 index d5b7015e23..0000000000 --- a/codex-rs/ext/skills/src/provider/orchestrator.rs +++ /dev/null @@ -1,380 +0,0 @@ -use std::collections::HashSet; -use std::time::Duration; - -use codex_mcp::CODEX_APPS_MCP_SERVER_NAME; -use codex_protocol::mcp::Resource; -use codex_protocol::mcp::ResourceContent; -use codex_protocol::protocol::SkillScope; -use url::Url; - -use crate::catalog::SkillAuthority; -use crate::catalog::SkillCatalog; -use crate::catalog::SkillCatalogEntry; -use crate::catalog::SkillPackageId; -use crate::catalog::SkillProviderError; -use crate::catalog::SkillReadResult; -use crate::catalog::SkillResourceId; -use crate::catalog::SkillSearchResult; -use crate::catalog::SkillSourceKind; -use crate::provider::MAX_SKILL_RESOURCE_CONTENT_BYTES; -use crate::provider::SkillListQuery; -use crate::provider::SkillProvider; -use crate::provider::SkillProviderFuture; -use crate::provider::SkillReadRequest; -use crate::provider::SkillSearchRequest; - -const ORCHESTRATOR_SKILL_MIME_TYPE: &str = "mcp/skill"; -const ORCHESTRATOR_SKILL_DISCOVERY_TIMEOUT: Duration = Duration::from_secs(10); -const ORCHESTRATOR_SKILL_DISCOVERY_DURATION_METRIC: &str = - "codex.skills.orchestrator.discovery.duration_ms"; -const ORCHESTRATOR_SKILL_DISCOVERY_RESOURCES_METRIC: &str = - "codex.skills.orchestrator.discovery.resources_total"; -const ORCHESTRATOR_SKILL_READ_TIMEOUT: Duration = Duration::from_secs(10); -const MAX_RESOURCE_PAGES: usize = 10; -const MAX_ORCHESTRATOR_SKILLS: usize = 100; -const MAX_HIDDEN_ORCHESTRATOR_SKILLS: usize = MAX_RESOURCE_PAGES * MAX_ORCHESTRATOR_SKILLS; -const MAX_SKILL_NAME_CHARS: usize = 64; -const MAX_QUALIFIED_SKILL_NAME_CHARS: usize = 128; -const MAX_SKILL_PACKAGE_URI_CHARS: usize = 1_024; -const MAX_SKILL_RESOURCE_URI_CHARS: usize = 2_048; -/// Discovers and reads skills owned by the orchestrator. -/// -/// The provider uses session-scoped resources without exposing the transport or -/// resource server to callers that configure the skills extension. -#[derive(Clone, Debug, Default)] -pub struct OrchestratorSkillProvider; - -impl OrchestratorSkillProvider { - pub fn new() -> Self { - Self - } -} - -impl SkillProvider for OrchestratorSkillProvider { - fn list(&self, query: SkillListQuery) -> SkillProviderFuture<'_, SkillCatalog> { - Box::pin(async move { - let Some(client) = query.mcp_resources else { - return Ok(SkillCatalog::default()); - }; - if !client.has_server(CODEX_APPS_MCP_SERVER_NAME).await { - return Ok(SkillCatalog::default()); - } - - let _discovery_timer = - codex_otel::start_global_timer(ORCHESTRATOR_SKILL_DISCOVERY_DURATION_METRIC, &[]) - .ok(); - let discovery_deadline = - tokio::time::Instant::now() + ORCHESTRATOR_SKILL_DISCOVERY_TIMEOUT; - let mut catalog = SkillCatalog::default(); - let mut cursor = None; - let mut seen_cursors = HashSet::new(); - let mut visible_skills_seen = 0usize; - let mut hidden_skills_seen = 0usize; - let mut skipped_resources = 0usize; - let mut truncated = false; - let mut completed_pages = 0usize; - let mut total_resources = 0usize; - - for _ in 0..MAX_RESOURCE_PAGES { - let page = match tokio::time::timeout_at( - discovery_deadline, - client.list_resources(CODEX_APPS_MCP_SERVER_NAME, cursor.clone()), - ) - .await - { - Ok(result) => result.map_err(|err| { - SkillProviderError::new(format!( - "failed to list orchestrator skill resources: {err:#}" - )) - }), - Err(_) => Err(SkillProviderError::new(format!( - "orchestrator skill discovery timed out after {ORCHESTRATOR_SKILL_DISCOVERY_TIMEOUT:?}" - ))), - }; - let result = match page { - Ok(result) => result, - Err(err) if completed_pages == 0 => return Err(err), - Err(err) => { - let page_word = if completed_pages == 1 { - "page" - } else { - "pages" - }; - catalog.warnings.push(format!( - "Orchestrator skill discovery stopped after {completed_pages} resource {page_word}: {}", - err.message - )); - cursor = None; - break; - } - }; - completed_pages = completed_pages.saturating_add(1); - total_resources = total_resources.saturating_add(result.resources.len()); - - for resource in &result.resources { - if resource.mime_type.as_deref() != Some(ORCHESTRATOR_SKILL_MIME_TYPE) { - continue; - } - match catalog_entry_from_resource(resource) { - Some(entry) => { - if entry.prompt_visible { - if visible_skills_seen >= MAX_ORCHESTRATOR_SKILLS { - truncated = true; - continue; - } - visible_skills_seen = visible_skills_seen.saturating_add(1); - } else { - if hidden_skills_seen >= MAX_HIDDEN_ORCHESTRATOR_SKILLS { - truncated = true; - continue; - } - hidden_skills_seen = hidden_skills_seen.saturating_add(1); - } - catalog.push_entry(entry); - } - None => skipped_resources = skipped_resources.saturating_add(1), - } - } - - let Some(next_cursor) = result.next_cursor else { - cursor = None; - break; - }; - if !seen_cursors.insert(next_cursor.clone()) { - catalog.warnings.push( - "Orchestrator skill resource pagination returned a duplicate cursor." - .to_string(), - ); - cursor = None; - break; - } - cursor = Some(next_cursor); - } - - if cursor.is_some() || truncated { - catalog.warnings.push(format!( - "Orchestrator skill discovery was truncated at {MAX_ORCHESTRATOR_SKILLS} visible skills, {MAX_HIDDEN_ORCHESTRATOR_SKILLS} hidden skills, or {MAX_RESOURCE_PAGES} resource pages." - )); - } - if skipped_resources > 0 { - catalog.warnings.push(format!( - "Skipped {skipped_resources} malformed orchestrator skill resources." - )); - } - - if let Some(metrics) = codex_otel::global() { - let _ = metrics.histogram( - ORCHESTRATOR_SKILL_DISCOVERY_RESOURCES_METRIC, - i64::try_from(total_resources).unwrap_or(i64::MAX), - &[], - ); - } - - Ok(catalog) - }) - } - - fn read<'a>( - &'a self, - request: SkillReadRequest<'a>, - ) -> SkillProviderFuture<'a, SkillReadResult> { - Box::pin(async move { - if request.authority - != SkillAuthority::new(SkillSourceKind::Orchestrator, CODEX_APPS_MCP_SERVER_NAME) - { - return Err(SkillProviderError::new(format!( - "orchestrator skill provider cannot read authority {}", - request.authority.id - ))); - } - if !resource_belongs_to_package(&request.package.0, request.resource.as_str()) { - return Err(SkillProviderError::new( - "orchestrator skill resource does not match its package", - )); - } - - let Some(client) = request.mcp_resources.as_ref() else { - return Err(SkillProviderError::new( - "session MCP resource client is not configured", - )); - }; - let result = tokio::time::timeout( - ORCHESTRATOR_SKILL_READ_TIMEOUT, - client.read_resource(CODEX_APPS_MCP_SERVER_NAME, request.resource.as_str()), - ) - .await - .map_err(|_| { - SkillProviderError::new(format!( - "orchestrator skill read timed out after {ORCHESTRATOR_SKILL_READ_TIMEOUT:?}" - )) - })? - .map_err(|err| { - SkillProviderError::new(format!( - "failed to read orchestrator skill resource {}: {err:#}", - request.resource.as_str() - )) - })?; - let contents = result - .contents - .into_iter() - .find_map(|contents| match contents { - ResourceContent::Text { uri, text, .. } if uri == request.resource.as_str() => { - Some(text) - } - ResourceContent::Text { .. } | ResourceContent::Blob { .. } => None, - }); - let Some(contents) = contents else { - return Err(SkillProviderError::new(format!( - "orchestrator skill resource {} did not return matching text contents", - request.resource.as_str() - ))); - }; - if contents.len() > MAX_SKILL_RESOURCE_CONTENT_BYTES { - return Err(SkillProviderError::new(format!( - "orchestrator skill resource {} exceeds the {MAX_SKILL_RESOURCE_CONTENT_BYTES}-byte read limit", - request.resource.as_str() - ))); - } - - Ok(SkillReadResult { - resource: request.resource, - contents, - }) - }) - } - - fn search(&self, _request: SkillSearchRequest) -> SkillProviderFuture<'_, SkillSearchResult> { - Box::pin(async { Ok(SkillSearchResult::default()) }) - } -} - -fn catalog_entry_from_resource(resource: &Resource) -> Option { - let uri = validated_skill_uri(resource.uri.as_str(), MAX_SKILL_PACKAGE_URI_CHARS)?; - let namespace = uri.strip_prefix("skill://")?.split_once('/')?.0; - let meta = resource.meta.as_ref()?.as_object()?; - let allow_implicit_invocation = meta - .get("allow_implicit_invocation") - .and_then(serde_json::Value::as_bool) - .unwrap_or(true); - let skill_name = normalized_label(meta.get("skill_name")?.as_str()?, MAX_SKILL_NAME_CHARS)?; - let user_owned = meta.get("source").and_then(|value| value.as_str()) == Some("user"); - let name = if user_owned { - skill_name - } else { - let plugin_name = - normalized_label(meta.get("plugin_name")?.as_str()?, MAX_SKILL_NAME_CHARS)?; - let qualified_name = format!("{plugin_name}:{skill_name}"); - (qualified_name.chars().count() <= MAX_QUALIFIED_SKILL_NAME_CHARS) - .then_some(qualified_name)? - }; - let description = normalized_description(resource.description.as_deref().unwrap_or_default())?; - let main_prompt = main_prompt_uri(uri); - - let mut entry = SkillCatalogEntry::new( - SkillPackageId(uri.to_string()), - SkillAuthority::new(SkillSourceKind::Orchestrator, CODEX_APPS_MCP_SERVER_NAME), - name, - description, - SkillResourceId::new(main_prompt), - ) - .with_display_path(uri) - .with_alias_root(format!("skill://{namespace}")); - entry.plugin_id = meta - .get("plugin_id") - .and_then(serde_json::Value::as_str) - .map(str::to_owned); - entry.canonical_skill_id = meta - .get("skill_id") - .and_then(serde_json::Value::as_str) - .map(str::to_owned); - entry.analytics_scope = user_owned.then_some(SkillScope::User); - - Some(if allow_implicit_invocation { - entry - } else { - entry.hidden_from_prompt() - }) -} - -fn validated_skill_uri(uri: &str, max_chars: usize) -> Option<&str> { - validated_skill_url(uri, max_chars).map(|_| uri) -} - -fn validated_skill_url(uri: &str, max_chars: usize) -> Option { - if uri.chars().count() > max_chars - || uri - .chars() - .any(|ch| ch.is_control() || ch.is_whitespace() || matches!(ch, '<' | '>')) - { - return None; - } - - let url = Url::parse(uri).ok()?; - let path_is_valid = url.path_segments().is_some_and(|segments| { - let segments = segments.collect::>(); - !segments.is_empty() && segments.iter().all(|segment| !segment.is_empty()) - }); - (url.scheme() == "skill" - && url.as_str() == uri - && url.host_str().is_some_and(|host| !host.is_empty()) - && url.username().is_empty() - && url.password().is_none() - && url.port().is_none() - && url.query().is_none() - && url.fragment().is_none() - && path_is_valid) - .then_some(url) -} - -fn resource_belongs_to_package(package: &str, resource: &str) -> bool { - let Some(package) = validated_skill_url(package, MAX_SKILL_PACKAGE_URI_CHARS) else { - return false; - }; - let Some(resource) = validated_skill_url(resource, MAX_SKILL_RESOURCE_URI_CHARS) else { - return false; - }; - - let Some(package_segments) = package.path_segments() else { - return false; - }; - let Some(resource_segments) = resource.path_segments() else { - return false; - }; - let package_segments = package_segments.collect::>(); - let resource_segments = resource_segments.collect::>(); - - package.scheme() == resource.scheme() - && package.host_str() == resource.host_str() - && resource_segments.len() > package_segments.len() - && resource_segments.starts_with(&package_segments) -} - -fn normalized_label(value: &str, max_chars: usize) -> Option { - let value = normalized_single_line(value, max_chars)?; - let invalid = value.is_empty() || value.chars().any(|ch| matches!(ch, '&' | '<' | '>')); - (!invalid).then_some(value) -} - -fn normalized_description(value: &str) -> Option { - let value = value.split_whitespace().collect::>().join(" "); - if value.chars().any(char::is_control) { - return None; - } - - Some( - value - .replace('&', "&") - .replace('<', "<") - .replace('>', ">"), - ) -} - -fn normalized_single_line(value: &str, max_chars: usize) -> Option { - let value = value.split_whitespace().collect::>().join(" "); - let valid = value.chars().count() <= max_chars && !value.chars().any(char::is_control); - valid.then_some(value) -} - -fn main_prompt_uri(package_uri: &str) -> String { - format!("{}/SKILL.md", package_uri.trim_end_matches('/')) -} diff --git a/codex-rs/ext/skills/src/render.rs b/codex-rs/ext/skills/src/render.rs index ba7a4b7e71..9f0bf4c824 100644 --- a/codex-rs/ext/skills/src/render.rs +++ b/codex-rs/ext/skills/src/render.rs @@ -191,7 +191,7 @@ struct SkillLine<'a> { impl<'a> SkillLine<'a> { fn new(entry: &'a SkillCatalogEntry, policy: SkillCatalogRenderPolicy) -> Self { let locator = match &entry.authority.kind { - SkillSourceKind::Executor | SkillSourceKind::Orchestrator => entry.id.0.as_str(), + SkillSourceKind::Executor | SkillSourceKind::Cloud => entry.id.0.as_str(), SkillSourceKind::Host | SkillSourceKind::Custom(_) => entry.rendered_path(), }; Self::with_locator(entry, policy, locator.to_string()) @@ -210,7 +210,7 @@ impl<'a> SkillLine<'a> { locator_kind: match &entry.authority.kind { SkillSourceKind::Host => "file", SkillSourceKind::Executor => "executor package", - SkillSourceKind::Orchestrator => "orchestrator package", + SkillSourceKind::Cloud => "cloud package", SkillSourceKind::Custom(_) => "custom resource", }, } @@ -460,7 +460,7 @@ pub(crate) struct AvailableSkillsRender { #[derive(Default)] pub(crate) struct RenderedSkillCatalogs { pub(crate) executor: Option, - pub(crate) orchestrator: Option, + pub(crate) cloud: Option, pub(crate) host: Option, } @@ -535,7 +535,7 @@ pub(crate) fn render_available_skills( pub(crate) fn render_combined_available_skills( executor_catalog: &SkillCatalog, - orchestrator_catalog: &SkillCatalog, + cloud_catalog: &SkillCatalog, host_catalog: &SkillCatalog, budget: SkillMetadataBudget, include_skills_usage_instructions: bool, @@ -545,7 +545,7 @@ pub(crate) fn render_combined_available_skills( .iter() .filter(|entry| entry.is_model_visible()) .collect::>(); - let mut orchestrator_entries = orchestrator_catalog + let mut cloud_entries = cloud_catalog .entries .iter() .filter(|entry| entry.is_model_visible()) @@ -556,11 +556,11 @@ pub(crate) fn render_combined_available_skills( .filter(|entry| entry.is_model_visible()) .collect::>(); SkillCatalogRenderPolicy::ExtensionCompatible.order_entries(&mut executor_entries); - SkillCatalogRenderPolicy::ExtensionCompatible.order_entries(&mut orchestrator_entries); + SkillCatalogRenderPolicy::ExtensionCompatible.order_entries(&mut cloud_entries); SkillCatalogRenderPolicy::CoreCompatible.order_entries(&mut host_entries); let nonempty_catalog_count = [ !executor_entries.is_empty(), - !orchestrator_entries.is_empty(), + !cloud_entries.is_empty(), !host_entries.is_empty(), ] .into_iter() @@ -574,8 +574,8 @@ pub(crate) fn render_combined_available_skills( budget, include_skills_usage_instructions, ), - orchestrator: render_available_skills( - orchestrator_catalog, + cloud: render_available_skills( + cloud_catalog, SkillCatalogRenderPolicy::ExtensionCompatible, budget, include_skills_usage_instructions, @@ -593,7 +593,7 @@ pub(crate) fn render_combined_available_skills( let host_policy = SkillCatalogRenderPolicy::CoreCompatible; let absolute = render_combined_lines( CatalogLines::unaliased(&executor_entries, extension_policy), - CatalogLines::unaliased(&orchestrator_entries, extension_policy), + CatalogLines::unaliased(&cloud_entries, extension_policy), CatalogLines::unaliased(&host_entries, host_policy), budget, ); @@ -601,28 +601,28 @@ pub(crate) fn render_combined_available_skills( let mut selected = absolute; let host_only_aliases = build_aliased_combined_catalog( CatalogLines::unaliased(&executor_entries, extension_policy), - CatalogLines::unaliased(&orchestrator_entries, extension_policy), + CatalogLines::unaliased(&cloud_entries, extension_policy), CatalogLines::aliased(&host_entries, host_policy), budget, include_skills_usage_instructions, ); let executor_only_aliases = build_aliased_combined_catalog( CatalogLines::aliased(&executor_entries, extension_policy), - CatalogLines::unaliased(&orchestrator_entries, extension_policy), + CatalogLines::unaliased(&cloud_entries, extension_policy), CatalogLines::unaliased(&host_entries, host_policy), budget, include_skills_usage_instructions, ); - let orchestrator_only_aliases = build_aliased_combined_catalog( + let cloud_only_aliases = build_aliased_combined_catalog( CatalogLines::unaliased(&executor_entries, extension_policy), - CatalogLines::aliased(&orchestrator_entries, extension_policy), + CatalogLines::aliased(&cloud_entries, extension_policy), CatalogLines::unaliased(&host_entries, host_policy), budget, include_skills_usage_instructions, ); let all_source_aliases = build_aliased_combined_catalog( CatalogLines::aliased(&executor_entries, extension_policy), - CatalogLines::aliased(&orchestrator_entries, extension_policy), + CatalogLines::aliased(&cloud_entries, extension_policy), CatalogLines::aliased(&host_entries, host_policy), budget, include_skills_usage_instructions, @@ -631,7 +631,7 @@ pub(crate) fn render_combined_available_skills( for candidate in [ host_only_aliases, executor_only_aliases, - orchestrator_only_aliases, + cloud_only_aliases, all_source_aliases, ] .into_iter() @@ -649,14 +649,14 @@ pub(crate) fn render_combined_available_skills( RenderedSkillCatalogs { executor: Some(selected.executor), - orchestrator: Some(selected.orchestrator), + cloud: Some(selected.cloud), host: Some(selected.host), } } struct CombinedAvailableSkillsRender { executor: AvailableSkillsRender, - orchestrator: AvailableSkillsRender, + cloud: AvailableSkillsRender, host: AvailableSkillsRender, } @@ -705,29 +705,23 @@ impl<'a> CatalogLines<'a> { fn render_combined_lines( executor: CatalogLines<'_>, - orchestrator: CatalogLines<'_>, + cloud: CatalogLines<'_>, host: CatalogLines<'_>, budget: SkillMetadataBudget, ) -> CombinedAvailableSkillsRender { let executor_end = executor.skills.len(); - let orchestrator_end = executor_end.saturating_add(orchestrator.skills.len()); + let cloud_end = executor_end.saturating_add(cloud.skills.len()); let mut lines = executor.skills; - lines.extend(orchestrator.skills); + lines.extend(cloud.skills); lines.extend(host.skills); let mut allocations = allocate_skill_lines(&lines, budget); - let omission_marker = reserve_non_host_omission_marker( - &lines, - executor_end, - orchestrator_end, - budget, - &mut allocations, - ); - let (executor_omission_marker, orchestrator_omission_marker) = - if executor_end == orchestrator_end { - (omission_marker, None) - } else { - (None, omission_marker) - }; + let omission_marker = + reserve_non_host_omission_marker(&lines, executor_end, cloud_end, budget, &mut allocations); + let (executor_omission_marker, cloud_omission_marker) = if executor_end == cloud_end { + (omission_marker, None) + } else { + (None, omission_marker) + }; CombinedAvailableSkillsRender { executor: render_combined_group( @@ -737,16 +731,16 @@ fn render_combined_lines( executor.root_lines, executor_omission_marker, ), - orchestrator: render_combined_group( - &lines[executor_end..orchestrator_end], - &allocations[executor_end..orchestrator_end], - orchestrator.prompt_kind, - orchestrator.root_lines, - orchestrator_omission_marker, + cloud: render_combined_group( + &lines[executor_end..cloud_end], + &allocations[executor_end..cloud_end], + cloud.prompt_kind, + cloud.root_lines, + cloud_omission_marker, ), host: render_combined_group( - &lines[orchestrator_end..], - &allocations[orchestrator_end..], + &lines[cloud_end..], + &allocations[cloud_end..], host.prompt_kind, host.root_lines, /*omission_marker*/ None, @@ -787,23 +781,19 @@ fn render_combined_group( fn build_aliased_combined_catalog( executor: CatalogLines<'_>, - orchestrator: CatalogLines<'_>, + cloud: CatalogLines<'_>, host: CatalogLines<'_>, budget: SkillMetadataBudget, include_skills_usage_instructions: bool, ) -> Option { - if [ - &executor.root_lines, - &orchestrator.root_lines, - &host.root_lines, - ] - .into_iter() - .all(Vec::is_empty) + if [&executor.root_lines, &cloud.root_lines, &host.root_lines] + .into_iter() + .all(Vec::is_empty) { return None; } - let table_cost = [&executor, &orchestrator, &host] + let table_cost = [&executor, &cloud, &host] .into_iter() .filter(|catalog| !catalog.root_lines.is_empty()) .map(|catalog| { @@ -826,7 +816,7 @@ fn build_aliased_combined_catalog( }; Some(render_combined_lines( executor, - orchestrator, + cloud, host, adjusted_budget, )) @@ -841,7 +831,7 @@ fn combined_render_is_better( let priority = |rendered: &CombinedAvailableSkillsRender| { ( rendered.executor.report.included_count, - rendered.orchestrator.report.included_count, + rendered.cloud.report.included_count, rendered.host.report.included_count, ) }; @@ -850,7 +840,7 @@ fn combined_render_is_better( } let truncated_chars = |rendered: &CombinedAvailableSkillsRender| { - [&rendered.executor, &rendered.orchestrator, &rendered.host] + [&rendered.executor, &rendered.cloud, &rendered.host] .into_iter() .fold(0usize, |total, catalog| { total.saturating_add(catalog.report.truncated_description_chars) @@ -869,7 +859,7 @@ fn combined_available_skills_cost( rendered: &CombinedAvailableSkillsRender, include_skills_usage_instructions: bool, ) -> usize { - [&rendered.executor, &rendered.orchestrator, &rendered.host] + [&rendered.executor, &rendered.cloud, &rendered.host] .into_iter() .fold(0usize, |used, catalog| { let root_cost = if !catalog.skill_root_lines.is_empty() { @@ -894,12 +884,12 @@ fn combined_available_skills_cost( fn reserve_non_host_omission_marker( skill_lines: &[SkillLine<'_>], executor_end: usize, - orchestrator_end: usize, + cloud_end: usize, budget: SkillMetadataBudget, allocations: &mut [SkillLineAllocation], ) -> Option { loop { - let omitted_count = allocations[..orchestrator_end] + let omitted_count = allocations[..cloud_end] .iter() .filter(|allocation| matches!(allocation, SkillLineAllocation::Omitted)) .count(); @@ -913,9 +903,9 @@ fn reserve_non_host_omission_marker( return Some(marker); } - let index = (orchestrator_end..allocations.len()) + let index = (cloud_end..allocations.len()) .rev() - .chain((executor_end..orchestrator_end).rev()) + .chain((executor_end..cloud_end).rev()) .chain((0..executor_end).rev()) .find(|index| { matches!( @@ -1049,7 +1039,7 @@ pub(crate) fn build_alias_plan(entries: &[&SkillCatalogEntry]) -> Option "r", SkillSourceKind::Executor => "e", - SkillSourceKind::Orchestrator => "o", + SkillSourceKind::Cloud => "c", SkillSourceKind::Custom(_) => return None, }; @@ -1057,7 +1047,7 @@ pub(crate) fn build_alias_plan(entries: &[&SkillCatalogEntry]) -> Option shared_host_alias_roots(&alias_ordered_entries), - SkillSourceKind::Executor | SkillSourceKind::Orchestrator => alias_ordered_entries + SkillSourceKind::Executor | SkillSourceKind::Cloud => alias_ordered_entries .iter() .filter_map(|entry| entry.alias_root()) .map(str::to_string) @@ -1071,7 +1061,7 @@ pub(crate) fn build_alias_plan(entries: &[&SkillCatalogEntry]) -> Option String { let locator = match &entry.authority.kind { - SkillSourceKind::Executor | SkillSourceKind::Orchestrator => entry.id.0.as_str(), + SkillSourceKind::Executor | SkillSourceKind::Cloud => entry.id.0.as_str(), SkillSourceKind::Host | SkillSourceKind::Custom(_) => entry.rendered_path(), }; if entry.alias_root().is_none() { diff --git a/codex-rs/ext/skills/src/render_observability.rs b/codex-rs/ext/skills/src/render_observability.rs index c9720155e8..f5e1d2eeb0 100644 --- a/codex-rs/ext/skills/src/render_observability.rs +++ b/codex-rs/ext/skills/src/render_observability.rs @@ -11,7 +11,7 @@ use crate::render::SkillRenderReport; pub(crate) enum CatalogSurface { ThreadContext, ExecutorWorldState, - OrchestratorWorldState, + CloudWorldState, HostWorldState, TurnInput, } @@ -21,7 +21,7 @@ impl CatalogSurface { match self { Self::ThreadContext => "thread_context", Self::ExecutorWorldState => "executor_world_state", - Self::OrchestratorWorldState => "orchestrator_world_state", + Self::CloudWorldState => "cloud_world_state", Self::HostWorldState => "host_world_state", Self::TurnInput => "turn_input", } diff --git a/codex-rs/ext/skills/src/render_tests.rs b/codex-rs/ext/skills/src/render_tests.rs index ed4c72b0b8..823702a499 100644 --- a/codex-rs/ext/skills/src/render_tests.rs +++ b/codex-rs/ext/skills/src/render_tests.rs @@ -260,20 +260,20 @@ fn host_only_prompts_preserve_existing_behavior_with_and_without_aliases() { insta::assert_snapshot!(unaliased.body(), @r###" ## Skills - A skill is a set of instructions provided through a `SKILL.md` source. Below is the list of skills that can be used. Each entry includes a name, description, and source locator. `file` locators are on the host filesystem, `executor package` locators are owned by their execution environment, `orchestrator package` locators are opaque package identifiers, and `custom resource` locators use their provider's access mechanism. + A skill is a set of instructions provided through a `SKILL.md` source. Below is the list of skills that can be used. Each entry includes a name, description, and source locator. `file` locators are on the host filesystem, `executor package` locators are owned by their execution environment, `cloud package` locators are opaque package identifiers, and `custom resource` locators use their provider's access mechanism. ### Available skills - alpha: Alpha skill. (file: /Users/test/.codex/plugins/cache/openai-curated/host-plugin/1.0.0/skills-with-a-long-shared-root/alpha/SKILL.md) - beta: Beta skill. (file: /Users/test/.codex/plugins/cache/openai-curated/host-plugin/1.0.0/skills-with-a-long-shared-root/beta/SKILL.md) - gamma: Gamma skill. (file: /Users/test/.codex/plugins/cache/openai-curated/host-plugin/1.0.0/skills-with-a-long-shared-root/gamma/SKILL.md) ### How to use skills - - Discovery: The list above is the skills available in this session (name + description + source locator). `file` entries live on the host filesystem, `executor package` and `orchestrator package` entries are accessed directly through `skills.read`, and `custom resource` entries use their provider's access mechanism. + - Discovery: The list above is the skills available in this session (name + description + source locator). `file` entries live on the host filesystem, `executor package` and `cloud package` entries are accessed directly through `skills.read`, and `custom resource` entries use their provider's access mechanism. - Trigger rules: If the user names a skill (with `$SkillName` or plain text) OR the task clearly matches a skill's description shown above, you must use that skill for that turn. Multiple mentions mean use them all. Do not carry skills across turns unless re-mentioned. - Missing/blocked: If a named skill isn't in the list or its source can't be read, say so briefly and continue with the best fallback. - How to use a skill (progressive disclosure): - 1) After deciding to use a skill, the main agent must read its `SKILL.md` completely before taking task actions. For a `file` entry, open the listed path. For an `executor package` or `orchestrator package`, pass the listed locator directly to `skills.read` as `package`; root aliases are resolved automatically. Omit `resource` to read `SKILL.md` directly without calling `skills.list`. If a read is paginated, follow `next_cursor` until EOF. - 2) When `SKILL.md` references another resource, use the same access mechanism. For executor and orchestrator skills, pass the complete package-contained resource identifier with the same package to `skills.read`; do not treat `skill://` identifiers as filesystem paths. + 1) After deciding to use a skill, the main agent must read its `SKILL.md` completely before taking task actions. For a `file` entry, open the listed path. For an `executor package` or `cloud package`, pass the listed locator directly to `skills.read` as `package`; root aliases are resolved automatically. Omit `resource` to read `SKILL.md` directly without calling `skills.list`. If a read is paginated, follow `next_cursor` until EOF. + 2) When `SKILL.md` references another resource, use the same access mechanism. For executor and cloud skills, pass the complete package-contained resource identifier with the same package to `skills.read`; do not treat `skill://` identifiers as filesystem paths. 3) If `SKILL.md` points to extra folders such as `references/`, use its routing instructions to identify the resources required for the task. The main agent must read each required instruction or reference file itself before acting on it. Do not delegate reading, summarizing, or interpreting skill instructions to a subagent. Subagents may still perform task work when the selected skill allows it. - 4) For filesystem-backed skills, prefer running or patching provided scripts instead of retyping large code blocks. For executor and orchestrator skills, use `skills.read` and the available tools; do not invent a local path. + 4) For filesystem-backed skills, prefer running or patching provided scripts instead of retyping large code blocks. For executor and cloud skills, use `skills.read` and the available tools; do not invent a local path. 5) Reuse provided assets or templates through the same source access mechanism instead of recreating them. - Coordination and sequencing: - If multiple skills apply, choose the minimal set that covers the request and state the order you'll use them. @@ -470,7 +470,7 @@ async fn host_alias_roots_follow_core_discovery_order() -> Result<(), Box package.clone(), + SkillSourceKind::Cloud => package.clone(), SkillSourceKind::Host | SkillSourceKind::Executor | SkillSourceKind::Custom(_) => format!("{package}/SKILL.md"), @@ -658,25 +658,18 @@ fn mixed_catalogs_alias_all_skill_sources_under_budget_pressure() { executor_root, "executor", ); - let orchestrator_catalog = catalog( - SkillSourceKind::Orchestrator, - "codex_apps", - orchestrator_root, - "orchestrator", - ); + let cloud_catalog = catalog(SkillSourceKind::Cloud, "codex_apps", cloud_root, "cloud"); let host_catalog = catalog(SkillSourceKind::Host, "host", host_root, "host"); let rendered = render_combined_available_skills( &executor_catalog, - &orchestrator_catalog, + &cloud_catalog, &host_catalog, SkillMetadataBudget::Characters(900), /*include_skills_usage_instructions*/ true, ); let executor = rendered.executor.expect("executor catalog should render"); - let orchestrator = rendered - .orchestrator - .expect("orchestrator catalog should render"); + let cloud = rendered.cloud.expect("cloud catalog should render"); let host = rendered.host.expect("host catalog should render"); assert_eq!( @@ -684,8 +677,8 @@ fn mixed_catalogs_alias_all_skill_sources_under_budget_pressure() { vec![format!("- `e0` = `{executor_root}`")] ); assert_eq!( - orchestrator.skill_root_lines, - vec![format!("- `o0` = `{orchestrator_root}`")] + cloud.skill_root_lines, + vec![format!("- `c0` = `{cloud_root}`")] ); assert_eq!( host.skill_root_lines, @@ -698,10 +691,10 @@ fn mixed_catalogs_alias_all_skill_sources_under_budget_pressure() { .any(|line| line.contains("(executor package: e0/executor-0)")) ); assert!( - orchestrator + cloud .skill_lines .iter() - .any(|line| line.contains("(orchestrator package: o0/orchestrator-0)")) + .any(|line| line.contains("(cloud package: c0/cloud-0)")) ); assert!( host.skill_lines @@ -711,7 +704,7 @@ fn mixed_catalogs_alias_all_skill_sources_under_budget_pressure() { assert_eq!( ( executor.report.included_count, - orchestrator.report.included_count, + cloud.report.included_count, host.report.included_count, ), (3, 3, 3) @@ -749,17 +742,17 @@ fn mixed_catalog_prefers_executor_inclusion_over_total_aliased_inclusion() { ], warnings: Vec::new(), }; - let orchestrator_resource = "skill://orchestrator/one"; - let orchestrator_catalog = SkillCatalog { + let cloud_resource = "skill://cloud/one"; + let cloud_catalog = SkillCatalog { entries: vec![ SkillCatalogEntry::new( - SkillPackageId("o1".to_string()), - SkillAuthority::new(SkillSourceKind::Orchestrator, "codex_apps"), - "o1", + SkillPackageId("c1".to_string()), + SkillAuthority::new(SkillSourceKind::Cloud, "codex_apps"), + "c1", "", - SkillResourceId::new(orchestrator_resource), + SkillResourceId::new(cloud_resource), ) - .with_display_path(orchestrator_resource), + .with_display_path(cloud_resource), ], warnings: Vec::new(), }; @@ -767,17 +760,17 @@ fn mixed_catalog_prefers_executor_inclusion_over_total_aliased_inclusion() { let RenderedSkillCatalogs { host, executor, - orchestrator, + cloud, } = render_combined_available_skills( &executor_catalog, - &orchestrator_catalog, + &cloud_catalog, &host_catalog, SkillMetadataBudget::Tokens(74), /*include_skills_usage_instructions*/ false, ); let host = host.expect("host catalog should render"); let executor = executor.expect("executor catalog should render"); - let orchestrator = orchestrator.expect("orchestrator catalog should render"); + let cloud = cloud.expect("cloud catalog should render"); assert_eq!( executor.report, @@ -799,7 +792,7 @@ fn mixed_catalog_prefers_executor_inclusion_over_total_aliased_inclusion() { truncated_description_count: 0, } ); - assert_eq!(orchestrator.report.total_count, 1); + assert_eq!(cloud.report.total_count, 1); assert_eq!(host.skill_root_lines, Vec::::new()); } @@ -845,7 +838,7 @@ async fn singleton_plugin_versions_share_the_marketplace_alias_root() host_snapshot: Some(Arc::new(HostSkillsSnapshot::new(Arc::new(outcome)))), include_host_skills: true, include_bundled_skills: false, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery: None, }) diff --git a/codex-rs/ext/skills/src/shadow_selection_experiment/mod.rs b/codex-rs/ext/skills/src/shadow_selection_experiment/mod.rs index 953fec778b..dde04d4b7c 100644 --- a/codex-rs/ext/skills/src/shadow_selection_experiment/mod.rs +++ b/codex-rs/ext/skills/src/shadow_selection_experiment/mod.rs @@ -90,10 +90,10 @@ impl ShadowSelectionExperiment { .filter(|(_, entry)| { entry.is_model_visible() // Invocation observation currently exists only for host shell use and - // orchestrator reads. Keep the candidate set aligned with that universe. + // cloud reads. Keep the candidate set aligned with that universe. && matches!( &entry.authority.kind, - SkillSourceKind::Host | SkillSourceKind::Orchestrator + SkillSourceKind::Host | SkillSourceKind::Cloud ) && !explicitly_selected_skill_resources .contains(&normalize_skill_resource(entry.main_prompt.as_str())) @@ -209,7 +209,7 @@ impl ShadowSelectionExperiment { entry.is_model_visible() && matches!( &entry.authority.kind, - SkillSourceKind::Host | SkillSourceKind::Orchestrator + SkillSourceKind::Host | SkillSourceKind::Cloud ) }) { task_context.record( diff --git a/codex-rs/ext/skills/src/skills_extension_state.rs b/codex-rs/ext/skills/src/skills_extension_state.rs new file mode 100644 index 0000000000..c4d6831f1f --- /dev/null +++ b/codex-rs/ext/skills/src/skills_extension_state.rs @@ -0,0 +1,168 @@ +//! Stores published skill catalogs, executor discovery projections, and cached cloud resources. + +use std::collections::HashMap; +use std::sync::Arc; +use std::sync::Mutex; + +use codex_exec_server::ExecutorCapabilityDiscoverySnapshot; +use codex_mcp::McpResourceClient; +use codex_mcp::McpResourceClientAuthKey; +use codex_protocol::capabilities::SelectedCapabilityRoot; + +use crate::catalog::SkillAuthority; +use crate::catalog::SkillCatalog; +use crate::catalog::SkillPackageId; +use crate::catalog::SkillReadResult; +use crate::catalog::SkillResourceId; +use crate::provider::SkillReadRequest; + +const MAX_CACHED_CLOUD_RESOURCES: usize = 100; +const MAX_CACHED_CLOUD_CONTENT_BYTES: usize = 8 * 1024 * 1024; + +/// Stores published cloud and executor catalogs for a thread. +#[derive(Clone, Debug, Default)] +pub(crate) struct SkillsExtensionState { + pub(crate) executor_catalog_selection: ExecutorCatalogSelection, + pub(crate) executor_cache: Vec, + pub(crate) executor_discovery_cache: Option, + pub(crate) cloud_cache: Option>, +} + +/// Selects the existing cache entries published by the most recent refresh. +#[derive(Clone, Debug, Default)] +pub(crate) enum ExecutorCatalogSelection { + #[default] + Discovery, + Roots(Vec), +} + +/// Keeps cloud metadata and contents within one published auth scope and Apps availability state. +/// A successful turn refresh replaces the Arc so late reads cannot populate its successor. +pub(crate) struct CloudSkillGeneration { + pub(crate) auth_cache_key: Option, + pub(crate) mcp_resources: Option, + pub(crate) catalog: Option, + pub(crate) resources: Mutex, +} + +impl CloudSkillGeneration { + pub(crate) fn is_current(&self) -> bool { + self.auth_cache_key + == self.mcp_resources.as_ref().map(|client| { + client.auth_cache_key_for_server(codex_mcp::CODEX_APPS_MCP_SERVER_NAME) + }) + } +} + +impl std::fmt::Debug for CloudSkillGeneration { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("CloudSkillGeneration") + .field("catalog", &self.catalog) + .finish_non_exhaustive() + } +} + +/// Retains the legacy per-root catalog until the thread is dropped. +#[derive(Clone, Debug)] +pub(crate) struct CachedExecutorCatalog { + pub(crate) root: SelectedCapabilityRoot, + pub(crate) catalog: SkillCatalog, +} + +/// Retains the latest projection for snapshots; refresh only reuses successful unchanged inputs. +#[derive(Clone, Debug)] +pub(crate) struct CachedExecutorDiscoveryCatalog { + pub(crate) roots: Vec, + pub(crate) discovery: ExecutorCapabilityDiscoverySnapshot, + pub(crate) include_bundled_skills: bool, + pub(crate) catalog: SkillCatalog, +} + +impl CachedExecutorDiscoveryCatalog { + pub(crate) fn matches( + &self, + roots: &[SelectedCapabilityRoot], + discovery: Option<&ExecutorCapabilityDiscoverySnapshot>, + include_bundled_skills: bool, + ) -> bool { + discovery.is_some_and(|discovery| { + self.roots == roots + && self.include_bundled_skills == include_bundled_skills + && self.discovery.sandbox_contexts() == discovery.sandbox_contexts() + && self.discovery.roots().len() == discovery.roots().len() + && self.discovery.roots().iter().zip(discovery.roots()).all( + |(previous, current)| { + previous.selected_root == current.selected_root + && match (&previous.result, ¤t.result) { + (Ok(previous), Ok(current)) => Arc::ptr_eq(previous, current), + _ => false, + } + }, + ) + }) + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub(crate) struct SkillReadCacheKey { + authority: SkillAuthority, + package: SkillPackageId, + pub(crate) resource: SkillResourceId, +} + +impl From<&SkillReadRequest<'_>> for SkillReadCacheKey { + fn from(request: &SkillReadRequest<'_>) -> Self { + Self { + authority: request.authority.clone(), + package: request.package.clone(), + resource: request.resource.clone(), + } + } +} + +#[derive(Clone, Default)] +pub(crate) struct CloudResourceCache { + entries: HashMap, + contents_bytes: usize, +} + +impl CloudResourceCache { + pub(crate) fn get(&self, key: &SkillReadCacheKey) -> Option { + self.entries.get(key).cloned() + } + + pub(crate) fn insert( + &mut self, + key: SkillReadCacheKey, + result: SkillReadResult, + ) -> SkillReadResult { + if let Some(cached) = self.entries.get(&key) { + return cached.clone(); + } + + let contents_bytes = result.contents.len(); + let Some(next_contents_bytes) = self.contents_bytes.checked_add(contents_bytes) else { + return result; + }; + if self.entries.len() >= MAX_CACHED_CLOUD_RESOURCES + || next_contents_bytes > MAX_CACHED_CLOUD_CONTENT_BYTES + { + return result; + } + + self.contents_bytes = next_contents_bytes; + self.entries.insert(key, result.clone()); + result + } +} + +impl std::fmt::Debug for CloudResourceCache { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("CloudResourceCache") + .field("entry_count", &self.entries.len()) + .field("contents_bytes", &self.contents_bytes) + .finish_non_exhaustive() + } +} diff --git a/codex-rs/ext/skills/src/sources.rs b/codex-rs/ext/skills/src/sources.rs index 691eb3fa86..2d5d198250 100644 --- a/codex-rs/ext/skills/src/sources.rs +++ b/codex-rs/ext/skills/src/sources.rs @@ -40,15 +40,15 @@ impl SkillProviderSource { Self::new(SkillSourceKind::Executor, label, provider) } - pub fn orchestrator(label: impl Into, provider: Arc) -> Self { - Self::new(SkillSourceKind::Orchestrator, label, provider) + pub fn cloud(label: impl Into, provider: Arc) -> Self { + Self::new(SkillSourceKind::Cloud, label, provider) } fn should_list(&self, query: &SkillListQuery) -> bool { match &self.kind { SkillSourceKind::Host => query.include_host_skills, SkillSourceKind::Executor => !query.executor_roots.is_empty(), - SkillSourceKind::Orchestrator => query.include_orchestrator_skills, + SkillSourceKind::Cloud => query.include_cloud_skills, SkillSourceKind::Custom(_) => true, } } @@ -95,16 +95,16 @@ impl SkillProviders { self } - pub fn with_orchestrator_provider(mut self, provider: Arc) -> Self { + pub fn with_cloud_provider(mut self, provider: Arc) -> Self { self.sources - .push(SkillProviderSource::orchestrator("orchestrator", provider)); + .push(SkillProviderSource::cloud("cloud", provider)); self } - pub(crate) fn has_orchestrator_provider(&self) -> bool { + pub(crate) fn has_cloud_provider(&self) -> bool { self.sources .iter() - .any(|source| source.kind == SkillSourceKind::Orchestrator) + .any(|source| source.kind == SkillSourceKind::Cloud) } pub(crate) fn has_host_provider(&self) -> bool { @@ -118,7 +118,7 @@ impl SkillProviders { .await } - pub(crate) async fn list_orchestrator_for_turn( + pub(crate) async fn list_cloud_for_turn( &self, query: SkillListQuery, ) -> SkillProviderResult { @@ -127,7 +127,7 @@ impl SkillProviders { for source in self .sources .iter() - .filter(|source| source.kind == SkillSourceKind::Orchestrator) + .filter(|source| source.kind == SkillSourceKind::Cloud) { let source_catalog = source.provider.list(query.clone()).await.map_err(|err| { SkillProviderError::new(format!( diff --git a/codex-rs/ext/skills/src/state.rs b/codex-rs/ext/skills/src/state.rs index 19e53c35b0..32dc1a9447 100644 --- a/codex-rs/ext/skills/src/state.rs +++ b/codex-rs/ext/skills/src/state.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::collections::HashSet; use std::sync::Arc; use std::sync::Mutex; @@ -7,42 +6,46 @@ use std::sync::Weak; use codex_exec_server::Environment; use codex_exec_server::FileSystemSandboxContext; use codex_extension_api::ExtensionMetrics; -use codex_mcp::CODEX_APPS_MCP_SERVER_NAME; use codex_mcp::McpResourceClient; -use codex_mcp::McpResourceServerCacheKey; use codex_protocol::capabilities::SelectedCapabilityRoot; -use tokio::sync::OnceCell; use crate::SkillsExtensionConfig; +use crate::SkillsExtensionState; use crate::catalog::SkillAuthority; use crate::catalog::SkillCatalog; use crate::catalog::SkillCatalogEntry; use crate::catalog::SkillPackageId; +use crate::catalog::SkillProviderError; use crate::catalog::SkillProviderResult; use crate::catalog::SkillReadResult; -use crate::catalog::SkillResourceId; use crate::catalog::SkillSourceKind; use crate::provider::SkillListQuery; use crate::provider::SkillReadRequest; use crate::shadow_selection_experiment::RecentSkillInvocations; use crate::shadow_selection_experiment::ShadowSelectionTurnState; use crate::shadow_selection_experiment::ShadowTaskContext; +use crate::skills_extension_state::CachedExecutorCatalog; +use crate::skills_extension_state::CachedExecutorDiscoveryCatalog; +use crate::skills_extension_state::CloudResourceCache; +use crate::skills_extension_state::CloudSkillGeneration; +use crate::skills_extension_state::ExecutorCatalogSelection; +use crate::skills_extension_state::SkillReadCacheKey; use crate::sources::SkillProviders; -const MAX_CACHED_ORCHESTRATOR_RESOURCES: usize = 100; -const MAX_CACHED_ORCHESTRATOR_CONTENT_BYTES: usize = 8 * 1024 * 1024; +#[cfg(test)] +#[path = "cloud_cache_tests.rs"] +mod cloud_cache_tests; pub(crate) struct SkillsSessionState { pub(crate) mcp_resources: Option>, pub(crate) extension_metrics: Option>, } -pub(crate) struct SkillsThreadState { +/// Thread-owned skill configuration and caches; consumers can only read catalog snapshots. +pub struct SkillsThreadState { config: Mutex, - orchestrator_skills_available: bool, - executor_cache: Mutex>, - executor_discovery_cache: Mutex>, - orchestrator_cache: Mutex>>, + cloud_skills_available: bool, + skills_extension_state: Mutex, shadow_selection_turn: Mutex>, pub(crate) executor_read_snapshot: Mutex>, pub(crate) recent_skill_invocations: Arc, @@ -50,13 +53,11 @@ pub(crate) struct SkillsThreadState { } impl SkillsThreadState { - pub(crate) fn new(config: SkillsExtensionConfig, orchestrator_skills_available: bool) -> Self { + pub(crate) fn new(config: SkillsExtensionConfig, cloud_skills_available: bool) -> Self { Self { config: Mutex::new(config), - orchestrator_skills_available, - executor_cache: Mutex::new(Vec::new()), - executor_discovery_cache: Mutex::new(None), - orchestrator_cache: Mutex::new(None), + cloud_skills_available, + skills_extension_state: Mutex::new(SkillsExtensionState::default()), shadow_selection_turn: Mutex::new(None), executor_read_snapshot: Mutex::new(None), recent_skill_invocations: Arc::new(RecentSkillInvocations::default()), @@ -72,14 +73,22 @@ impl SkillsThreadState { } pub(crate) fn set_config(&self, config: SkillsExtensionConfig) { - *self + let mut previous = self .config .lock() - .unwrap_or_else(std::sync::PoisonError::into_inner) = config; + .unwrap_or_else(std::sync::PoisonError::into_inner); + if previous.cloud_skill_enabled != config.cloud_skill_enabled { + let mut catalogs = self + .skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + catalogs.cloud_cache = None; + } + *previous = config; } - pub(crate) fn orchestrator_skills_enabled(&self) -> bool { - self.orchestrator_skills_available && self.config().orchestrator_skills_enabled + pub(crate) fn cloud_skill_enabled(&self) -> bool { + self.cloud_skills_available && self.config().cloud_skill_enabled } pub(crate) fn replace_shadow_selection_turn( @@ -109,175 +118,118 @@ impl SkillsThreadState { .map(|turn| Arc::clone(&turn.state)) } - /// Returns catalogs for stable selected roots. - /// - /// Successful catalogs, including empty or warning-bearing catalogs, remain cached until - /// this thread state is dropped. Catalogs backed by failed discovery are not cached, so - /// later steps can recover. There is no filesystem watcher because selected roots are stable. + /// Refreshes the current step's executor catalog in the existing caches. #[tracing::instrument( - name = "skills.executor.catalog_snapshot", + name = "skills.executor.refresh_executor_catalog", level = "info", skip_all, fields(root_count = query.executor_roots.len()) )] - pub(crate) async fn executor_catalog_snapshot( + pub(crate) async fn refresh_executor_catalog( &self, providers: &SkillProviders, mut query: SkillListQuery, - ) -> SkillCatalog { - if query.executor_capability_discovery.is_some() { - return self - .executor_discovery_catalog_snapshot(providers, query) + ) { + let selection = if query.executor_capability_discovery.is_some() { + // High-level discovery is enabled: reuse or project its discovery snapshot. + self.executor_discovery_catalog_snapshot(providers, query) .await; - } - let roots = std::mem::take(&mut query.executor_roots); - let mut catalog = SkillCatalog::default(); - for root in roots { - query.executor_roots = vec![root.clone()]; - catalog.extend( - self.executor_root_catalog(providers, root, query.clone()) - .await, - ); - } - catalog + ExecutorCatalogSelection::Discovery + } else { + // High-level discovery is not enabled: retain the legacy per-root cache path. + let roots = std::mem::take(&mut query.executor_roots); + for root in &roots { + query.executor_roots = vec![root.clone()]; + self.executor_root_catalog(providers, root.clone(), query.clone()) + .await; + } + ExecutorCatalogSelection::Roots(roots) + }; + self.skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .executor_catalog_selection = selection; } + /// Reads the most recently refreshed selection without invoking providers. + pub fn executor_catalog_snapshot(&self) -> SkillCatalog { + let state = self + .skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + match &state.executor_catalog_selection { + ExecutorCatalogSelection::Discovery => state + .executor_discovery_cache + .as_ref() + .map(|cached| cached.catalog.clone()) + .unwrap_or_default(), + ExecutorCatalogSelection::Roots(roots) => { + let mut catalog = SkillCatalog::default(); + for root in roots { + if let Some(cached) = state + .executor_cache + .iter() + .find(|cached| &cached.root == root) + { + catalog.extend(cached.catalog.clone()); + } + } + catalog + } + } + } + + /// Reuses matching successful discovery or retains a fresh result for snapshot reads. async fn executor_discovery_catalog_snapshot( &self, providers: &SkillProviders, query: SkillListQuery, ) -> SkillCatalog { - let discovery_failed = query - .executor_capability_discovery - .as_ref() - .is_some_and(|discovery| discovery.roots().iter().any(|root| root.result.is_err())); - let sandbox_contexts = query - .executor_capability_discovery - .as_ref() - .map(|discovery| discovery.sandbox_contexts().clone()) - .unwrap_or_default(); - if let Some(cached) = self - .executor_discovery_cache - .lock() - .unwrap_or_else(std::sync::PoisonError::into_inner) - .as_ref() - .filter(|cached| { - cached.roots == query.executor_roots && cached.sandbox_contexts == sandbox_contexts + let discovery = query.executor_capability_discovery.clone(); + let discovery_failed = discovery.as_ref().is_some_and(|discovery| { + discovery.roots().iter().any(|root| { + root.result + .as_ref() + .ok() + .is_none_or(|discovered| discovered.error.is_some()) }) + }); + if !discovery_failed + && let Some(cached) = self + .skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .executor_discovery_cache + .as_ref() + .filter(|cached| { + cached.matches( + &query.executor_roots, + discovery.as_ref(), + query.include_bundled_skills, + ) + }) { return cached.catalog.clone(); } + let roots = query.executor_roots.clone(); + let include_bundled_skills = query.include_bundled_skills; let discovered = providers.list_executor_for_turn(query).await; - if discovery_failed { - return discovered; - } - let mut cache = self - .executor_discovery_cache + let mut state = self + .skills_extension_state .lock() .unwrap_or_else(std::sync::PoisonError::into_inner); - if let Some(cached) = cache - .as_ref() - .filter(|cached| cached.roots == roots && cached.sandbox_contexts == sandbox_contexts) - { - return cached.catalog.clone(); - } - *cache = Some(CachedExecutorDiscoveryCatalog { - roots, - sandbox_contexts, - catalog: discovered.clone(), - }); + // Retain failures for read-only snapshots; discovery_failed above prevents reuse. + state.executor_discovery_cache = + discovery.map(|discovery| CachedExecutorDiscoveryCatalog { + roots, + discovery, + include_bundled_skills, + catalog: discovered.clone(), + }); discovered } - #[tracing::instrument( - name = "skills.orchestrator.catalog_snapshot", - level = "info", - skip_all - )] - pub(crate) async fn orchestrator_catalog_snapshot( - &self, - providers: &SkillProviders, - query: SkillListQuery, - ) -> SkillCatalog { - if !query.include_orchestrator_skills { - return SkillCatalog::default(); - } - - let cache = self.orchestrator_cache(query.mcp_resources.as_deref()); - cache - .catalog - .get_or_init(|| async { - providers - .list_orchestrator_for_turn(query) - .await - .unwrap_or_else(|err| SkillCatalog { - warnings: vec![err.message], - ..Default::default() - }) - }) - .await - .clone() - } - - pub(crate) async fn read_skill( - &self, - providers: &SkillProviders, - request: SkillReadRequest<'_>, - ) -> SkillProviderResult { - if request.authority.kind != SkillSourceKind::Orchestrator { - return providers.read(request).await; - } - - let cache = self.orchestrator_cache(request.mcp_resources.as_deref()); - let cache_key = SkillReadCacheKey::from(&request); - if let Some(result) = cache - .resources - .lock() - .unwrap_or_else(std::sync::PoisonError::into_inner) - .get(&cache_key) - { - return Ok(result); - } - - let result = providers.read(request).await?; - if result.resource != cache_key.resource { - return Ok(result); - } - - Ok(cache - .resources - .lock() - .unwrap_or_else(std::sync::PoisonError::into_inner) - .insert(cache_key, result)) - } - - fn orchestrator_cache( - &self, - mcp_resources: Option<&McpResourceClient>, - ) -> Arc { - let mut cache = self - .orchestrator_cache - .lock() - .unwrap_or_else(std::sync::PoisonError::into_inner); - let cache_key = - mcp_resources.and_then(|client| client.server_cache_key(CODEX_APPS_MCP_SERVER_NAME)); - if let Some(cache) = cache - .as_ref() - .filter(|cache| cache.mcp_cache_key == cache_key) - { - return Arc::clone(cache); - } - - let next_cache = Arc::new(OrchestratorGenerationCache { - mcp_cache_key: cache_key, - catalog: OnceCell::new(), - resources: Mutex::new(OrchestratorResourceCache::default()), - }); - *cache = Some(Arc::clone(&next_cache)); - next_cache - } - #[tracing::instrument(name = "skills.executor.catalog_root", level = "info", skip_all)] async fn executor_root_catalog( &self, @@ -286,9 +238,10 @@ impl SkillsThreadState { query: SkillListQuery, ) -> SkillCatalog { if let Some(cached) = self - .executor_cache + .skills_extension_state .lock() .unwrap_or_else(std::sync::PoisonError::into_inner) + .executor_cache .iter() .find(|cached| cached.root == root) { @@ -296,10 +249,11 @@ impl SkillsThreadState { } let discovered = providers.list_executor_for_turn(query).await; - let mut cache = self - .executor_cache + let mut state = self + .skills_extension_state .lock() .unwrap_or_else(std::sync::PoisonError::into_inner); + let cache = &mut state.executor_cache; if let Some(cached) = cache.iter().find(|cached| cached.root == root) { return cached.catalog.clone(); } @@ -309,6 +263,158 @@ impl SkillsThreadState { }); discovered } + + /// Reads the last authorized turn-start catalog without discovery or retries. + /// Same-auth failures may retain it; disabled or invalidated catalogs are empty. + pub fn cloud_catalog_snapshot(&self) -> SkillCatalog { + let config = self + .config + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + if !config.cloud_skill_enabled || !self.cloud_skills_available { + return SkillCatalog::default(); + } + self.skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .cloud_cache + .as_ref() + .filter(|cache| cache.is_current()) + .and_then(|cache| cache.catalog.clone()) + .unwrap_or_default() + } + + fn cloud_cache(&self, mcp_resources: Option<&McpResourceClient>) -> Arc { + let mut state = self + .skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + let cache_key = mcp_resources + .map(|client| client.auth_cache_key_for_server(codex_mcp::CODEX_APPS_MCP_SERVER_NAME)); + if let Some(cache) = state + .cloud_cache + .as_ref() + .filter(|cache| cache.auth_cache_key == cache_key) + { + return Arc::clone(cache); + } + + let next_cache = Arc::new(CloudSkillGeneration { + auth_cache_key: cache_key, + mcp_resources: mcp_resources.cloned(), + catalog: None, + resources: Mutex::new(CloudResourceCache::default()), + }); + state.cloud_cache = Some(Arc::clone(&next_cache)); + next_cache + } + + /// The serialized turn-start lifecycle is the only discovery writer. + /// Attempt once per turn; readers never retry, including after a failed refresh. + #[tracing::instrument(name = "skills.cloud.refresh_cloud_catalog", level = "info", skip_all)] + pub(crate) async fn refresh_cloud_catalog( + &self, + providers: &SkillProviders, + query: SkillListQuery, + ) -> SkillProviderResult<()> { + if !self.cloud_skill_enabled() { + return Ok(()); + } + // Switch generations before the fallible lookup; only same-auth-scope failures + // may retain previously authorized metadata and contents. + let cache = self.cloud_cache(query.mcp_resources.as_deref()); + let mut catalog = providers.list_cloud_for_turn(query).await?; + catalog.entries.sort_by(|a, b| a.id.0.cmp(&b.id.0)); + let mut catalogs = self + .skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + if !cache.is_current() + || !catalogs + .cloud_cache + .as_ref() + .is_some_and(|current| Arc::ptr_eq(current, &cache)) + { + return Err(SkillProviderError::new( + "cloud skill cache changed during discovery", + )); + } + catalogs.cloud_cache = Some(Arc::new(CloudSkillGeneration { + auth_cache_key: cache.auth_cache_key.clone(), + mcp_resources: cache.mcp_resources.clone(), + catalog: Some(catalog), + resources: Mutex::new(CloudResourceCache::default()), + })); + Ok(()) + } + + pub(crate) async fn read_skill( + &self, + providers: &SkillProviders, + request: SkillReadRequest<'_>, + ) -> SkillProviderResult { + if request.authority.kind != SkillSourceKind::Cloud { + return providers.read(request).await; + } + + let cache = self.cloud_cache(request.mcp_resources.as_deref()); + let cache_key = SkillReadCacheKey::from(&request); + { + let config = self + .config + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + if !config.cloud_skill_enabled || !self.cloud_skills_available { + return Err(SkillProviderError::new("cloud skills are disabled")); + } + let catalogs = self + .skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + if !cache.is_current() + || !catalogs + .cloud_cache + .as_ref() + .is_some_and(|current| Arc::ptr_eq(current, &cache)) + { + return Err(SkillProviderError::new( + "cloud skill cache changed before read", + )); + } + if let Some(result) = cache + .resources + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .get(&cache_key) + { + return Ok(result); + } + } + + let result = providers.read(request).await?; + let catalogs = self + .skills_extension_state + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); + if !cache.is_current() + || !catalogs + .cloud_cache + .as_ref() + .is_some_and(|current| Arc::ptr_eq(current, &cache)) + { + return Err(SkillProviderError::new( + "cloud skill cache changed during read", + )); + } + if result.resource != cache_key.resource { + return Ok(result); + } + Ok(cache + .resources + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .insert(cache_key, result)) + } } /// One bounded executor resource, retained for continuations until replacement or thread drop. @@ -327,72 +433,6 @@ struct ShadowSelectionTurn { state: Arc, } -struct CachedExecutorCatalog { - root: SelectedCapabilityRoot, - catalog: SkillCatalog, -} - -struct CachedExecutorDiscoveryCatalog { - roots: Vec, - sandbox_contexts: HashMap, - catalog: SkillCatalog, -} - -struct OrchestratorGenerationCache { - mcp_cache_key: Option, - catalog: OnceCell, - resources: Mutex, -} - -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -struct SkillReadCacheKey { - authority: SkillAuthority, - package: SkillPackageId, - resource: SkillResourceId, -} - -impl From<&SkillReadRequest<'_>> for SkillReadCacheKey { - fn from(request: &SkillReadRequest<'_>) -> Self { - Self { - authority: request.authority.clone(), - package: request.package.clone(), - resource: request.resource.clone(), - } - } -} - -#[derive(Default)] -struct OrchestratorResourceCache { - entries: HashMap, - contents_bytes: usize, -} - -impl OrchestratorResourceCache { - fn get(&self, key: &SkillReadCacheKey) -> Option { - self.entries.get(key).cloned() - } - - fn insert(&mut self, key: SkillReadCacheKey, result: SkillReadResult) -> SkillReadResult { - if let Some(cached) = self.entries.get(&key) { - return cached.clone(); - } - - let contents_bytes = result.contents.len(); - let Some(next_contents_bytes) = self.contents_bytes.checked_add(contents_bytes) else { - return result; - }; - if self.entries.len() >= MAX_CACHED_ORCHESTRATOR_RESOURCES - || next_contents_bytes > MAX_CACHED_ORCHESTRATOR_CONTENT_BYTES - { - return result; - } - - self.contents_bytes = next_contents_bytes; - self.entries.insert(key, result.clone()); - result - } -} - #[derive(Default)] pub(crate) struct EmittedCatalogBudgetWarnings(Mutex>); diff --git a/codex-rs/ext/skills/src/tools/mod.rs b/codex-rs/ext/skills/src/tools/mod.rs index 49052667a2..c2743e8551 100644 --- a/codex-rs/ext/skills/src/tools/mod.rs +++ b/codex-rs/ext/skills/src/tools/mod.rs @@ -67,9 +67,8 @@ pub(crate) fn skill_tools( let Some(thread_state) = thread_store.get::() else { return Vec::new(); }; - let orchestrator_available = - providers.has_orchestrator_provider() && thread_state.orchestrator_skills_enabled(); - if !orchestrator_available && executor_query.is_none() { + let cloud_available = providers.has_cloud_provider() && thread_state.cloud_skill_enabled(); + if !cloud_available && executor_query.is_none() { return Vec::new(); } let mcp_resources = session_store @@ -81,7 +80,7 @@ pub(crate) fn skill_tools( mcp_resources, thread_state, analytics, - orchestrator_available, + cloud_available, executor_query, selected_plugins, sandbox_contexts, @@ -195,7 +194,7 @@ struct SkillToolContext { mcp_resources: Option>, thread_state: Arc, analytics: Option, - orchestrator_available: bool, + cloud_available: bool, executor_query: Option, selected_plugins: Option>, sandbox_contexts: Option>>, @@ -206,26 +205,11 @@ struct SkillToolContext { impl SkillToolContext { async fn catalog(&self, turn_id: &str, authority: SkillToolAuthoritySelector) -> SkillCatalog { match authority { - SkillToolAuthoritySelector::Orchestrator => { - if !self.orchestrator_available { + SkillToolAuthoritySelector::Cloud => { + if !self.cloud_available { return SkillCatalog::default(); } - self.thread_state - .orchestrator_catalog_snapshot( - &self.providers, - SkillListQuery { - turn_id: turn_id.to_string(), - executor_roots: Vec::new(), - resolved_executor_roots: Vec::new(), - host_snapshot: None, - include_host_skills: false, - include_bundled_skills: false, - include_orchestrator_skills: true, - mcp_resources: self.mcp_resources.clone(), - executor_capability_discovery: None, - }, - ) - .await + self.thread_state.cloud_catalog_snapshot() } SkillToolAuthoritySelector::Executor => { let Some(mut query) = self.executor_query.clone() else { @@ -249,14 +233,14 @@ impl SkillToolContext { #[derive(Clone, Copy, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)] #[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)] enum SkillToolAuthoritySelector { - Orchestrator, + Cloud, Executor, } impl SkillToolAuthoritySelector { fn matches(self, authority: &SkillAuthority) -> bool { match self { - Self::Orchestrator => authority.kind == SkillSourceKind::Orchestrator, + Self::Cloud => authority.kind == SkillSourceKind::Cloud, Self::Executor => authority.kind == SkillSourceKind::Executor, } } @@ -265,29 +249,27 @@ impl SkillToolAuthoritySelector { #[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)] #[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)] pub(crate) enum SkillToolAuthority { - Orchestrator, + Cloud, Executor { id: String }, } impl SkillToolAuthority { fn selector(&self) -> SkillToolAuthoritySelector { match self { - Self::Orchestrator => SkillToolAuthoritySelector::Orchestrator, + Self::Cloud => SkillToolAuthoritySelector::Cloud, Self::Executor { .. } => SkillToolAuthoritySelector::Executor, } } pub(crate) fn from_authority(authority: &SkillAuthority) -> Option { match &authority.kind { - SkillSourceKind::Orchestrator if authority.id == CODEX_APPS_MCP_SERVER_NAME => { - Some(Self::Orchestrator) + SkillSourceKind::Cloud if authority.id == CODEX_APPS_MCP_SERVER_NAME => { + Some(Self::Cloud) } SkillSourceKind::Executor => Some(Self::Executor { id: authority.id.clone(), }), - SkillSourceKind::Host | SkillSourceKind::Orchestrator | SkillSourceKind::Custom(_) => { - None - } + SkillSourceKind::Host | SkillSourceKind::Cloud | SkillSourceKind::Custom(_) => None, } } } @@ -382,7 +364,7 @@ fn skill_json_output( })?; let output = JsonToolOutput::new(value); Ok(match authority { - SkillToolAuthoritySelector::Orchestrator => Box::new(output.with_external_context()), + SkillToolAuthoritySelector::Cloud => Box::new(output.with_external_context()), SkillToolAuthoritySelector::Executor => Box::new(output), }) } diff --git a/codex-rs/ext/skills/src/tools/read.rs b/codex-rs/ext/skills/src/tools/read.rs index 74f6c8c52e..5e94417994 100644 --- a/codex-rs/ext/skills/src/tools/read.rs +++ b/codex-rs/ext/skills/src/tools/read.rs @@ -81,7 +81,7 @@ impl<'call> ToolExecutor> for ReadTool { let mut selected_skill = None; for selector in [ - super::SkillToolAuthoritySelector::Orchestrator, + super::SkillToolAuthoritySelector::Cloud, super::SkillToolAuthoritySelector::Executor, ] { let catalog = self.context.catalog(&call.turn_id, selector).await; @@ -215,7 +215,7 @@ impl<'call> ToolExecutor> for ReadTool { "skill provider returned a different resource".to_string(), )); } - if output_authority == super::SkillToolAuthoritySelector::Orchestrator + if output_authority == super::SkillToolAuthoritySelector::Cloud && let Some(state) = self .context .thread_state diff --git a/codex-rs/ext/skills/src/world_state.rs b/codex-rs/ext/skills/src/world_state.rs index 466b8e56e5..a90c020231 100644 --- a/codex-rs/ext/skills/src/world_state.rs +++ b/codex-rs/ext/skills/src/world_state.rs @@ -8,14 +8,14 @@ use serde_json::json; use crate::render::SkillRenderReport; pub(crate) const SKILLS_WORLD_STATE_ID: &str = "skills"; -pub(crate) const ORCHESTRATOR_SKILLS_WORLD_STATE_ID: &str = "orchestrator_skills"; +pub(crate) const CLOUD_SKILLS_WORLD_STATE_ID: &str = "cloud_skills"; pub(crate) const HOST_SKILLS_WORLD_STATE_ID: &str = "host_skills"; const NO_EXECUTOR_SKILLS_BODY: &str = "\n## Skills update\nNo selected-environment skills are currently available.\n"; const HIDDEN_EXECUTOR_SKILLS_BODY: &str = "\n## Skills update\nSelected-environment skills are not listed automatically. Explicit skill mentions can still be resolved when available.\n"; -const NO_ORCHESTRATOR_SKILLS_BODY: &str = - "\n## Orchestrator skills update\nNo orchestrator skills are currently available.\n"; -const HIDDEN_ORCHESTRATOR_SKILLS_BODY: &str = "\n## Orchestrator skills update\nOrchestrator skills are not listed automatically. Explicit skill mentions can still be resolved when available.\n"; +const NO_CLOUD_SKILLS_BODY: &str = + "\n## Cloud skills update\nNo cloud skills are currently available.\n"; +const HIDDEN_CLOUD_SKILLS_BODY: &str = "\n## Cloud skills update\nCloud skills are not listed automatically. Explicit skill mentions can still be resolved when available.\n"; const NO_HOST_SKILLS_BODY: &str = "\n## Host skills update\nNo host skills are currently available.\n"; const HIDDEN_HOST_SKILLS_BODY: &str = "\n## Host skills update\nHost skills are not listed automatically. Explicit skill mentions can still be resolved when available.\n"; @@ -44,22 +44,22 @@ pub(crate) fn executor_skills_world_state_section( }) } -pub(crate) fn orchestrator_skills_world_state_section( +pub(crate) fn cloud_skills_world_state_section( body: Option, include_instructions: bool, enabled: bool, on_render: CatalogRenderCallback, ) -> WorldStateSectionContribution { skills_world_state_section( - ORCHESTRATOR_SKILLS_WORLD_STATE_ID, + CLOUD_SKILLS_WORLD_STATE_ID, body, include_instructions, Some(enabled), - NO_ORCHESTRATOR_SKILLS_BODY, + NO_CLOUD_SKILLS_BODY, if enabled { - HIDDEN_ORCHESTRATOR_SKILLS_BODY + HIDDEN_CLOUD_SKILLS_BODY } else { - NO_ORCHESTRATOR_SKILLS_BODY + NO_CLOUD_SKILLS_BODY }, on_render, ) diff --git a/codex-rs/ext/skills/src/world_state_catalogs.rs b/codex-rs/ext/skills/src/world_state_catalogs.rs index c1fab579f3..92303a456d 100644 --- a/codex-rs/ext/skills/src/world_state_catalogs.rs +++ b/codex-rs/ext/skills/src/world_state_catalogs.rs @@ -27,16 +27,16 @@ use crate::state::HostSkillsStepState; use crate::state::SkillsSessionState; use crate::state::SkillsThreadState; use crate::world_state::CatalogRenderCallback; +use crate::world_state::cloud_skills_world_state_section; use crate::world_state::executor_skills_world_state_section; use crate::world_state::host_skills_world_state_section; -use crate::world_state::orchestrator_skills_world_state_section; type CatalogWarningEmitter = Arc; #[derive(Clone, Copy, Eq, PartialEq)] enum CatalogKind { Executor, - Orchestrator, + Cloud, Host, } @@ -44,7 +44,7 @@ impl CatalogKind { fn metrics_surface(self) -> CatalogSurface { match self { Self::Executor => CatalogSurface::ExecutorWorldState, - Self::Orchestrator => CatalogSurface::OrchestratorWorldState, + Self::Cloud => CatalogSurface::CloudWorldState, Self::Host => CatalogSurface::HostWorldState, } } @@ -73,7 +73,7 @@ impl CatalogContribution { pub(crate) struct CatalogContributions { executor: CatalogContribution, - orchestrator: CatalogContribution, + cloud: CatalogContribution, host: CatalogContribution, } @@ -131,8 +131,8 @@ impl<'a> CatalogContext<'a> { } pub(crate) async fn discover_catalogs(&self) -> CatalogContributions { - let orchestrator_enabled = self.thread_state.orchestrator_skills_enabled() - && self.providers.has_orchestrator_provider(); + let cloud_enabled = + self.thread_state.cloud_skill_enabled() && self.providers.has_cloud_provider(); let query = SkillListQuery { turn_id: self.input.turn_id.to_string(), executor_roots: self.input.ready_selected_capability_roots.to_vec(), @@ -140,7 +140,7 @@ impl<'a> CatalogContext<'a> { host_snapshot: None, include_host_skills: false, include_bundled_skills: self.config.bundled_skills_enabled, - include_orchestrator_skills: orchestrator_enabled, + include_cloud_skills: cloud_enabled, mcp_resources: self .input .session_store @@ -149,24 +149,24 @@ impl<'a> CatalogContext<'a> { executor_capability_discovery: self.input.executor_capability_discovery.cloned(), }; - let (executor, orchestrator, host) = futures::join!( - self.discover_executor_catalog(query.clone()), - self.discover_orchestrator_catalog(query), + let cloud = self.cloud_catalog_contribution(&query); + let (executor, host) = futures::join!( + self.discover_executor_catalog(query), self.discover_host_catalog(), ); CatalogContributions { executor, - orchestrator, + cloud, host, } } async fn discover_executor_catalog(&self, query: SkillListQuery) -> CatalogContribution { - let mut catalog = self - .thread_state - .executor_catalog_snapshot(self.providers, query) + self.thread_state + .refresh_executor_catalog(self.providers, query) .await; + let mut catalog = self.thread_state.executor_catalog_snapshot(); if let Some(selected_plugins) = self.input.turn_store.get::() { attribute_executor_plugins(&mut catalog, &selected_plugins); } @@ -180,12 +180,12 @@ impl<'a> CatalogContext<'a> { } } - async fn discover_orchestrator_catalog(&self, query: SkillListQuery) -> CatalogContribution { - if !self.providers.has_orchestrator_provider() { + fn cloud_catalog_contribution(&self, query: &SkillListQuery) -> CatalogContribution { + if !self.providers.has_cloud_provider() { return CatalogContribution::unavailable(); } - if !query.include_orchestrator_skills { + if !query.include_cloud_skills { return CatalogContribution { catalog: SkillCatalog::default(), status: CatalogStatus::Disabled, @@ -193,10 +193,7 @@ impl<'a> CatalogContext<'a> { } CatalogContribution { - catalog: self - .thread_state - .orchestrator_catalog_snapshot(self.providers, query) - .await, + catalog: self.thread_state.cloud_catalog_snapshot(), status: CatalogStatus::Enabled, } } @@ -223,7 +220,7 @@ impl<'a> CatalogContext<'a> { host_snapshot: Some(host_snapshot), include_host_skills: true, include_bundled_skills: false, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery: None, }) @@ -249,7 +246,7 @@ impl<'a> CatalogContext<'a> { let rendered = if self.config.include_instructions { render_combined_available_skills( &catalogs.executor.catalog, - &catalogs.orchestrator.catalog, + &catalogs.cloud.catalog, &catalogs.host.catalog, self.metadata_budget, self.include_usage, @@ -260,11 +257,7 @@ impl<'a> CatalogContext<'a> { [ (CatalogKind::Executor, catalogs.executor, rendered.executor), - ( - CatalogKind::Orchestrator, - catalogs.orchestrator, - rendered.orchestrator, - ), + (CatalogKind::Cloud, catalogs.cloud, rendered.cloud), (CatalogKind::Host, catalogs.host, rendered.host), ] .map(|(kind, catalog, rendered)| RenderedCatalogContribution { @@ -315,7 +308,7 @@ impl<'a> CatalogContext<'a> { CatalogKind::Executor => { executor_skills_world_state_section(body, include_instructions, on_render) } - CatalogKind::Orchestrator => orchestrator_skills_world_state_section( + CatalogKind::Cloud => cloud_skills_world_state_section( body, include_instructions, status == CatalogStatus::Enabled, diff --git a/codex-rs/ext/skills/tests/executor_file_system_authority.rs b/codex-rs/ext/skills/tests/executor_file_system_authority.rs index ffdedc6e2f..ef7f6535a3 100644 --- a/codex-rs/ext/skills/tests/executor_file_system_authority.rs +++ b/codex-rs/ext/skills/tests/executor_file_system_authority.rs @@ -394,7 +394,7 @@ async fn selected_root_id_distinguishes_identical_executor_paths() { host_snapshot: None, include_host_skills: false, include_bundled_skills: true, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery: None, }) @@ -484,7 +484,7 @@ async fn executor_discovery_preserves_posix_and_windows_locator_alias_roots() { host_snapshot: None, include_host_skills: false, include_bundled_skills: true, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery: Some(discovery), }) @@ -601,7 +601,7 @@ async fn executor_discovery_routes_produce_equivalent_catalog_metadata() { host_snapshot: None, include_host_skills: false, include_bundled_skills: true, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery, }; @@ -753,7 +753,7 @@ async fn pre_discovered_executor_catalog_snapshot() { host_snapshot: None, include_host_skills: false, include_bundled_skills: true, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery: Some(executor_capability_discovery), }) @@ -870,7 +870,7 @@ async fn direct_executor_discovery_preserves_hidden_nested_and_probed_metadata() host_snapshot: None, include_host_skills: false, include_bundled_skills: true, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery: None, }) @@ -930,7 +930,7 @@ async fn high_level_discovery_reuses_materialized_skill_contents_for_reads() { host_snapshot: None, include_host_skills: false, include_bundled_skills: true, - include_orchestrator_skills: false, + include_cloud_skills: false, mcp_resources: None, executor_capability_discovery: Some(executor_capability_discovery), }) diff --git a/codex-rs/ext/skills/tests/skills_extension.rs b/codex-rs/ext/skills/tests/skills_extension.rs index b0ee66b8de..674b28f5a5 100644 --- a/codex-rs/ext/skills/tests/skills_extension.rs +++ b/codex-rs/ext/skills/tests/skills_extension.rs @@ -29,6 +29,7 @@ use codex_extension_api::ToolCall; use codex_extension_api::ToolCallSource; use codex_extension_api::ToolPayload; use codex_extension_api::TurnInputContext; +use codex_extension_api::TurnStartInput; use codex_extension_api::WorldStateContributionInput; use codex_extension_api::WorldStateSectionContribution; use codex_models_manager::model_info::model_info_from_slug; @@ -89,7 +90,7 @@ type TestResult = Result<(), Box>; mod shadow_task_context_tests; static NEXT_CODEX_HOME_ID: AtomicUsize = AtomicUsize::new(0); -const SKILLS_INTRO_WITH_ABSOLUTE_PATHS: &str = "A skill is a set of instructions provided through a `SKILL.md` source. Below is the list of skills that can be used. Each entry includes a name, description, and source locator. `file` locators are on the host filesystem, `executor package` locators are owned by their execution environment, `orchestrator package` locators are opaque package identifiers, and `custom resource` locators use their provider's access mechanism."; +const SKILLS_INTRO_WITH_ABSOLUTE_PATHS: &str = "A skill is a set of instructions provided through a `SKILL.md` source. Below is the list of skills that can be used. Each entry includes a name, description, and source locator. `file` locators are on the host filesystem, `executor package` locators are owned by their execution environment, `cloud package` locators are opaque package identifiers, and `custom resource` locators use their provider's access mechanism."; const DEMO_SKILL_CONTENTS: &str = "---\nname: demo\ndescription: Demo skill.\n---\n# Demo\n\nUse the demo skill.\n"; @@ -144,10 +145,39 @@ async fn skill_world_state_fragments( let executor = world_state_section(§ions, "skills") .render_diff(PreviousWorldStateSection::Absent) .ok_or("executor skills should render through world state")?; - let orchestrator = world_state_section(§ions, "orchestrator_skills") + let cloud = world_state_section(§ions, "cloud_skills") .render_diff(PreviousWorldStateSection::Absent) - .ok_or("orchestrator skills should render through world state")?; - Ok((executor, orchestrator)) + .ok_or("cloud skills should render through world state")?; + Ok((executor, cloud)) +} + +async fn start_registered_turn( + registry: &codex_extension_api::ExtensionRegistry, + session_store: &ExtensionData, + thread_store: &ExtensionData, + turn_id: &str, +) { + let turn_store = ExtensionData::new(turn_id); + let mode = codex_protocol::config_types::CollaborationMode { + mode: codex_protocol::config_types::ModeKind::Default, + settings: codex_protocol::config_types::Settings { + model: "test".to_string(), + reasoning_effort: None, + developer_instructions: None, + }, + }; + for contributor in registry.turn_lifecycle_contributors() { + contributor + .on_turn_start(TurnStartInput { + turn_id, + collaboration_mode: &mode, + token_usage_at_turn_start: None, + session_store, + thread_store, + turn_store: &turn_store, + }) + .await; + } } #[tokio::test] @@ -482,7 +512,7 @@ async fn persisted_host_snapshot_deduplicates_warning_after_reinitialization() - } #[tokio::test] -async fn executor_orchestrator_and_host_share_catalog_world_state_flow() -> TestResult { +async fn executor_cloud_and_host_share_catalog_world_state_flow() -> TestResult { let provider = |entry: SkillCatalogEntry| { Arc::new(StaticSkillProvider { catalog: SkillCatalog { @@ -501,11 +531,11 @@ async fn executor_orchestrator_and_host_share_catalog_world_state_flow() -> Test "executor/executor-skill", "skill://executor/executor-skill/SKILL.md", ))) - .with_orchestrator_provider(provider(test_entry( - SkillSourceKind::Orchestrator, + .with_cloud_provider(provider(test_entry( + SkillSourceKind::Cloud, "codex_apps", - "orchestrator/orchestrator-skill", - "skill://orchestrator/orchestrator-skill/SKILL.md", + "cloud/cloud-skill", + "skill://cloud/cloud-skill/SKILL.md", ))) .with_host_provider(provider( test_entry( @@ -533,6 +563,7 @@ async fn executor_orchestrator_and_host_share_catalog_world_state_flow() -> Test thread_store: &thread_store, }) .await; + start_registered_turn(®istry, &session_store, &thread_store, "turn-1").await; let selected_roots = [SelectedCapabilityRoot { id: "skills".to_string(), @@ -566,7 +597,7 @@ async fn executor_orchestrator_and_host_share_catalog_world_state_flow() -> Test .iter() .map(WorldStateSectionContribution::id) .collect::>(), - vec!["skills", "orchestrator_skills", "host_skills"] + vec!["skills", "cloud_skills", "host_skills"] ); assert!(metrics.samples().is_empty()); @@ -576,8 +607,8 @@ async fn executor_orchestrator_and_host_share_catalog_world_state_flow() -> Test "- executor-skill: Fix lint errors. (executor package: executor/executor-skill)", ), ( - "orchestrator_skills", - "- orchestrator-skill: Fix lint errors. (orchestrator package: orchestrator/orchestrator-skill)", + "cloud_skills", + "- cloud-skill: Fix lint errors. (cloud package: cloud/cloud-skill)", ), ( "host_skills", @@ -592,7 +623,7 @@ async fn executor_orchestrator_and_host_share_catalog_world_state_flow() -> Test let expected_metrics = [ "executor_world_state", - "orchestrator_world_state", + "cloud_world_state", "host_world_state", ] .into_iter() @@ -1268,13 +1299,13 @@ async fn default_context_truncates_catalog_descriptions() -> TestResult { "skill://executor/executor-long-description/SKILL.md", ); executor_entry.description = description.clone(); - let mut orchestrator_entry = test_entry( - SkillSourceKind::Orchestrator, + let mut cloud_entry = test_entry( + SkillSourceKind::Cloud, "codex_apps", - "orchestrator/orchestrator-long-description", - "skill://orchestrator/orchestrator-long-description/SKILL.md", + "cloud/cloud-long-description", + "skill://cloud/cloud-long-description/SKILL.md", ); - orchestrator_entry.description = description.clone(); + cloud_entry.description = description.clone(); let providers = SkillProviders::new() .with_executor_provider(Arc::new(StaticSkillProvider { catalog: SkillCatalog { @@ -1285,9 +1316,9 @@ async fn default_context_truncates_catalog_descriptions() -> TestResult { list_calls: None, fail_first_list: false, })) - .with_orchestrator_provider(Arc::new(StaticSkillProvider { + .with_cloud_provider(Arc::new(StaticSkillProvider { catalog: SkillCatalog { - entries: vec![orchestrator_entry], + entries: vec![cloud_entry], warnings: Vec::new(), }, read_requests: Arc::new(Mutex::new(Vec::new())), @@ -1313,16 +1344,13 @@ async fn default_context_truncates_catalog_descriptions() -> TestResult { thread_store: &thread_store, }) .await; + start_registered_turn(®istry, &session_store, &thread_store, "turn-1").await; - let (executor, orchestrator) = + let (executor, cloud) = skill_world_state_fragments(®istry, &session_store, &thread_store, "turn-1").await?; assert!(executor.body().contains("- executor-long-description:")); - assert!( - orchestrator - .body() - .contains("- orchestrator-long-description:") - ); - for rendered in [executor.body(), orchestrator.body()] { + assert!(cloud.body().contains("- cloud-long-description:")); + for rendered in [executor.body(), cloud.body()] { assert!(rendered.contains(&("x".repeat(1_021) + "..."))); assert!(!rendered.contains(&"x".repeat(1_024))); assert!(!rendered.contains(&description)); @@ -1347,11 +1375,11 @@ async fn moderate_budget_pressure_keeps_every_catalog_entry() -> TestResult { entry }) .collect(); - let orchestrator_entries = (0..5) + let cloud_entries = (0..5) .map(|index| { - let package_id = format!("orchestrator/orchestrator-skill-{index:02}"); + let package_id = format!("cloud/cloud-skill-{index:02}"); let mut entry = test_entry( - SkillSourceKind::Orchestrator, + SkillSourceKind::Cloud, "codex_apps", &package_id, &format!("skill://{package_id}/SKILL.md"), @@ -1370,9 +1398,9 @@ async fn moderate_budget_pressure_keeps_every_catalog_entry() -> TestResult { list_calls: None, fail_first_list: false, })) - .with_orchestrator_provider(Arc::new(StaticSkillProvider { + .with_cloud_provider(Arc::new(StaticSkillProvider { catalog: SkillCatalog { - entries: orchestrator_entries, + entries: cloud_entries, warnings: Vec::new(), }, read_requests: Arc::new(Mutex::new(Vec::new())), @@ -1398,35 +1426,33 @@ async fn moderate_budget_pressure_keeps_every_catalog_entry() -> TestResult { thread_store: &thread_store, }) .await; + start_registered_turn(®istry, &session_store, &thread_store, "turn-1").await; - let (executor, orchestrator) = + let (executor, cloud) = skill_world_state_fragments(®istry, &session_store, &thread_store, "turn-1").await?; - let description_lengths = [ - ("executor", executor.body()), - ("orchestrator", orchestrator.body()), - ] - .into_iter() - .flat_map(|(source, rendered)| (0..5).map(move |index| (source, rendered, index))) - .map(|(source, rendered, index)| { - let name = format!("{source}-skill-{index:02}"); - let package_id = format!("{source}/{name}"); - let line_prefix = format!("- {name}: "); - let line_suffix = if source == "executor" { - format!(" (executor package: {package_id})") - } else { - format!(" (orchestrator package: {package_id})") - }; - rendered - .lines() - .find_map(|line| { - line.strip_prefix(&line_prefix) - .and_then(|line| line.strip_suffix(&line_suffix)) - }) - .unwrap_or_else(|| panic!("rendered catalog should include {name}")) - .chars() - .count() - }) - .collect::>(); + let description_lengths = [("executor", executor.body()), ("cloud", cloud.body())] + .into_iter() + .flat_map(|(source, rendered)| (0..5).map(move |index| (source, rendered, index))) + .map(|(source, rendered, index)| { + let name = format!("{source}-skill-{index:02}"); + let package_id = format!("{source}/{name}"); + let line_prefix = format!("- {name}: "); + let line_suffix = if source == "executor" { + format!(" (executor package: {package_id})") + } else { + format!(" (cloud package: {package_id})") + }; + rendered + .lines() + .find_map(|line| { + line.strip_prefix(&line_prefix) + .and_then(|line| line.strip_suffix(&line_suffix)) + }) + .unwrap_or_else(|| panic!("rendered catalog should include {name}")) + .chars() + .count() + }) + .collect::>(); let shortest_description = *description_lengths .iter() .min() @@ -1438,7 +1464,7 @@ async fn moderate_budget_pressure_keeps_every_catalog_entry() -> TestResult { assert!(shortest_description > 0); assert!(longest_description < 1_024); assert!(longest_description.abs_diff(shortest_description) <= 1); - for rendered in [executor.body(), orchestrator.body()] { + for rendered in [executor.body(), cloud.body()] { assert!(!rendered.contains("additional skills omitted from this bounded skills list")); assert!(!rendered.contains(&"x".repeat(1_021))); } @@ -1461,16 +1487,16 @@ async fn extreme_budget_pressure_removes_descriptions_before_omitting_entries() entry }) .collect(); - let orchestrator_entries = (0..160) + let cloud_entries = (0..160) .map(|index| { - let package_id = format!("orchestrator/orchestrator-skill-{index:03}"); + let package_id = format!("cloud/cloud-skill-{index:03}"); let mut entry = test_entry( - SkillSourceKind::Orchestrator, + SkillSourceKind::Cloud, "codex_apps", &package_id, &format!("skill://{package_id}/SKILL.md"), ); - entry.description = format!("orchestrator-description-{index:03}"); + entry.description = format!("cloud-description-{index:03}"); entry }) .collect(); @@ -1484,9 +1510,9 @@ async fn extreme_budget_pressure_removes_descriptions_before_omitting_entries() list_calls: None, fail_first_list: false, })) - .with_orchestrator_provider(Arc::new(StaticSkillProvider { + .with_cloud_provider(Arc::new(StaticSkillProvider { catalog: SkillCatalog { - entries: orchestrator_entries, + entries: cloud_entries, warnings: Vec::new(), }, read_requests: Arc::new(Mutex::new(Vec::new())), @@ -1514,42 +1540,39 @@ async fn extreme_budget_pressure_removes_descriptions_before_omitting_entries() thread_store: &thread_store, }) .await; + start_registered_turn(®istry, &session_store, &thread_store, "turn-1").await; - let (executor, orchestrator) = + let (executor, cloud) = skill_world_state_fragments(®istry, &session_store, &thread_store, "turn-1").await?; let included_executor_count = executor .body() .lines() .filter(|line| line.starts_with("- executor-skill-")) .count(); - let included_orchestrator_count = orchestrator + let included_cloud_count = cloud .body() .lines() - .filter(|line| line.starts_with("- orchestrator-skill-")) + .filter(|line| line.starts_with("- cloud-skill-")) .count(); assert_eq!(40, included_executor_count); - assert!(included_orchestrator_count > 0); - assert!(included_orchestrator_count < 160); + assert!(included_cloud_count > 0); + assert!(included_cloud_count < 160); assert!( executor .body() .contains("- executor-skill-039: (executor package:") ); - assert!( - orchestrator - .body() - .contains("- orchestrator-skill-000: (orchestrator package:") - ); - assert!(!orchestrator.body().contains("- orchestrator-skill-159:")); - for rendered in [executor.body(), orchestrator.body()] { + assert!(cloud.body().contains("- cloud-skill-000: (cloud package:")); + assert!(!cloud.body().contains("- cloud-skill-159:")); + for rendered in [executor.body(), cloud.body()] { assert!(!rendered.contains("description-")); } assert!( - orchestrator + cloud .body() .contains("additional skills omitted from this bounded skills list") ); - let omitted_count = 200 - included_executor_count - included_orchestrator_count; + let omitted_count = 200 - included_executor_count - included_cloud_count; let warning = event_rx.try_recv()?.into_warning(); assert_eq!(warning.thread_id, "thread"); assert_eq!(warning.turn_id.as_deref(), Some("turn-1")); @@ -1567,20 +1590,20 @@ async fn extreme_budget_pressure_removes_descriptions_before_omitting_entries() #[tokio::test] async fn skills_list_only_returns_model_visible_bounded_metadata() -> TestResult { const OVERSIZED_WARNING: &str = "Some skills were omitted because their metadata is too large."; - const PROVIDER_WARNING: &str = "Some orchestrator skills could not be discovered because the provider disconnected before returning the complete catalog."; + const PROVIDER_WARNING: &str = "Some cloud skills could not be discovered because the provider disconnected before returning the complete catalog."; let supplementary_warning = "w".repeat(256); let opaque_suffix = "\\".repeat(1_500); let mut entry = test_entry( - SkillSourceKind::Orchestrator, + SkillSourceKind::Cloud, "codex_apps", - &format!("orchestrator/{opaque_suffix}"), - &format!("skill://orchestrator/{opaque_suffix}/SKILL.md"), + &format!("cloud/{opaque_suffix}"), + &format!("skill://cloud/{opaque_suffix}/SKILL.md"), ); entry.description = "x".repeat(1_025); let [first_entry, mut middle_entry, mut final_entry] = ["p0", "p1", "p2"].map(|name| { test_entry( - SkillSourceKind::Orchestrator, + SkillSourceKind::Cloud, "codex_apps", name, &format!("skill://{name}/SKILL.md"), @@ -1588,33 +1611,32 @@ async fn skills_list_only_returns_model_visible_bounded_metadata() -> TestResult }); middle_entry.description = "d".repeat(110); final_entry.description = "d".repeat(50); - let providers = - SkillProviders::new().with_orchestrator_provider(Arc::new(StaticSkillProvider { - catalog: SkillCatalog { - entries: vec![ - entry, - first_entry, - middle_entry, - final_entry, - test_entry( - SkillSourceKind::Orchestrator, - "codex_apps", - "orchestrator/hidden", - "skill://orchestrator/hidden/SKILL.md", - ) - .hidden_from_prompt(), - ], - warnings: vec![ - PROVIDER_WARNING.to_string(), - supplementary_warning.clone(), - supplementary_warning.clone(), - supplementary_warning.clone(), - ], - }, - read_requests: Arc::new(Mutex::new(Vec::new())), - list_calls: None, - fail_first_list: false, - })); + let providers = SkillProviders::new().with_cloud_provider(Arc::new(StaticSkillProvider { + catalog: SkillCatalog { + entries: vec![ + entry, + first_entry, + middle_entry, + final_entry, + test_entry( + SkillSourceKind::Cloud, + "codex_apps", + "cloud/hidden", + "skill://cloud/hidden/SKILL.md", + ) + .hidden_from_prompt(), + ], + warnings: vec![ + PROVIDER_WARNING.to_string(), + supplementary_warning.clone(), + supplementary_warning.clone(), + supplementary_warning.clone(), + ], + }, + read_requests: Arc::new(Mutex::new(Vec::new())), + list_calls: None, + fail_first_list: false, + })); let mut builder = ExtensionRegistryBuilder::new(); install_with_providers(&mut builder, providers, skills_extension_config); let registry = builder.build(); @@ -1634,6 +1656,7 @@ async fn skills_list_only_returns_model_visible_bounded_metadata() -> TestResult thread_store: &thread_store, }) .await; + start_registered_turn(®istry, &session_store, &thread_store, "turn-1").await; let tools = registry.tool_contributors()[0].tools(&session_store, &thread_store); let list_tool = tools @@ -1641,7 +1664,7 @@ async fn skills_list_only_returns_model_visible_bounded_metadata() -> TestResult .find(|tool| tool.tool_name().name == "list") .ok_or("skills.list tool should be registered")?; let payload = ToolPayload::Function { - arguments: serde_json::json!({"authority": {"kind": "orchestrator"}}).to_string(), + arguments: serde_json::json!({"authority": {"kind": "cloud"}}).to_string(), }; let call = ToolCall { turn_id: "turn-1".to_string(), @@ -1709,7 +1732,7 @@ async fn skills_list_only_returns_model_visible_bounded_metadata() -> TestResult { let payload = ToolPayload::Function { arguments: serde_json::json!({ - "authority": {"kind": "orchestrator"}, + "authority": {"kind": "cloud"}, "cursor": cursor, }) .to_string(), @@ -1754,7 +1777,7 @@ async fn skills_list_only_returns_model_visible_bounded_metadata() -> TestResult .ok_or("cursor should include its budget")?; let legacy_payload = ToolPayload::Function { arguments: serde_json::json!({ - "authority": {"kind": "orchestrator"}, + "authority": {"kind": "cloud"}, "cursor": legacy_cursor, }) .to_string(), @@ -1798,7 +1821,7 @@ async fn skills_list_only_returns_model_visible_bounded_metadata() -> TestResult // The resource fits the 2400-byte budget before escaping, but not after. let insufficient_budget_payload = ToolPayload::Function { arguments: serde_json::json!({ - "package": format!("orchestrator/{opaque_suffix}"), + "package": format!("cloud/{opaque_suffix}"), }) .to_string(), }; @@ -1829,109 +1852,79 @@ async fn skills_list_only_returns_model_visible_bounded_metadata() -> TestResult } #[tokio::test] -async fn orchestrator_catalog_snapshot_caches_failure() -> TestResult { - const PROVIDER_WARNING: &str = - "orchestrator skills unavailable: temporary orchestrator failure"; - - let list_calls = Arc::new(AtomicUsize::new(0)); - let providers = - SkillProviders::new().with_orchestrator_provider(Arc::new(StaticSkillProvider { - catalog: SkillCatalog { - entries: vec![test_entry( - SkillSourceKind::Orchestrator, - "codex_apps", - "orchestrator/first", - "skill://orchestrator/first/SKILL.md", - )], - warnings: Vec::new(), - }, +async fn cloud_discovery_is_gated_and_reports_failures() -> TestResult { + for cloud_skill_enabled in [false, true] { + let list_calls = Arc::new(AtomicUsize::new(0)); + let providers = SkillProviders::new().with_cloud_provider(Arc::new(StaticSkillProvider { + catalog: SkillCatalog::default(), read_requests: Arc::new(Mutex::new(Vec::new())), list_calls: Some(Arc::clone(&list_calls)), fail_first_list: true, })); - let (event_tx, event_rx) = std::sync::mpsc::channel(); - let mut builder = - ExtensionRegistryBuilder::with_event_sink(Arc::new(ChannelEventSink(event_tx))); - install_with_providers(&mut builder, providers, skills_extension_config); - let registry = builder.build(); - let session_store = ExtensionData::new("session"); - let thread_store = ExtensionData::new("thread"); - let session_source = SessionSource::Cli; - let config = default_config(); - registry.thread_lifecycle_contributors()[0] - .on_thread_start(ThreadStartInput { - config: &config, - session_source: &session_source, - persistent_thread_state_available: true, - environments: &[], - mcp_resource_client: None, - extension_metrics: None, - session_store: &session_store, - thread_store: &thread_store, - }) - .await; - - let initial_fragments = registry.context_contributors()[0] - .contribute_thread_context(&session_store, &thread_store) - .await; - assert!(initial_fragments.is_empty()); - assert!(event_rx.try_recv().is_err()); - - for turn_id in ["turn-1", "turn-2"] { - let fragments = registry.turn_input_contributors()[0] - .contribute( - TurnInputContext { - turn_id: turn_id.to_string(), - user_input: vec![UserInput::Text { - text: "$first".to_string(), - text_elements: Vec::new(), - }], - environments: Vec::new(), - }, - /*extension_metrics*/ None, - &session_store, - &thread_store, - &ExtensionData::new(turn_id), - ) + let (event_tx, event_rx) = std::sync::mpsc::channel(); + let mut builder = + ExtensionRegistryBuilder::with_event_sink(Arc::new(ChannelEventSink(event_tx))); + install_with_providers(&mut builder, providers, skills_extension_config); + let registry = builder.build(); + let session_store = ExtensionData::new("session"); + let thread_store = ExtensionData::new("thread"); + let session_source = SessionSource::Cli; + let config = TestConfig { + cloud_skill_enabled, + ..default_config() + }; + registry.thread_lifecycle_contributors()[0] + .on_thread_start(ThreadStartInput { + config: &config, + session_source: &session_source, + persistent_thread_state_available: true, + environments: &[], + mcp_resource_client: None, + extension_metrics: None, + session_store: &session_store, + thread_store: &thread_store, + }) .await; - assert!(fragments.is_empty()); + + assert_eq!( + registry + .turn_lifecycle_contributors() + .iter() + .map(|contributor| contributor.turn_start_phase(&thread_store)) + .collect::>(), + vec![ + codex_extension_api::TurnStartPhase::BeforeTaskRegistration, + if cloud_skill_enabled { + codex_extension_api::TurnStartPhase::RegularTaskStart + } else { + codex_extension_api::TurnStartPhase::BeforeTaskRegistration + }, + ] + ); + assert_eq!( + registry + .turn_lifecycle_contributors() + .iter() + .map(|contributor| contributor.requires_mcp_runtime(&thread_store)) + .collect::>(), + vec![false, cloud_skill_enabled] + ); + start_registered_turn(®istry, &session_store, &thread_store, "turn-1").await; + assert_eq!( + list_calls.load(Ordering::Relaxed), + usize::from(cloud_skill_enabled) + ); + if !cloud_skill_enabled { + assert!(event_rx.try_recv().is_err()); + let tools = registry.tool_contributors()[0].tools(&session_store, &thread_store); + assert!(tools.iter().all(|tool| tool.tool_name().name != "list")); + continue; + } let warning = event_rx.try_recv()?.into_warning(); assert_eq!(warning.thread_id, thread_store.level_id()); - assert_eq!(warning.turn_id.as_deref(), Some(turn_id)); - assert_eq!(warning.message, PROVIDER_WARNING); + assert_eq!(warning.turn_id.as_deref(), Some("turn-1")); + assert!(warning.message.contains("temporary cloud failure")); } - - let tools = registry.tool_contributors()[0].tools(&session_store, &thread_store); - let list_tool = tools - .iter() - .find(|tool| tool.tool_name().name == "list") - .ok_or("skills.list tool should be registered")?; - assert_eq!( - list_tool - .handle(ToolCall { - turn_id: "turn-1".to_string(), - call_id: "unavailable-skills".to_string(), - tool_name: list_tool.tool_name(), - model: "gpt-test".to_string(), - codex_turn_metadata: None, - truncation_policy: TruncationPolicy::Bytes(64), - source: ToolCallSource::Direct, - conversation_history: ConversationHistory::default(), - turn_item_emitter: Arc::new(NoopTurnItemEmitter), - environments: Vec::new(), - payload: ToolPayload::Function { - arguments: serde_json::json!({"authority": {"kind": "orchestrator"}}) - .to_string(), - }, - }) - .await - .err(), - Some(FunctionCallError::RespondToModel( - "skills.list response budget leaves no room for discovery warnings".to_string() - )) - ); - assert_eq!(1, list_calls.load(Ordering::Relaxed)); - Ok(()) } @@ -2044,13 +2037,13 @@ async fn root_qualified_locator_selects_only_the_matching_executor_skill() -> Te } #[tokio::test] -async fn model_context_window_scales_executor_and_orchestrator_catalogs() -> TestResult { - let orchestrator_entries = (0..40) +async fn model_context_window_scales_executor_and_cloud_catalogs() -> TestResult { + let cloud_entries = (0..40) .map(|index| { test_entry( - SkillSourceKind::Orchestrator, - "orchestrator", - &format!("orchestrator/skill-{index:02}"), + SkillSourceKind::Cloud, + "cloud", + &format!("cloud/skill-{index:02}"), &format!("skill-{index:02}/SKILL.md"), ) }) @@ -2066,9 +2059,9 @@ async fn model_context_window_scales_executor_and_orchestrator_catalogs() -> Tes }) .collect(); let providers = SkillProviders::new() - .with_orchestrator_provider(Arc::new(StaticSkillProvider { + .with_cloud_provider(Arc::new(StaticSkillProvider { catalog: SkillCatalog { - entries: orchestrator_entries, + entries: cloud_entries, warnings: Vec::new(), }, read_requests: Arc::new(Mutex::new(Vec::new())), @@ -2105,6 +2098,7 @@ async fn model_context_window_scales_executor_and_orchestrator_catalogs() -> Tes thread_store: &thread_store, }) .await; + start_registered_turn(®istry, &session_store, &thread_store, "turn-1").await; let mut model_info = model_info_from_slug("test-model"); model_info.context_window = Some(10_000); @@ -2157,14 +2151,10 @@ async fn model_context_window_scales_executor_and_orchestrator_catalogs() -> Tes .render_diff(PreviousWorldStateSection::Absent) .ok_or("bounded executor catalog should render")?; assert!(!executor_fragment.body().contains("skill-39")); - let orchestrator_fragment = world_state_section(§ions, "orchestrator_skills") + let cloud_fragment = world_state_section(§ions, "cloud_skills") .render_diff(PreviousWorldStateSection::Absent) - .ok_or("bounded orchestrator catalog should render")?; - assert!( - orchestrator_fragment - .body() - .contains("additional skills omitted") - ); + .ok_or("bounded cloud catalog should render")?; + assert!(cloud_fragment.body().contains("additional skills omitted")); let warnings = event_rx .try_iter() .map(CapturedExtensionEvent::into_warning) @@ -2594,7 +2584,7 @@ impl SkillProvider for StaticSkillProvider { let catalog = self.catalog.clone(); Box::pin(async move { if fail { - Err(SkillProviderError::new("temporary orchestrator failure")) + Err(SkillProviderError::new("temporary cloud failure")) } else { Ok(catalog) } @@ -2648,7 +2638,7 @@ fn test_entry( struct TestConfig { include_instructions: bool, bundled_skills_enabled: bool, - orchestrator_skills_enabled: bool, + cloud_skill_enabled: bool, shadow_selection_enabled: bool, } @@ -2656,7 +2646,7 @@ fn default_config() -> TestConfig { TestConfig { include_instructions: true, bundled_skills_enabled: true, - orchestrator_skills_enabled: true, + cloud_skill_enabled: true, shadow_selection_enabled: false, } } @@ -2666,7 +2656,7 @@ fn skills_extension_config(config: &TestConfig) -> SkillsExtensionConfig { include_instructions: config.include_instructions, max_context_tokens: None, bundled_skills_enabled: config.bundled_skills_enabled, - orchestrator_skills_enabled: config.orchestrator_skills_enabled, + cloud_skill_enabled: config.cloud_skill_enabled, shadow_selection_enabled: config.shadow_selection_enabled, } } diff --git a/codex-rs/thread-manager-sample/src/main.rs b/codex-rs/thread-manager-sample/src/main.rs index 1bcf5d15f3..251f1cbf03 100644 --- a/codex-rs/thread-manager-sample/src/main.rs +++ b/codex-rs/thread-manager-sample/src/main.rs @@ -220,7 +220,7 @@ fn new_config(model: Option, arg0_paths: Arg0DispatchPaths) -> anyhow::R include_collaboration_mode_instructions: false, include_skill_instructions: false, skill_max_context_tokens: None, - orchestrator_skills_enabled: false, + cloud_skill_enabled: false, orchestrator_mcp_enabled: false, include_environment_context: false, compact_prompt: None, diff --git a/codex-rs/tui/src/temporary_structured_request.rs b/codex-rs/tui/src/temporary_structured_request.rs index 591dd279f4..574ab35ef0 100644 --- a/codex-rs/tui/src/temporary_structured_request.rs +++ b/codex-rs/tui/src/temporary_structured_request.rs @@ -88,7 +88,7 @@ pub(crate) async fn start_temporary_thread( ("features.tool_suggest".to_string(), false.into()), ("features.unified_exec".to_string(), false.into()), ("features.view_image".to_string(), false.into()), - ("orchestrator.skills.enabled".to_string(), false.into()), + ("cloud.skills.enabled".to_string(), false.into()), ("skills.include_instructions".to_string(), false.into()), ( "tools.experimental_request_user_input.enabled".to_string(),