Skip to content

feat: async non-blocking command execution for tmux panes#287

Merged
ck3mp3r merged 13 commits intomainfrom
feature/sequential-pane-commands
Oct 29, 2025
Merged

feat: async non-blocking command execution for tmux panes#287
ck3mp3r merged 13 commits intomainfrom
feature/sequential-pane-commands

Conversation

@ck3mp3r
Copy link
Owner

@ck3mp3r ck3mp3r commented Oct 25, 2025

Summary

  • Implements async non-blocking command execution for tmux panes
  • Commands within each pane execute sequentially; multiple panes run in parallel
  • Session attaches immediately without waiting for commands to complete

Key Implementation Details

Async Architecture:

  • Added tokio runtime to Tmux for task management
  • Changed from Rc to Arc for thread-safe reference counting
  • Commands stored per-pane in HashMap<Target, VecDeque>
  • Each pane spawns its own tokio task for parallel execution

Pane Readiness Detection:

  • Waits for pane output to stabilize (2-second stability check)
  • Handles direnv/devenv initialization gracefully
  • Non-intrusive: no test commands injected into pane

Command Execution:

  • Sequential execution within each pane using async/await
  • Parallel execution across multiple panes via tokio::spawn
  • PID monitoring to detect command completion
  • Proper task cleanup via Drop trait to prevent panics

Benefits:

  • Instant session attachment - user can work immediately
  • Background commands execute without blocking
  • No race conditions or command interleaving per pane

@ck3mp3r ck3mp3r force-pushed the feature/sequential-pane-commands branch 5 times, most recently from 8f25469 to 6f4c0fb Compare October 25, 2025 20:57
- Implement function to detect child processes for a given pane using pgrep
- Add method to verify pane responsiveness by sending input and capturing output
- Add tokio async runtime for concurrent pane command execution
- Change from Rc to Arc for thread-safe reference counting
- Implement pane readiness checking before command execution
- Add child process monitoring to detect command completion
- Commands within a pane execute sequentially, multiple panes run in parallel
- Store JoinHandles and implement Drop to abort tasks on cleanup
- Session attachment no longer blocks on pane command execution
- Add Send + Sync + 'static bounds to Runner trait
- Replace intrusive echo test with PID-based readiness check
- Check if pane has no child processes to determine readiness
- Add wait_for_tasks method to ensure tasks complete before exit
- Block on task completion when using --skip-attach
- Add debug logging for pane readiness and command execution
- Add test YAML files to verify parallel/sequential execution

Verified working: Commands within each pane execute sequentially while
multiple panes run in parallel.
- Remove overly verbose debug logs
- Keep useful debug logs for -vvvv troubleshooting
- Remove test YAML files from repository root
- Change from 50 attempts × 100ms (5s) to 60 second timeout
- Increase poll interval to 200ms to reduce overhead
- Add elapsed time logging for better debugging
- Prevents commands from being skipped when shell startup is slow
- Replace PID-based readiness check with output stability detection
- Capture pane output twice with 200ms delay and compare
- Pane is ready when output stops changing (stabilized)
- Works correctly with slow shell initialization (direnv, devenv, plugins)
- PID check now only used for command completion detection
- Non-intrusive: no test commands or key presses sent to pane
- Always wait for async tasks to finish sending commands before CLI exits
- Previously tasks were aborted when attaching (not using --skip-attach)
- Commands are sent via tmux send-keys within async tasks
- If tasks abort, commands never get sent to panes
- Now waits for all tasks whether using --skip-attach or not
- attach-session blocks, keeping CLI alive while user is in session
- switch-client returns immediately, so must wait for tasks first
- skip-attach exits immediately, so must wait for tasks first
- This allows instant attach while ensuring commands execute
@ck3mp3r ck3mp3r force-pushed the feature/sequential-pane-commands branch from 122c81f to 958ab3c Compare October 27, 2025 12:26
- Replace flake-utils and systems inputs with flake-parts and nixpkgs-lib in flake.lock
- Add nixpkgs-lib_2 input and update references in flake.lock
- Update rustnix input dependencies to use flake-parts, devenv, and fenix
- Synchronize rustnix revision and narHash to latest state
- Add fenix and devenv input follows for rustnix in flake.nix
- Standardize argument structure in nix/devenv/ci.nix and developer.nix to explicit attribute sets
- Remove trailing newlines and minor formatting inconsistencies in Nix files
@ck3mp3r ck3mp3r force-pushed the feature/sequential-pane-commands branch from 35d0168 to a434e24 Compare October 28, 2025 09:27
- Add sysinfo as a dependency for enhanced process inspection
- Replace pgrep-based child process detection with sysinfo in TmuxClient
- Implement sysinfo-based methods for retrieving child processes and their commands
- Update pane_command logic to prefer sysinfo, falling back to pgrep for compatibility
- Remove unused debug import and refactor related code for clarity
- Remove legacy mux_get_session test relying on pgrep-based process detection
- Move task waiting logic into explicit branches for attach and switch-client scenarios
- Ensure tasks are awaited after switch-client and when skipping attach, aligning CLI exit behavior
- Remove redundant conditional block to streamline control flow
- Add comments clarifying when tasks are awaited versus run in background
@ck3mp3r ck3mp3r merged commit aa91c93 into main Oct 29, 2025
2 checks passed
@ck3mp3r ck3mp3r deleted the feature/sequential-pane-commands branch October 29, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant