fix(cli): strip leaked Device Attributes (DA) terminal responses - #27172
Open
Ramadas108 wants to merge 1 commit into
Open
fix(cli): strip leaked Device Attributes (DA) terminal responses#27172Ramadas108 wants to merge 1 commit into
Ramadas108 wants to merge 1 commit into
Conversation
…sResearch#14692) When prompt_toolkit's resize handler or terminal-query logic races with the input parser under resize storms or multiplexer tab switches, the terminal's Device Attributes response (ESC[?<params>c) can land in the input buffer as literal text — visible as the '1c' fragment in terminal startup noise like '1c/2424'. The existing _strip_leaked_terminal_responses_with_meta() sanitizer (added for issue NousResearch#14692) already handled Cursor Position Report (CPR) responses (ESC[<row>;<col>R) and SGR mouse reports (ESC[<...M/m) but was missing DA response stripping entirely. This commit adds: - _DA_ESC_RE — matches ESC[?<params>c (primary DA), ESC[><params>c (secondary DA), and bare ESC[c sequences at the byte level. - _DA_VISIBLE_RE — matches the caret-escape visible form ^[[?<params>c that appears when the ESC byte was stripped by a prior filter. - Both regexes wired into the ESC and visible branches of the sanitizer. 7 regression tests covering primary DA, secondary DA, bare DA, visible form, combined DA+CPR (the exact '1c/2424' artifact), and a negative test ensuring Cursor Forward (ESC[2C) is not confused with DA. Closes issue NousResearch#14692 (completing the coverage gap).
This comment was marked as spam.
This comment was marked as spam.
Contributor
|
Thanks for the focused sanitizer extension. I found no blocking issue in the proposed approach. Current Automated hermes-sweeper review. |
This was referenced Aug 5, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Terminal startup noise — visible "1c/2424" artifacts leaking into the CLI
input buffer. The "1c" fragment is a Device Attributes (DA) response
(ESC[?1;2c) from the terminal that the input sanitizer was not stripping.
Root Cause
The
_strip_leaked_terminal_responses_with_meta()sanitizer incli.py(added for issue #14692) handled Cursor Position Report (CPR) responses
and SGR mouse reports, but was missing Device Attributes (DA) response
stripping entirely. DA responses leak through the same mechanism —
prompt_toolkit terminal-queries racing with the input parser under resize
storms or multiplexer tab switches.
Changes
cli.py:2124_DA_ESC_RE— matches ESC[?c (primary DA), ESC[>c (secondary DA), and bare ESC[ccli.py:2125_DA_VISIBLE_RE— caret-escape visible form ^[[?ccli.py:2229_DA_ESC_RE.sub()into the ESC sanitization branchcli.py:2235_DA_VISIBLE_RE.sub()into the visible sanitization branchtests/cli/test_cli_terminal_response_sanitizer.pyTesting
All 22 tests pass.
Related
Completes the coverage gap from issue #14692.