Skip to content

Commit ba47f02

Browse files
tellahonpub14vtk7pvazqrq9639qu7e560wnqtl0d53ca4gjuvq6jzf3k2el23qqlwa7f
authored andcommitted
fix(desktop): handle model discovery setup states
- Reuse managed-agent runtime defaults, provider/model env injection, and Databricks defaults when querying agent models so discovery matches normal startup behavior. - Add a configurationError field to model discovery responses for known missing provider, model, or credential setup issues instead of treating them as generic subprocess failures. - Update the profile model picker to render actionable setup messaging for configuration gaps and reserve the red failure state for unexpected discovery errors. - Show provider-backed agents as remotely managed in the model focused view rather than exposing a local model picker. - Keep E2E Tauri mocks aligned with the expanded AgentModelsResponse shape. Co-authored-by: Taylor Ho <[email protected]> Signed-off-by: Taylor Ho <[email protected]>
1 parent 85a5438 commit ba47f02

7 files changed

Lines changed: 159 additions & 23 deletions

File tree

‎desktop/src-tauri/src/commands/agent_models.rs‎

Lines changed: 124 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use tauri::{AppHandle, State};
66
use crate::{
77
app_state::AppState,
88
managed_agents::{
9-
build_managed_agent_summary, default_agent_workdir, find_managed_agent_mut,
10-
known_acp_runtime, load_managed_agents, load_personas, managed_agent_avatar_url,
11-
missing_command_message, normalize_agent_args, resolve_command,
12-
resolve_effective_prompt_model_provider, save_managed_agents, sync_managed_agent_processes,
13-
try_regenerate_nest, AgentModelInfo, AgentModelsResponse, UpdateManagedAgentRequest,
14-
UpdateManagedAgentResponse,
9+
build_databricks_defaults, build_managed_agent_summary, default_agent_workdir,
10+
find_managed_agent_mut, known_acp_runtime, load_managed_agents, load_personas,
11+
managed_agent_avatar_url, missing_command_message, normalize_agent_args, resolve_command,
12+
resolve_effective_prompt_model_provider, runtime_metadata_env_vars, save_managed_agents,
13+
sync_managed_agent_processes, try_regenerate_nest, AgentModelInfo, AgentModelsResponse,
14+
UpdateManagedAgentRequest, UpdateManagedAgentResponse,
1515
},
1616
relay::{relay_ws_url_with_override, sync_managed_agent_profile},
1717
util::now_iso,
@@ -27,7 +27,16 @@ pub async fn get_agent_models(
2727
app: AppHandle,
2828
state: State<'_, AppState>,
2929
) -> Result<AgentModelsResponse, String> {
30-
let (resolved_acp, agent_command, agent_args, persisted_model, merged_env) = {
30+
let (
31+
resolved_acp,
32+
agent_command,
33+
agent_args,
34+
persisted_model,
35+
runtime_default_env,
36+
runtime_metadata_env,
37+
databricks_defaults,
38+
merged_env,
39+
) = {
3140
let _store_guard = state
3241
.managed_agents_store_lock
3342
.lock()
@@ -75,14 +84,51 @@ pub async fn get_agent_models(
7584

7685
// Resolve the effective model from the linked persona so the ModelPicker
7786
// dropdown shows the current persona model as selected.
78-
let (_prompt, effective_model, _provider) = resolve_effective_prompt_model_provider(
79-
record.persona_id.as_deref(),
80-
&personas,
81-
record.system_prompt.clone(),
82-
record.model.clone(),
83-
);
84-
85-
(resolved, resolved_agent, args, effective_model, env)
87+
let (_prompt, effective_model, effective_provider) =
88+
resolve_effective_prompt_model_provider(
89+
record.persona_id.as_deref(),
90+
&personas,
91+
record.system_prompt.clone(),
92+
record.model.clone(),
93+
);
94+
let runtime = known_acp_runtime(&record.agent_command);
95+
let runtime_default_env: Vec<(String, String)> = runtime
96+
.map(|meta| {
97+
meta.default_env
98+
.iter()
99+
.map(|(key, value)| ((*key).to_string(), (*value).to_string()))
100+
.collect()
101+
})
102+
.unwrap_or_default();
103+
let runtime_metadata_env: Vec<(String, String)> = runtime
104+
.map(|meta| {
105+
runtime_metadata_env_vars(
106+
meta.model_env_var,
107+
meta.provider_env_var,
108+
meta.provider_locked,
109+
effective_model.as_deref(),
110+
effective_provider.as_deref(),
111+
)
112+
.into_iter()
113+
.map(|(key, value)| (key.to_string(), value.to_string()))
114+
.collect()
115+
})
116+
.unwrap_or_default();
117+
let databricks_defaults: Vec<(String, String)> = build_databricks_defaults()
118+
.into_iter()
119+
.map(|(key, value)| (key.to_string(), value.to_string()))
120+
.collect();
121+
122+
(
123+
resolved,
124+
resolved_agent,
125+
args,
126+
effective_model,
127+
runtime_default_env,
128+
runtime_metadata_env,
129+
databricks_defaults,
130+
env,
131+
)
86132
}; // store lock released — subprocess runs without holding the lock
87133

88134
// Clone the env map for redaction below — `merged_env` is moved
@@ -105,13 +151,17 @@ pub async fn get_agent_models(
105151
.arg("--json")
106152
.env("BUZZ_ACP_AGENT_COMMAND", &agent_command)
107153
.env("BUZZ_ACP_AGENT_ARGS", agent_args.join(","));
108-
if let Some(meta) = known_acp_runtime(&agent_command) {
109-
for (key, value) in meta.default_env {
110-
if std::env::var(key).is_err() {
111-
cmd.env(key, value);
112-
}
154+
for (key, value) in &runtime_default_env {
155+
if std::env::var(key).is_err() {
156+
cmd.env(key, value);
113157
}
114158
}
159+
for (key, value) in &runtime_metadata_env {
160+
cmd.env(key, value);
161+
}
162+
for (key, value) in &databricks_defaults {
163+
cmd.env(key, value);
164+
}
115165
// User env layering — written LAST so it overrides any Buzz-set env above.
116166
for (k, v) in &merged_env {
117167
cmd.env(k, v);
@@ -132,6 +182,12 @@ pub async fn get_agent_models(
132182
// a failing child process echoed back.
133183
let stderr_redacted =
134184
crate::managed_agents::redact_env_values_in(stderr.as_ref(), &env_for_redaction);
185+
if let Some(configuration_error) = model_configuration_error(&stderr_redacted) {
186+
return Ok(unavailable_agent_models(
187+
persisted_model,
188+
configuration_error,
189+
));
190+
}
135191
return Err(format!(
136192
"buzz-acp models failed (exit {}): {stderr_redacted}",
137193
output.status.code().unwrap_or(-1)
@@ -413,5 +469,53 @@ fn normalize_agent_models(
413469
agent_default_model,
414470
selected_model: persisted_model,
415471
supports_switching,
472+
configuration_error: None,
473+
}
474+
}
475+
476+
fn unavailable_agent_models(
477+
persisted_model: Option<String>,
478+
configuration_error: String,
479+
) -> AgentModelsResponse {
480+
AgentModelsResponse {
481+
agent_name: "unknown".to_string(),
482+
agent_version: "unknown".to_string(),
483+
models: Vec::new(),
484+
agent_default_model: None,
485+
selected_model: persisted_model,
486+
supports_switching: false,
487+
configuration_error: Some(configuration_error),
488+
}
489+
}
490+
491+
fn model_configuration_error(stderr: &str) -> Option<String> {
492+
let normalized = stderr.to_ascii_lowercase();
493+
494+
if normalized.contains("buzz_agent_provider required") {
495+
return Some(
496+
"This agent does not have an LLM provider configured. Set a provider and model on the persona or agent, then retry."
497+
.to_string(),
498+
);
416499
}
500+
501+
if normalized.contains("anthropic_model required")
502+
|| normalized.contains("openai_compat_model required")
503+
|| normalized.contains("databricks_model required")
504+
{
505+
return Some(
506+
"This agent does not have an LLM model configured. Set a model on the persona or agent, then retry."
507+
.to_string(),
508+
);
509+
}
510+
511+
if normalized.contains("anthropic_api_key required")
512+
|| normalized.contains("openai_compat_api_key required")
513+
{
514+
return Some(
515+
"This agent is missing credentials for its configured LLM provider. Add the provider credentials, then retry."
516+
.to_string(),
517+
);
518+
}
519+
520+
None
417521
}

‎desktop/src-tauri/src/managed_agents/runtime.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ fn child_rust_log_filter() -> String {
18451845

18461846
/// Databricks host/model baked in at compile time for internal builds. Empty
18471847
/// in OSS builds, where the `BUZZ_BUILD_DATABRICKS_*` env is unset.
1848-
fn build_databricks_defaults() -> Vec<(&'static str, &'static str)> {
1848+
pub(crate) fn build_databricks_defaults() -> Vec<(&'static str, &'static str)> {
18491849
let mut defaults = Vec::new();
18501850
if let Some(host) = option_env!("BUZZ_DESKTOP_BUILD_DATABRICKS_HOST") {
18511851
if !host.is_empty() {
@@ -1977,7 +1977,7 @@ pub fn stop_managed_agent_process(
19771977
/// switching need the initial bootstrap value. Provider injection is skipped
19781978
/// when `provider_locked` is true (e.g. Claude runtimes that only work with
19791979
/// Anthropic).
1980-
fn runtime_metadata_env_vars<'a>(
1980+
pub(crate) fn runtime_metadata_env_vars<'a>(
19811981
model_env_var: Option<&'a str>,
19821982
provider_env_var: Option<&'a str>,
19831983
provider_locked: bool,

‎desktop/src-tauri/src/managed_agents/types.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ pub struct AgentModelsResponse {
535535
pub selected_model: Option<String>,
536536
/// Whether this agent supports model switching.
537537
pub supports_switching: bool,
538+
/// Human-readable setup issue that prevents model discovery.
539+
pub configuration_error: Option<String>,
538540
}
539541

540542
/// A single model available from an agent.

‎desktop/src/features/agents/ui/ModelPicker.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export function ModelPicker({
109109
) : error ? (
110110
<div className="space-y-2 px-3 py-2 text-sm">
111111
<p className="text-destructive">Failed to load models.</p>
112+
<p className="max-w-72 wrap-break-word text-xs text-muted-foreground">
113+
{error}
114+
</p>
112115
<button
113116
className="text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground"
114117
onClick={() => {
@@ -124,6 +127,25 @@ export function ModelPicker({
124127
<div className="px-3 py-2 text-sm text-muted-foreground">
125128
Open to load available models.
126129
</div>
130+
) : modelsData.configurationError ? (
131+
<div className="space-y-2 px-3 py-2 text-sm">
132+
<p className="font-medium text-foreground">
133+
Model provider not configured
134+
</p>
135+
<p className="max-w-72 wrap-break-word text-xs text-muted-foreground">
136+
{modelsData.configurationError}
137+
</p>
138+
<button
139+
className="text-xs text-muted-foreground underline underline-offset-2 hover:text-foreground"
140+
onClick={() => {
141+
setHasRequestedModels(true);
142+
void fetchModels();
143+
}}
144+
type="button"
145+
>
146+
Retry
147+
</button>
148+
</div>
127149
) : !modelsData.supportsSwitching ? (
128150
<div className="px-3 py-2 text-sm text-muted-foreground">
129151
{agent.model ? (

‎desktop/src/features/profile/ui/UserProfilePanelSections.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@ export function ModelFocusedView({
835835
modelLabel: string;
836836
onModelChanged: () => void;
837837
}) {
838+
const canPickModel = managedAgent?.backend.type === "local";
839+
838840
return (
839841
<div className="space-y-3 pt-4">
840842
<div className="flex items-center gap-3 rounded-2xl bg-muted/20 px-4 py-3">
@@ -849,8 +851,12 @@ export function ModelFocusedView({
849851
{modelLabel}
850852
</span>
851853
</span>
852-
{managedAgent ? (
854+
{canPickModel && managedAgent ? (
853855
<ModelPicker agent={managedAgent} onModelChanged={onModelChanged} />
856+
) : managedAgent ? (
857+
<span className="rounded-full bg-muted/45 px-2.5 py-1 text-xs font-medium text-muted-foreground">
858+
managed remotely
859+
</span>
854860
) : null}
855861
</div>
856862
</div>

‎desktop/src/shared/api/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ export type AgentModelsResponse = {
470470
agentDefaultModel: string | null;
471471
selectedModel: string | null;
472472
supportsSwitching: boolean;
473+
configurationError: string | null;
473474
};
474475
export type AgentModelInfo = {
475476
id: string;

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6724,6 +6724,7 @@ export function maybeInstallE2eTauriMocks() {
67246724
agentDefaultModel: null,
67256725
selectedModel: null,
67266726
supportsSwitching: false,
6727+
configurationError: null,
67276728
};
67286729
case "update_managed_agent":
67296730
return handleUpdateManagedAgent(

0 commit comments

Comments
 (0)