Skip to content

Fixes #34204, #34205: stop event consumers idling after a slow batch, and give fresh reads their own cache - #34209

Merged
manerow merged 2 commits into
mainfrom
fix/event-consumer-stall
Sep 29, 2026
Merged

manerow merged 2 commits into
mainfrom
fix/event-consumer-stall

Conversation

@manerow

@manerow manerow commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Tests that wait for a governance approval task time out on the MySQL lane, and real servers under load see the same delay: approval tasks and alert deliveries arrive minutes late.

Why it happened

Two things add up. First, every change event consumer is a repeating Quartz trigger in the clustered database job store. Quartz plans each next run from the previous planned time, so runs longer than the interval push the trigger further behind. After 60 seconds behind, normal scheduling skips it and only a check that runs every 60 seconds picks it up again, so a busy consumer sat idle up to a minute, every two minutes. Second, inside a fresh-read scope the per-request entity cache was switched off entirely, and every governance workflow runs inside one. Each workflow step then rebuilt the same entity from the database (three times for a new metric, about six with reviewers), which made workflow events 20 to 50% slower and the stall far more frequent.

What this PR changes

  • A consumer that is behind now runs again as soon as it can. Its triggers use Quartz's "run now and restart the timetable" policy, and the scheduler checks for late triggers every 5 seconds instead of every 60. App schedules are not touched.
  • Each fresh-read scope now gets its own empty request cache. Nothing read before the scope is visible inside it, which keeps the alert scheduler fix that switched the cache off. Reading the same entity twice inside one scope reads the database once, and writes still remove the entity from every cache on the thread. A workflow run therefore works on what it read at its start, the same rule an API request already follows for its own reads.

What users will notice

Approval tasks, workflow status changes and alert deliveries no longer lag by minutes when many entities change at once. Existing servers pick up the new schedule on their next restart.

How it was tested

New unit tests pin the scheduler settings (5 second misfire check, the "run now" policy on both polling triggers, and a trigger stored by an older version being rewritten on restart) and the scope rules (no earlier entries visible, repeated reads served from the scope, invalidation reaching every open scope, nothing surviving it). With the old code back, 6 scheduler tests and 5 cache tests fail; the tests that guard the alert scheduler fix pass both ways. 739 unit tests across the affected packages pass. A standalone Quartz reproduction with our settings: before, 20 seconds idle after a slow run; after, the next run starts within 0.1 seconds. This PR's integration lanes run the subscription scheduling, governance approval and cache suites; their approval-test durations and consumer pauses are compared with main.

Not in this PR

The 2.0 backport of the scheduler change (separate PR). A redesign of how consumers are scheduled and how workflows read entities is tracked separately.

Fixes #34204
Fixes #34205

@gitar-bot

gitar-bot Bot commented Sep 29, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Scheduler misfire timing and scoped entity caching alter backend execution behavior.

Fixes event consumer stall and fresh-read cache issues by running late consumers immediately with a 5-second misfire check instead of waiting up to 60 seconds, and giving each fresh-read scope its own request cache so workflows don't rebuild the same entities repeatedly. Approval tasks, workflow status changes, and alert deliveries will no longer lag by minutes under load. No issues found.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-09-29T13:14:40Z)

No failing check on merge-queue commit cd494cf — invalidated by an entry ahead in the queue, or a required check timed out.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

2 participants