fix(buzz-agent-core): advertise the model catalog on session/new

session/new returned only `sessionId`, so the desktop ModelPicker degraded to
"current model only" and buzz-acp could not resolve session/set_model targets
(resolve_model_switch_method, buzz-acp/src/acp.rs:1876).

This was a regression I introduced by deleting buzz-agent's catalog.rs without
replacing what it fed -- not a limitation of driving goose as a library. The
picker is the same UI and the same buzz-acp code path for every agent; goose's
CLI fills it via build_model_state, buzz-agent filled it via Databricks
discovery, and this crate filled it with nothing.

Cannot reuse goose's builder: build_model_state is pub(super)
(acp/response_builder.rs:130), invisible outside goose::acp. The underlying
data is public, so discover_models() rebuilds the same shape from
Provider::fetch_supported_models (goose-provider-types/base.rs:425) via
Agent::provider(), including goose's rule that the current model is prepended
when the provider's list omits it.

Absent catalog stays degraded UX, never a session failure -- matching
buzz-agent's Databricks fallback (catalog.rs:52-80).

New stdio test asserts the shape buzz-acp actually parses: currentModelId plus
availableModels entries keyed by `modelId`. 16 tests green.

Signed-off-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
Michael Neale
2026-07-27 15:20:24 +10:00
parent 63efbb24b6
commit 46124528ae
2 changed files with 106 additions and 1 deletions

View File

@@ -359,6 +359,16 @@ async fn session_new(app: &Arc<App>, id: Value, params: Value, wire_tx: &WireSen
};
let sid = format!("ses_{}", goose_session_id);
// Keep a handle for catalog discovery below; the Session takes ownership.
let session_agent = agent.clone();
let current_model = app
.cfg
.model
.clone()
.or_else(|| std::env::var("GOOSE_MODEL").ok())
.unwrap_or_default();
app.sessions.lock().await.insert(
sid.clone(),
Session {
@@ -374,7 +384,59 @@ async fn session_new(app: &Arc<App>, id: Value, params: Value, wire_tx: &WireSen
},
);
wire::send(wire_tx, wire::ok(id, json!({ "sessionId": sid }))).await;
// Advertise the model catalog. `buzz-acp` reads `models.availableModels`
// off this response (`acp.rs:1866`, `:1900`) to drive the desktop
// ModelPicker and to resolve `session/set_model` targets
// (`resolve_model_switch_method`, `acp.rs:1876`). Omitting it degrades the
// picker to "current model only" — which is what buzz-agent's `catalog.rs`
// existed to prevent.
//
// Goose builds the same structure internally (`build_model_state`,
// acp/response_builder.rs:130) but it is `pub(super)`, so an embedder
// cannot call it. The underlying data is public, though:
// `Provider::fetch_supported_models` (goose-provider-types/base.rs:425).
let mut result = json!({ "sessionId": sid });
if let Some(models) = discover_models(&session_agent, &current_model).await {
result["models"] = models;
}
wire::send(wire_tx, wire::ok(id, result)).await;
}
/// Build the `{currentModelId, availableModels}` object for `session/new`.
///
/// Mirrors goose's own `build_model_state`, including its rule that the
/// current model is prepended when the provider's list omits it — otherwise
/// `buzz-acp` cannot resolve a switch back to it.
///
/// Returns `None` when the provider cannot enumerate models (many can't;
/// `fetch_supported_models` defaults to an empty list). A missing catalog is
/// degraded UX, never a session failure — buzz-agent's Databricks discovery
/// made the same choice (`catalog.rs:52-80`).
async fn discover_models(agent: &Arc<Agent>, current_model: &str) -> Option<Value> {
let provider = agent.provider().await.ok()?;
let ids = provider.fetch_supported_models().await.ok()?;
let mut available: Vec<Value> = ids
.iter()
.map(|id| json!({ "modelId": id, "name": id }))
.collect();
if !ids.iter().any(|id| id == current_model) {
available.insert(
0,
json!({ "modelId": current_model, "name": current_model }),
);
}
if available.is_empty() {
return None;
}
Some(json!({
"currentModelId": current_model,
"availableModels": available,
}))
}
async fn session_prompt(app: &Arc<App>, id: Value, params: Value, wire_tx: &WireSender) {

View File

@@ -317,6 +317,49 @@ fn full_turn_over_stdio_carries_the_persona() {
// seen strictly BEFORE the session/prompt response was read.
}
#[test]
fn session_new_advertises_the_model_catalog() {
let (base_url, _rx) = spawn_fake_provider();
let home = tempfile::tempdir().expect("tempdir");
let cwd = tempfile::tempdir().expect("cwd");
let mut h = Harness::start(&base_url, home.path());
let id = h.request("initialize", json!({ "protocolVersion": 2 }));
let _ = h.await_response(id);
let id = h.request(
"session/new",
json!({ "cwd": cwd.path().to_str().unwrap(), "mcpServers": [] }),
);
let (resp, _) = h.await_response(id);
let result = &resp["result"];
// buzz-acp reads `models.availableModels` to drive the desktop
// ModelPicker and to resolve session/set_model targets
// (`buzz-acp/src/acp.rs:1866`, `:1900`). Without it the picker degrades
// to "current model only".
let models = &result["models"];
assert!(
models.is_object(),
"session/new must advertise a model catalog, got: {result}"
);
assert_eq!(models["currentModelId"], "fake-model");
let available = models["availableModels"]
.as_array()
.expect("availableModels array");
assert!(!available.is_empty());
// Key must be `modelId` — that is what resolve_model_switch_method matches.
assert!(
available.iter().any(|m| m["modelId"] == "fake-model"),
"current model must appear in availableModels, got: {available:#?}"
);
assert!(
available.iter().all(|m| m["modelId"].is_string()),
"every entry needs a modelId key"
);
}
#[test]
fn set_model_applies_from_the_next_prompt() {
let (base_url, system_rx) = spawn_fake_provider();