Repository navigation
[2.0] Fixes #38280: stop alert offset reads from saving a missing offset - #38281
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
| 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; |
There was a problem hiding this comment.
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!
| 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); |
There was a problem hiding this comment.
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!
1c35e60 to
c791b06
Compare
Code Review ✅ Approved 🟡 Medium riskSeparating 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, VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
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:
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.
syncOffsetfirst moves it to the latest offset.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:
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,AlertUtilTestand the threeEventSubscriptionScheduler*test classes, plusAlertCreatedDisabledITandAlertPendingCountITon MySQL + Elasticsearch, all passed.Playwright (UI) tests
Not applicable, no UI change.
Checklist:
Fixes #<issue-number>above.docs/decisions/.The behavior change looks sound, but the two outstanding repository requirements must be addressed before merging.
Findings
Summary
Separates reading an alert's position from saving its starting position.
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]Reviews (2) · Last reviewed commit: "Delete the alert AlertCreatedDisabledIT ..." · Reviewed by Greptile