terminal/tmux: disable bash history expansion to avoid ! mangling#1277
Merged
terminal/tmux: disable bash history expansion to avoid ! mangling#1277
Conversation
Co-authored-by: openhands <openhands@all-hands.dev>
…ng during init handshake\n\nCo-authored-by: openhands <openhands@all-hands.dev>
enyst
commented
Nov 28, 2025
openhands-tools/openhands/tools/terminal/terminal/subprocess_terminal.py
Show resolved
Hide resolved
xingyaoww
reviewed
Nov 29, 2025
Collaborator
xingyaoww
left a comment
There was a problem hiding this comment.
LGTM! Can we add a few tests for it?
Collaborator
Author
|
@OpenHands Let’s add unit tests for this PR. Make sure to find the right place for these tests, probably in the same test file(s) where other functions in these files are tested. |
|
I'm on it! enyst can track my progress at all-hands.dev |
…isabled in tmux and subprocess backends - Mock tmux to assert initialize sends 'set +H;' in TmuxTerminal - E2E check in SubprocessTerminal that '!' is preserved (no history expansion) Co-authored-by: openhands <openhands@all-hands.dev>
|
Summary of changes made
Validation steps performed
Checklist
|
xingyaoww
reviewed
Nov 29, 2025
| with patch( | ||
| "openhands.tools.terminal.terminal.tmux_terminal.libtmux.Server", FakeServer | ||
| ): | ||
| # Avoid isinstance check in clear_screen during initialize since we stub Pane |
Collaborator
There was a problem hiding this comment.
🤔 i think we do have some unit tests that are actually running a real libtmux Server?
Contributor
Coverage Report •
|
|||||||||||||||||||||||||
… subprocess backends - In test_terminal_session.py, add test_history_expansion_disabled to assert '!' is preserved and no history expansion occurs across both backends Co-authored-by: openhands <openhands@all-hands.dev>
…eal parametrized test - Delete tests/tools/terminal/test_disable_history_expansion.py as redundant - test_history_expansion_disabled in test_terminal_session.py now covers both tmux and subprocess Co-authored-by: openhands <openhands@all-hands.dev>
- Add @parametrize_terminal_types to ensure the test runs for both tmux and subprocess and fixture exists Co-authored-by: openhands <openhands@all-hands.dev>
xingyaoww
approved these changes
Nov 29, 2025
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.
I had the agent do this for itself in an overnight experiment where it created itself a TUI to use it for E2E testing of switching LLM Profiles
The TUI it made is here (it's not pretty but it worked without humans 😅):
I'm not sure when it needed disabling history expansion, but it seems like a good idea to me?
(Agent write-up)
This PR disables bash history expansion in the tmux-based terminal backend to prevent unintended "!" expansion that can mangle commands.
Change:
set +H;to the initialization command when configuring the shell inTmuxTerminal.initializeso that!characters are not interpreted by history expansion.Rationale:
!(e.g., URLs, JSON, or other content), bash history expansion can alter the input unexpectedly. Disabling it leads to more predictable behavior for programmatic terminal execution.Implementation details:
openhands-tools/openhands/tools/terminal/terminal/tmux_terminal.pyself.pane.send_keys(...)line to includeset +H;before settingPROMPT_COMMANDandPS2.This is a minimal, backwards-compatible change that only affects the initialization of the interactive shell used by the tmux terminal backend.
@enyst can click here to continue refining the PR
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:2a61f33-pythonRun
All tags pushed for this build
About Multi-Architecture Support
2a61f33-python) is a multi-arch manifest supporting both amd64 and arm642a61f33-python-amd64) are also available if needed