Skip to content

RHINENG-29746: backport notified - #2337

Merged
Dugowitch merged 2 commits into
RedHatInsights:masterfrom
Dugowitch:notified-backport
Sep 21, 2026
Merged

Dugowitch merged 2 commits into
RedHatInsights:masterfrom
Dugowitch:notified-backport

Conversation

@Dugowitch

@Dugowitch Dugowitch commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Secure Coding Practices Checklist GitHub Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Summary by Sourcery

Synchronize advisory notification status across account and workspace advisory data.

Bug Fixes:

  • Keep advisory notification state synchronized between account-level and workspace-level advisory records.

Enhancements:

  • Backfill existing account advisory records with notification state and propagate it to newly inserted workspace records.

Chores:

  • Add database migration 168 and update the schema version to support advisory notification synchronization.

@Dugowitch
Dugowitch requested a review from a team as a code owner September 17, 2026 15:24
@sourcery-ai

sourcery-ai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Backports advisory notification state synchronization by copying notified timestamps from advisory_account_data into account_advisory during backfills and notification processing, and by inheriting existing notification state for newly inserted workspace records. The database migration adds the trigger and updated backfill logic, with corresponding rollback support.

File-Level Changes

Change Details Files
Backfill and propagate advisory notification state from account-level advisory data to workspace-level records.
  • Extend account advisory backfill to copy non-null notified timestamps across matching workspaces.
  • Update notification processing to write notified timestamps to account_advisory after updating advisory_account_data.
  • Add a BEFORE INSERT trigger that inherits an existing notified value for newly created workspace records.
database_admin/migrations/168_backport_advisories_notified.up.sql
database_admin/schema/create_schema.sql
evaluator/notifications.go
Add migration rollback support for the notification synchronization behavior.
  • Restore the previous backfill function behavior.
  • Remove the insert trigger and its partition trigger registration.
database_admin/migrations/168_backport_advisories_notified.down.sql
Advance the database schema migration version and register the new trigger in the canonical schema.
  • Set schema migration version to 168.
  • Create the partition trigger for account_advisory inserts.
database_admin/schema/create_schema.sql

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="database_admin/migrations/168_backport_advisories_notified.up.sql" line_range="22-28" />
<code_context>
+    RETURNS TRIGGER AS
+$sync_notified_insert$
+BEGIN
+    IF NEW.notified IS NULL THEN
+        SELECT notified INTO NEW.notified
+        FROM account_advisory
+        WHERE rh_account_id = NEW.rh_account_id
+          AND advisory_id = NEW.advisory_id
+          AND notified IS NOT NULL
+        LIMIT 1;
+    END IF;
+    RETURN NEW;
</code_context>
<issue_to_address>
**issue (bug_risk):** A concurrent workspace insert can permanently retain a NULL `notified` value: the trigger reads existing `account_advisory` rows before the notification transaction updates them, while the notification UPDATE can finish before the new insert commits. The new row then remains unnotified even though `advisory_account_data.notified` and the existing workspace rows are set.

**Triggers:** When a new workspace for an already-notified advisory is inserted concurrently with `markAdvisoriesNotified`.

**Suggested fix:** Synchronize the insert and notification update with a locking or atomic database operation, or derive the inserted value from `advisory_account_data.notified` as well as existing `account_advisory` rows.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the backfill or synchronization logic is wrong, it can persist incorrect notification timestamps in account_advisory and cause notifications to be suppressed or retriggered. Reverting removes the trigger and code but does not undo those stored values, though the affected records are bounded and can be repaired or recomputed.

Blocking findings: database_admin/migrations/168_backport_advisories_notified.up.sql:28


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +22 to +28
IF NEW.notified IS NULL THEN
SELECT notified INTO NEW.notified
FROM account_advisory
WHERE rh_account_id = NEW.rh_account_id
AND advisory_id = NEW.advisory_id
AND notified IS NOT NULL
LIMIT 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): A concurrent workspace insert can permanently retain a NULL notified value: the trigger reads existing account_advisory rows before the notification transaction updates them, while the notification UPDATE can finish before the new insert commits. The new row then remains unnotified even though advisory_account_data.notified and the existing workspace rows are set.

Triggers: When a new workspace for an already-notified advisory is inserted concurrently with markAdvisoriesNotified.

Suggested fix: Synchronize the insert and notification update with a locking or atomic database operation, or derive the inserted value from advisory_account_data.notified as well as existing account_advisory rows.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.94%. Comparing base (0c472b1) to head (5c91d6f).

Files with missing lines Patch % Lines
evaluator/notifications.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2337      +/-   ##
==========================================
+ Coverage   58.92%   58.94%   +0.02%     
==========================================
  Files         150      150              
  Lines        9596     9601       +5     
==========================================
+ Hits         5654     5659       +5     
+ Misses       3349     3348       -1     
- Partials      593      594       +1     
Flag Coverage Δ
unittests 58.94% <60.00%> (+0.02%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dugowitch
Dugowitch merged commit d834770 into RedHatInsights:master Sep 21, 2026
8 checks passed
@Dugowitch
Dugowitch deleted the notified-backport branch September 21, 2026 09:25
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.

3 participants