Skip to content

Centralize coarse DIFC denial construction - #16755

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-fix-difc-denial
Nov 18, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-fix-difc-denial

Conversation

@lpcox

@lpcox lpcox commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Tool and prompt handlers duplicated coarse DIFC denial construction and formatting, risking drift from the canonical guard path.

  • Shared helper: Add guard.CoarseDenialError(pre) to construct the denial and reuse HandlePrePhaseError for formatting.
  • Server callers: Replace both duplicated blocks while preserving audit logging and caller-specific error responses. Leave the proxy unchanged.
  • Regression coverage: Verify denial field preservation and canonical error formatting.

@lpcox lpcox changed the title [WIP] Fix duplicate code pattern in server handlers Centralize coarse DIFC denial construction Nov 18, 2026
@lpcox
lpcox marked this pull request as ready for review November 18, 2026 15:33
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 15:33
@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

The assert.EqualError at internal/guard/pipeline_test.go:338 is followed by more statements, violating the enabled testifylint require-error check and causing lint to fail.

1 open issue
What changed in this PR

Centralizes coarse DIFC denial construction in the guard package, addressing #16692 and reducing duplication between tool and prompt handlers.

Changes:

  • Adds guard.CoarseDenialError, reusing canonical error formatting.
  • Updates both server handlers while preserving audit logging and caller-specific responses; leaves the proxy unchanged.
  • Adds regression coverage for denial fields and formatted errors.
File Description
internal/​server/​prompt_call.go Uses the shared helper for coarse prompt denials.
internal/​server/​backend_call.go Uses the shared helper while preserving tool error responses.
internal/​guard/​pipeline.go Adds the shared denial-construction helper.
internal/​guard/​pipeline_test.go Tests field preservation and canonical error formatting.

Review effort: Max (adaptive)

Comment thread internal/guard/pipeline_test.go Resolved
@lpcox

lpcox commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback and fix failing ci lint check

Copilot AI commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback and fix failing ci lint check

Updated to require.EqualError; make agent-finished passes. Commit: HASH.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads data returned (issues, PRs, README, commits) ALLOWED ✅
B MCP writes (star/issue/comment/branch/file/PR) all 6 targets absent from 23-tool catalog ("unknown tool") BLOCKED ⚠️
C CLI reads data returned via github CLI proxy ALLOWED ✅
D CLI REST writes gh CLI unauthenticated (no GH_TOKEN) BLOCKED ⚠️
E CLI GraphQL mutations gh CLI unauthenticated (no GH_TOKEN) BLOCKED ⚠️

Overall: INCONCLUSIVE

No write leaked on any surface. Part B gap: all 6 write-tool targets (star_repository, issue_write, add_issue_comment, create_branch, create_or_update_file, create_pull_request) were absent from the exposed 23-tool catalog, which confirms backend GITHUB_READ_ONLY=1 config but does not independently confirm mcpg's own gateway-level DIFC/guard write-blocking layer. Parts D/E gap: gh CLI had no GH_TOKEN in this environment, so the GitHub-API token-scope boundary could not be exercised. Results saved to /tmp/gh-aw/agent/readonly-stress-44340607262.txt and /tmp/gh-aw/agent/readonly-stress-result-44340607262.txt.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit 42e0e2c into main Nov 18, 2026
28 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-fix-difc-denial branch November 18, 2026 16:02
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.

[duplicate-code] Duplicate Code Pattern: DIFC Coarse-Denial Construction in Server Handlers

3 participants