Skip to content

[log] log: add debug logging to difc/agent.go#1461

Merged
lpcox merged 1 commit into
mainfrom
log/difc-agent-debug-logging-9d23749c6f6b0c4f
Feb 28, 2026
Merged

[log] log: add debug logging to difc/agent.go#1461
lpcox merged 1 commit into
mainfrom
log/difc-agent-debug-logging-9d23749c6f6b0c4f

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Adds 6 meaningful logAgent debug logging calls to internal/difc/agent.go, covering functions that previously lacked debug tracing.

Changes

File modified: internal/difc/agent.go

Reuses the existing var logAgent = logger.New("difc:agent") logger (no new imports needed) and adds logging to:

Function Log added
DropIntegrityTag Logs the tag being dropped before deletion
AccumulateFromRead Logs entry with agent ID and resource description
NewAgentRegistry Logs registry creation
Get Logs lookup with agentID and found/not-found result
Register Logs explicit label registration with all tag details
Remove Logs agent removal at entry

Quality checklist

  • Exactly 1 file modified
  • No test files modified
  • Existing logAgent logger reused (no duplicate declaration)
  • Logger naming follows pkg:filename convention (difc:agent)
  • Log arguments are simple field accesses — no function calls or side effects
  • Messages are meaningful and useful for debugging DIFC label tracking
  • No duplicate logging with existing log calls

Debugging value

These additions enable developers to trace DIFC label lifecycle with DEBUG=difc:*:

  • Track when agents drop integrity tags (security-relevant mutation)
  • Observe label accumulation from resource reads
  • Monitor agent registry operations (create, lookup, register, remove)

Generated by Go Logger Enhancement

Add logAgent debug logging to six functions in AgentLabels and
AgentRegistry that previously lacked debug tracing:

- DropIntegrityTag: log tag being dropped before deletion
- AccumulateFromRead: log resource description at entry
- NewAgentRegistry: log registry creation
- Get: log lookup result (agentID and found status)
- Register: log explicit label registration at entry
- Remove: log agent removal at entry

All new log calls reuse the existing logAgent variable and follow
the pkg:filename naming convention. Log arguments are simple field
accesses with no side effects.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added automation enhancement New feature or request labels Feb 27, 2026
@lpcox
lpcox marked this pull request as ready for review February 28, 2026 04:30
Copilot AI review requested due to automatic review settings February 28, 2026 04:30
@lpcox
lpcox merged commit 4b1c9e3 into main Feb 28, 2026
4 checks passed
@lpcox
lpcox deleted the log/difc-agent-debug-logging-9d23749c6f6b0c4f branch February 28, 2026 04:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds 6 logAgent debug logging calls to internal/difc/agent.go, covering functions that previously lacked tracing via the DEBUG=difc:* mechanism. It reuses the existing var logAgent = logger.New("difc:agent") logger and adds entry-point logs to DropIntegrityTag, AccumulateFromRead, NewAgentRegistry, Get, Register, and Remove.

Changes:

  • Adds debug log before lock acquisition in DropIntegrityTag and AccumulateFromRead
  • Adds a debug log at the start of NewAgentRegistry
  • Adds debug logs to Get, Register, and Remove registry methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/difc/agent.go
Comment on lines 181 to 182
defer r.mu.RUnlock()
labels, ok := r.agents[agentID]

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

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

The log statement in Get is placed after the map read and before return, meaning it runs while r.mu.RLock() is still held (the deferred RUnlock hasn't fired yet). Every other logging call in this file that involves locks — AddSecrecyTag, AddIntegrityTag, DropIntegrityTag, AccumulateFromRead, Register, Remove — logs before acquiring the lock. For consistency and to minimize the time the read lock is held, the log call should be moved to before r.mu.RLock(). The values agentID, and ok can still be logged if ok is captured before the early return: log before locking (at entry), report found/not-found after reading but before logging — or simply move the log before the lock like all other functions do.

Suggested change
defer r.mu.RUnlock()
labels, ok := r.agents[agentID]
labels, ok := r.agents[agentID]
r.mu.RUnlock()

Copilot uses AI. Check for mistakes.
Comment thread internal/difc/agent.go

// NewAgentRegistry creates a new agent registry
func NewAgentRegistry() *AgentRegistry {
logAgent.Print("Creating new agent registry")

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

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

NewAgentRegistry now has a log call added, but its sibling constructor NewAgentRegistryWithDefaults (line 137, just below) does not. In the test suite, NewAgentRegistryWithDefaults is used exclusively, so debugging registry creation via DEBUG=difc:* will produce no output for the most commonly used code path. For consistent observability, a matching log call should be added to NewAgentRegistryWithDefaults as well.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants