Skip to content

fix: prevent stderr bleed on session cancel#19856

Open
sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar:fix/cancel-stderr-bleed
Open

fix: prevent stderr bleed on session cancel#19856
sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar:fix/cancel-stderr-bleed

Conversation

@sjawhar
Copy link
Copy Markdown

@sjawhar sjawhar commented Mar 29, 2026

Issue for this PR

Closes #19855

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When you press Escape during active LLM generation, SessionPrompt.cancel() rejects pending callback promises. The abort endpoint at session.ts:384 calls cancel() without await or .catch() — it fires the async function and immediately returns c.json(true). The rejected promise has no handler, so Bun writes the stack trace to stderr. Since the TUI process has stderr pointed at the terminal (fd 2 → pts), the raw text renders over the TUI display.

Two additional SDK calls in the TUI prompt component also lack .catch():

  • sdk.client.session.abort() on double-Escape
  • sdk.client.session.command() on slash commands

The fix adds await + .catch(() => {}) to the abort endpoint handler, and .catch(() => {}) to the two SDK calls. The cancel rejection is expected behavior (it's how the prompt loop knows to stop), so swallowing it is correct.

How did you verify your code works?

  • Added test/session/cancel.test.ts that creates a session, starts the prompt loop, calls cancel, and asserts no unhandledRejection event fires
  • Traced the stack trace from user report (at cancel(worker.js:231904)) through source maps back to SessionPrompt.cancel in prompt.ts
  • Verified all three call sites: abort endpoint returns before cancel completes (fire-and-forget), prompt abort has no catch, command has no catch

Screenshots / recordings

Stack trace observed in TUI:

at cancel(/$bunfs/root/src/cli/cmd/tui/worker.js:231904:19)
at <anonymous> (/$bunfs/root/src/cli/cmd/tui/worker.js:306117:25)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant