Skip to content

Conversation

@connor4312
Copy link
Member

When approving requests and responses for a domain separately, the second approval would overwrite the first instead of merging them.

Fixes #286107

When approving requests and responses for a domain separately, the
second approval would overwrite the first instead of merging them. This
happened because _approvePattern was replacing the entire settings
object rather than merging the new approval flags with existing ones.

Now when approving a pattern, we preserve any existing approvals and
merge the new approval flags using OR logic, so both approveRequest and
approveResponse can be true simultaneously.

- Modified _approvePattern to check for and merge existing settings
- Uses OR logic to combine new flags with existing approvals
- Preserves both request and response approvals when set separately

Fixes #286107

(Commit message generated by Copilot)
Copilot AI review requested due to automatic review settings January 6, 2026 21:16
@vs-code-engineering vs-code-engineering bot added this to the December 2025 milestone Jan 6, 2026
Copy link
Contributor

Copilot AI left a comment

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 fixes a bug in the chat URL fetching approval system where approving requests and responses for the same domain separately would overwrite previous approvals instead of merging them. The fix implements proper merge logic that preserves existing approvals when adding new ones.

Key Changes:

  • Added merge logic to combine existing URL approval settings with new approvals using OR operations
  • Properly handles both boolean and object-based approval settings when merging
  • Ensures that once a request or response is approved for a pattern, it remains approved

Comment on lines +239 to 260
// Merge with existing settings for this pattern
const existingSettings = approvedUrls[pattern];
let existingRequest = false;
let existingResponse = false;
if (typeof existingSettings === 'boolean') {
existingRequest = existingSettings;
existingResponse = existingSettings;
} else if (existingSettings) {
existingRequest = existingSettings.approveRequest ?? false;
existingResponse = existingSettings.approveResponse ?? false;
}

const mergedRequest = approveRequest || existingRequest;
const mergedResponse = approveResponse || existingResponse;

// Create the approval settings
let value: boolean | IUrlApprovalSettings;
if (approveRequest === approveResponse) {
value = approveRequest;
if (mergedRequest === mergedResponse) {
value = mergedRequest;
} else {
value = { approveRequest, approveResponse };
value = { approveRequest: mergedRequest, approveResponse: mergedResponse };
}
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The merge logic for URL approval settings should have test coverage. This bug fix addresses a critical issue where sequential approvals would overwrite each other instead of merging. Consider adding tests that verify:

  1. Approving requests then responses results in both being approved
  2. Approving responses then requests results in both being approved
  3. The boolean optimization works (when both are true, stores as true instead of {approveRequest: true, approveResponse: true})
  4. Merging works correctly when starting from a boolean value

Copilot uses AI. Check for mistakes.
@connor4312 connor4312 merged commit 5a569e3 into main Jan 6, 2026
27 of 28 checks passed
@connor4312 connor4312 deleted the connor4312/286107 branch January 6, 2026 21:43
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.

Choosing Allow response from domain.com removes the Allow request

3 participants