Skip to content

Deduplicate Phase 5 DIFC collection filtering across unified server and proxy#7759

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-filtering-logic
Jun 19, 2026
Merged

Deduplicate Phase 5 DIFC collection filtering across unified server and proxy#7759
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-filtering-logic

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Phase 5 DIFC collection filtering had the same enforcement flow implemented independently in internal/server/unified.go and internal/proxy/handler.go, creating a high-risk divergence point. This change centralizes filtering/blocking decisions while preserving each caller’s response-shaping behavior.

  • What changed

    • Added shared Phase 5 helper in internal/difc/pipeline_decisions.go:
      • FilterAndConvertLabeledData(...)
      • FilterResult (final result, filtered collection metadata, strict-mode block decision)
    • Moved common logic into this helper:
      • detect collection-labeled responses
      • run FilterCollection(...)
      • apply ShouldBlockFilteredResponse(...)
      • convert filtered/simple labeled data via ToResult()
  • Unified server refactor (internal/server/unified.go)

    • Replaced inline Phase 5 branch tree with the shared helper call.
    • Retained server-specific behavior:
      • MCP error response formatting on strict block
      • singular-read-tool filtered-singleton optimization
      • existing filtered-item logging and notice behavior
  • Proxy refactor (internal/proxy/handler.go)

    • Replaced duplicated Phase 5 filtering decisions with the shared helper.
    • Removed local toResultOrWriteEmpty helper now made redundant.
    • Retained proxy-specific behavior:
      • HTTP 403 DIFC forbidden response path
      • GraphQL original-body passthrough vs rebuild behavior
      • search envelope rewrap / single-object unwrap paths
  • Coverage updates (internal/difc/pipeline_decisions_test.go)

    • Added focused tests for shared helper behavior in:
      • strict (block on filtered items)
      • filter (partial result)
      • propagate (partial result, no strict block)
      • nil/simple labeled data conversion
      • conversion error propagation
filterResult, err := difc.FilterAndConvertLabeledData(
    evaluator,
    pre.AgentLabels.Secrecy,
    pre.AgentLabels.Integrity,
    pre.Operation,
    labeledData,
    enforcementMode,
)
if err != nil { /* caller-specific error handling */ }
if filterResult.Blocked { /* strict-mode deny response */ }
finalResult := filterResult.FinalResult

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
GitHub Advanced Security started work on behalf of lpcox June 19, 2026 04:30 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 04:31
Copilot AI changed the title [WIP] Fix duplicate code pattern in Phase 5 collection filtering logic Deduplicate Phase 5 DIFC collection filtering across unified server and proxy 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
@lpcox lpcox marked this pull request as ready for review June 19, 2026 13:48
Copilot AI review requested due to automatic review settings June 19, 2026 13:48

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 Phase 5 DIFC fine-grained collection filtering decisions into a shared helper to reduce duplication and prevent drift between the unified MCP server and the HTTP proxy while preserving each caller’s response-shaping behavior.

Changes:

  • Added difc.FilterAndConvertLabeledData(...) + difc.FilterResult to encapsulate “is this a collection?”, filtering, strict-mode block decision, and ToResult() conversion.
  • Refactored unified server and proxy handlers to use the shared helper while keeping their caller-specific denial/response behavior (MCP error vs HTTP 403; GraphQL passthrough/rebuild; envelope wrapping).
  • Added unit tests for the shared helper in internal/difc/pipeline_decisions_test.go.
Show a summary per file
File Description
internal/server/unified.go Replaces inline Phase 5 branch logic with the shared helper while preserving strict-block and server-specific filtered-item handling.
internal/proxy/handler.go Removes duplicated Phase 5 conversion/filtering decisions and uses the shared helper while preserving proxy response shaping.
internal/difc/pipeline_decisions.go Introduces shared Phase 5 helper and result struct for filtering/blocking/conversion decisions.
internal/difc/pipeline_decisions_test.go Adds targeted tests for the new shared helper behavior.

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/difc/pipeline_decisions_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 19, 2026 14:34 View session
GitHub Advanced Security finished work on behalf of lpcox June 19, 2026 14:35
@lpcox lpcox merged commit da5dd40 into main Jun 19, 2026
27 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-filtering-logic 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