fix(agents): switching a saved task to a model of a legacy ACP agent no longer fails (#3856)

An agent that lists models through the legacy `models` field and reports no settings after `session/set_model` made the discovery wait five seconds and fail, and the model choice was reverted. Such a model now has no per-model settings instead. Agents with `configOptions` still report a missing answer as before.
This commit is contained in:
l0ng-ai
2026-11-17 09:33:33 +08:00
committed by GitHub
parent 88a5602239
commit ba5c56ade8
2 changed files with 38 additions and 6 deletions
+11 -6
View File
@@ -72,9 +72,8 @@ async fn run_once(
config::add_client_options(&launch.id, &mut options);
let model_option = options.iter().find(|o| o.category.as_deref() == Some("model"));
let mut levels = BTreeMap::new();
if new.get("configOptions").is_some_and(Value::is_array)
&& let Some(model) = model_option.and_then(|o| o.current.as_ref())
{
let has_config = new.get("configOptions").is_some_and(Value::is_array);
if has_config && let Some(model) = model_option.and_then(|o| o.current.as_ref()) {
levels.insert(model.clone(), levels_for_model_from_slice(&options));
}
if let Some(selected) = selected_model
@@ -88,7 +87,7 @@ async fn run_once(
updates.config.lock().session = Some(session.to_owned());
let response: Value = conn.request(method, params, None).await.map_err(discovery_error)?;
let settings = if let Some(settings) = selected_settings(&response, selected) {
settings
Some(settings)
} else {
tokio::time::timeout(CONFIG_UPDATE_TIMEOUT, async {
loop {
@@ -106,9 +105,15 @@ async fn run_once(
}
})
.await
.map_err(|_| "The agent did not report settings for the selected model".to_owned())?
.ok()
};
match settings {
Some(settings) => levels.insert(selected.to_owned(), levels_for_model_from_slice(&settings)),
// An agent on the legacy `models` field that says nothing more: the model has
// no settings of its own, and switching to it must not fail.
None if !has_config => levels.insert(selected.to_owned(), Vec::new()),
None => return Err("The agent did not report settings for the selected model".to_owned()),
};
levels.insert(selected.to_owned(), levels_for_model_from_slice(&settings));
}
let commands = updates
.commands
+27
View File
@@ -774,6 +774,33 @@ async fn selected_model_uses_legacy_set_model_and_authoritative_notifications()
assert!(!catalog.thought_levels.contains_key("default"), "legacy model lists alone do not assert no controls");
}
#[tokio::test]
async fn selected_legacy_model_without_settings_has_no_levels_instead_of_failing() {
let tmp = tempfile::tempdir().unwrap();
configure(tmp.path(), "one");
let mut harness = Harness::new();
let manager = make_manager(tmp.path(), Arc::default(), &harness);
let mut events = events(&manager);
manager.refresh_models(PROVIDER, false, Some("second")).unwrap();
harness
.next()
.await
.reply
.send(Ok(json!({
"sessionId": "discovery-only",
"models": { "currentModelId": "default", "availableModels": [
{ "modelId": "default", "name": "Default" }, { "modelId": "second", "name": "Second" }
] }
})))
.unwrap();
let selected = harness.next().await;
assert_eq!(selected.method, "session/set_model");
selected.reply.send(Ok(json!({}))).unwrap();
let catalog = completed(&mut events).await;
assert!(catalog.error.is_none(), "{:?}", catalog.error);
assert_eq!(catalog.thought_levels.get("second"), Some(&Vec::new()));
}
#[tokio::test]
async fn catalog_replacement_removes_selected_metadata_for_models_no_longer_listed() {
let tmp = tempfile::tempdir().unwrap();