Preserve selected profile settings over managed new-thread defaults (#44693)

## Why

Managed new-thread defaults could overwrite model, reasoning effort, and service tier settings from an explicitly selected profile.

## What changed

- Treat effective profile settings as explicit launch choices when applying managed defaults. A profile setting for either `model` or `model_reasoning_effort` opts out of both managed values; `service_tier` remains independent.
- Count a profile setting only when it supplies the highest-precedence active value, so settings shadowed by project configuration do not block defaults.

## Testing

Add regression coverage for profile precedence at startup, session replacement, and background task creation, plus custom-provider profiles, service tiers, unrelated profile settings, and project settings that shadow profiles.

GitOrigin-RevId: 98f036b8b7059bab8598283600dbc6967c71d3e3
This commit is contained in:
Alex Ryan authored and copyberry committed 2026-09-11 00:59:27 +00:00
1 parent e53c444964
commit aff3e0db94
7 files changed
+140 -18

No files matched your search

@@ -416,6 +416,7 @@ async fn background_task_preserves_explicit_choices_and_managed_defaults() -> Re
("saved", "server-model", "high"),
("cli_effort", "server-model", "low"),
("profile_model", "profile-model", "high"),
("profile_managed", "profile-model", "low"),
("managed", "managed-model", "medium"),
] {
let client_home = tempdir()?;
@@ -428,7 +429,7 @@ async fn background_task_preserves_explicit_choices_and_managed_defaults() -> Re
server_home.path().join("config.toml"),
"model = \"server-model\"\nmodel_reasoning_effort = \"high\"\n",
)?;
if choice == "managed" || choice.starts_with("cli_") {
if choice == "managed" || choice == "profile_managed" || choice.starts_with("cli_") {
std::fs::write(
server_home.path().join("requirements.toml"),
"[models.new_thread]\nmodel = \"managed-model\"\nmodel_reasoning_effort = \"medium\"\n",
@@ -440,9 +441,16 @@ async fn background_task_preserves_explicit_choices_and_managed_defaults() -> Re
"model_reasoning_effort".into(),
TomlValue::String("low".into()),
)),
"profile_model" => {
"profile_model" | "profile_managed" => {
let path = client_home.path().join("work.config.toml");
std::fs::write(&path, "model = \"profile-model\"\n")?;
std::fs::write(
&path,
if choice == "profile_managed" {
"model = \"profile-model\"\nmodel_reasoning_effort = \"low\"\n"
} else {
"model = \"profile-model\"\n"
},
)?;
app.loader_overrides.user_config_path = Some(path.abs());
app.loader_overrides.user_config_profile = Some("work".parse()?);
}
@@ -11,8 +11,16 @@ async fn replacement_uses_server_defaults_and_preserves_explicit_launch_settings
(Some("medium"), "effort", "server-model", "low"),
(None, "profile_model", "profile-model", "high"),
(None, "profile_effort", "server-model", "low"),
(Some(""), "profile", "managed-model", "low"),
(Some("medium"), "profile", "managed-model", "medium"),
(Some("medium"), "profile_model", "profile-model", "high"),
(Some("medium"), "profile_effort", "server-model", "low"),
(Some(""), "profile", "profile-model", "low"),
(Some("medium"), "profile", "profile-model", "low"),
(
Some("medium"),
"profile_unrelated",
"managed-model",
"medium",
),
] {
let (mut app, _events, _ops) = make_test_app_with_channels().await;
let server_home = tempdir()?;
@@ -68,13 +76,14 @@ async fn replacement_uses_server_defaults_and_preserves_explicit_launch_settings
"model_reasoning_effort".to_string(),
TomlValue::String("low".to_string()),
)),
profile @ ("profile" | "profile_model" | "profile_effort") => {
profile @ ("profile" | "profile_model" | "profile_effort" | "profile_unrelated") => {
let path = client_home.path().join("work.config.toml");
std::fs::write(
&path,
match profile {
"profile_model" => "model = \"profile-model\"\n",
"profile_effort" => "model_reasoning_effort = \"low\"\n",
"profile_unrelated" => "model_verbosity = \"low\"\n",
_ => "model = \"profile-model\"\nmodel_reasoning_effort = \"low\"\n",
},
)?;
@@ -178,6 +178,8 @@ async fn fresh_startup_uses_server_defaults_with_explicit_and_managed_precedence
("cli_effort", true, "server-model", "low"),
("profile_model", false, "profile-model", "high"),
("profile_effort", false, "server-model", "low"),
("profile_model", true, "profile-model", "high"),
("profile_effort", true, "server-model", "low"),
("managed", true, "managed-model", "medium"),
] {
let client_home = tempdir()?;