Deduplicate Phase 5 DIFC collection filtering across unified server and proxy#7759
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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.FilterResultto encapsulate “is this a collection?”, filtering, strict-mode block decision, andToResult()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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 5 DIFC collection filtering had the same enforcement flow implemented independently in
internal/server/unified.goandinternal/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
internal/difc/pipeline_decisions.go:FilterAndConvertLabeledData(...)FilterResult(final result, filtered collection metadata, strict-mode block decision)FilterCollection(...)ShouldBlockFilteredResponse(...)ToResult()Unified server refactor (
internal/server/unified.go)Proxy refactor (
internal/proxy/handler.go)toResultOrWriteEmptyhelper now made redundant.Coverage updates (
internal/difc/pipeline_decisions_test.go)strict(block on filtered items)filter(partial result)propagate(partial result, no strict block)