Repository: skypilot-org/skypilot
Pull request: [API server] attach setup of controllers
<!-- Describe the changes in this PR -->

close https://github.com/skypilot-org/skypilot/issues/4783

The total time of first `sky jobs launch` is unchanged.

<!-- Describe the tests ran -->
<!-- Unit tests (tests/test_*.py) are part of GitHub CI; below are tests that launch on the cloud. -->

This PR:

![image](https://github.com/user-attachments/assets/232ef0a3-4b32-4688-abf1-081196fcbdb7)


Master:

![image](https://github.com/user-attachments/assets/0463ef66-7359-485f-981d-2229538abad8)

Tested (run the relevant ones):

- [x] Code formatting: install pre-commit (auto-check on commit) or `bash format.sh`
- [ ] Any manual or new tests for this PR (please specify below)
- [ ] All smoke tests: `/smoke-test` (CI) or `pytest tests/test_smoke.py` (local)
- [x] Relevant individual tests: `/smoke-test -k test_name` (CI) or `pytest tests/test_smoke.py::test_name` (local)
- [ ] Backward compatibility: `/quicktest-core` (CI) or `conda deactivate; bash -i tests/backward_compatibility_tests.sh` (local)

<!-- CI commands (/-prefixed) can only be triggered by repo members -->


Problem statement:
[UX] Show jobs controller setup logs for the first `sky jobs launch`
When sky jobs launch for the first time, the output for the controller setup is hidden in `sky logs sky-jobs-controller-xxx 1` which is hard to find and may cause people wonder why a job stay in PENDING for a long time. 

This is a problem caused by our recent update to API server, where we make the `detach_setup=True` by default for all clusters including the jobs controller.

We should have the setup output shown.

Hints from issue discussion:

Commit message: lint

Signed-off-by: Aylei <rayingecho@gmail.com>

Patch to review:
diff --git a/sky/execution.py b/sky/execution.py
index 5ff8762acd3..b0261ab0718 100644
--- a/sky/execution.py
+++ b/sky/execution.py
@@ -529,6 +529,13 @@ def launch(
             ]
             skip_unnecessary_provisioning = True
 
+    detach_setup = True
+    if controller_utils.Controllers.from_name(cluster_name) is not None:
+        # Attach to setup if the cluster is a controller, so that user can
+        # see the setup logs when inspecting the launch process to know
+        # excatly what the job is waiting for.
+        detach_setup = False
+
     return _execute(
         entrypoint=entrypoint,
         dryrun=dryrun,
@@ -540,7 +547,7 @@ def launch(
         optimize_target=optimize_target,
         stages=stages,
         cluster_name=cluster_name,
-        detach_setup=True,
+        detach_setup=detach_setup,
         detach_run=True,
         idle_minutes_to_autostop=idle_minutes_to_autostop,
         no_setup=no_setup,


Code review comments:
diff_hunk: @@ -529,6 +529,13 @@ def launch(
             ]
             skip_unnecessary_provisioning = True
 
+    detach_setup = True
+    if controller_utils.Controllers.from_name(cluster_name) is not None:
path: sky/execution.py
text: @user1:
nit: can we just do `detach_setup = controller_utils.Controllers.from_name(cluster_name) is not None`?