`gh run watch` drops annotations for jobs that are queued on the first poll

Ouverte Adaptée aux débutants
#15,186 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

  • #15221 par @aloneangel45 — fermée sans fusion

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
84/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
github, go
Domaine
cli, testing

Piste de recherche

Lis renderRun dans pkg/cmd/run/watch/watch.go ainsi que les tests dans pkg/cmd/run/watch/watch_test.go. Reproduis le comportement de la première interrogation en attente et celui du cache, puis ajoute des tests pour les annotations ultérieures, plusieurs jobs terminés et les jobs terminés sans annotations. Le travail est terminé lorsque gh run watch conserve les annotations de chaque job et que les tests réussissent.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug gh-run priority-3
Describe the bug

gh run watch can show the wrong annotations, or none, for jobs in a run. Two cases:

  1. A job that is queued on the first poll never shows its annotations. Jobs that wait on needs: start out as queued. The watch loop caches every job whose status is not in_progress, including queued, so the job is cached with no annotations and is never fetched again. When it later fails, its error annotations are missing from the watch output and the final summary.
  2. Annotations from one job overwrite another's. On a cache hit the loop does annotations = as, which replaces everything collected so far in that poll instead of appending. The cache entry is also the running total for the poll, not that job's own annotations. Depending on job order, annotations from earlier jobs are dropped.

gh run view <id> shows the correct annotations for the same run, so the two commands disagree.

The code is in renderRun in pkg/cmd/run/watch/watch.go (trunk @ aec3808914, lines 247-271):

for _, job := range jobs {
    if as, ok := annotationCache[job.ID]; ok {
        annotations = as          // replaces instead of appending
        continue
    }
    as, err := shared.GetAnnotations(client, repo, job)
    ...
    annotations = append(annotations, as...)

    if job.Status != shared.InProgress {        // also true for queued / waiting / pending
        annotationCache[job.ID] = annotations   // caches the running total, not this job's `as`
    }
}
Affected version

Present in v2.95.0 and v2.106.0 (latest), and on trunk @ aec3808914. The logic is not platform-specific.

Steps to reproduce the behavior

Workflow (.github/workflows/repro.yml) in any test repo:

on: workflow_dispatch
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - run: sleep 30
  test:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo "::error::TEST_JOB_ERROR"
          exit 1
  1. gh workflow run repro.yml
  2. Right away, gh run watch <run-id> (test is queued while build runs)
  3. When the run finishes, compare with gh run view <run-id>
Expected vs actual behavior

Expected: the ANNOTATIONS section of gh run watch shows TEST_JOB_ERROR for the test job, the same as gh run view.

Actual: gh run watch shows no annotation for test, because the job was cached while it was queued. gh run view shows it.

Logs

I ran a direct port of the loop above over simulated polls. Current behavior vs. the proposed fix below:

case                                              current            fixed
test queued on poll 1, later errors               []                 [TEST_JOB_ERROR]
job order [slow, fast]; fast finishes first,      [EARLY_FAST]       [LATE_SLOW, EARLY_FAST]
  slow emits a warning later
Proposed fix

Cache each job's own annotations only once the job has completed, and append cached entries instead of replacing:

 	for _, job := range jobs {
 		if as, ok := annotationCache[job.ID]; ok {
-			annotations = as
+			annotations = append(annotations, as...)
 			continue
 		}
@@
 		annotations = append(annotations, as...)

-		if job.Status != shared.InProgress {
-			annotationCache[job.ID] = annotations
+		if job.Status == shared.Completed {
+			annotationCache[job.ID] = as
 		}
 	}

Suggested tests for pkg/cmd/run/watch/watch_test.go: a job that is queued on the first poll and later gets annotations; two completed jobs with different annotations, in either order; a completed job with zero annotations, which should still be cached and not re-fetched. Happy to open a PR with this if it helps.

Langage dominant
Go
Étoiles
47.4k
Forks
9.5k
Merge moyen
18 h 34 min
PR mergées (30 j)
70

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de cli/cli

Toutes les issues de cli/cli

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.