Skip to content

[CLI] Bulk selectors act on the active workspace and confirm others' resources - #11440

Merged
DanielZhangQD merged 15 commits into
masterfrom
sky-6876-cli-bulk
Nov 20, 2026
Merged

DanielZhangQD merged 15 commits into
masterfrom
sky-6876-cli-bulk

Conversation

@DanielZhangQD

@DanielZhangQD DanielZhangQD commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

-a, -u and glob selectors that change resources now act on the active workspace only. Their confirmation now says whose resources are affected.

  • Scope. The bulk selectors of these commands pick from the active workspace only, admins included:

    • sky down/stop/autostop/start
    • sky storage delete
    • sky volumes delete
    • sky jobs cancel
    • sky serve down
    • sky jobs pool down

    Before, they picked from every workspace the caller can read; for an admin, that was every workspace. For example, sky down -u as an admin tore down every cluster on the server.

    • Names given exactly are not narrowed.
    • Read-only listings are unchanged.
    • The active workspace is the one the server resolves for the request, from GET /users/me/workspace. It honours active_workspace from the config files and from --config.
    • A server too old to report the active workspace keeps the current selection.
    • An ambiguous workspace stops the command with the server's note.
  • Confirmation. When a bulk target belongs to another user, the prompt lists the targets by owner and defaults to [y/N]:

    Terminating 3 clusters in workspace 'ws-a':
      yours (1): a
      other users (2): bob: b; carol: c
    2 of them belong to other users. Proceed? [y/N]:
    
    • If every target is yours, the prompt is today's one line, [Y/n].
    • -y still skips the prompt.
    • Exact names keep today's prompt.
  • sky jobs cancel -a/-u without -y lists the jobs first, then cancels exactly the listed ids. A job submitted while the prompt is open is never cancelled unseen. With -y, the request is unchanged.

  • sky cancel CLUSTER -u defaults to [y/N], even when every job on the cluster is yours. Checking ownership would need an extra queue call per cluster.

  • sky serve down / sky jobs pool down with --all or a pattern preview what the server will tear down, using the caller's role from GET /users/role. An admin whose targets include other users' services gets the grouped [y/N] prompt. If the listing fails, the prompt is today's. The server still decides the actual set.

  • sky jobs pool down --all used to cancel the running jobs of every visible pool before tearing down, including pools it would not tear down. It now cancels only the jobs of the pools it tears down.

Test plan

  • New tests/unit_tests/test_sky/test_cli_bulk_selectors.py, covering:
    • narrowing for -a, -u and patterns (exact names not narrowed);
    • the grouped prompt with Enter aborting, and the own-only [Y/n];
    • -y, an old server, and an ambiguous workspace;
    • storage without a workspace, and volumes;
    • jobs cancel -u cancelling exactly the listed ids (deduped per job), and -y unchanged;
    • cancel -u defaulting to no;
    • serve down as admin and as user, and a failed listing;
    • pool down --all cancelling only the reached pools' jobs.
  • Existing CLI unit tests pass (414 across tests/test_cli.py, tests/test_jobs_and_serve.py and tests/unit_tests/**/test_cli*.py).
  • Each new check was removed in turn (10 variants); at least one test fails every time.
  • Manual (alice is a member of ws-a and ws-b, bob of ws-a; alice's active workspace is ws-a):
    • sky down -u, then press Enter: lists alice's and bob's ws-a clusters by owner and aborts; ws-b is not listed.
    • sky down -u -y: tears down only the ws-a clusters.
    • sky stop -a, then press Enter: stops alice's ws-a clusters only.
    • sky jobs cancel -u: lists the ws-a jobs by owner and cancels only those ids.

🤖 Generated with Claude Code


Devin Review

DanielZhangQD and others added 2 commits November 18, 2026 20:59
…resources

-a, -u and glob selectors of down/stop/autostop/start, storage delete,
volumes delete, jobs cancel, serve down and pool down act on the active
workspace only. The confirmation lists other users' targets by owner
and then defaults to no; jobs cancel -a/-u cancels exactly the jobs it
listed. cancel CLUSTER -u defaults to no. pool down --all cancels only
the jobs of the pools it tears down.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

DanielZhangQD and others added 3 commits November 18, 2026 21:13
Volume names are the table's primary key, so one name cannot be in two
workspaces.

This reverts commit 42ad858.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After a -a or pattern preview, serve down and pool down send the listed
names instead of -a or the patterns, so the server cannot reach more than
the user confirmed. Exact names that matched nothing are still sent so the
server reports them. The pool prompt now comes before the question about
cancelling the pools' jobs, and the workspace label comes from a record in
the target workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Records from a serve or pool controller older than the workspace field
carry none, and the server leaves such a down unscoped, so the preview
does too instead of reporting nothing to terminate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

DanielZhangQD and others added 8 commits November 18, 2026 21:25
Such a server answers the workspace lookup with 401, which aborted every
bulk command, -y included. Treat it like a server too old to answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Declining the job question in pool down aborts again instead of
  falling through to the teardown.
- Records without a workspace field (storage before it had one) are not
  narrowed.
- Serve and pool down without a known workspace keep the old prompt and
  let the server pick.
- The preview names services whose workspace is unknown.
- A workspace name that is not unique is reported as a usage error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The storage response model defaults the workspace to None, so the key is
always present and an older server's storage was still narrowed to
nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`sky volumes delete -a` and patterns now confirm through the grouped
bulk prompt, which dropped the k8s-hostpath cleanup warning that the
named-volume prompt shows. Pass it through, and default to no with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The in-process test server cannot answer GET /users/me/workspace on
Python 3.9: the sync handler's request context creates an asyncio.Event
in a worker thread without an event loop. These tests are about the
controllers, so mock the lookup as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DanielZhangQD
DanielZhangQD requested a review from aylei November 19, 2026 12:49
Comment thread sky/client/cli/command.py
return info['workspace']


def _in_workspace(records: List[Any], workspace_id: Optional[str]) -> List[Any]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Resources in other workspaces are now dropped silently. sky status still lists clusters from every workspace, but sky down -a / sky stop -a (and storage, volumes) now act on the active workspace only and say nothing about the rest, so a user can leave running clusters in another workspace without noticing. Also, sky jobs cancel -a without -y filters the ids here before they reach the server, so the "skipped, not in the active workspace" hint that #11439 keeps for -a never shows on this path.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch on both. Fixed in b179bec + 8e99f1b.

Wherever the CLI drops matches for being in another workspace, it now prints one line before acting:

Skipped 4 clusters in other workspaces: 3 yours (own-b, own-c and 1 more), 1 of other users. Switch the active workspace to act on them.
  • It covers down/stop/autostop/start with -a/-u/glob, storage delete, volumes delete and jobs pool down, with or without -y.
  • It also covers the serve down and jobs cancel -a/-u previews. Those previews run only without -y. With -y the server does the selection, and for jobs cancel -a -y it still prints its own "skipped" hint.
  • Your own resources are named, up to 2 and then "and N more". Other users' are only counted, which keeps admin -u short across many workspaces.
  • sky jobs cancel -a without -y now names your jobs left in other workspaces.
  • Nothing is printed when nothing is skipped, when the server cannot scope (older server or no auth), or for records with no workspace (for example legacy storage).

DanielZhangQD and others added 2 commits November 20, 2026 15:58
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DanielZhangQD
DanielZhangQD merged commit 0e3a238 into master Nov 20, 2026
29 of 30 checks passed
@DanielZhangQD
DanielZhangQD deleted the sky-6876-cli-bulk branch November 20, 2026 09:13
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