fix: deduplicate identical permission prompts in same session - #42244
Open
weiconghe wants to merge 1 commit into
Open
fix: deduplicate identical permission prompts in same session#42244weiconghe wants to merge 1 commit into
weiconghe wants to merge 1 commit into
Conversation
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.
Issue for this PR
Closes #41849
Type of change
What does this PR do?
Problem: When two identical permission requests (same
sessionID,permission, andpatterns) arrive within the same second, each creates an independent pending prompt. The user has to answer every duplicate individually — the reporter measured 141 groups of duplicates, worst case 5 identical prompts in a row.Root cause:
Permission.askinpackages/opencode/src/permission/index.tsgenerates a new unique request ID and adds it to thependingmap on every call, without checking whether an equivalent request is already pending. Both prompts block independently, so answering one does not dismiss the other.Fix: Before creating a new request, scan the
pendingmap for an entry with the same(sessionID, permission, patterns). If found, await the existing entry'sDeferredinstead of creating a duplicate. When the user responds — approve, reject, or "always" — all waiters proceed together via the shared deferred.The dedup key is
(sessionID, permission, patterns). Requests with different patterns (e.g.bash ["ls"]vsbash ["rm"]) or from different sessions are not deduplicated.How did you verify your code works?
Ran
bun test test/permission/next.test.ts— all 81 tests pass, including:"ask - deduplicates identical permission requests in same session"— two identical asks produce only 1 pending request; a single reply resolves both callers."ask - does not deduplicate requests with different patterns"— two asks with different patterns (["ls"]vs["rm"]) produce 2 pending requests as before."reply - always resolves matching pending requests in same session"— adjusted to use different patterns (["ls"]/["rm"]) so the cascade behavior is still tested without being deduplicated.Screenshots / recordings
N/A
Checklist