Skip to content

[CLI] Add --output id|json to sky jobs launch - #10879

Merged
aylei merged 3 commits into
masterfrom
aylei/jobs-launch-output
Sep 25, 2026
Merged

aylei merged 3 commits into
masterfrom
aylei/jobs-launch-output

Conversation

@aylei

@aylei aylei commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Scripts that chain work after sky jobs launch need the managed job ID, but today they have to parse it out of the human-readable output (Managed Job ID: N).

This adds --output/-o id|json to sky jobs launch:

  • -o id prints only the job IDs on stdout, one per line; --num-jobs gives one line per job.
  • -o json prints {"job_ids": [...]}.
  • Everything else the command prints, including the launch request logs and spinners, goes to stderr. The redirect covers the stdout file descriptor too, because logging handlers hold the original sys.stdout.
  • Log streaming is skipped, as with --detach-run.
  • --async is rejected with --output, because it returns before the IDs exist.
JOB_ID=$(sky jobs launch -y -o id task.yaml)

Tested (run the relevant ones):

  • Code formatting: yapf 0.32.0 and isort on the changed files; pylint on sky/client/cli/command.py and the test file
  • Any manual or new tests for this PR (please specify below)
    • pytest tests/unit_tests/test_sky/test_cli_launch_validation.py: 10 passed, including new cases for -o id, -o json, --num-jobs, the --async rejection, and the redirect of a stream bound to the original stdout.
    • Manual, against a remote API server: sky jobs launch -y -o id task.yaml wrote exactly 13\n to stdout, with the YAML, spinner and launch lines on stderr; -o json printed {"job_ids": [12]}.
  • All smoke tests: /smoke-test (CI) or pytest tests/test_smoke.py (local)
  • Relevant individual tests: /smoke-test -k test_name (CI) or pytest tests/test_smoke.py::test_name (local)
  • Backward compatibility: /quicktest-core (CI) or pytest tests/smoke_tests/test_backward_compat.py (local)

Scripts need the managed job ID to chain further commands. With --output, launch sends all other output to stderr, skips log streaming, and prints only the job IDs: one per line for id, or {"job_ids": [...]} for json.
@aylei
aylei marked this pull request as ready for review September 25, 2026 05:45

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

Devin Review

Comment thread sky/client/cli/command.py Resolved
--config and --workspace are applied in option callbacks, which run before the command body, so their debug logs reached stdout ahead of the IDs. --output is now eager and starts the redirect in its own callback; the IDs are written to the original stdout.
@aylei
aylei requested a review from Michaelvll September 25, 2026 06:04
Comment thread sky/client/cli/command.py Resolved
@aylei
aylei merged commit 954044b into master Sep 25, 2026
23 checks passed
@aylei
aylei deleted the aylei/jobs-launch-output branch September 25, 2026 06:26
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