Skip to content
Merged
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
13 changes: 13 additions & 0 deletions internal/difc/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package difc
import (
"log"
"sync"

"github.com/github/gh-aw-mcpg/internal/logger"
)

var logAgent = logger.New("difc:agent")

// AgentLabels associates each agent with their DIFC labels
// Tracks what secrecy and integrity tags an agent has accumulated
type AgentLabels struct {
Expand All @@ -16,6 +20,7 @@ type AgentLabels struct {

// NewAgentLabels creates a new agent with empty labels
func NewAgentLabels(agentID string) *AgentLabels {
logAgent.Printf("Creating new agent labels: agentID=%s", agentID)
return &AgentLabels{
AgentID: agentID,
Secrecy: NewSecrecyLabel(),
Expand All @@ -25,6 +30,8 @@ func NewAgentLabels(agentID string) *AgentLabels {

// NewAgentLabelsWithTags creates a new agent with initial tags
func NewAgentLabelsWithTags(agentID string, secrecyTags []Tag, integrityTags []Tag) *AgentLabels {
logAgent.Printf("Creating agent labels with tags: agentID=%s, secrecyTags=%v, integrityTags=%v",
agentID, secrecyTags, integrityTags)
return &AgentLabels{
AgentID: agentID,
Secrecy: NewSecrecyLabelWithTags(secrecyTags),
Expand All @@ -34,6 +41,7 @@ func NewAgentLabelsWithTags(agentID string, secrecyTags []Tag, integrityTags []T

// AddSecrecyTag adds a secrecy tag to the agent
func (a *AgentLabels) AddSecrecyTag(tag Tag) {
logAgent.Printf("Agent %s adding secrecy tag: %s", a.AgentID, tag)
a.mu.Lock()
defer a.mu.Unlock()
a.Secrecy.Label.Add(tag)
Expand All @@ -42,6 +50,7 @@ func (a *AgentLabels) AddSecrecyTag(tag Tag) {

// AddIntegrityTag adds an integrity tag to the agent
func (a *AgentLabels) AddIntegrityTag(tag Tag) {
logAgent.Printf("Agent %s adding integrity tag: %s", a.AgentID, tag)
a.mu.Lock()
defer a.mu.Unlock()
a.Integrity.Label.Add(tag)
Expand Down Expand Up @@ -132,10 +141,13 @@ func NewAgentRegistryWithDefaults(defaultSecrecy []Tag, defaultIntegrity []Tag)

// GetOrCreate gets an existing agent or creates a new one with default labels
func (r *AgentRegistry) GetOrCreate(agentID string) *AgentLabels {
logAgent.Printf("GetOrCreate called for agentID=%s", agentID)

Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

Line contains trailing whitespace on an otherwise blank line; please remove it (or run gofmt) to avoid noisy diffs and keep formatting consistent.

Suggested change

Copilot uses AI. Check for mistakes.
// Try to get existing agent first (read lock)
r.mu.RLock()
if labels, ok := r.agents[agentID]; ok {
r.mu.RUnlock()
logAgent.Printf("Found existing agent: %s", agentID)
return labels
}
r.mu.RUnlock()
Expand All @@ -146,6 +158,7 @@ func (r *AgentRegistry) GetOrCreate(agentID string) *AgentLabels {

// Double-check after acquiring write lock
if labels, ok := r.agents[agentID]; ok {
logAgent.Printf("Agent %s created by another goroutine", agentID)
return labels
Comment on lines 160 to 162
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

This debug log executes while holding r.mu (write lock). When DEBUG is enabled, logger.Printf performs I/O and can noticeably extend the critical section, increasing contention. Consider moving the log outside the locked section (e.g., capture the condition/labels, unlock, then log and return).

Copilot uses AI. Check for mistakes.
}

Expand Down
Loading