mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
fix(desktop): launch Databricks OAuth from passive model discovery (#5607)
When a user's agent runtime is `buzz-agent` with no cached Databricks OAuth token, the desktop app's passive model-discovery surfaces were forbidden from launching interactive auth. Discovery failed silently, so the model dropdown showed only built-in fallback models behind a vague "Could not load live models for `databricks_v2`" note (reported internally by Nick and Jose). ## What changed Both discovery surfaces — the passive draft-form discovery and the explicit saved-model picker — now launch the browser OAuth flow, matching goose's behavior. The only behavioral difference between them is cooldown handling: - **Passive draft discovery** fires on every form-state change, so a failed, cancelled, or timed-out sign-in records a per-host cooldown (5 min) that suppresses re-popping the browser on the next keystroke. While the cooldown is active it returns the "sign-in required" guidance instead of relaunching. - **The explicit model picker** is a deliberate user action, so it always launches and clears any stale cooldown first. Safety rails: - A 150s hard timeout (`AUTH_FLOW_TIMEOUT`) bounds the whole interactive flow so an abandoned SSO tab fails discovery cleanly rather than wedging the dropdown. Success clears the cooldown; failure and timeout both record it. - `AuthCooldown` recovers from a poisoned lock rather than wedging every future sign-in on one panic. The frontend maps the terminal Databricks sign-in states to typed, actionable copy in `formatModelDiscoveryErrorStatus`: "sign-in required" is a muted note pointing at the picker and `buzz-agent auth databricks`; a failed or timed-out sign-in is a warning pointing at the explicit retry. Other Databricks failures fall through to the existing generic notice. ## Scope Changes are confined to Databricks discovery and its frontend status formatter — no `agent_models.rs` call sites are touched. The interactive-auth helper takes an injected timeout so the timeout/cooldown policy is unit-testable without a live browser. ## Deferred Cooldown keys use the raw trimmed `DATABRICKS_HOST`, while the catalog and OAuth cache normalize trailing slashes (`crates/buzz-agent/src/catalog.rs:96`, `crates/buzz-agent/src/llm.rs:2046`). So `https://workspace/` and `https://workspace` share credentials but get separate cooldown entries — an equivalent-spelling change to the host field mid-cooldown can re-pop passive OAuth once within the 5-minute window. Self-limiting (one extra browser launch, never auth corruption). Follow-up: a `trim_end_matches('/')` on the cooldown key plus an equivalent-host test, picked up with the coordinator migration if [#5545](https://github.com/block/buzz/pull/5545) ever merges. Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -69,6 +69,53 @@ test("model discovery status stays quiet for missing Databricks defaults", () =>
|
||||
assert.equal(status, null);
|
||||
});
|
||||
|
||||
test("Databricks sign-in-required is a muted note pointing at the picker and CLI", () => {
|
||||
const status = formatModelDiscoveryErrorStatus(
|
||||
new Error(
|
||||
"Databricks sign-in is required; save this agent, then open its model picker to sign in, or run `buzz-agent auth databricks`",
|
||||
),
|
||||
"databricks_v2",
|
||||
);
|
||||
|
||||
assert.equal(status?.tone, "muted");
|
||||
assert.match(status?.message ?? "", /model picker/);
|
||||
assert.match(status?.message ?? "", /buzz-agent auth databricks/);
|
||||
});
|
||||
|
||||
test("Databricks sign-in failure warns and points at the explicit retry", () => {
|
||||
const status = formatModelDiscoveryErrorStatus(
|
||||
new Error("Databricks sign-in failed: oauth callback: access_denied"),
|
||||
"databricks_v2",
|
||||
);
|
||||
|
||||
assert.equal(status?.tone, "warning");
|
||||
assert.match(status?.message ?? "", /didn't complete/);
|
||||
assert.match(status?.message ?? "", /model picker/);
|
||||
});
|
||||
|
||||
test("Databricks sign-in timeout warns and points at the explicit retry", () => {
|
||||
const status = formatModelDiscoveryErrorStatus(
|
||||
new Error(
|
||||
"Databricks sign-in timed out; open the model picker to retry, or run `buzz-agent auth databricks`",
|
||||
),
|
||||
"databricks_v2",
|
||||
);
|
||||
|
||||
assert.equal(status?.tone, "warning");
|
||||
assert.match(status?.message ?? "", /didn't complete/);
|
||||
assert.match(status?.message ?? "", /buzz-agent auth databricks/);
|
||||
});
|
||||
|
||||
test("other Databricks discovery failures fall through to the generic notice", () => {
|
||||
const status = formatModelDiscoveryErrorStatus(
|
||||
new Error("Databricks model discovery failed: relay offline"),
|
||||
"databricks_v2",
|
||||
);
|
||||
|
||||
assert.equal(status?.tone, "warning");
|
||||
assert.match(status?.message ?? "", /Using built-in model options/);
|
||||
});
|
||||
|
||||
test("auth-required errors name the agent and ask for sign-in", () => {
|
||||
// Real shape from run_agent_models_command wrapping buzz-acp stderr when
|
||||
// cursor-agent is signed out (spec ErrorCode::AuthRequired text).
|
||||
|
||||
@@ -124,6 +124,16 @@ export function formatModelDiscoveryErrorStatus(
|
||||
return null;
|
||||
}
|
||||
|
||||
// Databricks transparent auth (agent_models_databricks.rs). The backend
|
||||
// launches the browser OAuth flow itself from every discovery surface, so
|
||||
// these are terminal outcomes the user should see, not raw error text.
|
||||
// Matched on the stable error strings the backend emits (string matching is
|
||||
// this file's convention until typed error codes arrive).
|
||||
const databricksStatus = formatDatabricksAuthStatus(message);
|
||||
if (databricksStatus !== null) {
|
||||
return databricksStatus;
|
||||
}
|
||||
|
||||
return {
|
||||
message: `Using built-in model options. Could not load live models for ${providerObjectLabel(
|
||||
provider,
|
||||
@@ -131,3 +141,35 @@ export function formatModelDiscoveryErrorStatus(
|
||||
tone: "warning",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the terminal Databricks sign-in states to user-facing guidance, or null
|
||||
* when the error is not a Databricks sign-in outcome. "Sign-in required" is a
|
||||
* quiet muted note (a passive surface hit its cooldown, or an unsaved draft
|
||||
* can't launch the browser); a failed, cancelled, or timed-out sign-in is a
|
||||
* warning that points the user at the explicit retry path.
|
||||
*/
|
||||
function formatDatabricksAuthStatus(
|
||||
message: string,
|
||||
): PersonaModelDiscoveryStatus | null {
|
||||
if (message.includes("Databricks sign-in is required")) {
|
||||
return {
|
||||
message:
|
||||
"Databricks sign-in is required. Open the model picker to sign in, or run `buzz-agent auth databricks` in a terminal.",
|
||||
tone: "muted",
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
message.includes("Databricks sign-in failed") ||
|
||||
message.includes("Databricks sign-in timed out")
|
||||
) {
|
||||
return {
|
||||
message:
|
||||
"Databricks sign-in didn't complete. Open the model picker to retry, or run `buzz-agent auth databricks` in a terminal.",
|
||||
tone: "warning",
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user