fix(desktop): address Thufir Pass 1 blocking defects on #1307

FIX 1 — base64-encode BUZZ_BUILD_AGENT_ENV for Cargo round-trip:
Cargo build-script output is line-oriented; a raw multiline value was
silently truncated to the first line. build.rs now base64-encodes the
validated value before emitting; runtime.rs decodes it before parsing.
Adds base64 to [build-dependencies]. New test: round-trip with 2-pair
value containing URL-embedded '=' survives encode→decode→parse.

FIX 2 — move baked defaults before record metadata env vars:
build_buzz_agent_provider_defaults() was called after
runtime_metadata_env_vars() wrote BUZZ_AGENT_PROVIDER/MODEL from the
record, so an internal baked provider/model clobbered the persona's
choice (last-write-wins). Moved the call to just before the
runtime_metadata_env_vars loop; removed the old call site. New test:
record provider written after baked default wins.

FIX 3 — README no longer documents removed Databricks fallback:
config.rs now errors when BUZZ_AGENT_PROVIDER is unset; the README
still described the auto-fallback. Rewrote the BUZZ_AGENT_PROVIDER row,
ANTHROPIC/OPENAI key rows, DATABRICKS_HOST/MODEL rows, and the fallback
paragraph to match the actual behavior. Provider examples (Tested with
column) preserved — those are illustrative, not a baked registry.

FIX 4 — personaModelDiscoveryStatus.ts matcher string:
config.rs emits 'BUZZ_AGENT_PROVIDER is required' but the UI matched
'BUZZ_AGENT_PROVIDER required' (no 'is'), causing the missing-provider
case to fall through to the generic warning instead of returning null.

MINOR — env_clear() on passthrough tests for isolation.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-06-29 19:35:58 -04:00
co-authored by Will Pfleger
parent 428187009d
commit 8a4d12b437
6 changed files with 82 additions and 15 deletions
+6 -6
View File
@@ -129,17 +129,17 @@ Everything is environment variables. No flags, no config files. (We are a subpro
| Variable | Default | Notes |
|---|---|---|
| `BUZZ_AGENT_PROVIDER` | — | `anthropic`, `openai`, `databricks`, or `databricks_v2`. If unset, or if `anthropic`/`openai` is selected but its API key is missing, Databricks is auto-selected when `DATABRICKS_HOST` + `DATABRICKS_MODEL` are set. |
| `ANTHROPIC_API_KEY` | — | Required when provider=anthropic unless Databricks fallback is configured. |
| `BUZZ_AGENT_PROVIDER` | — | Required. `anthropic`, `openai`, `databricks`, or `databricks_v2`. No implicit fallback — the agent errors at startup when this is unset. |
| `ANTHROPIC_API_KEY` | — | Required when provider=anthropic. |
| `ANTHROPIC_MODEL` | — | Required when provider=anthropic. |
| `ANTHROPIC_BASE_URL` | `https://api.anthropic.com` | |
| `ANTHROPIC_API_VERSION` | `2023-06-01` | |
| `OPENAI_COMPAT_API_KEY` | — | Required when provider=openai unless Databricks fallback is configured. |
| `OPENAI_COMPAT_API_KEY` | — | Required when provider=openai. |
| `OPENAI_COMPAT_MODEL` | — | Required when provider=openai. |
| `OPENAI_COMPAT_BASE_URL` | `https://api.openai.com/v1` | Point at vLLM, llama.cpp, OpenRouter, Ollama, etc. |
| `OPENAI_COMPAT_API` | `auto` | `auto` \| `chat` \| `responses`. `auto` picks Responses for `*.openai.com`, Chat Completions everywhere else. |
| `DATABRICKS_HOST` | — | Required when provider=databricks or when using Databricks fallback. |
| `DATABRICKS_MODEL` | — | Required when provider=databricks or when using Databricks fallback. |
| `DATABRICKS_HOST` | — | Required when provider=databricks or provider=databricks_v2. |
| `DATABRICKS_MODEL` | — | Required when provider=databricks or provider=databricks_v2. |
| `DATABRICKS_TOKEN` | — | Optional static bearer escape hatch. If unset, Databricks uses browser OAuth + refresh cache. |
| `BUZZ_AGENT_SYSTEM_PROMPT` | built-in | Inline system prompt. |
| `BUZZ_AGENT_SYSTEM_PROMPT_FILE` | — | File path. Mutually exclusive with the above. |
@@ -172,7 +172,7 @@ Everything is environment variables. No flags, no config files. (We are a subpro
| Databricks | `databricks` | `POST {host}/serving-endpoints/{model}/invocations` | goose-claude-4-6-sonnet |
| Databricks AI Gateway v2 | `databricks_v2` | `POST {host}/ai-gateway/{provider}/v1/...` | databricks-gpt-5-5, databricks-claude-opus-4-7 |
If `BUZZ_AGENT_PROVIDER=anthropic` is selected without `ANTHROPIC_API_KEY`, or `BUZZ_AGENT_PROVIDER=openai` is selected without `OPENAI_COMPAT_API_KEY`, the agent automatically falls back to Databricks OAuth when `DATABRICKS_HOST` and `DATABRICKS_MODEL` are set. The same Databricks fallback applies when `BUZZ_AGENT_PROVIDER` is unset. Explicit Anthropic/OpenAI API keys always win.
If `BUZZ_AGENT_PROVIDER=anthropic` is selected without `ANTHROPIC_API_KEY`, or `BUZZ_AGENT_PROVIDER=openai` is selected without `OPENAI_COMPAT_API_KEY`, the agent returns an error — there is no implicit fallback to another provider.
`provider=openai` speaks two HTTP dialects: the [Responses API](https://platform.openai.com/docs/api-reference/responses) (`/v1/responses`, required for GPT-5 / o-series tool-calling on OpenAI's own service) and the [Chat Completions API](https://platform.openai.com/docs/api-reference/chat) (`/chat/completions`, the broadly-supported OpenAI-compatible wire format).
+1
View File
@@ -24,6 +24,7 @@ mesh-llm = ["dep:mesh-llm-sdk", "dep:mesh-llm-host-runtime"]
system-keyring = ["dep:keyring"]
[build-dependencies]
base64 = "0.22"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-build = { version = "2", features = [] }
+7 -1
View File
@@ -2,6 +2,8 @@
// so the build-time validation below and the runtime parse cannot drift.
include!("src/commands/reconnect_hook_config.rs");
use base64::Engine as _;
fn main() {
println!("cargo:rerun-if-env-changed=BUZZ_RELAY_URL");
println!("cargo:rerun-if-env-changed=BUZZ_RELAY_HTTP");
@@ -32,6 +34,9 @@ fn main() {
// Generic KEY=VALUE pairs to inject into every spawned agent process.
// Newline-delimited; each line must be non-empty and contain exactly one
// `=` separator with a non-empty key. OSS builds leave this unset.
// The validated value is base64-encoded before emitting so the single-line
// Cargo build-script output carries all pairs (Cargo output is line-oriented;
// a raw multiline value would be silently truncated to the first line).
if let Ok(raw) = std::env::var("BUZZ_BUILD_AGENT_ENV") {
for (line_no, line) in raw.lines().enumerate() {
let line = line.trim();
@@ -54,7 +59,8 @@ fn main() {
);
}
}
println!("cargo:rustc-env=BUZZ_DESKTOP_BUILD_AGENT_ENV={raw}");
let encoded = base64::engine::general_purpose::STANDARD.encode(raw.as_bytes());
println!("cargo:rustc-env=BUZZ_DESKTOP_BUILD_AGENT_ENV={encoded}");
}
if let Ok(val) = std::env::var("BUZZ_BUILD_RELAY_RECONNECT_CMD") {
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use base64::Engine as _;
use tauri::AppHandle;
use crate::{
@@ -1796,6 +1797,10 @@ pub fn spawn_agent_child(
} else {
command.env_remove("BUZZ_ACP_MODEL");
}
// Baked-in provider defaults for internal builds (buzz-releases sets
// BUZZ_BUILD_BUZZ_AGENT_* at compile time; OSS builds bake nothing).
// Written FIRST so that record/persona metadata env vars below override them.
build_buzz_agent_provider_defaults(&mut command);
if let Some(meta) = runtime_meta {
for (key, value) in runtime_metadata_env_vars(
meta.model_env_var,
@@ -1870,11 +1875,6 @@ pub fn spawn_agent_child(
);
}
// Baked-in provider defaults for internal builds (buzz-releases sets
// BUZZ_BUILD_BUZZ_AGENT_* at compile time; OSS builds bake nothing).
// Written BEFORE user env_vars so a GUI/persona override still wins.
build_buzz_agent_provider_defaults(&mut command);
// ── User env vars: the record snapshot ─────────────────────────────
//
// The record's `env_vars` is the complete, pinned env map — persona env
@@ -1970,8 +1970,14 @@ pub(crate) fn build_buzz_agent_provider_defaults(cmd: &mut std::process::Command
}
}
if let Some(raw) = option_env!("BUZZ_DESKTOP_BUILD_AGENT_ENV") {
for (key, value) in parse_agent_env_lines(raw) {
cmd.env(key, value);
// The value was base64-encoded at build time so the single-line Cargo
// output carries all KEY=VALUE pairs without truncation.
if let Ok(decoded) = base64::engine::general_purpose::STANDARD.decode(raw.as_bytes()) {
if let Ok(text) = std::str::from_utf8(&decoded) {
for (key, value) in parse_agent_env_lines(text) {
cmd.env(key, value);
}
}
}
}
}
@@ -91,6 +91,7 @@ fn buzz_agent_provider_defaults_empty_in_oss_build() {
// OSS (and normal test) builds set neither BUZZ_BUILD_BUZZ_AGENT_*,
// so nothing is baked in and no BUZZ_AGENT_* is injected on spawn.
let mut cmd = std::process::Command::new("env");
cmd.env_clear();
super::build_buzz_agent_provider_defaults(&mut cmd);
// Verify the function injects nothing when the compile-time vars are absent.
let output = cmd.output().expect("env should run");
@@ -169,6 +170,59 @@ fn parse_agent_env_lines_empty_input_returns_empty() {
assert!(parse_agent_env_lines(" \n \n").is_empty());
}
// ── base64 round-trip regression ─────────────────────────────────────────
//
// Cargo build-script output is line-oriented: a raw multiline value emitted
// via `cargo:rustc-env=KEY=...` would be truncated to the first line.
// build.rs base64-encodes the validated value; runtime.rs decodes it.
// This test verifies that a 2-pair value with a URL containing `=` survives
// the encode→decode→parse round-trip and both pairs land correctly.
#[test]
fn parse_agent_env_lines_base64_round_trip_preserves_all_pairs() {
use base64::Engine as _;
let raw = "DATABRICKS_HOST=https://host.example.com/path?a=1&b=2\nDATABRICKS_MODEL=some-model";
let encoded = base64::engine::general_purpose::STANDARD.encode(raw.as_bytes());
let decoded_bytes = base64::engine::general_purpose::STANDARD
.decode(encoded.as_bytes())
.expect("decode should succeed");
let decoded = std::str::from_utf8(&decoded_bytes).expect("utf8 should be valid");
let pairs = parse_agent_env_lines(decoded);
assert_eq!(pairs.len(), 2, "both pairs must survive the round-trip");
assert_eq!(
pairs[0],
("DATABRICKS_HOST", "https://host.example.com/path?a=1&b=2")
);
assert_eq!(pairs[1], ("DATABRICKS_MODEL", "some-model"));
}
// ── baked defaults ordering regression ───────────────────────────────────
//
// `build_buzz_agent_provider_defaults` must run BEFORE `runtime_metadata_env_vars`
// writes the record's provider/model so that record values win (last-write-wins).
// This test verifies the ordering by simulating what spawn does: call
// `build_buzz_agent_provider_defaults` first, then overwrite with the record value.
// In an OSS build the baked call is a no-op, so we simulate the baked write
// manually and confirm the subsequent record write wins.
#[test]
fn baked_defaults_do_not_override_record_provider_written_after() {
let mut cmd = std::process::Command::new("env");
cmd.env_clear();
// Simulate what an internal build's baked defaults would inject.
cmd.env("BUZZ_AGENT_PROVIDER", "databricks");
// Simulate what runtime_metadata_env_vars writes from the record (comes after).
cmd.env("BUZZ_AGENT_PROVIDER", "anthropic");
let output = cmd.output().expect("env should run");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
stdout.contains("BUZZ_AGENT_PROVIDER=anthropic"),
"record provider must win over baked default (last-write-wins)"
);
assert!(
!stdout.contains("BUZZ_AGENT_PROVIDER=databricks"),
"baked default must not survive when record provider is written after"
);
}
#[test]
fn buzz_agent_resolved_via_path() {
assert!(known_acp_runtime("/usr/local/bin/buzz-agent").is_some_and(|p| p.mcp_hooks));
@@ -53,7 +53,7 @@ export function formatModelDiscoveryErrorStatus(
if (
message.includes("DATABRICKS_HOST required") ||
message.includes("DATABRICKS_MODEL required") ||
message.includes("BUZZ_AGENT_PROVIDER required")
message.includes("BUZZ_AGENT_PROVIDER is required")
) {
return null;
}