Skip to content

Deduplicate LogMarshaledForDebug callback wiring with formatted helper#7631

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-logmarshaledfordebug
Jun 16, 2026
Merged

Deduplicate LogMarshaledForDebug callback wiring with formatted helper#7631
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-logmarshaledfordebug

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

logger.LogMarshaledForDebug was used with near-identical success/failure callback blocks in three guard/server paths, creating avoidable duplication and drift risk in debug logging behavior. This change centralizes that wiring while preserving per-call-site message text and log level behavior.

  • What changed

    • Added logger.LogMarshaledForDebugf in internal/logger/rpc_helpers.go to standardize marshal-success / marshal-failure callback dispatch for formatted log functions.
    • Replaced three duplicated callback blocks with helper calls:
      • internal/guard/wasm.go (normalized policy log, parsed response log)
      • internal/server/guard_init.go (label_agent response log)
    • Added focused unit coverage for the new helper in internal/logger/rpc_helpers_test.go (success and marshal-failure formatting paths).
  • Design intent

    • Keep log message templates local to call sites.
    • Centralize only the callback/argument-plumbing pattern around JSON marshal-for-debug logging.
logger.LogMarshaledForDebugf(
    labelAgentResult,
    func(format string, args ...interface{}) {
        logger.LogInfoToServer(serverID, "difc", format, args...)
    },
    "label_agent response: session=%s, guard=%s, response=%s",
    func(format string, args ...interface{}) {
        logger.LogWarnToServer(serverID, "difc", format, args...)
    },
    "label_agent response (failed to serialize for logging): session=%s, guard=%s, error=%v",
    sessionID, g.Name(),
)

GitHub Advanced Security started work on behalf of lpcox June 16, 2026 17:05 View session
GitHub Advanced Security finished work on behalf of lpcox June 16, 2026 17:07
Copilot AI changed the title [WIP] Refactor duplicate LogMarshaledForDebug callback structure Deduplicate LogMarshaledForDebug callback wiring with formatted helper Jun 16, 2026
Copilot finished work on behalf of lpcox June 16, 2026 17:14
Copilot AI requested a review from lpcox June 16, 2026 17:14
@lpcox lpcox marked this pull request as ready for review June 16, 2026 17:14
Copilot AI review requested due to automatic review settings June 16, 2026 17:14
GitHub Advanced Security started work on behalf of lpcox June 16, 2026 17:15 View session
GitHub Advanced Security finished work on behalf of lpcox June 16, 2026 17:17

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 reduces duplicated debug-logging callback wiring around logger.LogMarshaledForDebug by introducing a formatted helper (LogMarshaledForDebugf) and migrating the existing call sites in guard/server paths to use it, while keeping message templates local to each call site.

Changes:

  • Added logger.LogMarshaledForDebugf to centralize the marshal-success / marshal-failure formatted-callback plumbing.
  • Updated guard/session initialization and WASM guard logging paths to use the new helper instead of duplicating callbacks.
  • Added unit tests covering success and marshal-failure behavior for LogMarshaledForDebugf.
Show a summary per file
File Description
internal/server/guard_init.go Replaces inline marshal success/failure callbacks with LogMarshaledForDebugf for label_agent response logging.
internal/logger/rpc_helpers.go Introduces LogMarshaledForDebugf, built on top of LogMarshaledForDebug, to standardize formatted callback wiring.
internal/logger/rpc_helpers_test.go Adds focused unit tests for the new formatted helper’s success and failure paths.
internal/guard/wasm.go Deduplicates guard policy/response debug logging by switching to LogMarshaledForDebugf with logWasm.Printf.

Copilot's findings

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Comment thread internal/logger/rpc_helpers_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox June 16, 2026 17:18 View session
GitHub Advanced Security finished work on behalf of lpcox June 16, 2026 17:19
@lpcox lpcox merged commit 208e947 into main Jun 16, 2026
26 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-logmarshaledfordebug branch June 16, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants