Skip to content

Removed the task implementation in unix agent#4409

Merged
ravirk91 merged 1 commit into
masterfrom
Issue_58103
Jan 16, 2026
Merged

Removed the task implementation in unix agent#4409
ravirk91 merged 1 commit into
masterfrom
Issue_58103

Conversation

@shahanemahesh

@shahanemahesh shahanemahesh commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

Description

Type of Change

  • Bug fix - [ ] New feature - [ ] Breaking change - [ ] Plugin update

Checklist

  • PR description clearly describes the changes
  • Target branch is correct (master for features, Releases/* for fixes)
  • Latest code from target branch merged
  • No commented/junk code included
  • No new build warnings or errors
  • All existing unit tests pass
  • New unit tests added for new functionality
  • Cross-platform compatibility verified (Windows/Linux/macOS)
  • CI/CD pipeline passes
  • Code follows project conventions (Act{Platform}{Type}, {Platform}Driver)
  • Repository objects use [IsSerializedForLocalRepository] where needed
  • Error handling uses Reporter.ToLog() pattern
  • Documentation updated for user-facing changes
  • Self-review completed and code review comments addressed

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved Unix shell connection reliability with timeout-based polling mechanism that automatically times out if connection cannot be established within the configured timeout period.
  • Refactor

    • Modified connection establishment flow to synchronous polling loop with keep-alive signaling, ensuring subsequent operations proceed only after connection is confirmed or timeout occurs.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Unix SSH connection logic was refactored from asynchronous Task-based execution to a synchronous polling loop approach. The new implementation uses a stopwatch-bounded polling mechanism that continuously checks connection status with 500ms intervals until successful connection or timeout occurs.

Changes

Cohort / File(s) Summary
Connection Logic Refactoring
Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs
Replaced async Task.StartNew connection block with synchronous polling loop. Immediately calls UnixClient.Connect() after instantiation, then implements time-bounded polling with 500ms sleep intervals until IsConnected becomes true or SSHConnectionTimeout elapses. Added keep-alive transmission and shell stream creation within polling success path. Error handling now routes through Reporter logging instead of task exception mechanism.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A polling loop hops through the SSH night,
No more async tasks—just sync and tight!
Five-hundred milliseconds, a steady beat,
Until the connection's finally complete!
Simple and steady wins the shell stream race,
With timeout grace and a determined pace. 🎯

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is almost entirely empty - the template is present but no actual content or context has been provided to describe the changes, reasoning, or impact. Fill in the Description section with details about what changed and why. Select the appropriate Type of Change checkbox. Complete relevant checklist items to confirm testing and compatibility verification.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: replacing asynchronous Task-based logic with synchronous polling in the Unix SSH connection implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Issue_58103

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs`:
- Around line 261-284: Remove the large commented-out test block related to
UnixClient/Task/Stopwatch (the lines referencing UnixClient.Connect,
UnixClient.CreateShellStream, task, st/Stopwatch, and SSHConnectionTimeout) so
only active production code remains; ensure you also delete any now-unused local
variables or references (e.g., task, st, ss) declared solely for that commented
section to avoid unused symbol warnings.
- Around line 286-303: Move the synchronous UnixClient.Connect() call into the
try-catch block and remove the redundant polling loop that waits on
UnixClient.IsConnected and Thread.Sleep; since SshClient.Connect() is blocking
and respects connectionInfo.Timeout, call UnixClient.Connect() inside the try,
then immediately (after a successful connect/IsConnected check) call
UnixClient.SendKeepAlive() and ss = UnixClient.CreateShellStream("dumb", 240,
24, 800, 600, 1024); ensure exceptions from Connect() are caught by the existing
catch and drop the SSHConnectionTimeout polling logic.
📜 Review details

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c673073 and e5b289d.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.cs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use Reporter.ToLog(eLogLevel.ERROR, message) for logging errors

Files:

  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs
🧠 Learnings (1)
📚 Learning: 2025-12-18T05:29:42.896Z
Learnt from: AmanPrasad43
Repo: Ginger-Automation/Ginger PR: 4385
File: Ginger/GingerCoreNET/Run/Excels/ExcelNPOIOperations.cs:468-475
Timestamp: 2025-12-18T05:29:42.896Z
Learning: In the Ginger codebase, assume file extensions are lowercase (e.g., .xlsx, .xls). Do not perform case-insensitive extension checks (such as StringComparison.OrdinalIgnoreCase) when using EndsWith() or similar methods to verify file extensions; rely on lowercase comparisons or convert to lowercase first. This ensures consistency and avoids unnecessary case-insensitive comparisons across C# source files.

Applied to files:

  • Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs
🧬 Code graph analysis (1)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs (2)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/DOSConsoleDriver.cs (1)
  • Connect (54-91)
Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/ConsoleDriverBase.cs (1)
  • Connect (92-92)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +261 to +284
//Commenting the code for testing the change
//var task = Task.Factory.StartNew(() =>
// {
// try
// {
// UnixClient.Connect();

// if (UnixClient.IsConnected)
// {
// UnixClient.SendKeepAlive();
// ss = UnixClient.CreateShellStream("dumb", 240, 24, 800, 600, 1024);
// }
// }
// catch (Exception ex)
// {
// Reporter.ToLog(eLogLevel.ERROR, "Error while connecting to Unix Client.", ex);
// }
// });

//var st = Stopwatch.StartNew();
//while (!task.IsCompleted && st.ElapsedMilliseconds < SSHConnectionTimeout * 1000)
//{
// task.Wait(500); // Give user feedback every 500ms
//}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove commented-out code before merging.

The comment on line 261 states this is "for testing the change," indicating this isn't production-ready. Commented-out code adds noise and maintenance burden. Version control preserves history if the old implementation needs to be referenced later.

Suggested fix
                UnixClient.Connect();

-                //Commenting the code for testing the change
-                //var task = Task.Factory.StartNew(() =>
-                // {
-                //     try
-                //     {                         
-                //         UnixClient.Connect();
-
-                //         if (UnixClient.IsConnected)
-                //         {
-                //             UnixClient.SendKeepAlive();
-                //             ss = UnixClient.CreateShellStream("dumb", 240, 24, 800, 600, 1024);
-                //         }
-                //     }
-                //     catch (Exception ex)
-                //     {
-                //         Reporter.ToLog(eLogLevel.ERROR, "Error while connecting to Unix Client.", ex);
-                //     }
-                // });
-
-                //var st = Stopwatch.StartNew();
-                //while (!task.IsCompleted && st.ElapsedMilliseconds < SSHConnectionTimeout * 1000)
-                //{
-                //    task.Wait(500);  // Give user feedback every 500ms
-                //}
-
                try
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
//Commenting the code for testing the change
//var task = Task.Factory.StartNew(() =>
// {
// try
// {
// UnixClient.Connect();
// if (UnixClient.IsConnected)
// {
// UnixClient.SendKeepAlive();
// ss = UnixClient.CreateShellStream("dumb", 240, 24, 800, 600, 1024);
// }
// }
// catch (Exception ex)
// {
// Reporter.ToLog(eLogLevel.ERROR, "Error while connecting to Unix Client.", ex);
// }
// });
//var st = Stopwatch.StartNew();
//while (!task.IsCompleted && st.ElapsedMilliseconds < SSHConnectionTimeout * 1000)
//{
// task.Wait(500); // Give user feedback every 500ms
//}
UnixClient.Connect();
try
🤖 Prompt for AI Agents
In `@Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs` around
lines 261 - 284, Remove the large commented-out test block related to
UnixClient/Task/Stopwatch (the lines referencing UnixClient.Connect,
UnixClient.CreateShellStream, task, st/Stopwatch, and SSHConnectionTimeout) so
only active production code remains; ensure you also delete any now-unused local
variables or references (e.g., task, st, ss) declared solely for that commented
section to avoid unused symbol warnings.

Comment on lines +286 to +303
try
{
task.Wait(500); // Give user feedback every 500ms
var st = Stopwatch.StartNew();
while (st.ElapsedMilliseconds < SSHConnectionTimeout * 1000)
{
Thread.Sleep(500);
if (UnixClient.IsConnected)
{
UnixClient.SendKeepAlive();
ss = UnixClient.CreateShellStream("dumb", 240, 24, 800, 600, 1024);
break;
}
}
}
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "Error while connecting to Unix Client.", ex);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Renci.SshNet SshClient.Connect() method synchronous blocking behavior

💡 Result:

SshClient.Connect() is a synchronous (blocking) call: it blocks the calling thread until the TCP/SSH session and authentication complete or an exception (e.g., timeout, SocketException, SshConnectionException, SshAuthenticationException) is thrown. Use ConnectionInfo.Timeout to control connection/authentication timeouts. If you need non‑blocking behavior use the provided async API (ConnectAsync with a CancellationToken). [1][2][3]

Sources:

  • SshClient.Connect() (API docs). [1]
  • ConnectionInfo.Timeout property (controls connect timeout). [2]
  • Session / ConnectAsync (async alternative). [3]

🏁 Script executed:

# First, let's locate and examine the file to understand the full context
find . -name "UnixShellDriver.cs" -type f

Repository: Ginger-Automation/Ginger

Length of output: 137


🏁 Script executed:

# Read the relevant section of the file to see full context
sed -n '250,310p' ./Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs | cat -n

Repository: Ginger-Automation/Ginger

Length of output: 3134


Redundant polling loop — Connect() is synchronous and blocking.

SshClient.Connect() (line 259) is a synchronous call that either succeeds (setting IsConnected = true immediately) or throws an exception. It won't return with IsConnected = false. This makes the polling loop redundant:

  1. If Connect() succeeds, IsConnected is already true before entering the loop
  2. If Connect() fails, an exception is thrown and the loop is never reached
  3. Thread.Sleep(500) on line 291 runs before checking IsConnected, causing an unnecessary 500ms delay
  4. The connection timeout is already configured via connectionInfo.Timeout (line 257)

Additionally, the current code calls Connect() outside the try-catch block (line 259), so exceptions are not caught. Move Connect() into the try-catch for proper error handling.

Suggested fix
                UnixClient = new SshClient(connectionInfo);
-                UnixClient.Connect();
-
-                try
-                {
-                    var st = Stopwatch.StartNew();
-                    while (st.ElapsedMilliseconds < SSHConnectionTimeout * 1000)
-                    {
-                        Thread.Sleep(500);
-                        if (UnixClient.IsConnected)
-                        {
-                            UnixClient.SendKeepAlive();
-                            ss = UnixClient.CreateShellStream("dumb", 240, 24, 800, 600, 1024);
-                            break;
-                        }
-                    }
-                }
-                catch (Exception ex)
-                {
-                    Reporter.ToLog(eLogLevel.ERROR, "Error while connecting to Unix Client.", ex);
-                }            
+                try
+                {
+                    UnixClient.Connect();
+                    if (UnixClient.IsConnected)
+                    {
+                        UnixClient.SendKeepAlive();
+                        ss = UnixClient.CreateShellStream("dumb", 240, 24, 800, 600, 1024);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    Reporter.ToLog(eLogLevel.ERROR, "Error while connecting to Unix Client.", ex);
+                }

                 if (UnixClient.IsConnected)
🤖 Prompt for AI Agents
In `@Ginger/GingerCoreNET/Drivers/CoreDrivers/Console/UnixShellDriver.cs` around
lines 286 - 303, Move the synchronous UnixClient.Connect() call into the
try-catch block and remove the redundant polling loop that waits on
UnixClient.IsConnected and Thread.Sleep; since SshClient.Connect() is blocking
and respects connectionInfo.Timeout, call UnixClient.Connect() inside the try,
then immediately (after a successful connect/IsConnected check) call
UnixClient.SendKeepAlive() and ss = UnixClient.CreateShellStream("dumb", 240,
24, 800, 600, 1024); ensure exceptions from Connect() are caught by the existing
catch and drop the SSHConnectionTimeout polling logic.

@ravirk91
ravirk91 enabled auto-merge January 16, 2026 04:59
@ravirk91
ravirk91 disabled auto-merge January 16, 2026 04:59
@ravirk91
ravirk91 merged commit e053f09 into master Jan 16, 2026
13 of 14 checks passed
@ravirk91
ravirk91 deleted the Issue_58103 branch January 16, 2026 05:00
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