Skip to content

Add detection for file paths mistakenly used as cluster names#9233

Merged
cg505 merged 10 commits into
masterfrom
claude/safeguard-cluster-name-56EMe
Apr 18, 2026
Merged

Add detection for file paths mistakenly used as cluster names#9233
cg505 merged 10 commits into
masterfrom
claude/safeguard-cluster-name-56EMe

Conversation

@Michaelvll
Copy link
Copy Markdown
Collaborator

@Michaelvll Michaelvll commented Mar 31, 2026

Review-level: checked the code manually and tried locally.

Description

This PR adds a safety check to detect when users accidentally pass file paths as cluster names in CLI commands. This addresses a common user mistake where users type commands like sky launch -c job.yaml instead of sky launch -c mycluster job.yaml.

Changes

  1. New utility function (sky/utils/common_utils.py):

    • Added cluster_name_looks_like_file_path() function that detects if a cluster name looks like a file path by checking for common file extensions (.yaml, .yml, .json) or if the path exists as a file on disk.
  2. CLI safeguards (sky/client/cli/command.py):

    • Added confirmation prompts in three commands:
      • launch: Warns when cluster name looks like a file path
      • exec: Warns when cluster name looks like a file path
      • jobs_launch: Warns when job name looks like a file path
    • Each prompt suggests the correct command syntax and allows users to proceed anyway if needed.
  3. Unit tests (tests/unit_tests/test_sky/utils/test_common_utils.py):

    • Added comprehensive test suite TestClusterNameLooksLikeFilePath covering:
      • Detection of .yaml, .yml, .json extensions (case-insensitive)
      • Normal cluster names (should not trigger)
      • Names with dots or hyphens (should not trigger)
      • None input handling
      • Existing file detection

Testing

  • Added 9 unit tests that cover all detection scenarios
  • Tests verify both positive cases (file-like names) and negative cases (valid cluster names)
  • Existing tests remain unmodified and passing

https://claude.ai/code/session_0127tbsbgCE95NTZ5h7SKv9w

claude added 3 commits March 31, 2026 17:48
…h -c flag

Detect when the cluster name argument to -c looks like a file path
(ends in .yaml/.yml/.json or is an existing file) and raise a helpful
error suggesting the correct syntax, e.g.:
  sky launch -c <cluster-name> job.yaml

Added checks in sky launch, sky exec, and sky jobs launch commands.

https://claude.ai/code/session_0127tbsbgCE95NTZ5h7SKv9w
…warning

Instead of rejecting cluster names that look like file paths, show a
warning and ask the user to confirm they want to proceed. This matches
the existing pattern used for entrypoint validation.

https://claude.ai/code/session_0127tbsbgCE95NTZ5h7SKv9w
When the user passes -y/--yes, skip the confirmation prompt for
cluster names that look like file paths, allowing the command to
proceed without interruption.

https://claude.ai/code/session_0127tbsbgCE95NTZ5h7SKv9w
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a validation check to prevent users from mistakenly providing a file path as a cluster or job name in the launch, exec, and jobs_launch commands. A new utility function, cluster_name_looks_like_file_path, was added along with unit tests to detect common file extensions or existing files on disk. Feedback suggests refactoring the duplicated confirmation prompt logic into a helper function to improve maintainability.

Comment thread sky/client/cli/command.py Outdated
Comment on lines +1221 to +1226
if not yes and common_utils.cluster_name_looks_like_file_path(cluster):
click.confirm(
f'Cluster name {cluster!r} looks like a file path. '
f'Did you mean: sky launch -c <cluster-name> {cluster}\n'
'Proceed anyway?',
abort=True)
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.

medium

The confirmation prompt logic is duplicated across three commands. Consider creating a helper function to encapsulate this validation and prompt logic to improve maintainability and reduce code duplication.

@Michaelvll Michaelvll requested a review from cg505 March 31, 2026 18:33
Copy link
Copy Markdown
Collaborator

@cg505 cg505 left a comment

Choose a reason for hiding this comment

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

nice

Copy link
Copy Markdown
Collaborator

@cg505 cg505 left a comment

Choose a reason for hiding this comment

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

meant to approve

@cg505 cg505 merged commit 20c2d08 into master Apr 18, 2026
29 of 31 checks passed
@cg505 cg505 deleted the claude/safeguard-cluster-name-56EMe branch April 18, 2026 00:25
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.

3 participants