Skip to content

Fix JQ query failures in GitHub workflow caused by double command execution bug#20

Merged
byron-infomagnus merged 3 commits intomainfrom
copilot/fix-19
Jul 11, 2025
Merged

Fix JQ query failures in GitHub workflow caused by double command execution bug#20
byron-infomagnus merged 3 commits intomainfrom
copilot/fix-19

Conversation

Copy link
Contributor

Copilot AI commented Jul 11, 2025

Problem

The pull-project-tasks.yml workflow was failing with "Invalid JSON response from GitHub API" errors despite receiving valid JSON responses from the GitHub GraphQL API. The error manifested as:

Error: Invalid JSON response from GitHub API:
Checking GraphQL API rate limit...
GraphQL API points remaining: 5000
Attempt 1 of 5: gh api graphql -f query=query($org: String!) { ... }
{"data":{"organization":{"projectsV2":{"nodes":[...]}}}}Command succeeded on attempt 1.
Error: Process completed with exit code 1.

Root Cause

Analysis revealed two critical bugs in the retry_with_backoff function used by all API calls:

  1. Double Command Execution: Failed commands were executed twice - once to test success/failure, then again to capture error output
  2. JSON Response Contamination: Success messages were concatenated with API responses, creating malformed JSON

Before:

if "$@"; then
  echo "Command succeeded on attempt $attempt."
  return 0
else
  local exit_code=$?
  response=$("$@" 2>&1)  # ❌ Command executed AGAIN
  echo "Command response: $response"

This resulted in captured responses like:

{"data":{"organization":{"projectsV2":{"nodes":[...]}}}}Command succeeded on attempt 1.

Solution

Fixed retry_with_backoff function (4 instances):

response=$("$@" 2>&1)      # ✅ Execute ONCE
exit_code=$?
if [ $exit_code -eq 0 ]; then
  echo "Command succeeded on attempt $attempt." >&2  # ✅ To stderr
  echo "$response"         # ✅ Clean JSON to stdout
  return 0

Key improvements:

  • Commands execute only once, eliminating double API calls
  • Success messages redirected to stderr to avoid JSON contamination
  • Clean response output for proper JSON parsing
  • Maintained proper error handling and retry logic

Verification

All JQ queries tested and verified against actual GitHub API v4 responses:

  • ✅ REST API rate limits: .rate.remaining / .rate.reset
  • ✅ GraphQL rate limits: .data.rateLimit.remaining / .data.rateLimit.resetAt
  • ✅ Project queries: .data.organization.projectsV2.nodes[]
  • ✅ Issue queries: .data.repository.issue.id
  • ✅ Error handling: .errors field detection

Expected Behavior

  • Valid project names: Workflow continues successfully with clean JSON parsing
  • Invalid project names: Clear error message listing available projects (expected behavior)
  • API errors: Proper retry logic with exponential backoff
  • Rate limiting: Accurate detection and handling

The workflow now handles all scenarios correctly, including cases where requested project names don't exist.

Fixes #19.


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

Copilot AI and others added 2 commits July 11, 2025 19:51
…and execution

Co-authored-by: byron-infomagnus <126528428+byron-infomagnus@users.noreply.github.com>
Co-authored-by: byron-infomagnus <126528428+byron-infomagnus@users.noreply.github.com>
Copilot AI changed the title [WIP] Bug: function is failing because the JQ query is searching for incorrect fields Fix JQ query failures in GitHub workflow caused by double command execution bug Jul 11, 2025
Copilot AI requested a review from byron-infomagnus July 11, 2025 19:58
@byron-infomagnus byron-infomagnus marked this pull request as ready for review July 11, 2025 20:56
@byron-infomagnus byron-infomagnus merged commit 11fd67c into main Jul 11, 2025
@byron-infomagnus byron-infomagnus deleted the copilot/fix-19 branch July 11, 2025 20:57
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.

Bug: function is failing because the JQ query is searching for incorrect fields

2 participants