Skip to content

fix: use clipboard paste and longer delay for automation bootstrap - #74

Open
mikhailsal wants to merge 1 commit into
thisnick:mainfrom
mikhailsal:fix/automation-bootstrap-timing
Open

fix: use clipboard paste and longer delay for automation bootstrap#74
mikhailsal wants to merge 1 commit into
thisnick:mainfrom
mikhailsal:fix/automation-bootstrap-timing

Conversation

@mikhailsal

Copy link
Copy Markdown

Summary

  • Fixes automation agent bootstrap failure when a foreground app (e.g. Steam, browser) is active during --enable-win-automation connection
  • The 500ms delay after Win+R was insufficient for the Run dialog to appear and grab focus, causing the typed PowerShell launch command to be partially or fully lost to the foreground app
  • Replaced character-by-character send_text() with clipboard pre-load + Ctrl+V paste, and increased Win+R delay from 500ms to 2000ms

Problem

When connecting with --enable-win-automation, the bootstrap sequence:

  1. Presses Win+R
  2. Waits 500ms
  3. Types the full PowerShell command character-by-character

If another application (Steam, browser, etc.) is maximized and has keyboard focus, the Run dialog takes 1-2+ seconds to appear. Characters typed during this window go to the foreground app and are lost. The result is a truncated or garbled command in the Run dialog, the PowerShell agent never starts, and the DVC handshake times out with:

Automation agent not ready. Agent may still be starting or failed to launch via DVC

Fix

  1. Pre-load clipboard: Set the launch command in clipboard before pressing Win+R
  2. Increase delay: Wait 2000ms after Win+R (vs 500ms) for the dialog to appear
  3. Paste via Ctrl+V: Single atomic paste operation instead of ~150 individual keystroke events

Test plan

  • Connected with --enable-win-automation while Steam was maximized in foreground
  • automate status returns agent_running=true on first attempt
  • automate run "hostname" --wait returns correct output
  • automate snapshot -i -c -d 2 returns accessibility tree
  • Disconnect + reconnect cycle works consistently
  • All existing tests pass (cargo test -p agent-rdp-daemon — 19 tests)
  • Desktop remains clean (no leftover dialogs or visible PowerShell windows)

The automation agent bootstrap was failing because the 500ms delay
between pressing Win+R and typing the PowerShell launch command was
insufficient when a foreground application (e.g. Steam, browser) was
active. The Run dialog takes 1-2 seconds to appear and steal keyboard
focus in such cases, causing the typed command to be partially sent to
the foreground app and lost.

This fix addresses the issue in two ways:

1. Use clipboard paste (Ctrl+V) instead of character-by-character
   send_text() to input the launch command into the Run dialog. This
   is an atomic operation that doesn't suffer from per-character timing
   issues with long commands containing backslashes and quotes.

2. Increase the delay after Win+R from 500ms to 2000ms, giving the
   Run dialog time to appear and grab focus even when other apps are
   in the foreground.

The command is pre-loaded into the clipboard before Win+R is pressed,
so the clipboard is ready by the time the dialog appears.

Tested with Steam maximized in the foreground — automation now
bootstraps reliably on first connection attempt.
@rgl

rgl commented Jun 4, 2026

Copy link
Copy Markdown

this whole thing feels too fragile. isn't there a way to pre-install an app in the server? and make that app somehow trigger the agent execution when the agent-rdp client connects? or maybe, somehow, register that app to trigger when the agent-rdp dvc is present in the RDP session? or even, can't dvc handlers be pre-registered on the server?

PS we could use a scheduled task as-in https://gist.github.com/rgl/19ae3a6b0a5d6f30bd9baa89a2d457c0

denisix pushed a commit to denisix/agent-rdp that referenced this pull request Aug 9, 2026
Merged from thisnick#74 (mikhailsal). 500ms after Win+R was
insufficient when a foreground app had focus, causing typed characters
to be lost. Pre-load clipboard and paste via Ctrl+V instead of typing
character-by-character, and increase the post-Win+R delay to 2000ms.
denisix pushed a commit to denisix/agent-rdp that referenced this pull request Aug 9, 2026
Update the automate run examples and bootstrap-sequence description to
match the clipboard-paste bootstrap (thisnick#74) and the new
--shell/--stream/run-poll flags, and note that legacy TLS targets are
unsupported (thisnick#73).
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.

2 participants