Skip to content

[BUG] Session cancel races cause lost cancels, stale aborts, and dangling waits #20095

@ESRE-dev

Description

@ESRE-dev

Description

Session cancellation has multiple race-condition failure modes:

  1. Lost cancel before start
    If cancel() is called before start() initializes session state, the cancellation is dropped and the session still runs.

  2. Stale cancel aborts new generation
    When a session is cancelled and quickly restarted (same session ID), a delayed cancel callback from the old run can abort the new run.

  3. Dangling permission/question waits after cancel
    Cancel does not reject pending permission/question waits, so tool execution can remain blocked indefinitely even though the session appears cancelled.

Plugins

None

OpenCode version

1.3.3 (also observed on dev as of 2026-03-30)

Steps to reproduce

  1. Start a prompt that triggers tool use and session loop activity.
  2. Immediately cancel before the first response is fully initialized.
  3. Re-send a prompt quickly in the same session.
  4. Observe one or more of:
    • cancel being ignored,
    • new run being aborted by stale cancel from prior run,
    • pending permission/question waits not being cleared.

Screenshot and/or share link

N/A

Operating System

macOS 15.4.1 (also seen in Linux CI)

Terminal

Ghostty

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions