Skip to content

fix(setup): drain residual events and filter key kind in onboard prompts (#937)#949

Merged
zmanian merged 1 commit intonearai:stagingfrom
reidliu41:fix/937-onboard-keypress
Mar 11, 2026
Merged

fix(setup): drain residual events and filter key kind in onboard prompts (#937)#949
zmanian merged 1 commit intonearai:stagingfrom
reidliu41:fix/937-onboard-keypress

Conversation

@reidliu41
Copy link
Copy Markdown
Contributor

Summary

On Windows, single keypresses during ironclaw onboard are registered
twice, causing channel/tool selection to skip or toggle incorrectly.
Two root causes:

  1. select_many() had no residual event drain, so Enter from a prior prompt was immediately consumed on entry, skipping the selection.

  2. Neither select_many() nor read_secret_line() filtered on KeyEventKind::Press, so Windows Key Release/Repeat events caused every keypress to fire twice (Space toggles cancel out, Enter triggers double-advance, arrows jump two positions).

Extract a shared drain_pending_events() helper (replacing the inline
drain in read_secret_line from #849), add it to select_many() entry,
and filter both event loops to only handle KeyEventKind::Press.

Change Type

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • CI/Infrastructure
  • Security
  • Dependencies

Linked Issue

Fixes #937

Validation

  • cargo fmt
  • cargo clippy --all --benches --tests --examples --all-features
  • Relevant tests pass:
  • Manual testing:

Security Impact

None

Database Impact

None

Blast Radius

Rollback Plan


Review track:

@github-actions github-actions Bot added size: S 10-49 changed lines scope: setup Onboarding / setup risk: high Safety, secrets, auth, or critical infrastructure contributor: experienced 6-19 merged PRs and removed size: S 10-49 changed lines labels Mar 11, 2026
…pts (nearai#937)

  On Windows, single keypresses during `ironclaw onboard` are registered
  twice, causing channel/tool selection to skip or toggle incorrectly.
  Two root causes:

  1. select_many() had no residual event drain, so Enter from a prior
     prompt was immediately consumed on entry, skipping the selection.

  2. Neither select_many() nor read_secret_line() filtered on
     KeyEventKind::Press, so Windows Key Release/Repeat events caused
     every keypress to fire twice (Space toggles cancel out, Enter
     triggers double-advance, arrows jump two positions).

  Extract a shared drain_pending_events() helper (replacing the inline
  drain in read_secret_line from nearai#849), add it to select_many() entry,
  and filter both event loops to only handle KeyEventKind::Press.

  Fixes nearai#937
[skip-regression-check]
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial fix for input handling within interactive setup prompts, particularly on Windows. By ensuring that residual events are cleared and only valid key press events are processed, it resolves issues where user input was misinterpreted or double-counted, significantly improving the reliability and user experience of the ironclaw onboard process.

Highlights

  • Event Draining: Implemented a shared drain_pending_events() helper function to clear residual key events from the terminal buffer, addressing issues where previous keypresses (like Enter) would prematurely trigger subsequent prompts.
  • Key Event Filtering: Modified select_many() and read_secret_line() functions to explicitly filter for KeyEventKind::Press events. This prevents double-firing of keypresses on Windows caused by Release or Repeat events, which led to incorrect selections or double advancements in prompts.
  • Bug Fix for Windows: Resolved a bug specific to Windows where single keypresses during ironclaw onboard prompts were registered twice, causing incorrect channel/tool selection and navigation issues.
Changelog
  • src/setup/prompts.rs
    • Added a new private helper function drain_pending_events() to clear the terminal event queue.
    • Updated the select_many() function to call drain_pending_events() upon entry.
    • Modified the event handling logic within select_many() to only process KeyEventKind::Press events.
    • Replaced the inline event draining loop in read_secret_line() with a call to the new drain_pending_events() helper.
    • Updated the event handling logic within read_secret_line() to only process KeyEventKind::Press events.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@reidliu41 reidliu41 force-pushed the fix/937-onboard-keypress branch from 616a71b to e362d9c Compare March 11, 2026 14:32
@github-actions github-actions Bot added the size: S 10-49 changed lines label Mar 11, 2026
Copy link
Copy Markdown
Collaborator

@zmanian zmanian left a comment

Choose a reason for hiding this comment

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

Review: fix(setup): drain residual events and filter key kind in onboard prompts (#937)

Verdict: APPROVE

Clean, small fix. Only touches src/setup/prompts.rs.

Correctness

  • Extracts the existing inline drain from read_secret_line() into a shared drain_pending_events() helper -- DRY
  • Adds the same drain to select_many() entry, which was missing it
  • Adds KeyEventKind::Press filtering to both select_many() and read_secret_line() -- this is the canonical crossterm pattern for Windows where Release and Repeat events are a well-known footgun
  • The fix correctly prevents double-firing that caused channel/tool selection to skip or toggle incorrectly

Note

Author only checked cargo fmt in the validation checklist, not clippy or tests. The change is straightforward but please confirm CI is green before merging.

No code issues found.

@reidliu41
Copy link
Copy Markdown
Contributor Author

I see it's already approved — is this good to merge?

@zmanian zmanian merged commit 6321bb4 into nearai:staging Mar 11, 2026
9 checks passed
@ironclaw-ci ironclaw-ci Bot mentioned this pull request Mar 12, 2026
bkutasi pushed a commit to bkutasi/ironclaw that referenced this pull request Mar 28, 2026
…pts (nearai#937) (nearai#949)

On Windows, single keypresses during `ironclaw onboard` are registered
  twice, causing channel/tool selection to skip or toggle incorrectly.
  Two root causes:

  1. select_many() had no residual event drain, so Enter from a prior
     prompt was immediately consumed on entry, skipping the selection.

  2. Neither select_many() nor read_secret_line() filtered on
     KeyEventKind::Press, so Windows Key Release/Repeat events caused
     every keypress to fire twice (Space toggles cancel out, Enter
     triggers double-advance, arrows jump two positions).

  Extract a shared drain_pending_events() helper (replacing the inline
  drain in read_secret_line from nearai#849), add it to select_many() entry,
  and filter both event loops to only handle KeyEventKind::Press.

  Fixes nearai#937
[skip-regression-check]
drchirag1991 pushed a commit to drchirag1991/ironclaw that referenced this pull request Apr 8, 2026
…pts (nearai#937) (nearai#949)

On Windows, single keypresses during `ironclaw onboard` are registered
  twice, causing channel/tool selection to skip or toggle incorrectly.
  Two root causes:

  1. select_many() had no residual event drain, so Enter from a prior
     prompt was immediately consumed on entry, skipping the selection.

  2. Neither select_many() nor read_secret_line() filtered on
     KeyEventKind::Press, so Windows Key Release/Repeat events caused
     every keypress to fire twice (Space toggles cancel out, Enter
     triggers double-advance, arrows jump two positions).

  Extract a shared drain_pending_events() helper (replacing the inline
  drain in read_secret_line from nearai#849), add it to select_many() entry,
  and filter both event loops to only handle KeyEventKind::Press.

  Fixes nearai#937
[skip-regression-check]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: experienced 6-19 merged PRs risk: high Safety, secrets, auth, or critical infrastructure scope: setup Onboarding / setup size: S 10-49 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keypress registered twice during ironclaw onboard skips prompts (API Key, channels, tools)

2 participants