Skip to content

.NET: fix: resolve CA1873 in GitHubCopilotAgent by using LoggerMessage sour…#6815

Merged
alliscode merged 1 commit into
microsoft:mainfrom
alliscode:bentho/fix-ca1873-github-copilot-logger
Jun 30, 2026
Merged

.NET: fix: resolve CA1873 in GitHubCopilotAgent by using LoggerMessage sour…#6815
alliscode merged 1 commit into
microsoft:mainfrom
alliscode:bentho/fix-ca1873-github-copilot-logger

Conversation

@alliscode

Copy link
Copy Markdown
Member

This pull request makes a minor update to the ConvertToAgentResponseUpdate method in GitHubCopilotAgent.cs. The change ensures that warning logs about approval gating being skipped due to a custom hook are only emitted if the logger is configured to show warnings, preventing unnecessary log output.

  • Logging improvements:
    • Added a check for logger.IsEnabled(LogLevel.Warning) before logging a warning when a custom OnPreToolUse hook is present, ensuring that warnings are only logged if enabled.

…ce generator

Replace the direct logger.LogWarning() call (which eagerly evaluates
string.Join()) with a [LoggerMessage]-generated extension method in
GitHubCopilotAgentLogMessages.cs.

Fixes build error:
  GitHubCopilotAgent.cs(580,13): error CA1873: Evaluation of this argument
  may be expensive and unnecessary if logging is disabled

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 30, 2026 02:06
@moonbox3 moonbox3 added the .NET Usage: [Issues, PRs], Target: .Net label Jun 30, 2026
@github-actions github-actions Bot changed the title fix: resolve CA1873 in GitHubCopilotAgent by using LoggerMessage sour… .NET: fix: resolve CA1873 in GitHubCopilotAgent by using LoggerMessage sour… Jun 30, 2026
@alliscode alliscode merged commit fdc7107 into microsoft:main Jun 30, 2026
30 checks passed

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 tightens warning logging in the .NET GitHub Copilot agent so that the “approval gating skipped due to custom hook” warning is only emitted when warning-level logging is enabled, avoiding unnecessary work when warnings are filtered out.

Changes:

  • Added a logger.IsEnabled(LogLevel.Warning) guard around the approval-gating warning log call.
  • Ensures the string.Join(...) for tool names is only computed when warning logs will be emitted.
Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs Guards a warning log emission to avoid unnecessary allocations/work when warning logging is disabled.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment on lines 576 to +581
// A caller-supplied OnPreToolUse hook takes precedence and is fully responsible for approval handling.
// Warn so the developer knows the ApprovalRequiredAIFunction marker(s) will not be automatically gated.
if (sessionConfig.Hooks?.OnPreToolUse is not null)
{
logger.LogApprovalGatingSkippedDueToCustomHook(
approvalRequiredToolNames.Count,
string.Join(", ", approvalRequiredToolNames));
if (logger.IsEnabled(LogLevel.Warning))
{

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 5 | Confidence: 94% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by alliscode's agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants