Skip to content

feat(cloud login): emit machine-readable login_url event in --json mode (BE-3365)#556

Open
mattmillerai wants to merge 2 commits into
mainfrom
matt/be-3365-login-url-event
Open

feat(cloud login): emit machine-readable login_url event in --json mode (BE-3365)#556
mattmillerai wants to merge 2 commits into
mainfrom
matt/be-3365-login-url-event

Conversation

@mattmillerai

Copy link
Copy Markdown
Collaborator

ELI-5

When you run comfy cloud login, the CLI prints a sign-in URL, opens your
browser, and waits for you to click through. In --json mode (how an agent/MCP
drives the CLI) it used to print nothing — the URL was only shown to humans —
so the command just sat silently for up to --timeout seconds (default 300) and
then dumped one final result line. An agent had no URL to open, so it could never
complete the login.

This PR makes comfy cloud login emit the authorize URL as a machine-readable
login_url event before it starts waiting, so an agent parent can read the
URL off the pipe, open it (or hand it to the user), and let the login finish.

What changed

  • comfy_cli/cloud/command.py_on_url: when the renderer is not
    pretty (global --json / --json-stream / agentic caller / non-TTY), emit a
    login_url event carrying url + timeout_s, then flush stdout so a
    pipe-reading parent sees it before run_login blocks on the loopback callback.
    Pretty-mode prints are byte-for-byte unchanged.
  • docs/json-output.md: document the login_url event (event table + a
    dedicated section) as part of the sign-in stream.
  • login help text: note the login_url event under --json/--json-stream.
  • Tests (tests/comfy_cli/cloud/test_login_command.py): JSON login streams
    the login_url event before the final, session-redacted envelope; pretty
    output is unchanged (URL printed, no event line); an OAuthTimeout renders a
    single ok=false envelope with code oauth_timeout.

No change to run_login itself — on_url_ready already fires at the right moment.

Judgment call (worth a reviewer's eye)

The ticket says to call renderer.event("login_url", ...). Renderer.event() is a
no-op unless the renderer is in NDJSON stream mode, and the global --json
flag resolves to single-envelope JSON mode — so a bare event() call would emit
nothing and the acceptance test (comfy --json cloud login produces the event
line) would fail. To make the event actually reach stdout I first call
renderer.force_stream(), exactly as comfy run --json does
(cmdline.py:781) to upgrade into the one NDJSON dialect. Net effect: under
--json, login now emits an NDJSON stream (event line + terminal type: "envelope" line) rather than a single envelope. That is the documented dialect
(consumers discriminate the final line by type), and force_stream only runs
once the URL is built (i.e. right before the command would otherwise block), so
non-machine paths are untouched.

Deliberately out of scope

discovery.py's STREAM_EVENT_SCHEMAS (which advertises, per command, a JSON
schema its event lines validate against) is not updated — registering login
there implies authoring a login_event schema file, which is a separate additive
change. Kept out to keep this PR small and matched to the ticket's narrow doc
scope; happy to file a follow-up.

Negative-claim note

This change adds a capability (surfacing the URL for agents) and removes a
silent-block dead-end; it introduces no "not supported"/deny path, so no
capability-falsification was required.

Testing

  • uv run --extra dev pytest tests/comfy_cli/cloud/test_login_command.py → 3 passed.
  • uv run --extra dev pytest tests/comfy_cli/cloud tests/comfy_cli/auth tests/comfy_cli/output tests/comfy_cli/command/test_run_json.py → 382 passed.
  • ruff check / ruff format --check clean on the touched files.

…de (BE-3365)

Under a non-pretty renderer (global --json / --json-stream / agentic / non-tty),
comfy cloud login now surfaces the OAuth authorize URL as an event/1 line and
flushes it before run_login blocks on the loopback callback, so an agent/MCP
parent can open the URL instead of the command silently blocking for --timeout
seconds and emitting only the final envelope.

- _on_url upgrades the renderer to the NDJSON stream (matching comfy run --json)
  and emits {"type":"login_url","url":...,"timeout_s":...}; pretty-mode
  prints are unchanged.
- Document the event in docs/json-output.md and the login help text.
- Cover the JSON login stream (event before redacted envelope), unchanged pretty
  output, and the OAuthTimeout error envelope.
@mattmillerai mattmillerai added the agent-coded PR authored by the agent-work loop label Jul 17, 2026
@mattmillerai
mattmillerai marked this pull request as ready for review July 17, 2026 23:59
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f23d7dec-8dff-4dcf-9bda-c12b773bca61

📥 Commits

Reviewing files that changed from the base of the PR and between a732f5c and dfa1e12.

📒 Files selected for processing (6)
  • comfy_cli/cloud/command.py
  • comfy_cli/cloud/oauth.py
  • comfy_cli/command/setup.py
  • docs/json-output.md
  • tests/comfy_cli/auth/test_oauth.py
  • tests/comfy_cli/cloud/test_login_command.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch matt/be-3365-login-url-event
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch matt/be-3365-login-url-event

Comment @coderabbitai help to get the list of available commands.

@mattmillerai mattmillerai added the cursor-review Request Cursor bot review label Jul 17, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Cursor Review — Consolidated panel

Triggered by @mattmillerai.

Found 5 finding(s).

Severity Count
🟡 Medium 1
🟢 Low 3
⚪ Nit 1

Panel: 6/8 reviewers contributed findings.

Reviewers that did not contribute: kimi-k2.5:adversarial (empty), kimi-k2.5:edge-case (empty)

Comment thread comfy_cli/cloud/command.py
Comment thread comfy_cli/cloud/command.py
Comment thread tests/comfy_cli/cloud/test_login_command.py Outdated
Comment thread comfy_cli/cloud/command.py Outdated
Comment thread comfy_cli/cloud/command.py Outdated
Address the cursor-review panel findings on #556:

- Fail fast on a broken machine stream: run_login now re-raises OSError from
  the on_url_ready callback (a piped --json parent that hung up) instead of
  swallowing it and blocking the full `timeout` on a loopback callback nobody
  will complete. login_cmd and setup.py's _auth_browser both catch OSError and
  exit/return cleanly. (Medium)
- Escape the authorize URL for Rich in pretty mode so an IPv6 base_url
  (`http://[::1]:8188`) can't trigger MarkupError. (Low)
- Rewrite the timeout test to emit `login_url` before the `oauth_timeout`
  envelope — the real run_login fires on_url_ready before the callback wait, so
  the previous single-line assertion encoded an impossible ordering and left
  the headline guarantee untested. (Low)
- Drop the redundant explicit machine_stream.flush(); renderer.event() already
  writes + flushes the line. (Nit)

Add tests: run_login propagates OSError from the URL callback without blocking,
and login_cmd fails fast when the login_url write breaks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mattmillerai

Copy link
Copy Markdown
Collaborator Author

Review pass: all 5 review threads addressed and resolved (4 fixes in dfa1e12 — OSError fail-fast propagation, `rich.markup.escape` for IPv6 URLs, timeout-test URL ordering, dropped redundant flush; 1 by-design on the NDJSON streaming contract). All 52 tests in test_login_command.py/test_oauth.py pass locally; diff is ruff- and format-clean.

The two red checks (build and the Windows test) are the current repo-wide infra breaks, not this PR — its diff touches only cloud/, command/setup.py, docs, and tests:

  • build: the 9 tomlkit "Comment cannot contain line breaks" failures in registry/test_config_parser.py + test_node_init.py (newer tomlkit rejects multi-line comments; tracked as BE-3290).
  • Windows test: the pydantic_core cannot import name '__version__' install flake seen on every open PR.

Ready to merge once the infra CI issues clear.

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

Labels

agent-coded PR authored by the agent-work loop cursor-review Request Cursor bot review enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant