Skip to content

Fix ctrl-c in docker agent serve api and fix docker agent defaulting to docker agent run#1782

Merged
rumpl merged 1 commit intodocker:mainfrom
dgageot:fix-ctrl-c-docker-agent
Feb 19, 2026
Merged

Fix ctrl-c in docker agent serve api and fix docker agent defaulting to docker agent run#1782
rumpl merged 1 commit intodocker:mainfrom
dgageot:fix-ctrl-c-docker-agent

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Feb 18, 2026

No description provided.

…r agent run`

Signed-off-by: David Gageot <david.gageot@docker.com>
@dgageot dgageot requested a review from a team as a code owner February 18, 2026 17:47
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

Review Summary

Found 2 potential issues in the refactored plugin mode execution logic:

  1. Missing error handling for plugin.Run() - errors could be silently swallowed
  2. Asymmetric argument handling between rootCmd.SetArgs() and os.Args manipulation

Both issues are in newly added code. Please review the inline comments.

rootCmd.SetArgs(append(args[0:1], defaultToRun(rootCmd, args[1:])...))
os.Args = append(os.Args[0:2], defaultToRun(rootCmd, os.Args[2:])...)

plugin.Run(func(dockerCli command.Cli) *cobra.Command {
Copy link

Choose a reason for hiding this comment

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

Missing Error Handling

The plugin.Run() function returns an error (signature: func Run(fn func(Cli) *cobra.Command, meta Metadata) error), but this return value is not being captured or handled. This means any errors that occur during plugin execution will be silently swallowed, and the function will unconditionally return nil on line 189.

In contrast, the standalone mode path (lines 155-159) properly checks and handles errors:

if err := rootCmd.Execute(); err != nil {
    return processErr(ctx, err, stderr, rootCmd)
}

Consider wrapping the plugin.Run() call:

return plugin.Run(func(dockerCli command.Cli) *cobra.Command {
    // ... existing callback code ...
}, metadata.Metadata{
    // ... existing metadata ...
})

This ensures error conditions are properly propagated to the caller.

Copy link
Collaborator

Choose a reason for hiding this comment

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

plugin.Run() does not return an error, it directly os.exit(x) after displaying errors on stderr.

}

// When no subcommand is given, default to "run".
rootCmd.SetArgs(append(args[0:1], defaultToRun(rootCmd, args[1:])...))
Copy link

Choose a reason for hiding this comment

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

Asymmetric Argument Handling

There's an asymmetry in how arguments are processed for rootCmd.SetArgs() vs os.Args:

  • Line 166: Preserves args[0:1] (1 element) and processes args[1:]
  • Line 167: Preserves os.Args[0:2] (2 elements) and processes os.Args[2:]

This creates different slicing offsets. For example:

  • If args = ["docker-agent", "myfile.yaml"] and os.Args = ["docker", "agent", "myfile.yaml"]
  • After processing:
    • rootCmd gets: ["docker-agent", "run", "myfile.yaml"]
    • os.Args becomes: ["docker", "agent", "run", "myfile.yaml"]

This divergence could cause issues if the Docker plugin framework or other code reads os.Args directly after this point. Could you confirm this asymmetry is intentional? If so, consider adding a comment explaining why args and os.Args need different handling.

@rumpl rumpl merged commit 428cee5 into docker:main Feb 19, 2026
8 checks passed
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

Comments