Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions codex-rs/app-server/tests/suite/v2/executor_skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,20 @@ stream_max_retries = 0
let request_id = app_server
.send_thread_start_request_with_auto_env(ThreadStartParams {
model: Some("mock-model".to_string()),
config: matches!(
scenario,
config: match scenario {
ExecutorSkillScenario::VisibleWithBudgetWarning => Some(HashMap::from([(
"skills.max_context_tokens".to_string(),
json!(1_000),
)])),
ExecutorSkillScenario::RestrictedPermittedReference
| ExecutorSkillScenario::RestrictedDeniedReference
)
.then(|| HashMap::from([("tool_output_token_limit".to_string(), json!(250))])),
| ExecutorSkillScenario::RestrictedDeniedReference => Some(HashMap::from([(
"tool_output_token_limit".to_string(),
json!(250),
)])),
ExecutorSkillScenario::ExplicitOnly | ExecutorSkillScenario::RestrictedVisible => {
None
}
},
selected_capability_roots: Some(vec![SelectedCapabilityRoot {
id: "demo-plugin@1".to_string(),
location: CapabilityRootLocation::Environment {
Expand Down Expand Up @@ -444,12 +452,8 @@ stream_max_retries = 0
.await?;
}
if scenario == ExecutorSkillScenario::VisibleWithBudgetWarning {
let is_skills_budget_warning = |message: &str| {
message.starts_with("Exceeded skills context budget.")
|| message.starts_with(
"Skill descriptions were shortened to fit the skills context budget.",
)
};
let is_skills_budget_warning =
|message: &str| message.starts_with("Exceeded skills context budget.");
let warning = timeout(READ_TIMEOUT, async {
loop {
let warning: WarningNotification = app_server.read_notification("warning").await?;
Expand Down
9 changes: 1 addition & 8 deletions codex-rs/core/tests/suite/skills_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3754,9 +3754,7 @@ async fn production_turn_fairly_shortens_extension_catalog_descriptions() -> Res
.collect(),
warnings: Vec::new(),
};
let (event_tx, event_rx) = std::sync::mpsc::channel();
let mut extensions =
ExtensionRegistryBuilder::<Config>::with_event_sink(Arc::new(ChannelEventSink(event_tx)));
let mut extensions = ExtensionRegistryBuilder::<Config>::new();
install_with_providers(
&mut extensions,
SkillProviders::new().with_provider(SkillProviderSource::new(
Expand Down Expand Up @@ -3812,11 +3810,6 @@ async fn production_turn_fairly_shortens_extension_catalog_descriptions() -> Res
.all(|length| *length > 0 && *length < 1_024)
);
assert!(!catalog_text.contains("additional skills omitted"));
let warning = event_rx.try_recv()?.into_warning();
assert_eq!(
warning.message,
"Skill descriptions were shortened to fit the skills context budget. Codex can still see every skill, but some descriptions are shorter. Disable unused skills or plugins to leave more room for the rest."
);

Ok(())
}
6 changes: 1 addition & 5 deletions codex-rs/ext/skills/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const MAX_SKILL_PROMPT_BYTES: usize = 8_000;
const SKILL_METADATA_CONTEXT_WINDOW_PERCENT: usize = 2;
const MAX_CATALOG_SKILL_DESCRIPTION_CHARS: usize = 1_024;
const TRUNCATED_SKILL_DESCRIPTION_SUFFIX: &str = "...";
const SKILL_DESCRIPTION_TRUNCATION_WARNING_THRESHOLD_CHARS: usize = 100;
const APPROX_BYTES_PER_TOKEN: usize = 4;
const SKILL_DESCRIPTION_TRUNCATED_WARNING: &str = "Skill descriptions were shortened to fit the skills context budget. Codex can still see every skill, but some descriptions are shorter. Disable unused skills or plugins to leave more room for the rest.";
const SKILL_DESCRIPTIONS_REMOVED_WARNING_PREFIX: &str =
"Exceeded skills context budget. All skill descriptions were removed and";
pub(crate) const MAX_SKILL_NAME_BYTES: usize = 256;
Expand Down Expand Up @@ -108,9 +106,7 @@ impl SkillRenderReport {
));
}

(self.average_truncated_description_chars()
> SKILL_DESCRIPTION_TRUNCATION_WARNING_THRESHOLD_CHARS)
.then(|| SKILL_DESCRIPTION_TRUNCATED_WARNING.to_string())
None
}

pub(crate) fn average_truncated_description_chars(&self) -> usize {
Expand Down
59 changes: 0 additions & 59 deletions codex-rs/ext/skills/src/render_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,62 +1085,3 @@ fn catalog_preserves_report_when_no_fragment_fits_budget() {
.is_none()
);
}

#[test]
fn substantial_description_shortening_emits_warning() {
let catalog = SkillCatalog {
entries: vec![
entry(
"long-skill",
&"a".repeat(250),
/*short_description*/ None,
),
entry("empty-skill", "", /*short_description*/ None),
],
warnings: Vec::new(),
};
let skill_lines = catalog
.entries
.iter()
.map(|entry| SkillLine::new(entry, SkillCatalogRenderPolicy::ExtensionCompatible))
.collect::<Vec<_>>();
let minimum_cost = skill_lines.iter().fold(0usize, |used, line| {
used.saturating_add(line.minimum_cost(SkillMetadataBudget::Characters(usize::MAX)))
});
let render = render_available_skills(
&catalog,
SkillCatalogRenderPolicy::ExtensionCompatible,
SkillMetadataBudget::Characters(minimum_cost + 49),
/*include_skills_usage_instructions*/ false,
)
.expect("catalog should render");

assert_eq!(
render.report.warning_message(),
Some(
"Skill descriptions were shortened to fit the skills context budget. Codex can still see every skill, but some descriptions are shorter. Disable unused skills or plugins to leave more room for the rest."
.to_string()
)
);
}

#[test]
fn substantial_description_shortening_warning_starts_above_threshold() {
let report_at_threshold = SkillRenderReport {
total_count: 2,
included_count: 2,
omitted_count: 0,
truncated_description_chars: 200,
truncated_description_count: 2,
};
assert_eq!(report_at_threshold.warning_message(), None);

let report_above_threshold = SkillRenderReport {
truncated_description_chars: 201,
..report_at_threshold
};
assert_eq!(
report_above_threshold.warning_message(),
Some(SKILL_DESCRIPTION_TRUNCATED_WARNING.to_string())
);
}
Loading