From ac0325c257143338159c9a7073c90ac62c8a1119 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 27 Apr 2026 06:44:36 -0700 Subject: [PATCH] diagnostic(cli): log slow bracketed-paste handler (>500ms) for #16263 (#16575) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a paste takes longer than 500ms to process on the prompt_toolkit event-loop thread, emit a logger.warning with elapsed time, byte size, line count, and sys.platform. Gives us concrete repro data for the recurring 'CLI freezes after paste on macOS' class of reports (issue #16263, plus sibling reports across Claude Code / Cursor / Lightroom against macOS Tahoe 26). Pure diagnostic — no behavior change. Two time.perf_counter() calls and one conditional per paste event. Log line only fires when the handler is actually slow, so normal pastes add no log noise. --- cli.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cli.py b/cli.py index 4f0cc68760..0d5bcf9fda 100644 --- a/cli.py +++ b/cli.py @@ -9928,6 +9928,12 @@ class HermesCLI: placeholder while preserving any existing user text in the buffer. """ + # Diagnostic canary: measure how long the paste handler blocks + # the prompt_toolkit event loop. If this exceeds ~500ms we log + # it so recurring "CLI freezes on paste" reports (issue #16263, + # macOS Tahoe 26 + iTerm2/Ghostty) arrive with data attached. + _paste_handler_start = time.perf_counter() + _paste_raw_size = len(event.data or "") pasted_text = event.data or "" # Normalise line endings — Windows \r\n and old Mac \r both become \n # so the 5-line collapse threshold and display are consistent. @@ -9956,6 +9962,17 @@ class HermesCLI: buf.insert_text(prefix + placeholder) else: buf.insert_text(pasted_text) + _paste_handler_elapsed_ms = (time.perf_counter() - _paste_handler_start) * 1000.0 + if _paste_handler_elapsed_ms > 500.0: + logger.warning( + "Slow bracketed-paste handler: %.1fms to process %d bytes " + "(%d lines) on %s. If the input becomes unresponsive after " + "this, attach this log line to the bug report.", + _paste_handler_elapsed_ms, + _paste_raw_size, + pasted_text.count('\n') + 1 if pasted_text else 0, + sys.platform, + ) @kb.add('c-v') def handle_ctrl_v(event):