fix(device-utils): stabilize remote shell sessions - #32
Merged
Conversation
Improve EX/SRX remote shell handling by waiting for the initial shell output before sending the first keystrokes, buffering that output for the caller, and ignoring websocket close races during send. Add ShellSession.send_commands() as a convenience wrapper for sending multiple commands without manually appending line endings. Replace the sshkeyboard-based interactive shell with platform-specific terminal input loops, including POSIX raw-mode handling and Windows console key mapping. Remove the now-unused sshkeyboard dependency and update the lockfile. Update shell tests and README documentation for the new behavior.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the stability and usability of device remote shell sessions (EX/SRX) by adding a “wait for initial shell output” readiness phase, buffering that initial output for callers, and modernizing the interactive shell input handling while removing the sshkeyboard dependency.
Changes:
- Add
ShellSession._wait_for_shell_ready()and buffering so the first shell output is captured before the first keystrokes are sent. - Introduce
ShellSession.send_commands()for sending multiple commands with automatic line endings. - Replace
sshkeyboard-based interactive input with platform-specific loops (POSIX raw-mode + Windows console mapping) and removesshkeyboardfrom dependencies; update tests and README.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
uv.lock |
Updates the resolved dependency graph (notably removing sshkeyboard) and bumps mistapi to 0.63.1. |
pyproject.toml |
Removes sshkeyboard from project dependencies. |
src/mistapi/device_utils/__tools/shell.py |
Implements readiness waiting + buffering, adds send_commands(), and replaces interactive input handling with POSIX/Windows loops. |
tests/unit/test_shell.py |
Expands unit coverage for readiness waiting, send close-races, and Windows key mapping behavior. |
README.md |
Updates examples and documents the new send_commands() API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Improve EX/SRX remote shell handling by waiting for the initial shell output before sending the first keystrokes, buffering that output for the caller, and ignoring websocket close races during send.
Add ShellSession.send_commands() as a convenience wrapper for sending multiple commands without manually appending line endings.
Replace the sshkeyboard-based interactive shell with platform-specific terminal input loops, including POSIX raw-mode handling and Windows console key mapping. Remove the now-unused sshkeyboard dependency and update the lockfile.
Update shell tests and README documentation for the new behavior.