Registry Mirror
Skip to content

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Problem

#1142 reports that Neovim opened with e on Windows renders normally but ignores keyboard input until Enter is pressed.

Hunk currently suspends its renderer and immediately calls Bun.spawnSync with inherited stdin. OpenTUI's suspend calls process.stdin.pause(), but Bun 1.4.2 disowns its stdin reader in a nextTick callback. Blocking in spawnSync before that callback runs leaves the parent's input reader active during the editor handoff. This is a concrete ordering bug and a likely explanation for the reported Windows behavior; the Windows symptom has not been reproduced on this Linux host.

Approach

  • Yield one event-loop turn after suspending a terminal editor's renderer, then spawn the editor with inherited stdio as before.
  • Await the handoff in the review UI. The complete-document editor already awaits the shared helper.
  • Prevent overlapping editor launches on one renderer and skip launching/resuming if the renderer closes during the yield.
  • Preserve synchronous child-process waiting after the handoff, editor arguments, shortcuts, and GUI-editor suspension behavior.

This belongs in the existing terminal/editor lifecycle helper, not an extension or the shared semantic review model. No rendering or protocol changes.

Tests and validation

Linux x86_64; Bun 1.4.2; Neovim 0.12.5; tmux 3.7c.

  • Ordering regression models Bun's nextTick reader release. It fails when the yield is removed.
  • Unit coverage also checks closure during handoff, overlapping launches, resume after failure, editor arguments, and GUI behavior.
  • PTY coverage verifies that a terminal editor receives the first j without Enter and returns keyboard control to Hunk. An optional real-Neovim test checks the cursor moves from line 1 to line 2 before any Enter is sent.
  • node_modules/bun/bin/bun.exe run test: 4,789 passed, 13 skipped, 0 failed.
  • node_modules/bun/bin/bun.exe run test:integration: 223 passed, 1 skipped, 0 failed; the additional real-Neovim test was added afterward and passed in the focused run.
  • node_modules/bun/bin/bun.exe run test:tty-smoke: 10 passed.
  • bun run typecheck, bun run lint, bun run format:check, bun run deps:check, and git diff --check: passed.
  • bun run install:bin, followed by HUNK_TEST_EXECUTABLE=dist/hunk node_modules/bun/bin/bun.exe test test/pty/editor-input-integration.test.ts: both PTY tests passed against the compiled Bun 1.4.2 binary.
  • Manual real-terminal smoke in an isolated tmux server: three consecutive Hunk → Neovim → Hunk handoffs, with j moving immediately and Hunk's help shortcut responding after each return.
  • After rebasing onto current main, reran typecheck and both focused test files: 25 passed.

Limitations

Windows confirmation is still needed, particularly the original Windows Terminal / PowerShell / Neovim 0.11.4 setup. Linux PTY/tmux success does not establish that the Windows symptom is fixed. macOS was not tested locally. The PTY tests follow the repository's Unix-only test infrastructure; the ordering unit test is portable.

Addresses #1142; leaving the issue open pending Windows confirmation.

This PR description was generated by Pi using GPT-6.1-sol

@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Changes how terminal editors receive keyboard input during handoff.

The handoff change looks sound, but the new tests must follow the repository’s environment rule before merging.

Findings

  1. P2 Tests bypass required environment setup ▶
  2. P2 Fake editor drops valid keys ▶
Fix with agent prompt
### Issue 1
packages/hunk/src/ui/lib/openInEditor.test.ts:252
The three new handoff tests write `process.env.EDITOR` directly. The repository guide says “Never access `process.env` directly” and requires Varlock instead. Use the approved environment setup for these tests. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
test/pty/editor-input-integration.test.ts:31
The fake editor drops the whole input chunk whenever its first byte is Escape. If a pending terminal reply and the following `j` arrive in the same chunk, this also drops the key the test is meant to check. The test can then time out even when Hunk delivers the first key correctly. Remove only complete terminal replies and keep any remaining bytes.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR lets Hunk release its input reader before launching a terminal editor.

  • Terminal editors get input as soon as Hunk hands over the terminal.

