Skip to content

[2.0] Fixes #38280: stop alert offset reads from saving a missing offset - #38281

Merged
manerow merged 3 commits into
2.0from
fix/disabled-alert-position-2.0
Nov 24, 2026
Merged

manerow merged 3 commits into
2.0from
fix/disabled-alert-position-2.0

Conversation

@manerow

@manerow manerow commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #38280

Problem. Since 2.0.2, the method that looks up an alert's saved position also saves one at the latest change event when none exists (PR #32589). That save is right when an alert starts running: it keeps restarts and edits from moving the alert's start forward. But the alert's details page and diagnostics read the position through the same method.

So the first time anyone opens the page of an alert created disabled, which has never run, a position is saved at that moment. From then on:

  • the page and diagnostics report every later change event as pending, a backlog that keeps growing;
  • when the alert is enabled, it starts from that old position and sends every change since the first page view.

Fix. Reads now use a new read-only lookup, AlertUtil.storedOffsetOrLatest. It returns the saved position, or the latest offset without saving anything, which is what reads did before 2.0.2. EventSubscriptionScheduler.getEventSubscriptionOffset, the one read path that reached the saving method, now uses it, which covers the page, events record and diagnostics.

The saving method is unchanged and still runs where an enabled alert is scheduled or run, so what PR #32589 protects still holds.

What this does not change.

  • Positions that reads already saved on 2.0.2 to 2.0.x stay. Such an alert still sends the changes since that save when it is enabled; calling syncOffset first moves it to the latest offset.
  • An alert that ran and was then disabled still resumes from where it stopped when enabled again. Skipping that backlog is a behaviour change, and it stays on 2.1 and later.

On main the same issue is fixed by PR #38279, which goes further: a disabled alert reports nothing pending at all. The rule is recorded in docs/decisions/2026-11-20-reading-an-alert-offset-never-saves-it.md.

Type of change:

  • Bug fix

Tests:

Unit tests

  • AlertOffsetReadTest (new): a read with no saved position saves nothing and reads as the latest offset; the start path still saves.

Backend integration tests

  • AlertCreatedDisabledIT (new): create an alert disabled and read its details page, and no position is saved. Create table A, enable the alert, create table B. A local webhook receives B and never A. With the fix reverted it fails with "a read must not save an offset".

Run locally: 66 unit tests across AlertOffsetReadTest, AlertUtilTest and the three EventSubscriptionScheduler* test classes, plus AlertCreatedDisabledIT and AlertPendingCountIT on MySQL + Elasticsearch, all passed.

Playwright (UI) tests

Not applicable, no UI change.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added a test that covers the exact scenario we are fixing.
  • Decision check: the rule is recorded under docs/decisions/.

RetriggerView in GreptileConfidence Score: 4/5

The behavior change looks sound, but the two outstanding repository requirements must be addressed before merging.

Findings

  1. P2 Unchanged values lack final ▶
  2. P2 Tests mock internal database calls ▶

Summary

Separates reading an alert's position from saving its starting position.

  • Reading an alert no longer saves where its first run starts.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Page or diagnostic read] --> B[storedOffsetOrLatest]
  B --> C{Saved offset exists?}
  C -->|Yes| D[Return saved offset]
  C -->|No| E[Return latest without saving]
  F[Schedule or run alert] --> G[getStartingOffset]
  G --> H[Save starting offset if missing]
Loading

Reviews (2) · Last reviewed commit: "Delete the alert AlertCreatedDisabledIT ..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner November 20, 2026 07:51
@manerow
manerow requested review from harshach and removed request for a team November 20, 2026 07:51
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@manerow manerow added the safe to test Add this label to run secure Github workflows on PRs label Nov 20, 2026
Comment on lines +362 to +367
public static EventSubscriptionOffset storedOffsetOrLatest(UUID eventSubscriptionId) {
String json =
Entity.getCollectionDAO()
.eventSubscriptionDAO()
.getSubscriberExtension(eventSubscriptionId.toString(), OFFSET_EXTENSION);
long latest = json == null ? Entity.getCollectionDAO().changeEventDAO().getLatestOffset() : 0L;

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.

P2 Unchanged values lack final

The new helper leaves unchanged parameters and local variables without final. The Java guide requires final on locals and parameters that do not change. Apply it here and to the new test code. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +71 to +78
private <T> T withDao(Function<UUID, T> read) {
when(changeEvents.getLatestOffset()).thenReturn(LATEST);
CollectionDAO dao = mock(CollectionDAO.class);
when(dao.changeEventDAO()).thenReturn(changeEvents);
when(dao.eventSubscriptionDAO()).thenReturn(subscriptions);
try (MockedStatic<Entity> entity = mockStatic(Entity.class)) {
entity.when(Entity::getCollectionDAO).thenReturn(dao);
return read.apply(alertId);

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.

P2 Tests mock internal database calls

AlertOffsetReadTest mocks Entity, CollectionDAO, and both DAO types, then checks internal calls with verify(). The testing guide says not to mock the project's own classes and to assert saved state rather than internal calls. Use the database-backed test for these checks, or extend it to cover the saved-offset and start cases. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@manerow manerow added the skip-pr-checks Bypass PR metadata validation check label Nov 20, 2026
@manerow
manerow force-pushed the fix/disabled-alert-position-2.0 branch from 1c35e60 to c791b06 Compare November 20, 2026 13:38
@gitar-bot

gitar-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Separating read-only offset lookup from start-time initialization means disabled alerts may omit events created before they are enabled.

Reads of an alert's saved position now use a read-only lookup, AlertUtil.storedOffsetOrLatest, so opening the details page or diagnostics of a never-run disabled alert no longer saves an offset. The save still runs when an enabled alert is scheduled. No open issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@manerow
manerow merged commit d7726dd into 2.0 Nov 24, 2026
65 of 68 checks passed
@manerow
manerow deleted the fix/disabled-alert-position-2.0 branch November 24, 2026 10:18
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 skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant