Skip to content

fix: deduplicate identical permission prompts in same session - #42244

Open
weiconghe wants to merge 1 commit into
anomalyco:devfrom
weiconghe:fix/permission-dedup
Open

fix: deduplicate identical permission prompts in same session#42244
weiconghe wants to merge 1 commit into
anomalyco:devfrom
weiconghe:fix/permission-dedup

Conversation

@weiconghe

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #41849

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Problem: When two identical permission requests (same sessionID, permission, and patterns) 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.ask in packages/opencode/src/permission/index.ts generates a new unique request ID and adds it to the pending map 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 pending map for an entry with the same (sessionID, permission, patterns). If found, await the existing entry's Deferred instead 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"] vs bash ["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:

  • New: "ask - deduplicates identical permission requests in same session" — two identical asks produce only 1 pending request; a single reply resolves both callers.
  • New: "ask - does not deduplicate requests with different patterns" — two asks with different patterns (["ls"] vs ["rm"]) produce 2 pending requests as before.
  • Updated: "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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate permission prompts in the same second are not deduplicated

1 participant