Skip to content

fix(capabilities): resolve the terminal query on a later turn - #3

Merged
BlankParticle merged 1 commit into
alchemy-run:mainfrom
itsAster0:fix/bun-stdin-query-handoff
Nov 12, 2026
Merged

BlankParticle merged 1 commit into
alchemy-run:mainfrom
itsAster0:fix/bun-stdin-query-handoff

Conversation

@itsAster0

Copy link
Copy Markdown
Contributor

Fixes #2.

On Bun, process.stdin releases its native reader on the tick after pause() if readableFlowing is not true. When the terminal answers the query before the timeout, finish() runs inside the 'data' handler, and App.tsx adds the 'readable' listener back in a microtask, before that tick. Bun then releases the reader, and no key press reaches the app after that.

This change resolves the query in setImmediate, so the 'readable' listener is added after Bun releases the reader and gets a new one. Under Node, the only change is that the query resolves one turn later.

Testing

Answer after 20 ms Answer after 700 ms
Before key lost key shown
After key shown, 3 of 3 runs key shown, 3 of 3 runs

I also used the patched dist/ with alchemy deploy in a terminal that answers quickly, and the prompt takes input again.

On Bun, process.stdin releases its reader on the tick after pause(). When the
terminal answers before the timeout, finish() runs inside the data handler and
the readable listener is reattached before that tick, so Bun releases the
reader under it and every later key press is lost. Resolving in setImmediate
reattaches after the release.

Fixes alchemy-run#2
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.

Keyboard input stops on Bun when the terminal answers the query in time

2 participants