Skip to content

fix(sessions): preempt paste-end Enter race with belt-and-suspenders double-Enter#240

Open
brianjones-v4n wants to merge 1 commit into
JKHeadley:mainfrom
brianjones-v4n:fix/preempt-paste-end-enter-race
Open

fix(sessions): preempt paste-end Enter race with belt-and-suspenders double-Enter#240
brianjones-v4n wants to merge 1 commit into
JKHeadley:mainfrom
brianjones-v4n:fix/preempt-paste-end-enter-race

Conversation

@brianjones-v4n
Copy link
Copy Markdown
Contributor

Summary

The Enter after bracketed-paste-end is occasionally eaten by a race with the paste-end (\e[201~) sequence on Claude Code v2.1.105+ TUIs. Today this is recovered asynchronously by verifyInjection, but in practice the recovery fires routinely (12 events in 48h on one production host) rather than rarely — meaning the "fallback" has become the de-facto primary path.

This adds a preemptive second Enter ~100ms after the primary Enter in the bracketed-paste branch of rawInject. The mechanism:

  • If the first Enter was eaten by the race → the second submits the input.
  • If the first Enter succeeded → the second arrives at an empty input prompt and is a no-op in the Claude Code TUI.

verifyInjection stays in place as the last-resort safety net for the rare case both Enters miss.

Test plan

  • Added two unit tests in tests/unit/SessionManager-injection.test.ts:
    • asserts two send-keys Enter calls follow the paste-end sequence
    • asserts the inter-Enter sleep is present (~100ms)
    • asserts the verifyInjection doc acknowledges the new primary-path layering
  • npx vitest run tests/unit/SessionManager-injection.test.ts — 8/8 passing
  • Diff is contained to the multi-line bracketed-paste branch — single-line injection path untouched
  • In-the-wild verification on the production host that produced the 12 events (will report back after merge)

Risk

Low. The second Enter is sent ~100ms after the first; if it ever fires when the input box is non-empty, that would be due to a separate ordering bug already present today — and verifyInjection would still cover the recovery.

🤖 Generated with Claude Code

…double-Enter

The Enter after bracketed-paste-end is occasionally eaten by a race with
the paste-end (\e[201~) sequence on Claude Code v2.1.105+ TUIs. Today
this is recovered asynchronously by verifyInjection, but the recovery
fires routinely (12 events in 48h on one host) rather than rarely.

This adds a preemptive second Enter ~100ms after the primary Enter in
the bracketed-paste branch of rawInject. If the first Enter was eaten
by the race, the second submits; if the first succeeded, the second
arrives at an empty input prompt and is a no-op in the Claude Code TUI.

verifyInjection stays in place as the last-resort safety net for the
rare case both Enters miss.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

@brianjones-v4n is attempting to deploy a commit to the sagemind Team on Vercel.

A member of the Team first needs to authorize it.

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