Skip to content

fix(pr-watch): report a head's CI result once when two runs in a suite share a name - #52701

Merged
nwparker merged 1 commit into
stablyai:mainfrom
NicholasTing:NicholasTing/fix-ci-green-spam
Nov 30, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
NicholasTing:NicholasTing/fix-ci-green-spam

Conversation

@NicholasTing

@NicholasTing NicholasTing commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca kept posting "CI green" to a chat every poll for the same commit. That happened when a PR had two check runs with the same name in one suite. Now it posts once.

What Changed

  • Before: a head with two same-named runs in one check suite got a new "CI green" (or failure) line on every PR-watch poll.
  • After: each real result gets one line. A real rerun still posts a line.
  • Mechanism: evaluatePRCheckOccurrence (src/main/github/pr-watch/pr-check-occurrence.ts) now builds observed contexts through observedContexts. It sorts the runs by run id and adds #2, #3, ... to the key of each repeated name, so each run gets its own saved row.

Why

The context key is suite + name, so two same-named runs shared one saved row. On every read, one of the two had a different run id from the saved row, which looks like a rerun, so a new occurrence was reported. That collision is the root cause, and giving each run its own deterministic key fixes it at the source. GitHub can return the runs in any order, which is why they are sorted by run id first.

Linked Issue

Fixes #52700

Visual Proof

N/A. This is main-process PR-watch logic with no UI change. The visible effect (no repeated chat lines) is covered by the unit test and the probes below.

Testing

  • The new test pr-check-occurrence.test.ts reads the same head twice, with the same-named runs in a different order the second time. It fails on main (expected 'success' to be null) and passes with this change.
  • Probe scenarios, run against main and then this branch:
    • Five identical polls with the runs in rotated order: 5 events on main, 1 on this branch.
    • A real rerun of one of the pair: 2 events (one per real result).
    • Pending to complete across run ids 9 and 10 (a digit boundary): 2 events.
    • Three same-named runs across two suites with a failure: 6 events on main, 1 on this branch.
    • Heads where every run name is unique: no change from main.
  • Ran the targeted vitest on src/main/github/pr-watch/, oxlint, oxfmt, the anti-slop, code-quality and ast-grep gates, and the changed-code quality gate. All pass. Checked on macOS. The logic has no platform-specific code.

Performance

PR-watch polling runs in the main process, once per watched head per poll. The cost is one sort and one map over that head's check rows. Per evaluatePRCheckOccurrence call:

Check rows on the head main this PR
30 (typical) ~10 us ~14 us
100 ~33 us ~49-59 us
1000 (adversarial) ~330 us ~650 us
5000 (adversarial) ~1.6 ms ~3.7-4.3 ms

Every case stays far under 16 ms. It adds no I/O, subprocess or polling. The work scales only with that head's own rows, not with other watched PRs.

Risk

Level: Low

The first read after upgrading can post one extra CI line for a head with same-named runs, because the #2 key is new to the saved rows. Edge case: a job literally named Publish#2 next to two Publish runs could collide. That is unlikely and no worse than main. The key is a value in an existing text column, so there is no schema change. A plain revert backs it out.

Review

Main-process logic only, with no path, shell or platform code, so it behaves the same on macOS, Linux, Windows and SSH hosts. No IPC or mobile protocol change.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • Targeted tests, lint, format and static gates pass locally; CI covers the full suite

Original fix by @NicholasTing.

@NicholasTing
NicholasTing marked this pull request as ready for review November 29, 2026 23:27
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge, with the previously reported name-collision edge case remaining as a non-blocking issue.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with the previously reported name-collision edge case remaining as a non-blocking issue.

Findings

  1. P2 Generated keys match real names ▶

Summary

The PR gives same-named checks separate saved rows so unchanged polls stop repeating a CI result.

  • PR-watch keeps same-named check runs separate across polls.

Reviews (2) · Last reviewed commit: "fix(pr-watch): report a head's CI result..." · Reviewed by Greptile

.map((row) => {
const count = (seen.get(row.context) ?? 0) + 1
seen.set(row.context, count)
return count === 1 ? row : { ...row, context: `${row.context}#${count}` }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Generated keys match real names

Two runs named build and one named build#2 in the same suite produce two rows with the same context. The database keeps only one, so an unchanged poll still reports a new CI result. Use a collision-free key for repeated names and add this case to the regression test.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The occurrence evaluator now sorts observed checks by run ID and assigns distinct context keys to repeated check names in one suite. It uses those keys when comparing observations and saving state. A new test verifies that evaluating the same runs in a different order returns a null verdict.

Merge Risk: Low · up to f39ca

The change fixes repeated "CI green" messages for same-named check runs. Two edge cases remain: a check named like a generated suffix, and runs with null IDs. In those cases an extra notification could still appear. This is low impact and unlikely to be hit.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (pr-watch) and the specific behavior: a head's CI result is reported once when two runs in a suite share a name. This matches the raw summary, which describes disambiguating sa…
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #52700), Visual Proof (N/A with reason), Testing with checklist items, Performance with a one-…
Linked Issues check Passed Issue #52700 requires one "CI green" line per commit when two same-named check runs share one check suite. The whole-PR diff (merge base to head f39ca35) adds observedContexts() in src/main/github/pr-…
Out of Scope Changes check Passed The whole-PR diff against merge base 9b27fdb touches only src/main/github/pr-watch/pr-check-occurrence.ts (observedContexts helper and its use in evaluatePRCheckOccurrence) and the new test file src/m…
Full details: Title check

Explanation

The title names the fix (pr-watch) and the specific behavior: a head's CI result is reported once when two runs in a suite share a name. This matches the raw summary, which describes disambiguating same-named check runs so each occurrence is tracked separately and unchanged reads return null. The title is specific and scoped to the main change.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #52700), Visual Proof (N/A with reason), Testing with checklist items, Performance with a one-line justification, Risk with a level and revert plan, AI Disclosure, Review, the upstream boundary checkbox, Notes, and the checklist. The 'Fixes #' placeholder in the template is filled with a real issue number. The Risk section names the riskiest part (one extra CI line for PRs with same-named runs) and how to back it out.

Full details: Linked Issues check

Explanation

Issue #52700 requires one "CI green" line per commit when two same-named check runs share one check suite. The whole-PR diff (merge base to head f39ca35) adds observedContexts() in src/main/github/pr-watch/pr-check-occurrence.ts. It sorts observed rows by runId and appends #2, #3 to repeated context keys (check:<suiteId>:<name>). evaluatePRCheckOccurrence() now calls observedContexts(rollup) instead of the earlier per-row flatMap. Each run keeps its own key, so an unchanged read compares equal and reports no new final verdict. A real rerun gets a new run id, so it still reports. The new test in pr-check-occurrence.test.ts reads two skipped same-named runs in one suite, then reads them again in a different order with the prior contexts, and expects verdict null on the second read. I did not run the test, so the claim that it fails without the fix rests on code reading. The incremental diff from the previous reviewed head (3cbc31e) could not be read, so this verdict uses the whole-PR diff. Minor uncertainty: keys are assigned by a string sort of runId, so a rerun that changes sort order could move the suffix between runs. The test does not cover that case. The PR description states one extra line appears after update, which the issue allows.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against merge base 9b27fdb touches only src/main/github/pr-watch/pr-check-occurrence.ts (observedContexts helper and its use in evaluatePRCheckOccurrence) and the new test file src/main/github/pr-watch/pr-check-occurrence.test.ts. Both serve issue #52700: the helper implements the fix and the test covers its regression. No unrelated source, UI, IPC, schema, or dependency change appears in the reviewed diff. The PR description's non-code sections do not add code changes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2d6014bf-c6a4-43e9-b8ce-11ffa5492e83
Commits

Reviewing files that changed from the base of the PR and between 3cbc31e and f39ca35.

Files selected for processing: 1

  • src/main/github/pr-watch/pr-check-occurrence.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@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

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 143aef4d-a202-41f4-acff-68fc7807c079
Commits

Reviewing files that changed from the base of the PR and between b0120a2 and 3cbc31e.

Files selected for processing: 2

  • src/main/github/pr-watch/pr-check-occurrence.test.ts
  • src/main/github/pr-watch/pr-check-occurrence.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

const seen = new Map<string, number>()
return rollup
.flatMap((row) => observedContext(row) ?? [])
.toSorted((a, b) => (a.runId ?? '').localeCompare(b.runId ?? ''))

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.

Minor · Functional Correctness · Quick win

Break ties between null-ID runs by state in observedContexts.

Runs with a null databaseId get runId: null, so their sort key is ''. Two same-name runs in one suite with null IDs compare as equal. toSorted is stable, so the rollup's input order decides which run receives the base key and which receives #2. If the rows arrive in the other order on a later read, the keys swap between states. The final comparison then sees a state change for both keys and can emit another verdict line, even though no check changed. The CheckRun schema permits a null databaseId, and prCheckRollupRows passes such rows through without filtering.

Break the tie by state so the key assignment does not depend on input order:

Suggested fix

--- "a/src/main/github/pr-watch/pr-check-occurrence.ts"
+++ "b/src/main/github/pr-watch/pr-check-occurrence.ts"
@@ -61,7 +61,9 @@
   const seen = new Map<string, number>()
   return rollup
     .flatMap((row) => observedContext(row) ?? [])
-    .toSorted((a, b) => (a.runId ?? '').localeCompare(b.runId ?? ''))
+    .toSorted(
+      (a, b) => (a.runId ?? '').localeCompare(b.runId ?? '') || a.state.localeCompare(b.state)
+    )
     .map((row) => {
       const count = (seen.get(row.context) ?? 0) + 1
       seen.set(row.context, count)

Numeric run IDs still sort first, so the existing behavior for distinct IDs does not change. Add a test with two same-name null-ID runs in both input orders.

Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
.toSorted((a, b) => (a.runId ?? '').localeCompare(b.runId ?? ''))
.toSorted(
(a, b) => (a.runId ?? '').localeCompare(b.runId ?? '') || a.state.localeCompare(b.state)
)

.map((row) => {
const count = (seen.get(row.context) ?? 0) + 1
seen.set(row.context, count)
return count === 1 ? row : { ...row, context: `${row.context}#${count}` }

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.

Minor · Functional Correctness · Quick win

Prevent collisions between suffixes and check names.

For suite 7, use runs named job, job, and job#2 with IDs 1, 2, and 3. This line assigns check:7:job#2 to both IDs 2 and 3.

The prior Map cannot retain both run IDs under that key. Each unchanged successful observation therefore produces another success verdict.

Use an unambiguous encoding of the base context and occurrence for every row, including the first occurrence.

…e share a name

Check runs were keyed by suite and name, so two same-named runs in one
suite shared one saved row. Every poll one of them carried a different run
id than the saved row and read as a rerun, posting a new "CI green" line
for the same head. Sort observed runs by run id and suffix repeated names
(stablyai#2, stablyai#3) so each run keeps its own row and an unchanged read compares equal.

Fixes stablyai#52700

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the NicholasTing/fix-ci-green-spam branch from 3cbc31e to f39ca35 Compare November 29, 2026 23:58
@nwparker
nwparker merged commit f0a4c8f into stablyai:main Nov 30, 2026
56 checks passed
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.

A PR's chat gets a new "CI green" line every minute when two check runs in one suite share a name

2 participants