Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

fix(codex): honor baseInstructions in ProxyChat catalogs (#10166)

Lingbouac987877204a
diff --git a/src-tauri/src/codex_config.rs b/src-tauri/src/codex_config.rs
index 1c15fbb74..2eda46635 100644
--- a/src-tauri/src/codex_config.rs
+++ b/src-tauri/src/codex_config.rs
@@ -1357,6 +1357,33 @@ fn apply_codex_reasoning_level_override(
true
}
+/// Explicit, non-empty user instructions override the template / official entry
+/// identity. Codex reads `model_messages.instructions_template` first when
+/// present, so keep both instruction fields in sync.
+fn apply_catalog_base_instructions_override(
+ entry: &mut serde_json::Map<String, Value>,
+ spec: &CodexCatalogModelSpec,
+) {
+ let Some(base_instructions) = spec
+ .base_instructions
+ .as_deref()
+ .map(str::trim)
+ .filter(|s| !s.is_empty())
+ else {
+ return;
+ };
+ entry.insert("base_instructions".to_string(), json!(base_instructions));
+ if let Some(messages) = entry
+ .get_mut("model_messages")
+ .and_then(Value::as_object_mut)
+ {
+ messages.insert(
+ "instructions_template".to_string(),
+ json!(base_instructions),
+ );
+ }
+}
+
fn codex_catalog_model_entry(
template: &Value,
spec: &CodexCatalogModelSpec,
@@ -1405,6 +1432,8 @@ fn codex_catalog_model_entry(
)),
);
+ apply_catalog_base_instructions_override(entry_obj, spec);
+
if !matches!(
profile,
CodexCatalogToolProfile::ProxyChat | CodexCatalogToolProfile::Copilot
@@ -1417,8 +1446,9 @@ fn codex_catalog_model_entry(
//
// NOTE: `base_instructions` is NOT stripped — Codex's catalog parser
// treats it as a REQUIRED field and refuses to load the file without
- // it ("missing field `base_instructions`"). The template carries a
- // neutral identity default; per-vendor official text overrides below.
+ // it ("missing field `base_instructions`"). Explicit per-row overrides
+ // were applied above; the template keeps its neutral identity default
+ // otherwise.
for key in [
"apply_patch_tool_type",
"web_search_tool_type",
@@ -1428,15 +1458,6 @@ fn codex_catalog_model_entry(
entry_obj.remove(key);
}
entry_obj.insert("shell_type".to_string(), json!("shell_command"));
-
- if let Some(base_instructions) = spec
- .base_instructions
- .as_deref()
- .map(str::trim)
- .filter(|s| !s.is_empty())
- {
- entry_obj.insert("base_instructions".to_string(), json!(base_instructions));
- }
if let Some(parallel) = spec.supports_parallel_tool_calls {
entry_obj.insert("supports_parallel_tool_calls".to_string(), json!(parallel));
}
@@ -3072,6 +3093,14 @@ fn codex_catalog_from_specs_for_row(
)
}
};
+ // ProxyChat aliases such as `gpt-5.5-relay` match the official gpt-5.5
+ // entry by prefix, so the template branch alone is not enough. Apply the
+ // explicit override after both branches converge.
+ if profile == CodexCatalogToolProfile::ProxyChat {
+ if let Some(obj) = entry.as_object_mut() {
+ apply_catalog_base_instructions_override(obj, spec);
+ }
+ }
// A changed window needs a matching compaction threshold in single-provider
// catalogs too. Otherwise an official/template threshold can stay at 244800
// even after the user requests 1M. Keep untouched official defaults intact.
diff --git a/src-tauri/src/codex_config/tests.rs b/src-tauri/src/codex_config/tests.rs
index feeacde5b..552976e8d 100644
--- a/src-tauri/src/codex_config/tests.rs
+++ b/src-tauri/src/codex_config/tests.rs
@@ -816,6 +816,99 @@ fn codex_model_catalog_uses_provider_models_and_context() {
);
}
+#[test]
+fn proxy_chat_profile_applies_explicit_base_instructions_override() {
+ let template = json!({
+ "slug": "gpt-5.5",
+ "base_instructions": "You are Codex, a coding agent based on GPT-5.",
+ "model_messages": {
+ "instructions_template": "You are Codex, a coding agent based on GPT-5."
+ }
+ });
+ let settings = json!({
+ "modelCatalog": {
+ "models": [
+ {
+ "model": "deepseek-v4-flash",
+ "baseInstructions": "You are Codex, a coding agent based on DeepSeek V4 Flash."
+ },
+ { "model": "kimi-k2" }
+ ]
+ }
+ });
+
+ let specs = codex_catalog_model_specs(&settings);
+ let catalog = codex_model_catalog_from_specs(
+ &specs,
+ &template,
+ CodexCatalogToolProfile::ProxyChat,
+ 128_000,
+ );
+ let models = catalog["models"].as_array().expect("models array");
+
+ assert_eq!(
+ models[0].get("base_instructions").and_then(Value::as_str),
+ Some("You are Codex, a coding agent based on DeepSeek V4 Flash."),
+ "ProxyChat must apply an explicit, non-empty baseInstructions override"
+ );
+ assert_eq!(
+ models[0]
+ .get("model_messages")
+ .and_then(|messages| messages.get("instructions_template"))
+ .and_then(Value::as_str),
+ Some("You are Codex, a coding agent based on DeepSeek V4 Flash."),
+ "Codex reads instructions_template first, so it must be updated together"
+ );
+ assert_eq!(
+ models[1].get("base_instructions").and_then(Value::as_str),
+ Some("You are Codex, a coding agent based on GPT-5."),
+ "ProxyChat must keep the template default when baseInstructions is absent"
+ );
+ assert_eq!(
+ models[1]
+ .get("model_messages")
+ .and_then(|messages| messages.get("instructions_template"))
+ .and_then(Value::as_str),
+ Some("You are Codex, a coding agent based on GPT-5."),
+ "absent override must keep the template instructions_template"
+ );
+}
+
+#[test]
+fn proxy_chat_official_prefix_alias_applies_explicit_base_instructions_override() {
+ // #5969 follow-up: third-party relay aliases such as `gpt-5.5-relay` match the
+ // official gpt-5.5 entry by prefix, so the template branch alone is not enough.
+ let settings = json!({
+ "modelCatalog": {
+ "models": [
+ {
+ "model": "gpt-5.5-relay",
+ "baseInstructions": "You are Codex, a coding agent based on a third-party model."
+ }
+ ]
+ }
+ });
+
+ let catalog =
+ codex_model_catalog_from_settings(&settings, "", CodexCatalogToolProfile::ProxyChat)
+ .expect("catalog generation should not error")
+ .expect("non-empty modelCatalog must yield a catalog");
+
+ let entry = &catalog["models"][0];
+ assert_eq!(
+ entry.get("base_instructions").and_then(Value::as_str),
+ Some("You are Codex, a coding agent based on a third-party model.")
+ );
+ assert_eq!(
+ entry
+ .get("model_messages")
+ .and_then(|messages| messages.get("instructions_template"))
+ .and_then(Value::as_str),
+ Some("You are Codex, a coding agent based on a third-party model."),
+ "official prefix aliases must also honor the explicit instructions override"
+ );
+}
+
#[test]
fn native_responses_catalog_honors_per_model_reasoning_levels() {
// The native template only declares none/high. A per-model