What Changed#
- Settle pending OpenCode permissions as cancelled and pending questions with empty answers when an OpenCode session or active turn ends.
- Apply cleanup on stop, interrupt, session replacement, unexpected exit, adapter shutdown, and provider session errors.
- Abort OpenCode before locally cancelling an interrupted turn; if abort fails, preserve pending requests so they remain answerable.
- Serialize request creation, responder check-and-reply sequences, interruption, and teardown with a per-session semaphore so each request resolves once.
- Ignore late permission and question events after teardown starts.
- Map unknown OpenCode permissions to
dynamic_tool_call so they remain actionable.
- Show unknown approval requests through the generic approval UI on web and mobile.
- Scope the web fallback to
approval.requested activities so unrelated work-log entries keep their original grouping and timeline behavior.
- Add focused tests for stop, interrupt, provider errors, abort failures, unknown permission types, and deterministic races.
Why#
OpenCode only removed pending requests after receiving a provider reply. If a session ended first, the request remained in projection_pending_approvals, kept pending_approval_count above zero, and prevented the thread from settling.
This closes the teardown parity gap described in #7113 and follows the cleanup behavior used by the other provider adapters.
The semaphore gives request events, responses, interruption, and teardown one serialized order. A request is either resolved normally or cancelled, never both.
Unknown OpenCode permission types now use the generic approval flow. The fallback is applied only to approval requests, avoiding changes to search grouping, work-log labels, and timeline-anchor behavior.
Session teardown cleanup is best-effort, so cancellation failures do not prevent the OpenCode process and local session scope from closing.
User interruption only settles pending requests after OpenCode confirms the abort. If the abort fails, those requests remain actionable.
This PR does not migrate historical pending rows already stored in existing databases. That recovery path can be handled separately.
Verification#
- OpenCode adapter tests: 38 passed
- Focused web and mobile approval derivation tests
- Deterministic abort-failure, reply-versus-interruption, and request-open race coverage
- Server typecheck
- Targeted formatting and lint checks
Closes #7113
Closes #4795
Related to #5119
Related to #7173
UI Changes#
Previously, unsupported OpenCode permission types could appear as unknown requests without actionable approval UI. They now use the generic approval flow on web and mobile.
Before#
https://github.com/user-attachments/assets/b2c79de2-29ac-46e7-85f4-7dc497944dfa
After#
https://github.com/user-attachments/assets/dd9c6605-74d9-447a-9217-c589602bd853
Checklist#
Built and verified with Codex (GPT-5).
Note
Medium Risk
Changes OpenCode session teardown, approval projection, and concurrency around permission/question handling; incorrect settlement could leave threads stuck or double-resolve requests, but behavior is covered by new race and lifecycle tests.
Overview
Fixes threads that stayed stuck with pending approvals when an OpenCode session ended before the user replied.
OpenCode adapter now cancels open permission prompts (request.resolved with cancel) and closes open questions (user-input.resolved with empty answers) during stop, interrupt, session replacement, unexpected exit, layer shutdown, and session.error. A per-session pendingGate serializes permission/question events with replies and teardown so each request resolves once; late permission/question events are ignored after stop starts. Unknown OpenCode permissions map to dynamic_tool_call instead of unknown, and permission.replied uses the stored permission for the resolved request type.
Web and mobile treat approval.requested activities with unknown requestType as actionable generic command approvals (only for that activity kind, so work-log entries are not mislabeled).
Adds adapter tests for stop/interrupt/error paths, failed abort, reply-vs-interrupt races, and teardown event races.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9193685815ab4707709d583a0153ceac4a3e6543. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
Note
Settle pending permission/question requests during OpenCode teardown and interruptions#
- Adds
settlePendingRequests to the OpenCode adapter, which emits request.resolved (cancel) for pending permissions and user-input.resolved (empty answers) for pending questions, then clears them. Wired into session stop, interruptTurn, session.error, emitUnexpectedExit, and replacing an existing session in startSession.
- Introduces a
pendingGate semaphore on OpenCodeSessionContext to serialize permission/question operations with interrupts and stops. respondToRequest and respondToUserInput now validate presence under the gate and return ProviderAdapterRequestError for already-consumed requests.
handleSubscribedEvent drops pending-request events after stop, and now emits request.resolved/user-input.resolved only when a matching pending entry exists, using the stored permission's requestType instead of 'unknown'.
- Maps unknown permission types to
'dynamic_tool_call' in mapPermissionToRequestType; derivePendingApprovals in both web and mobile now falls back to 'command' for unknown approval.requested kinds.
- Risk:
mapPermissionToRequestType default change means request.resolved events for non-bash/read/edit permissions now report 'dynamic_tool_call' instead of 'unknown'; downstream consumers keyed on 'unknown' in OpenCodeAdapter.ts and session-logic.ts may need updating.
Macroscope summarized 9193685.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
16f7cfd5-767b-4759-842b-b0a4366b1f9eYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.