From e657867d1e29c1d5a95f9e08ff020fd8b36e8f7a Mon Sep 17 00:00:00 2001 From: Michael Dwan Date: Tue, 19 May 2026 17:21:09 -0600 Subject: [PATCH 1/2] Add experimental warning to weights commands --- pkg/cli/weights.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/cli/weights.go b/pkg/cli/weights.go index 15565341c4..78eade4a72 100644 --- a/pkg/cli/weights.go +++ b/pkg/cli/weights.go @@ -20,10 +20,23 @@ import ( func newWeightsCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "weights", - Short: "Manage model weights", - Long: "Commands for managing model weight files.", + Use: "weights", + Short: "Manage model weights (experimental)", + Long: `Commands for managing model weight files. + +NOTE: cog weights is experimental. Behavior may change in future versions. +Do not rely on it in production workflows.`, Hidden: true, + PersistentPreRun: func(cmd *cobra.Command, args []string) { + // Chain the root command's PersistentPreRun (debug, color, update check) + // since cobra does not do this automatically. + if parent := cmd.Parent(); parent != nil && parent.PersistentPreRun != nil { + parent.PersistentPreRun(cmd, args) + } + console.Warnf("NOTE: cog weights is experimental. Behavior may change in future versions.") + console.Warnf("Do not rely on it in production workflows.") + console.Info("") + }, } cmd.AddCommand(newWeightsImportCommand()) From 3e85821e3e7425c523501a8dd4b539e54ff26cb5 Mon Sep 17 00:00:00 2001 From: Michael Dwan Date: Wed, 20 May 2026 11:57:08 -0600 Subject: [PATCH 2/2] Fix stack overflow: enable cobra hook traversal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable cobra.EnableTraverseRunHooks so PersistentPreRun hooks chain from root → child automatically. Remove the manual parent chaining in weights.go that caused infinite recursion when subcommands ran. --- pkg/cli/root.go | 7 +++++++ pkg/cli/weights.go | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/cli/root.go b/pkg/cli/root.go index f69f369d83..6de4283905 100644 --- a/pkg/cli/root.go +++ b/pkg/cli/root.go @@ -11,6 +11,13 @@ import ( "github.com/replicate/cog/pkg/util/console" ) +func init() { + // Allow child commands to define their own PersistentPreRun hooks + // without shadowing the root command's. Cobra will invoke them in + // order from root → child. + cobra.EnableTraverseRunHooks = true +} + func NewRootCommand() (*cobra.Command, error) { rootCmd := cobra.Command{ Use: "cog", diff --git a/pkg/cli/weights.go b/pkg/cli/weights.go index 78eade4a72..de9c1941a4 100644 --- a/pkg/cli/weights.go +++ b/pkg/cli/weights.go @@ -28,11 +28,6 @@ NOTE: cog weights is experimental. Behavior may change in future versions. Do not rely on it in production workflows.`, Hidden: true, PersistentPreRun: func(cmd *cobra.Command, args []string) { - // Chain the root command's PersistentPreRun (debug, color, update check) - // since cobra does not do this automatically. - if parent := cmd.Parent(); parent != nil && parent.PersistentPreRun != nil { - parent.PersistentPreRun(cmd, args) - } console.Warnf("NOTE: cog weights is experimental. Behavior may change in future versions.") console.Warnf("Do not rely on it in production workflows.") console.Info("")