fix: use cmd.Context() instead of context.Background()#2981
Merged
Conversation
docker-agent
reviewed
Jun 3, 2026
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
This is a clean, well-scoped fix. The change correctly replaces context.Background() with cmd.Context() in the completeMessage shell-completion handler.
Analysis:
cmd.Context()in Cobra always returns a non-nil context (falls back tocontext.Background()if none is explicitly set), so this is strictly safer than a barecontext.Background().- The existing error handling (
return nil, cobra.ShellCompDirectiveNoFileComponconfig.Loaderror) already handles any context-cancellation-driven errors gracefully. - The
contextimport removal is correct — no other usages of thecontextpackage remain in the file. - The change is minimal, targeted, and correct. No bugs were found.
rumpl
approved these changes
Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During an audit of
context.Background()usage in the codebase, this was identified as the one genuinely suspicious instance. The shell-completion handler forcompleteMessagewas passingcontext.Background()toconfig.Load(), which meant completion operations ignored the cobra command's own context and could not be cancelled or respect deadline constraints.This change passes
cmd.Context()instead, ensuring that shell completion respects cancellation and any deadlines set by the caller. The now-unusedcontextimport was removed.All other
context.Background()occurrences in the codebase were reviewed and deemed intentional (detached long-lived resources,sync.Oncecaches, fire-and-forget calls), so no further changes are needed.