Skip to content

perf(webhook): give every coalesce family the quiet window its key needs - #10133

Merged
JSONbored merged 1 commit into
mainfrom
perf/webhook-coalesce-windows
Jul 31, 2026
Merged

perf(webhook): give every coalesce family the quiet window its key needs#10133
JSONbored merged 1 commit into
mainfrom
perf/webhook-coalesce-windows

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Closes #10127

githubWebhookCoalesceKey computes a job coalesce key for five event families. githubWebhookCoalesceDelaySeconds returned a non-zero window for exactly one of them — the push family (#9479) — and 0 for the rest. A zero-delay job is claimed off the queue before a sibling can arrive, so there is no pending row to merge into.

The file already says this, in the push section:

On a queue that coalesces (self-host pg/sqlite, which is where the ORB runs) this is what CREATES the window: without a delay the first push is claimed immediately and later pushes find no pending row to merge into.

That reasoning was never extended to the other four. Their keys were derived, attached to the job, and structurally unable to do anything.

Measured on the Orb, not projected

 event_name  | action    | deliveries (since 2026-07-30)
 check_suite | completed |       2143

 records | heads | per_head
    1528 |   519 |    2.944

Nearly three full gate passes per distinct head SHA. Worked example — #10098, eleven hold records at one head SHA in 33 minutes, every one upstream_state_change.

The LLM review is not duplicated. ai_review_pr shows 415 calls against 519 distinct heads, so the per-head review cache is holding. The waste is GitHub REST/GraphQL quota, queue churn, decision_records writes, and label/comment reconciliation — which is exactly why it went unnoticed: the cost line looked fine.

The change

The key and its window now come from one classifier, so a family cannot have one without the other:

type WebhookCoalescePlan = { key: string; quietWindowSeconds: number };
function planGithubWebhookCoalesce(eventName, payload): WebhookCoalescePlan | null;

Both exported functions become projections of it. That coupling is the actual fix — the numbers below are tuning.

family window why
pr-push 45s unchanged (#9479)
ci-completed 45s interchangeable — whichever delivery wins re-fetches the same settled CI state. Kept under CI_COALESCE_WINDOW_SECONDS (60s) so the downstream per-PR throttle stays the outer bound
pr-label 15s shorter: a maintainer removing a hold label expects prompt notice
review-surface 15s payload-interchangeable within a family
pr-refresh 0 lifecycle — opened/reopened/ready_for_review each happen once and start the clock a contributor waits on. Keyed so a same-instant duplicate still collapses, never delayed

Lifecycle keeping a zero window is deliberate. Delaying a PR's first verdict to save a redelivery trades a real cost for an imaginary one: 203 opened deliveries against 1,727 CI completions in the same period — lifecycle is not a burst source.

Verification

  • Full suite and the whole check-* sweep green.
  • The invariant is asserted as "key implies window" over the real families rather than against expected constants, so a family added later cannot quietly reintroduce a keyed-but-inert delivery. That framing also survived the constants becoming module-local when dead-exports:check (correctly) objected to exporting them.
  • Mutation-tested:
mutation tests failed
CI window → 0 (literally the original bug) 1
surface window → 0 1
lifecycle gains a 30s delay (the opposite error) 1

What I am not claiming

How much this actually collapses depends on how CI suites cluster in time, which I cannot predict from here. Baseline is captured (2.944 records/head at 2026-07-31T08:14:58Z); I will re-measure on the Orb after the deploy and report the real figure rather than a projection.

Separately checked and found already handled, so deliberately not touched: the 2,064 issue_comment deliveries are the bot's own comment churn, and isSelfAuthoredAppCommentWebhook / isBotAuthoredIssueCommentEditWebhook already drop them at ingest before any gate pass.

githubWebhookCoalesceKey computes a job coalesce key for five event
families. githubWebhookCoalesceDelaySeconds returned a non-zero window for
exactly one of them, the push family, and 0 for the rest -- and a zero-delay
job is claimed off the queue before a sibling can arrive, so there is no
pending row to merge into. The file already says as much in its push section;
that reasoning was never extended to the other four, leaving their keys
derived, attached, and structurally unable to do anything.

On the Orb: 1,727 check_suite.completed deliveries in a day and a half, and
2.94 decision records per distinct head SHA -- nearly three full gate passes
over state that had not changed. The LLM review is not duplicated (415
ai_review_pr calls against 519 heads, so the per-head cache holds); the waste
is GitHub quota, queue churn and ledger writes, which is why a healthy cost
line hid it.

The key and the window now come from one classifier returning both, so a
family cannot have one without the other. Windows: 45s for CI completion
(under the 60s downstream per-PR throttle, which stays the outer bound), 15s
for label and review-surface bursts, and deliberately 0 for the lifecycle
family -- opened/reopened/ready_for_review each happen once and start the
clock a contributor is waiting on, and at 203 opened deliveries against 1,727
CI completions they are not a burst source anyway.

The invariant is asserted as "key implies window" over the real families
rather than as expected constants, so a family added later cannot quietly
reintroduce a keyed-but-inert delivery.

Closes #10127
@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Important

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏳ LoopOver is waiting…

LoopOver has seen this pull request and is waiting on CI checks to finish before reviewing it. This comment will update once the review runs.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed · 🟨 Waiting

@JSONbored JSONbored self-assigned this Jul 31, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@JSONbored
JSONbored merged commit cc6db92 into main Jul 31, 2026
2 checks passed
@JSONbored
JSONbored deleted the perf/webhook-coalesce-windows branch July 31, 2026 08:27
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.09%. Comparing base (645b323) to head (37bd684).
⚠️ Report is 7 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10133      +/-   ##
==========================================
- Coverage   91.96%   91.09%   -0.88%     
==========================================
  Files         931      931              
  Lines      113966   113972       +6     
  Branches    27513    27514       +1     
==========================================
- Hits       104808   103820     -988     
- Misses       7858     9047    +1189     
+ Partials     1300     1105     -195     
Flag Coverage Δ
backend 94.12% <100.00%> (-1.56%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/github/webhook-coalesce.ts 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

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.

perf(webhook): four of five coalesce families are keyed but windowless, so they never coalesce

1 participant