mirror of
https://github.com/openai/codex.git
synced 2026-11-21 07:09:23 +00:00
Use captured step model settings for extension context (#44202)
## Why Model switches within a turn can leave extension context using stale model metadata. Skill catalogs, context windows, and metric attribution need to match the model captured for each sampling step. ## What changed - Pass captured model metadata and step-specific telemetry to world-state contributors. - Use that metadata for skill catalog budgets and usage instructions, preserving configured budget overrides. - Supply the captured model's usable context window to turn-context contributors, including when rebuilding context. ## Testing Add regression coverage for model switches during skill discovery, catalog budgets and metric attribution, and extension context windows after `new_context` and retained-step context rebuilds. GitOrigin-RevId: c51b40b739a380b9767a54ea8c8ee6de45bf01c8
This commit is contained in:
1 parent
b4507997e0
commit
8ff4aa8ee4
9 files changed
+447
-99
No files matched your search
@@ -6,7 +6,6 @@ use codex_extension_api::ExtensionWarning;
|
||||
use codex_extension_api::SelectedPluginSnapshot;
|
||||
use codex_extension_api::WorldStateContributionInput;
|
||||
use codex_extension_api::WorldStateSectionContribution;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
|
||||
use crate::HostSkillsSnapshot;
|
||||
use crate::SkillsExtensionConfig;
|
||||
@@ -102,13 +101,8 @@ impl<'a> CatalogContext<'a> {
|
||||
) -> Option<Self> {
|
||||
let thread_state = input.thread_store.get::<SkillsThreadState>()?;
|
||||
let config = thread_state.config();
|
||||
let model_info = input.thread_store.get::<ModelInfo>();
|
||||
let include_usage = model_info
|
||||
.as_deref()
|
||||
.is_some_and(|model_info| model_info.include_skills_usage_instructions);
|
||||
let context_window = model_info
|
||||
.as_deref()
|
||||
.and_then(ModelInfo::resolved_context_window);
|
||||
let include_usage = input.model_info.include_skills_usage_instructions;
|
||||
let context_window = input.model_info.resolved_context_window();
|
||||
let metadata_budget = skill_metadata_budget(context_window, config.max_context_tokens);
|
||||
let emitted_warnings = input
|
||||
.turn_store
|
||||
|
||||
@@ -40,6 +40,7 @@ use codex_otel::THREAD_SKILLS_KEPT_TOTAL_METRIC;
|
||||
use codex_otel::THREAD_SKILLS_TRUNCATED_METRIC;
|
||||
use codex_protocol::capabilities::CapabilityRootLocation;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
use codex_protocol::protocol::EnvironmentConfigState;
|
||||
use codex_protocol::protocol::Event;
|
||||
use codex_protocol::protocol::SKILLS_INSTRUCTIONS_CLOSE_TAG;
|
||||
@@ -92,6 +93,15 @@ const SKILLS_INTRO_WITH_ABSOLUTE_PATHS: &str = "A skill is a set of instructions
|
||||
const DEMO_SKILL_CONTENTS: &str =
|
||||
"---\nname: demo\ndescription: Demo skill.\n---\n# Demo\n\nUse the demo skill.\n";
|
||||
|
||||
fn catalog_model_info() -> ModelInfo {
|
||||
ModelInfo {
|
||||
context_window: None,
|
||||
max_context_window: None,
|
||||
include_skills_usage_instructions: false,
|
||||
..model_info_from_slug("test-model")
|
||||
}
|
||||
}
|
||||
|
||||
fn world_state_section<'a>(
|
||||
sections: &'a [WorldStateSectionContribution],
|
||||
id: &str,
|
||||
@@ -118,6 +128,7 @@ async fn skill_world_state_fragments(
|
||||
}];
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id,
|
||||
environments: &[],
|
||||
@@ -272,6 +283,7 @@ async fn host_world_state_records_catalog_metrics_on_publish_and_change() -> Tes
|
||||
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -298,6 +310,7 @@ async fn host_world_state_records_catalog_metrics_on_publish_and_change() -> Tes
|
||||
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -334,6 +347,7 @@ async fn host_world_state_records_catalog_metrics_on_publish_and_change() -> Tes
|
||||
turn_store.insert(HostSkillsSnapshot::new(Arc::new(outcome)));
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -400,11 +414,11 @@ async fn persisted_host_snapshot_deduplicates_warning_after_reinitialization() -
|
||||
.await;
|
||||
let mut model_info = model_info_from_slug("test-model");
|
||||
model_info.context_window = Some(50);
|
||||
thread_store.insert(model_info);
|
||||
let turn_store = ExtensionData::new("turn-1");
|
||||
turn_store.insert(host_snapshot.clone());
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &model_info,
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -441,11 +455,11 @@ async fn persisted_host_snapshot_deduplicates_warning_after_reinitialization() -
|
||||
.await;
|
||||
let mut model_info = model_info_from_slug("test-model");
|
||||
model_info.context_window = Some(50);
|
||||
resumed_thread_store.insert(model_info);
|
||||
let resumed_turn_store = ExtensionData::new("turn-2");
|
||||
resumed_turn_store.insert(host_snapshot);
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &model_info,
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-2",
|
||||
environments: &[],
|
||||
@@ -534,6 +548,7 @@ async fn executor_orchestrator_and_host_share_catalog_world_state_flow() -> Test
|
||||
let metrics = Arc::new(RecordingMetrics::default());
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -641,6 +656,7 @@ async fn nonempty_executor_empty_host_records_catalog_metrics() -> TestResult {
|
||||
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -718,6 +734,7 @@ async fn host_world_state_uses_provider_catalog_with_core_compatible_rendering()
|
||||
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -797,6 +814,7 @@ async fn shadow_selection_uses_host_catalog_when_instructions_are_disabled() ->
|
||||
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -1054,6 +1072,7 @@ async fn selected_executor_catalog_follows_step_availability_and_reuses_its_cach
|
||||
};
|
||||
let available_sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: std::slice::from_ref(&turn_environment),
|
||||
@@ -1109,6 +1128,7 @@ async fn selected_executor_catalog_follows_step_availability_and_reuses_its_cach
|
||||
let unavailable_turn_store = ExtensionData::new("turn-2");
|
||||
let unavailable_sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-2",
|
||||
environments: &[],
|
||||
@@ -1133,6 +1153,7 @@ async fn selected_executor_catalog_follows_step_availability_and_reuses_its_cach
|
||||
let restored_turn_store = ExtensionData::new("turn-3");
|
||||
let restored_sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-3",
|
||||
environments: &[turn_environment],
|
||||
@@ -1176,6 +1197,7 @@ async fn selected_executor_catalog_follows_step_availability_and_reuses_its_cach
|
||||
] {
|
||||
registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id,
|
||||
environments: &[],
|
||||
@@ -1201,6 +1223,7 @@ async fn selected_executor_catalog_follows_step_availability_and_reuses_its_cach
|
||||
let listing_disabled_turn_store = ExtensionData::new("turn-4");
|
||||
let listing_disabled_sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-4",
|
||||
environments: &[],
|
||||
@@ -1972,6 +1995,7 @@ async fn root_qualified_locator_selects_only_the_matching_executor_skill() -> Te
|
||||
let turn_store = ExtensionData::new("turn-1");
|
||||
registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[TurnEnvironmentSelection {
|
||||
@@ -2083,7 +2107,6 @@ async fn model_context_window_scales_executor_and_orchestrator_catalogs() -> Tes
|
||||
.await;
|
||||
let mut model_info = model_info_from_slug("test-model");
|
||||
model_info.context_window = Some(10_000);
|
||||
thread_store.insert(model_info);
|
||||
|
||||
let thread_fragments = registry.context_contributors()[0]
|
||||
.contribute_thread_context(&session_store, &thread_store)
|
||||
@@ -2100,6 +2123,7 @@ async fn model_context_window_scales_executor_and_orchestrator_catalogs() -> Tes
|
||||
let turn_store = ExtensionData::new("turn-1");
|
||||
let sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &model_info,
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -2114,6 +2138,7 @@ async fn model_context_window_scales_executor_and_orchestrator_catalogs() -> Tes
|
||||
// Core rebuilds world state before each sampling step.
|
||||
let _repeated_sections = registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &model_info,
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
@@ -2213,6 +2238,7 @@ async fn executor_catalog_emits_at_most_four_warnings() -> TestResult {
|
||||
|
||||
registry.context_contributors()[0]
|
||||
.contribute_world_state(WorldStateContributionInput {
|
||||
model_info: &catalog_model_info(),
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
turn_id: "turn-1",
|
||||
environments: &[],
|
||||
|
||||
Reference in new issue
Block a user