8000 Add detect blocking IO option to Supervisor options by agners · Pull Request #570 · home-assistant/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add detect blocking IO option to Supervisor options #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the comm 8000 unity.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

agners
Copy link
Member
@agners agners commented Jun 12, 2025

Add a new detect blocking IO option to the Supervisor options call introduced in home-assistant/supervisor#5746.

Summary by CodeRabbit

  • New Features
    • Added a new "detect-blocking-io" option to the supervisor command, allowing users to specify blocking IO detection behavior ("on", "on-at-startup", or "off").
    • Enabled shell autocompletion for the "detect-blocking-io" option with the valid values.

Add a new detect blocking IO option to the Supervisor options call
introduced in home-assistant/supervisor#5746.
@agners agners requested a review from mdegat01 June 12, 2025 13:12
Copy link
coderabbitai bot commented Jun 12, 2025
📝 Walkthrough

Walkthrough

A new string flag named "detect-blocking-io" was introduced to the supervisor options command. This flag is now processed alongside other string options, with its value normalized and added to the options map. Shell completion for this flag was also implemented, offering three predefined values.

Changes

File(s) Change Summary
cmd/supervisor_options.go Added "detect-blocking-io" string flag, integrated it into options processing, and added shell completion for its values.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant SupervisorOptionsCmd

    User->>CLI: Run supervisor options command with --detect-blocking-io flag
    CLI->>SupervisorOptionsCmd: Parse flags
    SupervisorOptionsCmd->>SupervisorOptionsCmd: Normalize flag key and add to options map
    SupervisorOptionsCmd-->>CLI: Execute command logic
    CLI-->>User: Output result

    User->>CLI: Request shell completion for --detect-blocking-io
    CLI->>SupervisorOptionsCmd: Provide completion options
    SupervisorOptionsCmd-->>CLI: Return [on, on-at-startup, off]
    CLI-->>User: Show completion options
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
cmd/supervisor_options.go (3)

31-41: Consider validating the value before POSTing to the Supervisor API

detect-blocking-io is appended to the generic []string loop and accepted verbatim.
If the caller passes an arbitrary string (typo, upper-case, etc.) it will be forwarded to the Supervisor and only fail there. Doing a quick client-side guard avoids a round-trip and yields clearer feedback.

Example:

-			val, err := cmd.Flags().GetString(value)
-			if val != "" && err == nil && cmd.Flags().Changed(value) {
-				options[strings.ReplaceAll(value, "-", "_")] = val
-			}
+			val, err := cmd.Flags().GetString(value)
+			if val == "" || err != nil || !cmd.Flags().Changed(value) {
+				continue
+			}
+			if value == "detect-blocking-io" {
+				switch val {
+				case "on", "on-at-startup", "off":
+				default:
+					return fmt.Errorf("invalid value for --detect-blocking-io: %s", val)
+				}
+			}
+			options[strings.ReplaceAll(value, "-", "_")] = val

83-83: Minor wording nit – follow existing flag descriptions

Other flags document accepted values without parentheses (e.g. Channel to track stable|beta|dev).
For consistency drop the parentheses and mirror that pattern:

"Detect blocking IO: on|on-at-startup|off"


102-104: Improve shell completion by filtering on user input

The completion callback always returns all three candidates, ignoring the toComplete prefix. Filtering improves UX and is already trivial with strings.HasPrefix.

-supervisorOptionsCmd.RegisterFlagCompletionFunc("detect-blocking-io", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
-		return []string{"on", "on-at-startup", "off"}, cobra.ShellCompDirectiveNoFileComp
-	})
+supervisorOptionsCmd.RegisterFlagCompletionFunc("detect-blocking-io", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+		candidates := []string{"on", "on-at-startup", "off"}
+		var filtered []string
+		for _, c := range candidates {
+			if strings.HasPrefix(c, toComplete) {
+				filtered = append(filtered, c)
+			}
+		}
+		return filtered, cobra.ShellCompDirectiveNoFileComp
+	})
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 1ffb7fd and eb77d1e.

📒 Files selected for processing (1)
  • cmd/supervisor_options.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`*/**(html|markdown|md)`: - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure t...

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'
  • cmd/supervisor_options.go
`*/**(html|markdown|md)`: - Use bold to mark UI strings. - If "" are used to mark UI strings, replace them by bold.

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.
  • cmd/supervisor_options.go
`*/**(html|markdown|md)`: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

*/**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

  • cmd/supervisor_options.go
`*/**(html|markdown|md)`: - Use sentence-style capitalization also in headings.

*/**(html|markdown|md): - Use sentence-style capitalization also in headings.

  • cmd/supervisor_options.go
`*/**(html|markdown|md)`: do not comment on HTML used for icons

*/**(html|markdown|md): do not comment on HTML used for icons

  • cmd/supervisor_options.go
`*/**(html|markdown|md)`: Avoid flagging inline HTML for embedding videos in future reviews for this repository.

*/**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

  • cmd/supervisor_options.go

@@ -97,6 +99,9 @@ func init() {
supervisorOptionsCmd.RegisterFlagCompletionFunc("channel", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"stable", "beta", "dev"}, cobra.ShellCompDirectiveNoFileComp
})
supervisorOptionsCmd.RegisterFlagCompletionFunc("detect-blocking-io", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"on", "on-at-startup", "off"}, cobra.ShellCompDirectiveNoFileComp
Copy link
Contributor
@mdegat01 mdegat01 Jun 18, 2025

Choose a reason for hiding this comment

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

Suggested change
return []string{"on", "on-at-startup", 8000 "off"}, cobra.ShellCompDirectiveNoFileComp
return []string{"on", "on_at_startup", "off"}, cobra.ShellCompDirectiveNoFileComp

Supervisor expects on_at_startup not on-at-startup for the value of this field. Alternatively we can handle it above but I think you'd have to remove detect-blocking-io from the loop and handle it separately. We cannot just do this in the loop:

options[strings.ReplaceAll(value, "-", "_")] = strings.ReplaceAll(val, "-", "_")

Because we can't blindly replace dashes with underscores in values for hostname or timezone.

Copy link
Member Author
@agners agners Jun 20, 2025

Choose a reason for hiding this comment

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

Actually, I think this is the only place in the API where we use underlines in values. E.g. the networking API uses dashes in constant string values (e.g. stable-privacy or wpa-psk). Those are not even directly mapped to NM, so we could have used anything there, It seems on_at_startup is the oddball here. Since this is really a new API and very unlikely used to be used anywhere just yet, I'd suggest to just change this on Superviser API side...

Copy link
Member Author

Choose a reason for hiding this comment

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

PR to change the API endpoint: home-assistant/supervisor#5964

@home-assistant home-assistant bot marked this pull request as draft June 18, 2025 16:53
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@agners agners marked this pull request as ready for review June 20, 2025 10:52
@home-assistant home-assistant bot requested a review from mdegat01 June 20, 2025 10:52
@agners agners dismissed mdegat01’s stale review June 20, 2025 11:33

Alternative fix implemented.

@agners agners merged commit b4b889a into master Jun 20, 2025
9 checks passed
@agners agners deleted the add-detect-blocking-io-option branch June 20, 2025 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0