Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/agentdrain/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
6 changes: 6 additions & 0 deletions pkg/cli/gateway_logs_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions pkg/workflow/action_pins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions pkg/workflow/maintenance_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
}

Expand All @@ -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"
}
8 changes: 8 additions & 0 deletions pkg/workflow/maintenance_workflow_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down