Skip to content

Commit 4cd82f5

Browse files
wesbillmanBrain
andauthored
feat(buzz-agent): add opt-in workspace-scoped Databricks reuse (#7606)
Posted by Brain, Wes Billman’s AI assistant, on behalf of `wesbillman`. ## Summary Add an opt-in `databricks::DatabricksConnection` over the existing PKCE/coordinator and v2 catalog machinery. It accepts an explicit HTTPS workspace origin, absolute caller-owned cache root, and browser opener; it does not start an agent or infer credentials/host from the environment. - Validate both OAuth endpoints on the actual discovery response used for grants; native HTTP redirects are disabled and requests have a 30-second timeout. - Keep strict cache/single-flight state in a separate namespace. Connect is explicit/user-initiated; catalog lookup and its one 401 refresh stay headless. Tokens are not exposed by the connection API. - Preserve existing legacy constructors, endpoint/redirect policy, cache layout, intents, and catalog filtering/pagination/partial/default semantics. No internal host default, credential migration, app integration or release configuration changes. ### Intentional shared changes OAuth success/discovery JSON is capped at 1 MiB; error JSON at 16 KiB. Oversized/malformed responses are infrastructure failures, while bounded client-error `invalid_grant` retains its existing classification. OAuth diagnostics omit raw bodies/URLs/opener/callback details. Overflowing token expiry returns an infrastructure failure. These changes affect legacy callers too and have synthetic regression coverage. See [the reuse contract](crates/buzz-agent/DATABRICKS_REUSE.md) for API, compatibility and caller obligations. Total operation deadlines, stale-result fencing, private root ownership, nonlogging opener behavior and credential-removal UX remain the caller’s responsibility. ### Related issue Related discovery work: #6918. Searched existing Databricks PRs and OAuth issues; no duplicate of this strict opt-in API was found among those results. This is a new reuse boundary, not a claim of a live credential leak. ### Testing Published head: `cf33eb2f4f267d5808e068e35127d5504f0bc674`, based on main `78618804ec86a014524ad7d1fb55928e8f5c3edf`. Two implementation/doc commits were transplanted from a release-derived local base to exclude unrelated release files. `git range-diff` reports both patches unchanged; independent source review of the transplant found no blocker. **At the published head:** normal pre-push hooks passed: branch skew, push-head scope, file-size checks, Rust test lane and desktop Tauri Clippy/tests. The fallback Rust lane actually ran `buzz-agent --lib`: 542 passed / 1 ignored, NOT the full package integration suite. Hosted full package/repository CI remains pending. The first push attempt was interrupted by the command runner’s 300-second limit; the second completed normally with all hooks enabled. **At reviewed implementation checkpoint `8cb3b72d4`:** 16 strict, 27 auth, 32 catalog and 63 coordinator/OAuth/CLI tests passed, independently rerun; 18 author-selected mutations and four independent reviewer mutations failed tests with passing restored controls. The subsequent `539319411` delta changed only two doc-comment blocks. These earlier test/mutation results are not silently attributed to the rebased head. Synthetic coverage includes HTTPS grants/catalog, off-origin endpoint and redirect rejection, cancellation/socket/listener cleanup, host/root/legacy namespace isolation, bounded declared/chunked bodies and exact-limit controls, redaction with positive log capture, malformed expiry, legacy endpoint/redirect controls, and real CLI cached-auth aliases. Desktop native checks used fail-closed sidecar stubs: compile/test evidence, **not** a runnable or packaged app. No real provider credentials, browser sign-in, app launch, or agent cutover was performed. Cross-platform execution and real-provider acceptance remain separate gates. No merge or downstream adoption is requested by this PR. --------- Signed-off-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz> Co-authored-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz>
1 parent 6c35e82 commit 4cd82f5

11 files changed

Lines changed: 1649 additions & 54 deletions

File tree

‎Cargo.lock‎

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/buzz-agent/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ fs2 = "0.4"
7373
nix = { version = "0.31", default-features = false, features = ["signal", "process"] }
7474

7575
[dev-dependencies]
76+
# Synthetic TLS OAuth/catalog servers exercise the strict HTTPS production path.
77+
rcgen = { version = "0.14", default-features = false, features = ["crypto", "ring"] }
78+
tokio-rustls = { version = "0.26", default-features = false, features = ["ring", "tls12"] }
7679
tokio = { workspace = true, features = ["test-util", "rt-multi-thread", "macros", "io-std", "io-util", "sync", "process", "time", "net"] }
7780
nix = { version = "0.31", default-features = false, features = ["signal", "process"] }
7881
axum = { workspace = true }
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Opt-in Databricks connection reuse
2+
3+
`databricks::DatabricksConnection` reuses the PKCE coordinator and v2 catalog
4+
without running an agent, ACP, a CLI subprocess or any runtime configuration.
5+
6+
- Construct with an explicit HTTPS workspace origin, an absolute app-owned cache
7+
root and a `BrowserOpener`. No host default or environment credential lookup.
8+
Construction can read/create that cache, but never networks or opens a browser.
9+
- `connect()` is user-initiated authentication only; it does not fetch models.
10+
- `discover_models(filter)` is always headless, including one 401-driven refresh.
11+
It never selects a model. Existing filtering, partial-success and labelled
12+
authenticated-empty/no-filter fallback remain; a vector is not proof of a
13+
complete catalog.
14+
- Strict discovery validates both OAuth endpoints from the very response used
15+
for refresh/code exchange. They must be same-origin HTTPS with no userinfo,
16+
query or fragment. Native discovery/token/catalog redirects are disabled.
17+
Browser SSO navigation is separate from the native client's redirect policy.
18+
- The caller chooses and exclusively owns its cache root BEFORE construction.
19+
`databricks-strict` separates strict state from legacy `databricks` caches and
20+
single-flight coordination even if roots coincide. It is not credential
21+
migration. Existing host/client/scopes hash and Unix owner-only atomic token
22+
persistence remain. Non-Unix token persistence remains disabled.
23+
- Keep secrets native. The supplied opener must not log authorization URLs or
24+
its failure details. Drop the operation future to cancel actual requests and
25+
the callback listener. Set an app-level overall deadline, generation-fence
26+
results, and never await under the agent-controller lock. A synchronous opener
27+
must return promptly; the library cannot cancel a blocking caller callback.
28+
- A cache root is an application trust boundary, not protection against a
29+
malicious process with the same OS user or a caller lending out that root.
30+
31+
## Legacy compatibility and intentional shared changes
32+
33+
Existing public OAuth config/constructors, auth intents, cache defaults, static
34+
bearer selection, CLI auth, desktop discovery and v1/v2 catalog APIs remain.
35+
They DO NOT inherit strict same-origin or no-redirect policy.
36+
37+
Shared OAuth response handling has three intentional observable differences:
38+
39+
1. Discovery and successful token responses are stream-capped at **1 MiB**;
40+
OAuth error responses at **16 KiB**. Exact-boundary JSON succeeds; oversized,
41+
malformed or unreadable responses are infrastructure failures, never grant
42+
rejection. Only a client-error `error: invalid_grant` within the bound retains
43+
refresh/code rejection classification. Non-success discovery bodies are not
44+
consumed. Existing catalog limits/retries are unchanged.
45+
2. OAuth logs no longer include raw response bodies, transport/decode details,
46+
callback error text or opener error text. Status/category logs remain. The
47+
legacy default opener still prints its manual sign-in URL deliberately; the
48+
strict API never selects that opener automatically. Strict catalog errors
49+
project fixed auth/infrastructure messages; legacy catalog diagnostics remain.
50+
3. A token response whose `expires_in` overflows epoch arithmetic now fails as an
51+
infrastructure error instead of panicking/wrapping.
52+
53+
No old cache migration/deletion, credential rewrite, app launch, internal host,
54+
internal release settings, or production dependency on a developer checkout is
55+
part of this patch.
56+
57+
## Validation boundaries
58+
59+
Synthetic HTTPS servers use ephemeral test-only certificates; all cache contents,
60+
refresh tokens and callback codes are fabricated. Tests cover new and legacy
61+
paths, positive destination controls, refresh/code exchange, redirects, response
62+
limits, classifications, captured diagnostics, cancellation/retry, cache roots
63+
and namespace isolation. A real CLI child tests legacy auth aliases/cache reuse;
64+
existing coordinator tests include real subprocess single-flight/locking.
65+
66+
Before integration, require independent compatibility review at an exact commit,
67+
full `buzz-agent` package-suite evidence, affected desktop checks and repository
68+
gates. Focused tests are not a substitute. App orchestration, internal build-input
69+
wiring, credential-removal UX, native preview acceptance and real sign-in are
70+
separate subsequent work, not claims made by this helper patch.

0 commit comments

Comments
 (0)