Skip to content

Race condition: addLabels fails with 'Could not resolve to a node' immediately after PR creation #4321

@akhozya-dojo

Description

@akhozya-dojo

Description

When creating a PR and applying labels in quick succession, the addLabels API call can fail with:

Error: Validation Failed: {"resource":"Label","code":"unprocessable","field":"data","message":"Could not resolve to a node with the global id of 'PR_kwDOOCYeos7H8Z48'."}

Root Cause

The action creates the PR first, then immediately calls octokit.rest.issues.addLabels(). Due to GitHub API eventual consistency, the PR may not be immediately resolvable via the API in the milliseconds between creation and the label API call.

Reproduction

This is intermittent and timing-dependent. It seems to occur more frequently when:

  • GitHub API is under load
  • The target repository has webhooks/bots that react to PR creation

Example failed run: PR was created at 17:47:28Z, label application failed at the same second.

Relevant Code

In src/github-helper.ts:

// 1. Create PR
const pull = await this.createOrUpdate(inputs, baseRepository, headRepository)

// 2. Immediately try to add labels - can fail due to eventual consistency
if (inputs.labels.length > 0) {
  await this.octokit.rest.issues.addLabels({
    issue_number: pull.number,
    labels: inputs.labels
  })
}

Suggested Fix

Add retry logic with a small delay for the label application:

if (inputs.labels.length > 0) {
  core.info(`Applying labels '${inputs.labels}'`)
  for (let attempt = 1; attempt <= 3; attempt++) {
    try {
      await this.octokit.rest.issues.addLabels({
        ...this.parseRepository(baseRepository),
        issue_number: pull.number,
        labels: inputs.labels
      })
      break
    } catch (e) {
      if (attempt === 3) throw e
      core.warning(`Label application failed (attempt ${attempt}/3), retrying in 1s...`)
      await new Promise(r => setTimeout(r, 1000))
    }
  }
}

The same pattern could be applied to assignees, reviewers, and milestone application.

Environment

  • Action version: v7.0.11 (also checked v8.1.0 - same code)
  • Runner: ubuntu-latest
  • Occurs when labels input is provided

Workaround

Re-running the workflow usually succeeds since the timing is intermittent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions