{{ message }}
Refactor DIFC pre-phase error handling into a shared guard helper#7760
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix duplicate code pattern in DIFC Pipeline error handling
Refactor DIFC pre-phase error handling into a shared guard helper
Jun 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors DIFC pre-phase denial handling to eliminate duplicated *guard.PipelineAccessDenied unpacking/formatting logic across the unified MCP server and the HTTP proxy, by centralizing classification + detailed violation formatting in guard.HandlePrePhaseError.
Changes:
- Added
guard.HandlePrePhaseError(err)to classifyRunPipelinePrePhaseserrors viaerrors.Asand produce a formatted DIFC violation error. - Updated unified MCP server denial handling to use the shared helper while continuing to return the detailed MCP error payload.
- Updated proxy denial handling to use the shared helper while preserving the existing short 403 body, and added guard-level tests for denied vs non-denied pre-phase errors.
Show a summary per file
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 on lines
208
to
212
| if denied, detailedErr := guard.HandlePrePhaseError(err); denied != nil { | ||
| logHandler.Printf("[DIFC] Phase 2: BLOCKED %s %s — %s", r.Method, path, denied.EvalResult.Reason) | ||
| deniedErr := fmt.Errorf("DIFC policy violation: %s", denied.EvalResult.Reason) | ||
| tracing.RecordSpanError(difcSpan, deniedErr, "access denied: "+denied.EvalResult.Reason) | ||
| tracing.RecordSpanError(difcSpan, detailedErr, "access denied: "+denied.EvalResult.Reason) | ||
| writeDIFCForbidden(w, deniedErr.Error()) |
Collaborator
|
@copilot address review feedback |
Contributor
Author
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.

RunPipelinePrePhasesdenial handling had drift-prone duplication in the unified MCP server and HTTP proxy. Both callers were separately unpacking*PipelineAccessDeniedand formatting denial responses from the same guard contract.Centralize pre-phase error classification
guard.HandlePrePhaseError(err)ininternal/guard/pipeline.goPipelineAccessDenieddetection and detailed DIFC violation formatting behind one helpererrors.Asso wrapped denial errors still resolve consistentlyKeep caller-specific response behavior
internal/server/unified.gonow uses the shared helper and continues returning the detailed formatted MCP errorinternal/proxy/handler.gonow uses the same helper while preserving the existing short HTTP 403 bodyTighten the guard contract with focused tests