Skip to content

fix(opencode): resolve permission blocks on reply in OpenCode 1 - #7596

Merged
Meraj-08 merged 2 commits into
OrchestratorInc:mainfrom
ApexYash11:fix/7564-opencode-permission-resolved
Nov 9, 2026
Merged

Meraj-08 merged 2 commits into
OrchestratorInc:mainfrom
ApexYash11:fix/7564-opencode-permission-resolved

Conversation

@ApexYash11

Copy link
Copy Markdown
Collaborator

Code changes: +10 -5
Tests: +7 -0
Others: +0 -0

Problem

On OpenCode 1, answering a permission or question prompt (approve or reject) left the AO session blocked in Needs You until the whole turn ended. Everything delivered to the session in that window was refused.

The plugin forwarded the reply as generic active, but the lifecycle tool-flight precedence deliberately suppresses generic active while a dialog is open (it must not let sibling tool traffic clear a live dialog), and the OpenCode payload carries no tool identity, so no correlated tool post could clear it either. Only a turn-boundary event lifts the block.

Fix

  • The plugin now reports permission.replied, question.replied, and question.rejected as permission-resolved — the same turn-boundary event the OpenCode 2 plugin already emits — instead of generic active.
  • The OpenCode 1 deriver maps permission-resolved to active. The lifecycle reducer already treats that event as definitive, so the block clears as soon as the user answers, and the session returns to idle at the turn end.

Verification

  • go test ./internal/adapters/agent/opencode/...
  • Deriver table test covers the new mapping; the installed-plugin test asserts the reply handler emits permission-resolved and that the event is wired through ao hooks opencode.
  • The manager-side sequence (blocked → suppressed active → permission-resolved → active) is already pinned by TestToolPrecedence_DefinitivePermissionResolutionClearsBlocked.

Fixes #7564

OpenCode 1 reported permission/question replies as generic `active`, which the lifecycle tool-flight precedence suppresses while the session is blocked, so a session stayed in Needs You until the turn ended. Report `permission-resolved` (the turn-boundary event the OpenCode 2 plugin already emits) and map it to active in the OpenCode 1 deriver.

Fixes OrchestratorInc#7564
@OrcInc OrcInc added bug Something isn't working comp/daemon Go daemon, process lifecycle, and backend control plane. labels Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🏆 Review leaderboard

Oct 26, 2026–Nov 2, 2026 · UTC

Rank Reviewer PRs reviewed Review rounds PR comments
🥇 @Vaibhaav-Tiwari @Vaibhaav-Tiwari 50 76 23
🥈 @ronishrohan @ronishrohan 45 82 16
🥉 @illegalcall @illegalcall 12 22 1
4 @neversettle17-101 @neversettle17-101 10 17 1
5 @nikhilachale @nikhilachale 9 56 6
6 @Rishet11 @Rishet11 9 11 141
7 @somewherelostt @somewherelostt 8 18 3
8 @Pritom14 @Pritom14 8 11 8
9 @Prasad-D-Ware @Prasad-D-Ware 8 11 0
10 @Meraj-08 @Meraj-08 7 17 5

Ranked by distinct external PRs reviewed, then review rounds, then PR comments. Self-activity and bot activity are excluded.

Show 7 more reviewers
Rank Reviewer PRs reviewed Review rounds PR comments
11 @ApexYash11 @ApexYash11 6 22 2
12 @mohakchakraborty2004 @mohakchakraborty2004 5 5 0
13 @harshitsinghbhandari @harshitsinghbhandari 4 8 0
14 @Annieeeee11 @Annieeeee11 3 7 0
15 @codebanditssss @codebanditssss 2 2 1
16 @AgentWrapper @AgentWrapper 2 2 0
17 @Vansh-Singhal @Vansh-Singhal 1 1 1

@OrcInc OrcInc added this to the Agents & orchestration milestone Nov 2, 2026

@Meraj-08 Meraj-08 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the single-prompt case works: on real OpenCode 1.18.18, answering "Allow once" now returns the session to active within 2s and ao send is delivered, where main stays blocked and refuses it. Reject behaves the same as before.

[P1] With two prompts open, the first reply lets AO type into the second dialog. When the model makes two bash calls in one step, OpenCode 1 shows a second permission prompt after the first is answered. On c0285d65c9, the first reply moves the session to active while that prompt is still on screen, so ao send is accepted and its keystrokes go into the dialog. The message never reached the agent, and the dialog moved to OpenCode's "Allow always" confirmation for whoami *, one Enter away from a standing grant. main refuses the send in this state. Could the plugin track open asks by their request id and send permission-resolved only once none remain?

OpenCode can hold several permission/question dialogs at once. The plugin
reported every reply, so answering the first of two prompts sent AO back to
active while the second dialog was still on screen - `ao send` was accepted
again and its keystrokes typed into that dialog instead of reaching the
agent. The plugin now tracks open asks by their request id and emits the
turn-boundary permission-resolved event only when the last dialog closes;
while one remains open there is no report, the session stays blocked, and
AO keeps refusing sends. Replies that carry no matching id fall back to
closing the oldest tracked ask.

Addresses the review P1 on PR OrchestratorInc#7596.
@ApexYash11

ApexYash11 commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

Addressed the P1 in 89c44aa: the plugin now tracks open asks by their request id (openAsks) and emits permission-resolved only once none remain, so with two prompts open the first reply no longer moves the session to active - it stays blocked, ao send keeps being refused, and the turn-boundary report fires when the last dialog closes. Details: ask ids are read as permissionID ?? requestID ?? id (permission.* on 1.x carries permissionID on ask and reply); a reply matching no tracked ask falls back to closing the oldest one (covers short payloads and a plugin restart between ask and reply, and stays strictly stricter than reporting every reply); the set is cleared on session switch and on stop so stale state cannot suppress the next turn's resolve. TestGetAgentHooksInstallsPlugin now pins the tracking markers, and the embedded plugin transpiles cleanly under Bun. One follow-up worth its own PR: the OpenCode 2 plugin has the same two-dialog shape on main (it emits permission-resolved per reply, ids available as data.id/data.requestID) - happy to do that separately.

@ApexYash11
ApexYash11 requested a review from Meraj-08 November 8, 2026 15:06

@Meraj-08 Meraj-08 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Reviewed through 89c44aa355 on real OpenCode 1.18.18: with two prompts open, answering the first now keeps the session blocked and ao send refused until the second is answered, and a single prompt still returns to active within 2s.

@Meraj-08
Meraj-08 merged commit 4b082ed into OrchestratorInc:main Nov 9, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working comp/daemon Go daemon, process lifecycle, and backend control plane.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(opencode): approving a permission leaves the session stuck in Needs You until the turn ends

3 participants