From 883e15679819d8b7793533c416584c1a89b44daf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 15 Apr 2026 21:43:31 +0000 Subject: [PATCH] log: add debug logging to 5 pkg/ files Add logger declarations and meaningful log calls to files that lacked instrumentation: maintenance_cron.go (cron frequency decisions), maintenance_workflow_yaml.go (YAML generation parameters and mode branches), action_pins.go (pin resolution outcomes), gateway_logs_aggregation.go (guard policy event categorization), and defaults.go (weight loading paths). Co-Authored-By: Claude Sonnet 4.6 --- pkg/agentdrain/defaults.go | 7 +++++++ pkg/cli/gateway_logs_aggregation.go | 6 ++++++ pkg/workflow/action_pins.go | 6 ++++++ pkg/workflow/maintenance_cron.go | 14 ++++++++++++++ pkg/workflow/maintenance_workflow_yaml.go | 8 ++++++++ 5 files changed, 41 insertions(+) diff --git a/pkg/agentdrain/defaults.go b/pkg/agentdrain/defaults.go index 4360a0a01ee..0f9136bbdbf 100644 --- a/pkg/agentdrain/defaults.go +++ b/pkg/agentdrain/defaults.go @@ -3,8 +3,12 @@ package agentdrain import ( "bytes" _ "embed" + + "github.com/github/gh-aw/pkg/logger" ) +var defaultsLog = logger.New("agentdrain:defaults") + //go:embed data/default_weights.json var defaultWeightsJSON []byte @@ -20,11 +24,14 @@ var defaultWeightsJSON []byte // then rebuilding the binary. func (c *Coordinator) LoadDefaultWeights() error { if len(defaultWeightsJSON) == 0 { + defaultsLog.Print("No default weights embedded; skipping load") return nil } // A bare "{}" file means no weights have been trained yet. if string(bytes.TrimSpace(defaultWeightsJSON)) == "{}" { + defaultsLog.Print("Default weights file is empty ({}); skipping load") return nil } + defaultsLog.Printf("Loading embedded default weights: bytes=%d", len(defaultWeightsJSON)) return c.LoadWeightsJSON(defaultWeightsJSON) } diff --git a/pkg/cli/gateway_logs_aggregation.go b/pkg/cli/gateway_logs_aggregation.go index 0ad9a8a1d71..665bd610751 100644 --- a/pkg/cli/gateway_logs_aggregation.go +++ b/pkg/cli/gateway_logs_aggregation.go @@ -2,8 +2,13 @@ package cli +import "github.com/github/gh-aw/pkg/logger" + +var gatewayLogsAggregationLog = logger.New("cli:gateway_logs_aggregation") + // calculateGatewayAggregates calculates aggregate statistics func calculateGatewayAggregates(metrics *GatewayMetrics) { + gatewayLogsAggregationLog.Printf("Calculating gateway aggregates: servers=%d", len(metrics.Servers)) for _, server := range metrics.Servers { for _, tool := range server.Tools { if tool.CallCount > 0 { @@ -15,6 +20,7 @@ func calculateGatewayAggregates(metrics *GatewayMetrics) { // buildGuardPolicySummary creates a GuardPolicySummary from GatewayMetrics. func buildGuardPolicySummary(metrics *GatewayMetrics) *GuardPolicySummary { + gatewayLogsAggregationLog.Printf("Building guard policy summary: totalBlocked=%d events=%d", metrics.TotalGuardBlocked, len(metrics.GuardPolicyEvents)) summary := &GuardPolicySummary{ TotalBlocked: metrics.TotalGuardBlocked, Events: metrics.GuardPolicyEvents, diff --git a/pkg/workflow/action_pins.go b/pkg/workflow/action_pins.go index ac46c5edf8b..d6b37c22d6c 100644 --- a/pkg/workflow/action_pins.go +++ b/pkg/workflow/action_pins.go @@ -4,8 +4,11 @@ import ( "strings" actionpins "github.com/github/gh-aw/pkg/actionpins" + "github.com/github/gh-aw/pkg/logger" ) +var actionPinsLog = logger.New("workflow:action_pins") + // Type aliases — callers within pkg/workflow use these names directly. // ActionYAMLInput is defined in pkg/actionpins; aliased here so all files in @@ -48,6 +51,7 @@ func extractActionVersion(uses string) string { func getActionPin(repo string) string { pins := actionpins.GetActionPinsByRepo(repo) if len(pins) == 0 { + actionPinsLog.Printf("No embedded pins found for repo: %s", repo) return "" } return actionpins.FormatReference(repo, pins[0].SHA, pins[0].Version) @@ -124,9 +128,11 @@ func applyActionPinToTypedStep(step *WorkflowStep, data *WorkflowData) *Workflow pinnedRef, err := getActionPinWithData(actionRepo, rawVersion, data) if err != nil || pinnedRef == "" { + actionPinsLog.Printf("Skipping pin for %s@%s: no pin available", actionRepo, rawVersion) return step } + actionPinsLog.Printf("Pinned action: %s@%s -> %s", actionRepo, rawVersion, pinnedRef) result := step.Clone() result.Uses = pinnedRef return result diff --git a/pkg/workflow/maintenance_cron.go b/pkg/workflow/maintenance_cron.go index 2e5ed34a7b5..e90bd18e8ba 100644 --- a/pkg/workflow/maintenance_cron.go +++ b/pkg/workflow/maintenance_cron.go @@ -3,8 +3,12 @@ package workflow import ( "fmt" "hash/fnv" + + "github.com/github/gh-aw/pkg/logger" ) +var maintenanceCronLog = logger.New("workflow:maintenance_cron") + // generateMaintenanceCron generates a cron schedule based on the minimum expires value in days // Schedule runs at minimum required frequency to check expirations at appropriate intervals // Returns cron expression and description. @@ -16,16 +20,20 @@ func generateMaintenanceCron(minExpiresDays int) (string, string) { // Run at least as often as the shortest expiration would need if minExpiresDays <= 1 { // For 1 day or less, run every 2 hours + maintenanceCronLog.Printf("Selected cron frequency: every 2 hours (minExpiresDays=%d)", minExpiresDays) return fmt.Sprintf("%d */2 * * *", minute), "Every 2 hours" } else if minExpiresDays == 2 { // For 2 days, run every 6 hours + maintenanceCronLog.Printf("Selected cron frequency: every 6 hours (minExpiresDays=%d)", minExpiresDays) return fmt.Sprintf("%d */6 * * *", minute), "Every 6 hours" } else if minExpiresDays <= 4 { // For 3-4 days, run every 12 hours + maintenanceCronLog.Printf("Selected cron frequency: every 12 hours (minExpiresDays=%d)", minExpiresDays) return fmt.Sprintf("%d */12 * * *", minute), "Every 12 hours" } // For more than 4 days, run daily + maintenanceCronLog.Printf("Selected cron frequency: daily (minExpiresDays=%d)", minExpiresDays) return fmt.Sprintf("%d %d * * *", minute, 0), "Daily" } @@ -48,20 +56,26 @@ func generateSideRepoMaintenanceCron(repoSlug string, minExpiresDays int) (strin // Derive a deterministic minute in 0-59 from the seed. minute := int(seed % 60) + maintenanceCronLog.Printf("Generating side-repo cron: repoSlug=%q minExpiresDays=%d minute=%d", repoSlug, minExpiresDays, minute) + if minExpiresDays <= 1 { // Every 2 hours — vary the starting minute only. + maintenanceCronLog.Printf("Selected side-repo cron frequency: every 2 hours") return fmt.Sprintf("%d */2 * * *", minute), "Every 2 hours" } else if minExpiresDays == 2 { // Every 6 hours — vary the starting hour within the 6-hour window. startHour := int((seed >> 8) % 6) + maintenanceCronLog.Printf("Selected side-repo cron frequency: every 6 hours (startHour=%d)", startHour) return fmt.Sprintf("%d %d,%d,%d,%d * * *", minute, startHour, startHour+6, startHour+12, startHour+18), "Every 6 hours" } else if minExpiresDays <= 4 { // Every 12 hours — vary the starting hour within the 12-hour window. startHour := int((seed >> 8) % 12) + maintenanceCronLog.Printf("Selected side-repo cron frequency: every 12 hours (startHour=%d)", startHour) return fmt.Sprintf("%d %d,%d * * *", minute, startHour, startHour+12), "Every 12 hours" } // Daily — vary the hour of day (0-23) to spread load. hour := int((seed >> 8) % 24) + maintenanceCronLog.Printf("Selected side-repo cron frequency: daily (hour=%d)", hour) return fmt.Sprintf("%d %d * * *", minute, hour), "Daily" } diff --git a/pkg/workflow/maintenance_workflow_yaml.go b/pkg/workflow/maintenance_workflow_yaml.go index 2ef197b8d3d..98ee52e40a3 100644 --- a/pkg/workflow/maintenance_workflow_yaml.go +++ b/pkg/workflow/maintenance_workflow_yaml.go @@ -3,8 +3,12 @@ package workflow import ( "strconv" "strings" + + "github.com/github/gh-aw/pkg/logger" ) +var maintenanceWorkflowYAMLLog = logger.New("workflow:maintenance_workflow_yaml") + // buildMaintenanceWorkflowYAML generates the complete YAML content for the // agentics-maintenance.yml workflow. It is called by GenerateMaintenanceWorkflow // after the cron schedule and setup parameters have been resolved. @@ -17,6 +21,8 @@ func buildMaintenanceWorkflowYAML( resolver ActionSHAResolver, configuredRunsOn RunsOnValue, ) string { + maintenanceWorkflowYAMLLog.Printf("Building maintenance workflow YAML: actionMode=%s minExpiresDays=%d cronSchedule=%q", actionMode, minExpiresDays, cronSchedule) + var yaml strings.Builder // Add workflow header with logo and instructions @@ -97,6 +103,7 @@ jobs: // Add checkout step only in dev/script mode (for local action paths) if actionMode == ActionModeDev || actionMode == ActionModeScript { + maintenanceWorkflowYAMLLog.Printf("Adding checkout step for close-expired-entities (actionMode=%s)", actionMode) yaml.WriteString(" - name: Checkout actions folder\n") yaml.WriteString(" uses: " + getActionPin("actions/checkout") + "\n") yaml.WriteString(" with:\n") @@ -392,6 +399,7 @@ jobs: // These jobs are specific to the gh-aw repository and require go.mod, make build, etc. // User repositories won't have these dependencies, so we skip them in release mode if actionMode == ActionModeDev { + maintenanceWorkflowYAMLLog.Printf("Adding dev-only jobs: compile-workflows and secret-validation") // Add compile-workflows job yaml.WriteString(` compile-workflows: