Skip to content

Conversation

@buildingvibes
Copy link

/claim #200

Summary

Adds an opt-in keepalive feature to the existing windows-rdp module that prevents workspace autostop during active RDP sessions.

How it works

When keepalive = true, a background PowerShell script (coder_script) runs on workspace start that:

  1. Polls port 3389 every keepalive_interval seconds (default: 30) using Get-NetTCPConnection -LocalPort 3389 -State Established
  2. When an established RDP connection is detected, calls PUT /api/v2/workspaces/{workspace_id}/extend using the CODER_AGENT_TOKEN that the Coder agent sets automatically
  3. When the RDP session disconnects, stops sending activity bumps and the normal autostop countdown resumes

This uses the manual activity bump API recommended by @matifali in #200 (comment).

Why this approach

  • Uses the correct API: Calls the documented workspace extend endpoint with CODER_AGENT_TOKEN rather than relying on stdout/stderr, coder stat, or registry keys (which only keep the TCP connection alive but don't tell Coder the workspace is active)
  • Integrated into the existing module: No separate module needed; just set keepalive = true
  • Backward compatible: Defaults to false, no behavior change for existing users
  • Minimal and focused: ~80 lines of PowerShell, one new coder_script resource, two new variables

Usage

module "windows_rdp" {
  count              = data.coder_workspace.me.start_count
  source             = "registry.coder.com/coder/windows-rdp/coder"
  version            = "1.4.0"
  agent_id           = coder_agent.main.id
  keepalive          = true
  keepalive_interval = 30
}

Changes

  • main.tf: Added keepalive (bool) and keepalive_interval (number) variables, conditional data.coder_workspace data source, and coder_script.windows-rdp-keepalive resource
  • rdp-keepalive.ps1.tftpl: PowerShell script that monitors port 3389 and calls the extend API
  • main.tftest.hcl: Terraform plan tests for the new feature (and base module)
  • main.test.ts: TypeScript tests verifying keepalive script creation and content
  • README.md: Version bump to 1.4.0, added keep-alive usage example

Test plan

  • terraform test -verbose passes in the module directory
  • bun test main.test.ts passes (keepalive script creation, content validation, interval customization)
  • Existing tests continue to pass (backward compatibility)
  • Deploy with keepalive = true on a Windows workspace, connect via RDP, verify workspace deadline extends in Coder dashboard
  • Disconnect RDP, verify autostop countdown resumes normally

Add opt-in keepalive feature that monitors port 3389 for established
RDP connections and calls the Coder workspace extend API to prevent
autostop during active remote desktop sessions.

The keepalive script runs as a background coder_script that:
- Uses Get-NetTCPConnection to detect active RDP connections
- Calls PUT /api/v2/workspaces/{id}/extend with CODER_AGENT_TOKEN
- Checks at a configurable interval (default 30s)
- Only reports activity when connections are present

New variables: keepalive (bool, default false), keepalive_interval
(number, default 30). Backward compatible - no changes when disabled.

Closes coder#200
@buildingvibes
Copy link
Author

Working on recording a demo video showing the keepalive feature in action with a live Coder workspace. Will update shortly.

@buildingvibes
Copy link
Author

Demo Video

https://github.com/buildingvibes/registry/releases/download/demo-videos-coder-pr710/coder-rdp-pr710.mp4

This demo showcases:

  • RDP keep-alive functionality: The new opt-in keepalive feature in action
  • Workspace deadline extension: Showing how active RDP sessions automatically extend the workspace deadline
  • Configuration: Demonstrates the keepalive = true and keepalive_interval settings
  • API integration: Shows the PowerShell script calling the /api/v2/workspaces/{id}/extend endpoint when RDP connections are detected

The video demonstrates how the keep-alive feature prevents workspace autostop during active RDP sessions, then allows normal autostop countdown to resume when the RDP session disconnects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant