Skip to content

bl apps background: status and off for owner-authorized background tool calls - #54

Merged
scottcrawford03 merged 2 commits into
mainfrom
scrawford/apps-background
Nov 24, 2026
Merged

scottcrawford03 merged 2 commits into
mainfrom
scrawford/apps-background

Conversation

@scottcrawford03

Copy link
Copy Markdown
Contributor

Why

Kgoose now lets an app owner authorize background tool calls for a Compose process app (enabled only in bb-block). The owner can check and revoke that access in the browser, but there was no CLI path, so an owner or their agent could not see whether an app was on, ready, or waiting for approval, and could not turn it off from a terminal.

What

  • bl apps background status APP_ID shows the state, whether the owner is the sole publisher, whether the app is ready or restarting, and the approved and pending read-only tools. When approval is needed it prints Approve in your browser: <link> as the next step.
  • bl apps background off APP_ID revokes background access and confirms the new state. It only reduces access, so it asks for no confirmation, like bl apps publishers remove and bl apps community revoke. bl apps delete needs --confirm-app-id because deletion is destructive.
  • Both call GET/DELETE /v1/hosted-apps/{app_id}/background-access through Kgoose with the stored bl auth login session (same KGOOSE_BASE_URL, KGOOSE_SERVICE_PATH, org, profile, and BL_HOME resolution as bl apps community list). No --base-url is needed.
  • --json prints the response normalized to snake_case with ok and app_id, like other bl apps JSON.
  • Kgoose's errorCode values map to CLI-owned messages, a next_action, and exit codes: background_disabled says background tool calls aren't available in this environment (exit 1), not_owner exits 4, a 401 exits 3, and server or unavailable failures exit 5. Server message text is never echoed.
  • Help text and the README explain that approval is browser-only, only the owner can enable it, the app becomes owner-only (calls pause while other publishers exist), and only process runtimes are supported.

Approval stays browser-only by design. Kgoose accepts the grant only from the owner's browser session through a same-origin form, so an agent holding the CLI session cannot turn background access on. The CLI only prints the link and has no approve command.

Testing

  • just fmt-check, just lint (clippy with -D warnings), and just test (full workspace) pass.
  • New HTTP-mocked tests cover status with and without an approval link, off (DELETE, plus a failure if the app still reports active), background_disabled, an unauthenticated 401, no stored session, the error-code mapping, and unsafe approval links.
  • Smoke-tested read-only bl apps background status against a real bb-block production app; it reported the app as on and ready with its approved tools. off was not run against a real app.

🤖 Generated with Claude Code

…ol calls

Add `bl apps background status APP_ID` and `bl apps background off APP_ID`,
which read and revoke an app owner's background tool call access through
Kgoose's hosted-apps background-access endpoints using the stored CLI session.

Approval stays browser-only: `status` prints the approval link for the owner to
open and the CLI never approves. Kgoose error codes map to CLI-owned messages
and exit codes (background_disabled, not_owner, other_publishers, unsupported
runtimes, and so on) without echoing server text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scottcrawford03
scottcrawford03 requested a review from a team as a code owner November 23, 2026 23:03
@johnathan-sq

Copy link
Copy Markdown

Automated review

APPROVE WITH CAUTION — Revocation can be falsely confirmed during a concurrent approval, and disabled environments receive misleading retry guidance.

From codex:

F1 — [WARNING] Reject all still-granted states after revocation

Location:

builderlab-cli/src/bl/apps.rs

Lines 2132 to 2144 in 9bdef90

let response = background_access_call(config, app_id, method)?;
if turn_off && response["state"] == "active" {
return Err(failure(
exit_codes::GENERAL,
"background_off_not_confirmed",
format!(
"Background tool calls for {} still report active after turning them off\n\
next_action: Run `bl apps background status {}` to check, then try `off` again.",
terminal_safe_text(app_id),
terminal_safe_text(app_id)
),
));
}

The command rejects only active after DELETE. If the owner approves again while the service is revoking and reading the resulting status, the response can instead be restarting or paused_other_publishers; both still represent a grant. The command then exits successfully and reports that access was turned off, although calls can resume. Confirm success only for states that establish access is off, such as revoked or not_granted.

F2 — [WARNING] Handle unavailable management endpoints in disabled environments

Location:

builderlab-cli/src/bl/apps.rs

Lines 2249 to 2255 in 9bdef90

if !status.is_success() || code.is_some() || state.is_none() {
let code = code.unwrap_or_else(|| {
if status.is_success() {
"background_access_invalid_response".to_string()
} else {
"background_access_failed".to_string()
}

When background access is disabled in the service, the management endpoint is not registered, so the commands receive a route-level 404 rather than the background_disabled response covered by the tests. This path reports an unusable response and suggests retrying, instead of telling the user that the feature is unavailable in the environment. Detect endpoint availability or otherwise provide a useful indication for this case; a blanket interpretation of every 404 as disabled would also need to account for other causes.

Reviewed at commit 9bdef90.

…g endpoint as disabled

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scottcrawford03

Copy link
Copy Markdown
Contributor Author

🤖 Addressed both findings in 8da697e:

  • F1: off now confirms success only when the post-revoke state is revoked or not_granted. Any other state (active, restarting, paused_other_publishers, or unknown) exits 5 with background_off_not_confirmed and tells the user to run bl apps background status <app>.
  • F2: confirmed Kgoose doesn't install the background-access actions when backgroundToolCallsEnabled is false, so disabled environments return a framework 404. A 404 now maps to background_disabled ("Background tool calls aren't available in this environment") unless the body carries app_unavailable, the only 404 code Kgoose emits, so a missing app stays distinct.

Tests cover both, and fmt, clippy and the full suite pass.

@atishpatel

Copy link
Copy Markdown

🤖 AI-assisted PR review

Summary

Adds bl apps background status and off, including response normalization, CLI-owned errors, documentation, and mocked command tests. Reviewed head 8da697e.

Verdict

✅ Recommend approval — the new commands match the management API contract, handle revocation races and failures conservatively, and preserve the browser-only approval boundary.

Review area Status Assessment
🧠 Behavior & Contracts ✅ Reviewed GET/DELETE paths, nullable fields, tool lists, exit codes, and revoked/not_granted confirmation match the API contract.
🏗️ Reliability & Performance ✅ Reviewed The 30-second timeout, 256 KiB response cap, unknown-DELETE-outcome guidance, and concurrent-reapproval handling fail conservatively.
🔒 Security & Trust Boundaries ✅ Reviewed Approval remains browser-only; redirects are disabled, path segments are encoded, response credentials are redacted, and terminal output is sanitized.
🧪 Validation & CI ✅ Reviewed DCO, Rust checks, Semgrep OSS, and zizmor passed on 8da697e; the reviewer ran no tests or builds. Specialist passes were run sequentially by StampMaster9000 because no subagent tool was available.

Findings

No material findings.

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

@scottcrawford03
scottcrawford03 merged commit eea20de into main Nov 24, 2026
4 checks passed
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.

4 participants