Skip to content

Fix silent runner startup after login - #2

Merged
nevstop merged 4 commits into
mainfrom
fix/autostart-runner-silently
Sep 4, 2026
Merged

Fix silent runner startup after login#2
nevstop merged 4 commits into
mainfrom
fix/autostart-runner-silently

Conversation

@nevstop

@nevstop nevstop commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • start the runner automatically when Windows launches the tray at login
  • keep login startup silent while recording its result in the host log
  • migrate existing tray-only autostart commands with failure-safe, directory-aware registry updates

Validation

  • Pester 5.5.0: 14 passed
  • PowerShell syntax parser: passed
  • PSScriptAnalyzer (Error): passed
  • git diff --check: passed

@nevstop

nevstop commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Development log: investigation and regression

  • Confirmed the repository was clean on main and no open PR existed.
  • Traced the defect to Get-AutostartCommand: Windows login launched only the tray, while Start-RunnerControl was reachable only from the menu or CLI.
  • Added regression coverage requiring the autostart command to request runner startup and requiring silent startup to log its result without invoking UI.
  • Verified the new test failed on the previous implementation because Start-RunnerSilently did not exist.
  • Local Pester 3.4 was incompatible with the repository's Pester 5 assertions, so installed and used the CI-pinned Pester 5.5.0 for authoritative results.

@nevstop

nevstop commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Development log: implementation and validation

  • Added -StartRunnerOnLaunch exclusively to the registry autostart command.
  • On login startup, the runner is started before the tray message loop; the result is written to .trayicon/runner-host.log, and no success confirmation dialog is shown.
  • Preserved the existing interactive menu behavior.
  • Added migration for an existing same-path tray-only registry command so upgraded users receive the fix without toggling autostart off and on.
  • Updated the README behavior description.
  • Validation passed: Pester 5.5.0 (12/12), PowerShell parser, PSScriptAnalyzer Error severity, and git diff --check.
  • Initial push was rejected by GitHub private-email protection; changed only this repository's Git email to the authenticated account's noreply address, amended the unpublished commit metadata, and pushed successfully.

@nevstop

nevstop commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Development log: independent review round 1

The Explore subagent found one blocking migration issue and one related multi-runner risk:

  • Replacement previously removed the shared legacy value before writing the new hashed value, so a write failure could disable startup.
  • Enabling one runner could remove a shared legacy value belonging to another runner directory.

Remediation in ef0b39c:

  • Write the per-directory value first, then remove the shared legacy value only when it exactly matches this runner's current or tray-only command.
  • Catch migration-write failures, retain the old command, log the failure best-effort, and still request runner startup for the current login.
  • Added regression tests for unrelated shared-value preservation and migration-write failure.
  • Full local validation passed: Pester 5.5.0 (14/14), parser, PSScriptAnalyzer Error severity, and git diff --check.

A second independent review will run after CI completes.

@nevstop

nevstop commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Development log: independent review round 2

The second Explore review confirmed the migration-write blocker was fixed, then found one remaining ownership issue: disabling autostart still removed the shared legacy value unconditionally.

Remediation in 63db098:

  • The disable path now removes the shared legacy value only when it exactly belongs to the current runner directory.
  • Extended regression coverage to verify another runner directory's shared value survives both enabling and disabling this runner's autostart.
  • Full local validation passed again: Pester 5.5.0 (14/14), parser, PSScriptAnalyzer Error severity, and git diff --check.

A third independent review will run after CI completes.

@nevstop

nevstop commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Development log: independent review round 3

The third Explore review found no blocking issues and judged PR #2 deliverable. It rechecked all earlier migration and ownership findings, silent login startup, PowerShell 5.1 compatibility, and test coverage.

One non-blocking documentation mismatch remained: the README implied the shared legacy value was always removed when disabling autostart. Commit 033699f now states that cleanup occurs only when the value points to the current runner directory. Pester 5.5.0 remains green (14/14), and git diff --check passed.

A final quick review and latest CI confirmation will close the delivery gate.

@nevstop

nevstop commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Delivery gate passed

  • Final reviewed HEAD: 033699f
  • Independent Explore review: no blocking findings; deliverable verdict YES
  • GitHub CI: Static analysis, Pester (Windows PowerShell), and Pester (pwsh) all passed
  • Local validation: Pester 5.5.0 (14/14), parser, PSScriptAnalyzer Error severity, and git diff --check
  • PR is open, non-draft, mergeable, and the local branch is clean and synchronized with origin

PR #2 is ready for delivery.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new legacy-autostart cleanup/migration logic relies on exact command-string equality (including the exact PowerShell executable path), which can fail to detect/clean legacy entries that still target the same script, leading to missed migration and possible double-launch behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the tray launcher so that when started at Windows login it will automatically start the runner silently and record the outcome to the host log, while also safely migrating older “tray-only” autostart registry entries to the new behavior.

Changes:

  • Add -StartRunnerOnLaunch to the autostart command line and wire it into startup flow.
  • Add a silent runner-start helper that logs success/failure without UI.
  • Add legacy autostart migration/repair logic and extend Pester coverage + README documentation accordingly.
File summaries
File Description
runner-tray.ps1 Adds login-triggered silent runner startup and legacy autostart migration/cleanup logic.
tests/runner-tray.Tests.ps1 Extends Pester tests to validate silent startup logging and legacy registry migration behavior.
README.md Updates documentation to reflect silent startup and safer legacy autostart cleanup behavior.
Review details

Suppressed comments (2)

runner-tray.ps1:354

  • Same issue in the disable path: the legacy fixed-name value is only removed when it exactly matches the currently generated command strings. If it still points at this script but differs in exe path/flags, disabling autostart can leave the legacy entry behind, so Windows will continue launching the tray.
    try {
        $legacyValue = (Get-ItemProperty -Path $AutostartRegPath -Name $LegacyAutostartValueName -ErrorAction Stop).$LegacyAutostartValueName
        if ($legacyValue -and ($legacyValue.Trim() -iin @((Get-AutostartCommand), (Get-LegacyAutostartCommand)))) {
            Remove-ItemProperty -Path $AutostartRegPath -Name $LegacyAutostartValueName -ErrorAction SilentlyContinue
        }

runner-tray.ps1:366

  • Repair-LegacyAutostartCommand only recognizes legacy entries when the entire stored command equals Get-LegacyAutostartCommand (including the exact $PowerShellExe path). If the legacy value still points at this runner-tray.ps1 but uses a different exe path/flags, migration (and the intended silent runner start) will never trigger.
    $legacyCommand = Get-LegacyAutostartCommand
    foreach ($valueName in @($AutostartValueName, $LegacyAutostartValueName)) {
        try {
            $currentValue = (Get-ItemProperty -Path $AutostartRegPath -Name $valueName -ErrorAction Stop).$valueName
            if ($currentValue -and ($currentValue.Trim() -ieq $legacyCommand)) {
                try {
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread runner-tray.ps1
Comment on lines +338 to +342
try {
$legacyValue = (Get-ItemProperty -Path $AutostartRegPath -Name $LegacyAutostartValueName -ErrorAction Stop).$LegacyAutostartValueName
if ($legacyValue -and ($legacyValue.Trim() -iin @((Get-AutostartCommand), (Get-LegacyAutostartCommand)))) {
Remove-ItemProperty -Path $AutostartRegPath -Name $LegacyAutostartValueName -ErrorAction SilentlyContinue
}
@nevstop
nevstop merged commit 87902b5 into main Sep 4, 2026
4 checks passed
@nevstop
nevstop deleted the fix/autostart-runner-silently branch September 4, 2026 08:46
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