Move reflex-hosting-cli onto reflex-build-sdk

Merged
AD
2mo ago
+4315-7372

reflex_cli/utils/hosting.py was a 3487-line hand-rolled HTTP layer: an AuthenticatedClient carrying a raw token, a per-function httpx.<verb>(urljoin(...), headers=authorization_header(...)), its own presigned-upload and retry machinery, and a bespoke error-to-string conversion at every call site. reflex-build-sdk already covers every endpoint the CLI reaches, with typed results, retries that only repeat what is safe to repeat, and typed errors — so the CLI now goes through it.

The module drops to 1645 lines and keeps only what is the CLI's own: interactive name resolution, the config files, the browser login, ScaleParams, and build-log sanitising. AuthenticatedClient becomes the SDK client paired with the identity its token authenticates as, and the v2 command modules call the SDK directly rather than through a wrapper.

Two helpers replace the idioms that are gone:

  • reporting_api_errors() wraps a command body, so a refusal reads as the sentence the API wrote and an expired token says to run reflex login wherever it turns up — not only where the command started by authenticating.
  • as_json_document() renders a typed result as the plain data a --json document is made of, so the documents keep the shape they had when response bodies were printed straight through.

Deploys now always reserve signed upload URLs and PUT to storage; the multipart relay fallback for control planes without /deployments/reserve is gone, and upload progress is wired to the existing transfer bar. The SDK imports live inside the functions that use them: importing reflex_build_sdk pulls in httpx and aiohttp, and reflex cloud --help must not pay for an HTTP stack it will not use (tests/units/test_reflex.py guards this).

Behaviour changes

Declared in +build-sdk.breaking.md, each forced by the SDK's shapes:

  • A refused request exits non-zero rather than printing a "... failed: ..." line and exiting 0, and --json writes no document on that path. apps stop, apps start and apps delete are the ones most likely to be scripted against.
  • apps history --json reports the deployment's url in place of hostname.
  • apps logs --json returns every line in the window with a null cursor instead of one page. The old cursor was never consumable — there was no --cursor option to pass it back to.
  • project role-permissions lists permission names rather than objects.
  • reflex deploy requires a control plane that signs upload URLs.

Two smaller ones worth calling out in review:

  • The SDK's status classifier does not read "deployment failed" as a failure; the CLI's predicate always has, so deployment_status_failed keeps the stricter reading as an explicit override. Worth deciding whether the SDK should match.
  • A watch that loses its connection now warns that it stopped following and points at reflex cloud apps status --watch, rather than looping forever. It exits 0: the deployment was submitted and is still running, so claiming failure would be a wrong guess.

Notes for the reviewer

  • AppSummary carries no project name, so the interactive conflict table and the deploy confirmation prompt look the project up — one extra request, only when disambiguating.
  • set_instance_bounds reads the app first, because the endpoint replaces both bounds and the CLI's contract is to change only what was passed.
  • v2/apps.py still resolves an app id two different ways (_resolve_app_id prefers --app-name over the configured appid; three inline copies prefer the config). Consolidating would change behaviour, so both are left as they were.

Verification

ruff check/format, pyright, check_min_deps.py (all 20 packages) and --check-dev-pins clean; full unit suite 9599 passed at 78.87% coverage. The real commands were also driven against the live API read-only (vmtypes, regions, apps.list, secrets.list, projects.list).