← Back to Pull requests

Fix possible race condition with reentrant callback groups in EventsCBGExecutor scheduler #3234

Closed
unknown closed this pull request without merging on Aug 23, 2026 23:16 UTC
View on GitHub
unknown unknown commented on Aug 23, 2026 05:16 UTC
Author

Description

<!--
Please include a summary of the changes and the related issue.
Highlight any key points or areas of concern.
-->
Since #3178, although the setting of handle->in_queue = true was protected under ready_callback_groups_mutex, the read is not. This makes the following races possible with more than one worker thread:

if handle->in_queue is loaded stale false while another thread enqueues it and marks handle->in_queue = true, a duplicate handle can be pushed. Removing the callback group or node from a running executor later on can lead to a possible use-after-free if checking for work on the remaining duplicate (dangling) callback handle.

In a more rare case, if the check for handle->in_queue is loaded stale true by the last worker thread to touch it, while another thread sets handle->in_queue = false, a reentrant CBG could have ready work but not be enqueued and stay permanently starved during the lifetime of the executor.

Fixed by ensuring that handle->in_queue is checked under ready_callback_groups_mutex.

Also adds a check in remove_callback_group so that it is only removed from ready_callback_groups if it was found in the queue. previously if it wasn't ready when being removed, std::find could return ready_callback_groups.end() and unconditionally erase that from ready_callback_groups, which is undefined behavior.

<!--
Automatically closes linked issue when PR is merged.
Usage: Fixes #<issue number>, or Fixes (paste link of issue).

-->

Is this user-facing behavior change?


fixes the possibility of duplicate reentrant groups being pushed to the queue, or a push being skipped indefinitely if the last pending worker thread loads a stale in_queue = true

<!--
If no, just leave this section empty.
If yes, please explain how user-experience changes with this pull request.
-->

Did you use Generative AI?


This came up as a possible race while running a large benchmark sweep, partially instrumented by Claude Opus 5
<!--
If this pull request was generated using Generative AI, please specify the tool and model used (e.g., GitHub Copilot, GPT-4.1).
If only specific parts were generated by Generative AI, please list those parts (e.g., function A, class B, etc.).
-->

Additional Information

<!--
If applicable, provide any additional context or details about the changes.
-->

Diff: 302 lines (+226 / -76) across 3 files Reviewer: jmachowinski Review duration: 1080m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 302 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.342
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3234"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 40.1% (MEDIUM) · Higher = larger blast radius
40.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.3% · Safe to merge
17.3%
Repository