Skip to content

bl apps background on: walk owners through turning on background tool calls - #57

Merged
scottcrawford03 merged 1 commit into
mainfrom
scrawford/background-on
Dec 4, 2026
Merged

scottcrawford03 merged 1 commit into
mainfrom
scrawford/background-on

Conversation

@scottcrawford03

Copy link
Copy Markdown
Contributor

Summary

Turning on Kgoose background tool calls for a hosted app meant copying approval_url from bl apps background status into a browser. When approval was refused (for example owner_consent_required, because the owner hadn't approved the app's own tool access yet), the CLI didn't say why or what to do.

  • New bl apps background on <APP_ID> (--no-browser, --timeout, default 600s):
    • If Kgoose reports a blocked_reason with a link (owner consent), prints the reason and next step, opens the app, and waits until it clears.
    • Opens the approval page, then polls every 3s through approval → sandbox restart → active and ready.
    • Stops with the reason and next step on refusal, paused_other_publishers/revoked, or timeout. Retries transient network/5xx errors.
    • Progress goes to stderr; --json prints one final object on stdout.
    • Never opens a browser on Blox, through the workstation proxy, or with --no-browser.
  • bl apps background status shows blocked_reason ({code, message, next_step, url}, null when absent).
  • owner_consent_required gets its own explanation instead of "declared tools changed".
  • Process-only wording updated: fetch-js apps are supported too.

Dependency

blocked_reason comes from a Kgoose change in squareup/cash-server: https://github.com/squareup/cash-server/pull/159449. This PR works without it (the field is just null), but the consent step only appears once Kgoose ships, so merge after it.

Testing

  • just ci passes (rustfmt, clippy -D warnings, tests; 15 new tests in apps.rs).
  • Tests use the local test server and a stubbed browser opener; not run against a live Kgoose.

🤖 Generated with Claude Code

… calls

Add `bl apps background on APP_ID` (--no-browser, --timeout): it opens the
approval link, polls until the app's sandbox has restarted and background
tool calls are on and ready, and exits non-zero with a reason when approval
is blocked, access is paused or revoked, or the wait times out. Progress
goes to stderr; --json prints one final status object on stdout.

Status now surfaces Kgoose's optional blockedReason (as blocked_reason), so
owner_consent_required and no_read_capabilities are visible. Fix
owner_consent_required being reported as "declared tools changed", and say
"process or fetch-js apps" instead of process-only. Test builds never open a
real browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scottcrawford03
scottcrawford03 requested a review from a team as a code owner December 4, 2026 17:22
@cnwobi

cnwobi commented Dec 4, 2026

Copy link
Copy Markdown

Automated review

APPROVE WITH CAUTION — Three nonblocking issues at dbb8fc2: paused grants cannot reach reapproval, requests can exceed --timeout, and interrupted response bodies bypass retries.

From codex:

F1 — [WARNING] Allow initially paused grants to reach reapproval

Location: src/bl/apps.rs:2928–2941

paused_other_publishers also represents older grants without owner-only mode and restarts that were not confirmed. Such responses can include an approval URL even when no other publishers exist. This branch immediately exits, omits that link, and tells the owner to remove publishers and rerun—a loop that cannot resolve those cases. Allow an initially paused grant to enter reapproval, or provide its approval link and accurate recovery guidance. The existing status command and manual browser approval provide a workaround.

F2 — [WARNING] Bound each status request by the remaining timeout

Location: src/bl/apps.rs:2896–2897

The loop checks its deadline only after fetching, while each fetch retains a fixed 30-second HTTP timeout. Consequently, --timeout 1 can wait roughly 30 seconds on a stalled request. Sleeping until the deadline also starts another request unconditionally, and a successful response after expiry can return success. Check the deadline before further requests and cap request timeouts by the remaining duration.

F3 — [WARNING] Retry transport failures while reading response bodies

Location: src/bl/apps.rs:2802–2806

If the server sends headers and then the connection drops or the body times out, read_limited_response_body propagates a contextual I/O error without a CliFailure carrying NETWORK. This predicate rejects it, so the new approval workflow exits immediately instead of retrying the transient failure. Classify response-body transport errors as retryable while keeping size-limit and decoding failures distinct.

Reviewed at commit dbb8fc2.

@atishpatel

Copy link
Copy Markdown

🤖 AI-assisted PR review

Summary

Adds bl apps background on with browser handoff, polling, blocked-reason guidance, transient-error retries, JSON output, and corresponding status/docs support. Reviewed head dbb8fc2; with no subagent tool available, the three specialist passes were run sequentially by this reviewer.

Verdict

⚠️ Recommend approval with caution — three bounded workflow/retry issues remain, with manual status/browser approval or rerunning the command as workarounds.

Review area Status Assessment
🧠 Behavior & Contracts ⚠️ Nonblocking (F1) The happy path and older-server compatibility are preserved, but an initially paused grant can receive incorrect recovery guidance instead of reapproval.
🏗️ Reliability & Performance ⚠️ Nonblocking (F2, F3) Polling is bounded between requests, but a request can overrun the deadline and response-body transport failures are not retried.
🔒 Security & Trust Boundaries ✅ Reviewed Approval remains browser-only; credentials are not delegated to browsers, links are restricted to HTTP(S), and upstream terminal text is sanitized.
🚀 Deployment & Staging ℹ️ Advisory Older servers tolerate the new client field as absent; the consent-handoff step requires the companion Kgoose rollout. Local-server tests, not live Kgoose validation, were inspected.
🧪 Validation & CI ✅ Reviewed Source and test changes inspected; no tests/builds run by this reviewer. DCO, Rust checks, Semgrep OSS, and zizmor pass at the reviewed head.

Findings

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

F1 — [WARNING] Allow initially paused grants to reach reapproval

Location: src/bl/apps.rs lines 2928–2941

paused_other_publishers also covers a grant whose owner-only restart remained unconfirmed past the restart window, including when no other publisher remains. Such a status can include an approval URL, but this branch exits before using it and directs the owner to remove publishers, leaving background on unable to recover that case. Allow an initially paused grant with an approval link to enter reapproval, or print the link with guidance that distinguishes a stuck restart; manual status and browser approval remain workarounds. Existing discussion.

F2 — [WARNING] Enforce the timeout across each status request

Location: src/bl/apps.rs lines 2896–2897

The deadline is checked only after fetch, while each HTTP request retains a fixed 30-second timeout. A stalled request can therefore exceed --timeout 1 by roughly 30 seconds, and a delayed successful response can return success after the requested deadline because success is handled before the clock check. Check the deadline before starting another request and before returning success, and cap each request by the remaining duration. Existing discussion.

F3 — [WARNING] Retry response-body transport failures

Location: src/bl/apps.rs lines 2802–2806

If headers arrive and the connection then drops or times out while read_limited_response_body reads the body, that helper returns a contextual I/O error without a CliFailure carrying the network exit code. This predicate therefore exits immediately instead of providing the advertised transient-network retry. Classify body-read transport failures as retryable while keeping size-limit and UTF-8/JSON decoding failures distinct; rerunning the command is the current workaround. Existing discussion.

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

@scottcrawford03
scottcrawford03 merged commit 0392e82 into main Dec 4, 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.

3 participants