← Back to PRs

#20817: feat(process): paced send-keys for PTY sessions

by Operative-001 open 2026-02-19 10:02 View on GitHub →
agents size: S trusted-contributor
Fixes #20797 ## Summary - add optional `delayMs` to `process send-keys` so callers can pace key-token delivery - keep existing behavior as default (`delayMs` omitted or `0` still sends in one burst) - clamp delay to `0..5000ms` to avoid abuse and huge sleeps - add e2e coverage asserting paced writes apply inter-key delay and still complete expected PTY input ## Why Issue #20797 reports dropped/out-of-order input with bursty `send-keys` into interactive PTY tools. Pacing gives callers a bounded, opt-in way to serialize key delivery for fragile TUIs without changing existing callers. ## Testing - `pnpm -s vitest --config vitest.e2e.config.ts run src/agents/bash-tools.process.send-keys.e2e.test.ts` - `pnpm -s vitest run src/agents/bash-tools.process.poll-timeout.test.ts src/agents/bash-tools.process.supervisor.test.ts` - `pnpm -s oxlint src/agents/bash-tools.process.ts src/agents/bash-tools.process.send-keys.e2e.test.ts` <!-- greptile_comment --> <h3>Greptile Summary</h3> Added optional `delayMs` parameter to `process send-keys` action to pace key-token delivery for PTY sessions. The implementation clamps delay values to 0-5000ms range to prevent abuse, defaults to 0 (burst mode) to maintain backward compatibility, and applies inter-key delays only when `delayMs > 0`. The feature allows callers to serialize key delivery for fragile interactive TUI tools that may drop or reorder input with bursty send-keys. **Changes:** - Added `delayMs` optional parameter to process tool schema (lines 72-77) - Implemented `resolveSendKeysDelayMs()` validation function with 5000ms upper bound (lines 95-108) - Refactored `send-keys` action to support paced delivery: processes hex/literal prefix first, then iterates through key tokens with delays between them (lines 494-566) - Added e2e test coverage verifying paced writes apply inter-key delay and complete expected PTY input **Testing:** - New e2e test validates timing (3 inter-key waits of 60ms = minimum 130ms elapsed, allowing timer jitter) - Existing tests for Enter encoding and submit action remain passing - Test design uses obfuscated string construction to avoid triggering event-based exit conditions <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation is well-designed with proper input validation, maintains backward compatibility, includes comprehensive e2e test coverage, and follows the repository's coding patterns. The 5000ms upper bound prevents abuse, and the delay logic correctly applies only between key tokens (not after the last one). - No files require special attention <sub>Last reviewed commit: 5120098</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs