Skip to content

fix: unhandled promise rejection on session cancel bleeds stderr into TUI #19855

Closed as not planned

Description

@sjawhar

Bug

When pressing Escape to cancel an in-progress LLM generation in the TUI, an unhandled promise rejection stack trace writes to stderr and corrupts the terminal display.

Root Cause

The abort HTTP endpoint at session.ts:384 calls SessionPrompt.cancel() without await or .catch(). cancel() internally calls cb.reject(new Error("Session cancelled")) to reject pending promises. Since the endpoint returns c.json(true) before cancel() completes, the rejection is unhandled and Bun writes the stack trace to stderr.

Two additional fire-and-forget calls in prompt/index.tsx also lack .catch():

  • sdk.client.session.abort() (line 262)
  • sdk.client.session.command() (line 654)

Reproduction

  1. Start a session in the TUI
  2. Send a message that triggers LLM generation
  3. Press Escape twice during generation
  4. Observe stack trace text bleeding over the TUI rendering

Fix

See sjawhar#1

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 29, 2026
  2. ESRE-dev commented on Apr 1, 2026

    @ESRE-dev

    This should be resolved by two upstream changes:

    1. 814a515a8a — fix: improve plugin system robustness (#18280) (Mar 24) adds a .catch() handler to the prompt_async route that catches rejected promises and publishes them to the bus via Bus.publish(Session.Event.Error, ...) instead of letting them become unhandled rejections that bleed into stderr. This commit includes a test verifying the handler exists.

    2. c5442d418d — refactor(session): effectify SessionPrompt service (#19483) (Mar 30) introduces a Runner state machine where cancel is handled via Fiber.interrupt with typed Runner.Cancelled errors. This eliminates the class of unhandled rejections that occurred when cancel raced with prompt processing — the interruption propagates cleanly through Effect's fiber model instead of producing uncaught promise rejections.

    cc #20095 (related issue, now closed)

  3. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions