Skip to content

Add a distribution org fallback for bl - #56

Open
scottcrawford03 wants to merge 2 commits into
mainfrom
scrawford/default-org-fallback
Open

scottcrawford03 wants to merge 2 commits into
mainfrom
scrawford/default-org-fallback

Conversation

@scottcrawford03

@scottcrawford03 scottcrawford03 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

A managed bl distribution may know its default organization, but a fresh install still requires each user to set org before CLI authentication and routing work. That default must not replace a user's saved choice.

What

Use BL_DEFAULT_ORG only when no stored organization preference exists. Ignore it in local development and never write it to preferences.

How

Apply the same validated fallback when the CLI resolves its profile and when it selects the organization route. Treat blank defaults as unset; name invalid defaults in errors. Keep bl config usable to repair a bad default.

Risk

The fallback can select the Kgoose host for a new session. Organization values are validated, stored preferences take precedence, and the change does nothing unless the environment variable is set. Please review the credential-routing boundary.

Testing

No manual testing; the CLI test suite covers fallback, precedence, invalid values, local development and unchanged preference files.

Generated with Goose

Use BL_DEFAULT_ORG only when no stored organization is set. Keep local development and user preferences unchanged.

Co-authored-by: fast dog <d71ecbde2677b28bf331e139cd0c0b551ae846c9c70b11d49f916a63021ecd20@buzz.block.builderlab.xyz>
@atishpatel

Copy link
Copy Markdown

🤖 AI-assisted PR review

Summary

Adds a validated, non-persisted BL_DEFAULT_ORG fallback for bl and bl tools, with stored-preference precedence and --local-dev isolation; reviewed at 4ea7edd. I ran the behavior/contracts, reliability/performance, and security/trust-boundary passes sequentially because no subagent tool is available.

Verdict

✅ Recommend approval — the fallback preserves explicit-org precedence, local-development behavior, preference-file integrity, and org-scoped credential routing without changing agent-tools.

Review area Status Assessment
🧠 Behavior & Contracts ✅ Reviewed Stored org wins before the environment is read; the normalized fallback satisfies existing org prerequisites, while saved-org reads/writes and local-development behavior remain unchanged.
🏗️ Reliability & Performance ✅ Reviewed Invalid fallback values fail before routing or credential lookup; no preference writes, retries, shared mutable state, or unbounded work are introduced.
🔒 Security & Trust Boundaries ✅ Reviewed Org validation prevents host injection, credential lookup is namespaced by the routed base URL and service path, agent-tools bypasses this fallback, and the trusted workstation-proxy early return is preserved.
🧪 Validation & CI ⏳ Pending DCO, Semgrep OSS, and zizmor passed at the reviewed head; GitHub's Rust checks are still running. No local tests or builds were run under the read-only review policy.

Findings

No material findings.

🤖 Review by StampMaster9000 · not a substitute for human review · reviewed at commit 4ea7edd

@scottcrawford03

Copy link
Copy Markdown
Contributor Author

Automated review

APPROVE WITH CAUTION — Credential routing for the BL_DEFAULT_ORG fallback is consistent and validated; nonblocking issue: an empty or invalid value blocks every command, including bl config set org, with an error that does not name the variable.

From claude:

F1 — [WARNING] Empty or invalid BL_DEFAULT_ORG breaks every command, including bl config set org, with an error that does not name the variable

Location:

pub fn resolve_default_org(stored: Option<String>, local_dev: bool) -> Result<Option<String>> {
if stored.is_some() || local_dev {
return Ok(stored);
}
read_optional_env(BL_DEFAULT_ORG_ENV_VAR)?
.map(|value| normalize_org(&value))
.transpose()
}
(called from L158)

Trigger: no org is stored, and BL_DEFAULT_ORG is set to an empty string, whitespace, or a value that normalize_org rejects. The empty case is easy to hit, for example a wrapper that does BL_DEFAULT_ORG=${ORG:-}. read_optional_env returns Some("") for an empty variable, and normalize_org then fails.

Effect:

  • resolve_default_org runs inside resolve_with_org_routing, which backs both SkillsConfig::resolve and resolve_for_config, so the error is raised before any subcommand is dispatched.
  • Every command fails, including bl config path, bl config get, bl config set org <org>, and the interactive login org prompt. The existing missing-org error tells users to run exactly those commands to fix the problem.
  • The error text is org cannot be empty or org must contain only lowercase ASCII letters..., so users will look in their preferences file rather than at the environment.
  • --json callers get a plain error instead of a structured payload.
  • The only recovery is to unset the variable, which the message never suggests.

Before this change, those config commands worked with no org set.

Fix:

  • Treat an empty or whitespace value as unset. KGOOSE_PLAYPEN already does this at L113-L116.
  • Add context to the validation error that names BL_DEFAULT_ORG.
  • Consider skipping fallback validation in resolve_for_config, so bl config set org can always store an org that overrides a bad default.

F2 — [INFO] bl config get org prints an empty value while the fallback org is in effect

Location:

"org" => json!(preferences.org.unwrap_or_default()),

Trigger: no org is stored and BL_DEFAULT_ORG=acme is set.

Effect:

  • bl auth login, bl skills, bl tools and bl curl all route to acme.<host>, and the login org prompt is skipped.
  • bl config get org prints an empty string because it reads only the preferences file.
  • No command reports the org actually in effect, which makes "which org am I on?" hard to debug.

Fix: optionally have config get org or auth status report the effective org and where it came from (stored or distribution default).

Reviewed at commit 4ea7edd.

atishpatel
atishpatel previously approved these changes Dec 3, 2026
Treat blank distribution defaults as absent, name invalid values in errors, and avoid resolving the fallback before config commands.

Co-authored-by: fast dog <d71ecbde2677b28bf331e139cd0c0b551ae846c9c70b11d49f916a63021ecd20@buzz.block.builderlab.xyz>
@scottcrawford03

Copy link
Copy Markdown
Contributor Author

🤖 Addressed F1 in ed88f27: blank or whitespace BL_DEFAULT_ORG is now unset, invalid values identify the environment variable, and bl config path/set org remain usable when the default is invalid. Added regression tests; full local suite: 507 passed, fmt and Clippy clean. F2 (showing the effective org in config get/auth status) is deferred as a separate UX change; config get org still means the stored preference. The PR remains draft for human review.

@scottcrawford03
scottcrawford03 marked this pull request as ready for review December 3, 2026 21:10
@scottcrawford03
scottcrawford03 requested a review from a team as a code owner December 3, 2026 21:10
@atishpatel

Copy link
Copy Markdown

🤖 AI-assisted PR review

Summary

Adds a validated, non-persisted BL_DEFAULT_ORG fallback for bl and bl tools, now including blank-value handling and recovery from invalid distribution defaults; reviewed at ed88f27. I ran the behavior/contracts, reliability/performance, and security/trust-boundary passes sequentially because no subagent tool is available.

Verdict

⚠️ Recommend approval with caution — only a non-blocking INFO remains: bl config get org reports the stored preference rather than the fallback org currently used for routing.

Review area Status Assessment
🧠 Behavior & Contracts ⚠️ Nonblocking (F1) Stored preferences win, blank defaults behave as unset, invalid defaults identify their source, and config commands remain available for recovery; config get org still exposes only stored state (F1).
🏗️ Reliability & Performance ✅ Reviewed Invalid routed commands fail before credential lookup with an actionable error, while bl config path and bl config set org bypass fallback validation; no new writes, retries, shared mutable state, or unbounded work.
🔒 Security & Trust Boundaries ✅ Reviewed Org validation prevents host injection, credentials remain namespaced by routed base URL and service path, agent-tools bypasses the fallback, and the trusted workstation-proxy early return is preserved.
🧪 Validation & CI ✅ Reviewed DCO, Semgrep OSS, zizmor, and Rust checks passed at the reviewed head; the Rust job completed repository CI and isolated Docker acceptance tests. No local tests or builds were run under the read-only review policy.

Findings

⚠️ Approval recommended with findings — the findings below were judged non-blocking. Read them before merging.

F1 — [INFO] bl config get org omits the active distribution fallback

Location: src/bl/skills.rs:1677

With no stored org and a valid BL_DEFAULT_ORG, bl and bl tools route through the fallback, but bl config get org reads preferences directly and prints an empty value. This leaves no command that clearly reports the effective org and its source; the behavior remains in this head and was explicitly deferred in the existing review discussion. Consider exposing the effective org and source in config get or auth status while continuing to write only explicit preferences.

🤖 Review by StampMaster9000 · not a substitute for human review · reviewed at commit ed88f27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants