@@ -195,12 +195,12 @@ func New(ctx context.Context, cfg Config) (*App, error) {
195195 }
196196 return nil , fmt .Errorf ("failed to prepare guardrail definitions: %w" , err )
197197 }
198- if err := guardrailResult .Service .EnsureSeedDefinitions (ctx , seedGuardrails ); err != nil {
198+ if err := guardrailResult .Service .UpsertDefinitions (ctx , seedGuardrails ); err != nil {
199199 closeErr := errors .Join (app .guardrails .Close (), app .aliases .Close (), app .batch .Close (), app .usage .Close (), app .audit .Close (), app .providers .Close ())
200200 if closeErr != nil {
201- return nil , fmt .Errorf ("failed to seed guardrails: %w (also: close error: %v)" , err , closeErr )
201+ return nil , fmt .Errorf ("failed to upsert guardrails: %w (also: close error: %v)" , err , closeErr )
202202 }
203- return nil , fmt .Errorf ("failed to seed guardrails: %w" , err )
203+ return nil , fmt .Errorf ("failed to upsert guardrails: %w" , err )
204204 }
205205
206206 // Build runtime execution dependencies. Policy is passed explicitly into the
@@ -225,7 +225,7 @@ func New(ctx context.Context, cfg Config) (*App, error) {
225225 }
226226 return nil , fmt .Errorf ("failed to initialize execution plans: %w" , err )
227227 }
228- defaultExecutionPlan := defaultExecutionPlanInput (appCfg , guardrailResult .Service .Names ())
228+ defaultExecutionPlan := defaultExecutionPlanInput (appCfg , guardrailResult .Service .Names (), seedGuardrails )
229229 if err := executionPlanResult .Service .EnsureDefaultGlobal (ctx , defaultExecutionPlan ); err != nil {
230230 closeErr := errors .Join (executionPlanResult .Close (), app .guardrails .Close (), app .aliases .Close (), app .batch .Close (), app .usage .Close (), app .audit .Close (), app .providers .Close ())
231231 if closeErr != nil {
@@ -731,7 +731,7 @@ func configGuardrailDefinitions(cfg config.GuardrailsConfig) ([]guardrails.Defin
731731 return definitions , nil
732732}
733733
734- func defaultExecutionPlanInput (cfg * config.Config , availableGuardrails []string ) executionplans.CreateInput {
734+ func defaultExecutionPlanInput (cfg * config.Config , availableGuardrails []string , configuredGuardrails []guardrails. Definition ) executionplans.CreateInput {
735735 fallbackEnabled := fallbackFeatureEnabledGlobally (cfg )
736736 payload := executionplans.Payload {
737737 SchemaVersion : 1 ,
@@ -746,6 +746,13 @@ func defaultExecutionPlanInput(cfg *config.Config, availableGuardrails []string)
746746 for _ , name := range availableGuardrails {
747747 available [strings .TrimSpace (name )] = struct {}{}
748748 }
749+ for _ , definition := range configuredGuardrails {
750+ name := strings .TrimSpace (definition .Name )
751+ if name == "" {
752+ continue
753+ }
754+ available [name ] = struct {}{}
755+ }
749756 if cfg .Guardrails .Enabled && len (cfg .Guardrails .Rules ) > 0 {
750757 payload .Guardrails = make ([]executionplans.GuardrailStep , 0 , len (cfg .Guardrails .Rules ))
751758 for _ , rule := range cfg .Guardrails .Rules {
@@ -765,8 +772,8 @@ func defaultExecutionPlanInput(cfg *config.Config, availableGuardrails []string)
765772 return executionplans.CreateInput {
766773 Scope : executionplans.Scope {},
767774 Activate : true ,
768- Name : "default-global" ,
769- Description : "Bootstrapped from runtime configuration" ,
775+ Name : executionplans . ManagedDefaultGlobalName ,
776+ Description : executionplans . ManagedDefaultGlobalDescription ,
770777 Payload : payload ,
771778 }
772779}
0 commit comments