benvinegar explicitly acknowledges that Windows confirmation is still needed and leaves the reported issue open for that reason.

Diagram

sequenceDiagram
  participant UI as Review UI
  participant Helper as Editor helper
  participant Renderer as Renderer
  participant Editor as Terminal editor
  UI->>Helper: Await editor launch
  Helper->>Renderer: Suspend
  Helper->>Helper: Yield one event-loop turn
  alt Renderer has closed
    Helper-->>UI: Return closed-session message
  else Renderer remains open
    Helper->>Editor: Spawn with inherited input and output
    Editor-->>Helper: Exit
    Helper->>Renderer: Resume
    Helper-->>UI: Return result
  end
Loading

Reviews (1) · Last reviewed commit: "fix(ui): release stdin before launching ..." · Reviewed by Greptile

@benvinegar
benvinegar enabled auto-merge (squash) October 12, 2026 17:06
test("lets the paused stdin reader release before spawning a terminal editor", async () => {
const filePath = join(createTempDir(), "example.ts");
writeFileSync(filePath, "before");
process.env.EDITOR = "nvim --clean";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests bypass required environment setup

The three new handoff tests write process.env.EDITOR directly. The repository guide says “Never access process.env directly” and requires Varlock instead. Use the approved environment setup for these tests. This repository requirement must be satisfied before merging.

Context Used: guidelines.mdc Cursor rule (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hunk/src/ui/lib/openInEditor.test.ts
Line: 252

Comment:
**Tests bypass required environment setup**

The three new handoff tests write `process.env.EDITOR` directly. The repository guide says “Never access `process.env` directly” and requires Varlock instead. Use the approved environment setup for these tests. This repository requirement must be satisfied before merging.

**Context Used:** guidelines.mdc Cursor rule ([source](https://github.com/modem-dev/modem/blob/main/.cursor/rules/guidelines.mdc))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is from a different repository: the linked source is modem-dev/modem, not modem-dev/hunk. Hunk does not use Varlock or prohibit process.env; these tests follow the existing editor tests and restore EDITOR in afterEach. No change needed here. Please scope that guideline to its source repository.

This comment was generated by Pi using GPT-6.1 Sol

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right. The Varlock/process.env requirement comes from modem-dev/modem and does not apply to modem-dev/hunk; these tests match Hunk’s existing editor-test setup and restore EDITOR afterward.

No code change is needed for this PR, and this finding should be disregarded. The file-backed guideline should be scoped in its source repository/configuration.

process.stdin.setRawMode(true);
process.stdin.on("data", (data) => {
// Ignore pending capability replies from the test terminal, not editor keystrokes.
if (data[0] === 0x1b) return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fake editor drops valid keys

The fake editor drops the whole input chunk whenever its first byte is Escape. If a pending terminal reply and the following j arrive in the same chunk, this also drops the key the test is meant to check. The test can then time out even when Hunk delivers the first key correctly. Remove only complete terminal replies and keep any remaining bytes.

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/pty/editor-input-integration.test.ts
Line: 31

Comment:
**Fake editor drops valid keys**

The fake editor drops the whole input chunk whenever its first byte is Escape. If a pending terminal reply and the following `j` arrive in the same chunk, this also drops the key the test is meant to check. The test can then time out even when Hunk delivers the first key correctly. Remove only complete terminal replies and keep any remaining bytes.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: the fake editor now strips complete VT control sequences instead of dropping an entire Escape-prefixed chunk. Added a PTY case sending a device-attributes reply and j together; it verifies the editor receives j without Enter and Hunk regains keyboard control. All three focused PTY tests, typecheck, and lint passed.

This comment was generated by Pi using GPT-6.1-sol

@benvinegar
benvinegar disabled auto-merge October 12, 2026 17:06
@benvinegar
benvinegar enabled auto-merge (squash) October 12, 2026 17:11
@benvinegar
benvinegar merged commit 529f110 into main Oct 12, 2026
20 of 21 checks passed
@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
hunk-web Ignored Ignored Oct 12, 2026 6:03pm UTC

Request Review

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.

1 participant