Skip to content

fix(cli): bracketed-paste timeout prevents permanent input freeze (#16263)#32018

Merged
teknium1 merged 2 commits into
mainfrom
fix/bracketed-paste-timeout
May 25, 2026
Merged

fix(cli): bracketed-paste timeout prevents permanent input freeze (#16263)#32018
teknium1 merged 2 commits into
mainfrom
fix/bracketed-paste-timeout

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

When the terminal drops the ESC[201~ end mark during a bracketed paste — SSH glitch, terminal race, macOS sleep/wake, torn network write — prompt_toolkit's Vt100Parser keeps buffering all later input in _paste_buffer forever. From the user's perspective, the CLI appears frozen. The only recovery was killing the tab. Fixes #16263.

Fix

Monkey-patch Vt100Parser.feed() to track a _hermes_bp_start timestamp when bracketed-paste mode is entered. If ESC[201~ hasn't arrived after 2 seconds, flush the buffered content as a normal BracketedPaste event, restore normal parsing, and log a warning so the user can correlate it with #16263 in agent.log.

The patch is idempotent — repeated calls are no-ops via a sentinel on the module.

Changes

  • cli.py — new _apply_bracketed_paste_timeout_patch() function (~80 LOC) defined alongside the existing _strip_leaked_bracketed_paste_wrappers, called once during app setup right before _original_on_resize = app._on_resize.
  • tests/cli/test_bracketed_paste_timeout.py — 8 regression tests covering normal paste, timeout recovery, torn end marks, buffered-content preservation, normal-keys-after-recovery, no-timeout-on-quick-end-mark, subsequent-data-after-incomplete, no-timeout-under-threshold.
  • scripts/release.pyAUTHOR_MAP entry mapping 66773372+Tranquil-Flow@users.noreply.github.com to @Tranquil-Flow for the attribution check.

Validation

Before After
Paste with intact ESC[201~ works works (unchanged)
Paste with dropped ESC[201~ input frozen forever flushes after 2s, prompt resumes
Subsequent input after frozen paste ignored forever works after flush
User notification none — silent freeze logger.warning("Bracketed-paste timeout (...)" + #16263)
Idempotent patch application N/A yes — sentinel on module guards re-patching

Targeted tests: tests/cli/test_bracketed_paste_timeout.py — 8/8 passing.

Salvage notes

Surgical reapply of PR #27518 by @Tranquil-Flow (commit 098643c5e, Evi Nova <66773372+Tranquil-Flow@users.noreply.github.com>). The original branch was many months stale against current main and a direct cherry-pick would have reverted 1,193 unrelated files (−172,209 LOC), including the entire kanban tutorial, docker s6 infrastructure, dozens of skill files, and hundreds of test files. The substantive ~80 LOC patch function in cli.py (with a _apply_bracketed_paste_timeout_patch() call at app setup) plus the new 157-line regression test file were reapplied by hand onto current main with the contributor's authorship preserved via git commit --author=.

Original PR #27518 will be closed pointing to this one. Issue #16263 will auto-close from the merge commit footer.

Infographic

bracketed-paste-timeout

https://v3b.fal.media/files/b/0a9b9df7/VSCZbTjTxtN78Bft8Or6A_TRm7Jxv5.png

@github-actions

github-actions Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/bracketed-paste-timeout vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9318 on HEAD, 9312 on base (🆕 +6)

🆕 New issues (5):

Rule Count
unresolved-import 4
invalid-argument-type 1
First entries
tests/cli/test_bracketed_paste_timeout.py:45: [invalid-argument-type] invalid-argument-type: Argument to function `exec` is incorrect: Expected `str | Buffer | CodeType`, found `str | None`
cli.py:2380: [unresolved-import] unresolved-import: Cannot resolve imported module `prompt_toolkit.input.vt100_parser`
tests/cli/test_bracketed_paste_timeout.py:51: [unresolved-import] unresolved-import: Cannot resolve imported module `prompt_toolkit.input.vt100_parser`
cli.py:2382: [unresolved-import] unresolved-import: Cannot resolve imported module `prompt_toolkit.key_binding.key_processor`
tests/cli/test_bracketed_paste_timeout.py:14: [unresolved-import] unresolved-import: Cannot resolve imported module `prompt_toolkit.keys`

✅ Fixed issues: none

Unchanged: 4924 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

Tranquil-Flow and others added 2 commits May 25, 2026 05:06
…6263)

When the terminal drops the ESC[201~ end mark during a bracketed paste
(terminal race, torn write, SSH glitch, macOS sleep/wake), prompt_toolkit's
Vt100Parser keeps buffering all later input in _paste_buffer forever. From
the user's perspective, the CLI appears frozen — the only recovery was
closing the tab/session.

This patch monkey-patches Vt100Parser.feed() so that bracketed-paste mode
flushes buffered content as a normal BracketedPaste event after 2 seconds
without an end marker, then restores normal parsing.

Includes 8 regression tests covering normal paste, timeout recovery,
torn end marks, and edge cases.

Surgical reapply of PR #27518. Original branch was many months stale
(1193 files / 172k LOC of unrelated reverts); the substantive ~77 LOC
patch in cli.py plus the new 157-line test file were reapplied onto
current main with the contributor's authorship preserved via --author.
@teknium1 teknium1 force-pushed the fix/bracketed-paste-timeout branch from 2460b73 to 1c71e9c Compare May 25, 2026 12:07
@teknium1 teknium1 merged commit 4909dd8 into main May 25, 2026
21 of 22 checks passed
@teknium1 teknium1 deleted the fix/bracketed-paste-timeout branch May 25, 2026 12:07
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/cli CLI entry point, hermes_cli/, setup wizard labels May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI input freezes after pasting text (not limited to sleep/wake)

3 participants