Skip to content

add hybrid idle detection (ssh connections + marker file)#1

Merged
aayushshah15 merged 1 commit intomainfrom
hybrid-idle-detection
Feb 15, 2026
Merged

add hybrid idle detection (ssh connections + marker file)#1
aayushshah15 merged 1 commit intomainfrom
hybrid-idle-detection

Conversation

@aayushshah15
Copy link
Contributor

@aayushshah15 aayushshah15 commented Feb 15, 2026

Summary

  • Replaces marker-file-only idle detection with a hybrid approach: checks for active SSH connections to the runner port first (catches interactive sessions, long-running commands, rsync), falls back to the ~/.testbox-last-activity marker file for short-lived CLI commands
  • Updates README to document the hybrid detection mechanism

Made with Cursor


Open with Devin

instead of relying solely on the marker file, the idle loop now
checks for active ssh connections to the runner port first. this
catches interactive sessions and long-running commands generically.
the marker file remains as a fallback for short-lived cli commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
@aayushshah15 aayushshah15 merged commit 0feba4e into main Feb 15, 2026
1 check passed
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

if [ -f ~/.testbox-last-activity ]; then
LAST_ACTIVITY=$(stat -c %Y ~/.testbox-last-activity)
# Check for active SSH connections to the runner's SSH port
if ss -tnp 2>/dev/null | grep -q ":${RUNNER_SSH_PORT}\b" ; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 SSH port grep matches outgoing connections, not just incoming ones

The ss output grep pattern :${RUNNER_SSH_PORT}\b matches the port number anywhere on the line, including in the Peer Address:Port column. This means outgoing connections from the runner to remote port 22 (e.g., git clone git@github.com:..., ssh to another host) are falsely detected as incoming SSH activity.

Root cause and impact

ss -tnp output has this format:

State  Recv-Q  Send-Q  Local Address:Port   Peer Address:Port  Process
ESTAB  0       0       172.16.9.2:54321     1.2.3.4:22         users:(("ssh"...))

The grep pattern grep -q ":${RUNNER_SSH_PORT}\b" scans the entire line, so it matches :22 in the Peer Address column too. For the default port 22, any outgoing SSH connection from the runner (git over SSH, scp, ssh tunnels) will keep LAST_ACTIVITY pinned to $NOW on every polling cycle, preventing the idle timeout from ever triggering.

Impact: Runners using the default SSH port 22 that have any outgoing SSH connection will never idle-timeout, staying alive until the GitHub Actions job-level timeout (typically 6 hours). This wastes compute resources and money.

The fix should constrain the match to the local address column only. For example, by checking that the port appears as a local listening port:

if ss -tnp state established 2>/dev/null | awk '{print $4}' | grep -q ":${RUNNER_SSH_PORT}$" ; then
Suggested change
if ss -tnp 2>/dev/null | grep -q ":${RUNNER_SSH_PORT}\b" ; then
if ss -tnp 2>/dev/null | awk '{print $4}' | grep -q ":${RUNNER_SSH_PORT}$" ; then
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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