Skip to content

fix: prevent stderr bleed on session cancel#1

Closed
sjawhar wants to merge 66 commits intodevfrom
fix/cancel-stderr-bleed
Closed

fix: prevent stderr bleed on session cancel#1
sjawhar wants to merge 66 commits intodevfrom
fix/cancel-stderr-bleed

Conversation

@sjawhar
Copy link
Copy Markdown
Owner

@sjawhar sjawhar commented Mar 29, 2026

Closes anomalyco#19855

Summary

When pressing Escape to cancel an in-progress LLM generation in the TUI, an unhandled promise rejection stack trace bleeds through to stderr, corrupting the terminal display.

Root Cause

Three fire-and-forget async calls without .catch() handlers:

  1. session.ts:384 (primary): The abort HTTP endpoint 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.

  2. prompt/index.tsx:262: sdk.client.session.abort() called without .catch() when Escape is pressed twice.

  3. prompt/index.tsx:654: sdk.client.session.command() called without .catch().

Fixes

  • session.ts:384: await SessionPrompt.cancel(...).catch(() => {})
  • prompt/index.tsx:262: Added .catch(() => {}) to abort call
  • prompt/index.tsx:654: Added .catch(() => {}) to command call

Test

Added test/session/cancel.test.ts:

  • Verifies SessionPrompt.cancel() rejects pending callbacks without producing unhandled rejections
  • Verifies cancel on non-existent session doesn't throw

Note: Test requires @ai-sdk dependency fix to run (pre-existing issue with createProviderToolFactoryWithOutputSchema export).

How to reproduce

  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

nexxeln and others added 30 commits March 26, 2026 10:14
kommander and others added 22 commits March 27, 2026 20:55
@github-actions
Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@sjawhar
Copy link
Copy Markdown
Owner Author

sjawhar commented Mar 29, 2026

Moving to upstream repo

@sjawhar sjawhar closed this Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

10 participants