Repository navigation
fix: skip permission notification when request is auto-approved - #98
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new pending-permission check can silently suppress notifications when the raw HTTP client is missing or the response shape is unexpected, breaking the intended fail-open behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the notifier plugin’s permission.asked handling to avoid spamming “Session needs permission” notifications when OpenCode auto-approves requests, by checking whether the specific permission request is still pending before notifying.
Changes:
- Added
getPermissionIDFromEventto extract the permission request ID from event payloads. - Introduced a short delay and a raw HTTP
/permissionlookup to detect whether the request is still pending. - Conditioned the permission notification on the request remaining pending (with an intended “fail-open” fallback).
File summaries
| File | Description |
|---|---|
| src/index.ts | Adds permission request ID extraction and conditional notification logic based on pending-permission lookup. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Is there an update on when this PR can be merged? Right now this bug can be a bit disruptive to auto-approved workflow. |
The pending check now runs before the shared 1s dedupe window is claimed, so a silently skipped auto-approved request no longer mutes a real request that arrives within the same second. Verified with a fake client: auto-approved stays silent, pending notifies, every fail-open path notifies, a real request 250ms after an auto-approved one still notifies, and hook+event for the same request delivers exactly one notification.
|
Quick update on the current head ( Automated checks: Fail-open behavior corrected (per the Copilot review): the pending check now defaults to "notify" and suppresses only when the pending list is fetched successfully and the request ID is absent. A missing raw client or an unexpected response shape no longer silently swallows notifications. Dedupe ordering fixed: the shared permission dedupe window is now claimed only when a notification is actually about to fire. Previously an auto-approved request silently consumed that window, so a request that genuinely needed approval and arrived within the same second was deduped away and never notified. The decision logic was verified by driving the real
Two limitations worth flagging explicitly so expectations are clear:
The 300 ms grace window is a heuristic: auto-approved requests are resolved immediately by the server, so a request still pending after that delay is treated as a real one. It is deliberately not configurable to keep the change minimal. |
|
@nghiant03 Not merged yet, but you can already run it from your own fork: gh repo fork mohak34/opencode-notifier --clone
cd opencode-notifier
gh pr checkout 98 --repo mohak34/opencode-notifier
bun install
bun run buildThen back up Heads-up: an |
Follow-up to mohak34#98: the inline pending-list probe becomes an exported isPermissionStillPending helper (fail-open on every lookup failure), the 300ms grace becomes a named constant, getPermissionIDFromEvent is exported, and the author's claimed decision matrix is now covered by tests against stub clients.
Fixes #94
Problem
When OpenCode's auto-approve mode is enabled, permission requests are resolved automatically and instantly. The notifier plugin still fired a "Session needs permission" notification for every such request, which spams the user even though no manual approval is needed.
Root cause
The plugin notified unconditionally on the permission.asked event. It had no way to distinguish between:
An initial attempt to check pending state via the SDK client failed at runtime: the plugin is handed a v1 SDK client (PluginInput["client"]) which exposes no permission.list / client.permission.request.list API, so the pending lookup threw a TypeError and the notification was silently skipped in all cases — including the pending case where it was actually needed.
Solution
On permission.asked:
Result:
Notes
Session needs permissionnotification is gone, and with auto-approve disabled it still fires.questionandcompletenotifications are unaffected, as expected.