Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 2, 2025

This PR fixes an issue where bash and Ansible tasks were reporting Success or Failed status before the script execution and log processing were fully complete, leading to false positives and preventing manual task termination.

Problem

The issue occurred because ShellApp.Run() and AnsiblePlaybook methods were calling cmd.Wait() to wait for process completion but were not calling WaitLog() to wait for log processing goroutines to finish. This created a race condition where:

  1. The bash script/ansible playbook completes and cmd.Wait() returns
  2. The task is immediately marked as successful in the UI
  3. Log processing goroutines continue running in the background, still reading and displaying output
  4. Users see "Success" status while logs are still being processed, creating the impression that the task completed prematurely
  5. The Stop button becomes unavailable since the task appears "done"

This was particularly problematic for long-running commands like rsync where users would see the task marked as complete while the actual transfer was still in progress.

Solution

Added WaitLog() calls after cmd.Wait() in:

  • ShellApp.Run() - for bash, Python, PowerShell and other shell-based tasks
  • AnsiblePlaybook.RunPlaybook() - for Ansible playbook execution
  • AnsiblePlaybook.runCmd() - for Ansible Galaxy and other ansible commands

The fix ensures that task status is only reported as complete after both:

  1. The process itself has finished (cmd.Wait() returns)
  2. All log processing goroutines have finished reading output (WaitLog() returns)

Note: TerraformApp already had the correct implementation with WaitLog() calls, so no changes were needed there.

Testing

  • All existing unit tests continue to pass
  • Created demonstration scripts to validate the fix behavior
  • Manual testing confirms tasks now wait for complete log processing before status updates
  • Verified the server starts and runs correctly with the changes

Fixes #3234.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Problem: Bash Tasks report a Success or Failed status before script is done running Fix premature task status reporting for bash and Ansible tasks Sep 2, 2025
@Copilot Copilot AI requested a review from fiftin September 2, 2025 20:44
Copilot finished work on behalf of fiftin September 2, 2025 20:44
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.

Problem: Bash Tasks report a Success or Failed status before script is done running
2 participants