Skip to content

Refactor duplicate label-agent guard initialization into shared helper#7758

Merged
lpcox merged 4 commits into
mainfrom
copilot/duplicate-code-guard-policy-initialization
Jun 19, 2026
Merged

Refactor duplicate label-agent guard initialization into shared helper#7758
lpcox merged 4 commits into
mainfrom
copilot/duplicate-code-guard-policy-initialization

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

internal/server/guard_init.go and internal/proxy/proxy.go both implemented the same two-step label-agent init flow (BuildLabelAgentPayload + RunLabelAgentForAgent), with small argument drift over time. This PR centralizes that flow to reduce API-change risk and keep server/proxy behavior aligned.

  • Shared guard init abstraction

    • Added guard.RunLabelAgentInit(...) in internal/guard/label_agent.go.
    • Encapsulates payload construction and label-agent execution in one call.
  • Server path now uses shared helper

    • Replaced direct RunLabelAgentForAgent(...) invocation in internal/server/guard_init.go.
    • Preserves existing semantics: server still passes trustedUsers=nil, and session policy-hash caching remains unchanged.
  • Proxy path now uses shared helper

    • Replaced inline payload-build + run sequence in internal/proxy/proxy.go.
    • Keeps proxy-specific behavior intact, including explicit trustedUsers injection and mode override handling.
  • Focused unit coverage

    • Added/updated guard tests to validate that the helper:
      • injects trusted-bots and trusted-users correctly,
      • preserves existing allow-only policy fields.
mode, result, err := guard.RunLabelAgentInit(
    ctx, g, policy, trustedBots, trustedUsers,
    backend, caps, registry, agentID, defaultMode,
)

GitHub Advanced Security started work on behalf of lpcox June 19, 2026 04:25 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 04:26
Copilot AI changed the title [WIP] Refactor duplicate guard policy initialization code Refactor duplicate label-agent guard initialization into shared helper Jun 19, 2026
Copilot finished work on behalf of lpcox June 19, 2026 04:33
Copilot AI requested a review from lpcox June 19, 2026 04:33
GitHub Advanced Security started work on behalf of lpcox June 19, 2026 04:41 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 04:42
GitHub Advanced Security started work on behalf of lpcox June 19, 2026 04:42 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 04:44
@lpcox lpcox marked this pull request as ready for review June 19, 2026 13:47
Copilot AI review requested due to automatic review settings June 19, 2026 13:47

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 centralizes the common “build label_agent payload + execute LabelAgent for an agent” initialization sequence into a shared helper in internal/guard, then updates both the unified server guard-init path and the proxy guard-init path to use it to keep behavior aligned and reduce drift risk.

Changes:

  • Added guard.RunLabelAgentInit(...) to encapsulate BuildLabelAgentPayload(...) + RunLabelAgentForAgent(...).
  • Updated server (internal/server/guard_init.go) and proxy (internal/proxy/proxy.go) to call the shared helper instead of duplicating the sequence.
  • Added unit coverage to ensure the helper produces payloads that correctly inject trusted-bots and trusted-users while preserving existing policy fields.
Show a summary per file
File Description
internal/server/guard_init.go Switches unified server guard initialization to call the shared label-agent init helper.
internal/proxy/proxy.go Replaces inline payload-build + label-agent run with the shared helper, preserving proxy-specific inputs.
internal/guard/label_agent.go Introduces RunLabelAgentInit helper that composes payload creation and agent label initialization.
internal/guard/init_test.go Extends guard init tests to validate helper-driven payload construction and execution wiring.

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/server/guard_init.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 19, 2026 14:34 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 14:35
@lpcox lpcox merged commit 90dd325 into main Jun 19, 2026
27 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-guard-policy-initialization branch June 19, 2026 14:50
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