Skip to content

AI-3373: send the unowned usage alert at most once a day - #2115

Merged
kanat merged 6 commits into
mainfrom
fix/ai-3373-unowned-alert-repeat
Nov 25, 2026
Merged

kanat merged 6 commits into
mainfrom
fix/ai-3373-unowned-alert-repeat

Conversation

@aliev

@aliev aliev commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Why

The unowned usage alert holds for as long as one usage row waits for an organization, which can be days. The alerts loop sends a condition that holds at most once per Options.Limit, one minute for every condition, so unowned went out about 1440 times a day.

How it works

loop tick (every 15 s)
└─ condition holds?
   ├─ no  -> has a Repeat? forget its last send (next spell goes out at once)
   └─ yes -> sent before?
      ├─ no  -> send now
      └─ yes -> since last send >= repeat(condition)?
         ├─ yes -> send
         └─ no  -> hold back

repeat(condition)
├─ condition.Repeat != 0 -> condition.Repeat   (unowned: 24 h)
└─ otherwise             -> Options.Limit      (1 min, unchanged)

For an Items condition the same holds per item: an item that is no longer held loses its last send, so it goes out at once when it comes back.

Change Result Test that proves it
Condition.Repeat, Loop.repeat (acceleration/internal/alerts/alerts.go:68, :189) a condition with a Repeat that keeps holding is held back for it, not for Limit TestAConditionWithItsOwnRepeatIsSentAgainOnlyAfterIt
checkItems uses repeat(condition) (acceleration/internal/alerts/alerts.go:176) each item of an Items condition is held back for the Repeat TestAnItemOfAConditionWithItsOwnRepeatIsSentAgainOnlyAfterIt
last send forgotten when a Repeat condition stops holding (acceleration/internal/alerts/alerts.go:148) a new spell is sent at once, not 24 h after the last one TestANewSpellOfAConditionWithItsOwnRepeatIsSentAtOnce
same per item (acceleration/internal/alerts/alerts.go:169) an item that comes back is sent at once; others stay held back TestAnItemThatComesBackIsSentAtOnce
only for conditions with a Repeat alerts without one keep Limit across spells, as before, and so do their items TestAConditionWithoutARepeatKeepsTheLimitAcrossSpells, TestAnItemOfAConditionWithoutARepeatKeepsTheLimitAcrossSpells
unowned gets Repeat: 24 * time.Hour (acceleration/internal/routing/alerts.go:66) only unowned repeats once a day TestOnlyUnownedRepeatsOnceADay
unowned Before After
First event of a spell once rows rose in both halves of the last 15 min (about 7m30s after they start waiting) same
Events per day while it holds ~1440 per pod sending it 1
A new spell after it stopped holding sent at once sent at once
Level warn warn
Other alerts' rate 1 min 1 min

The Repeat doc says a check given the loop's limit (IncreasedSinceAlert, IncreasedPer) must be given the Repeat instead; no condition combines them today.

Validation

  • go vet ./internal/alerts/ ./internal/routing/: clean. go test ./internal/alerts/ ./internal/routing/: pass. -race on TestAlertsSuite: pass.
  • TestAConditionWithItsOwnRepeatIsSentAgainOnlyAfterIt and TestAnItemOfAConditionWithItsOwnRepeatIsSentAgainOnlyAfterIt failed on the old loop (5 and 4 events where 1 is expected): they catch a loop that ignores Repeat, and one that never sends again after 24 h.
  • TestANewSpellOfAConditionWithItsOwnRepeatIsSentAtOnce and TestAnItemThatComesBackIsSentAtOnce failed before the last send was forgotten (1 and 2 events where 2 and 3 are expected): they catch a new spell held back by the previous one's send.
  • TestAConditionWithoutARepeatKeepsTheLimitAcrossSpells and TestAnItemOfAConditionWithoutARepeatKeepsTheLimitAcrossSpells catch forgetting the last send for every condition or every item, which would change the rate of the alerts this PR leaves alone. The item test fails with the forget made unconditional in checkItems (2 events where 1 is expected).
  • TestOnlyUnownedRepeatsOnceADay catches unowned losing its 24 h repeat, and any other alert picking one up.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The alert loop now supports an optional repeat interval for each condition and its items. If a condition has no repeat interval, the loop uses its configured limit. For conditions with a repeat interval, the loop clears the recorded send time when the condition stops holding or an item disappears. The unowned routing warning uses a 24-hour interval. Tests cover repeat timing, resumed alerts, and routing alert intervals.

Merge Risk: Minimal · up to 49098

This change limits the unowned usage alert to one send per day while it keeps holding. It still sends immediately when a new spell starts. Other alerts keep their current behavior. Tests cover the new timing and the unchanged paths, and no merge-blocking risk is evident.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5194c50 and 49098cf.

Files selected for processing: 1

  • acceleration/internal/alerts/alerts_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 8caa583 merged onto main bb12cb4. CI: all checks pass. go vet, gofmt, go test -race ./internal/alerts/ ./internal/routing/: clean.

Checked and sound:

  • Every alert other than unowned keeps Options.Limit: only routing/alerts.go:66 sets Repeat. A 48 h tick run of a flapping Check condition and an Items condition with Repeat zero sends the same events at the same ticks on base and head.
  • The first event of a spell is not held back (7m30s on base and head).
  • Breaking repeat() back to Limit gives 5 and 4 events, as the description says. 14 mutations tried; the only survivor (!= 0 to > 0) is equivalent.
  • Multi-pod: usageUnowned only rises on the pod that holds the shard's ship lock (sweeper.go:134-141, :224). So the rate is about 1 event a day per shard, plus one each time the lock moves or the pod restarts.

[Nit] R1.2 acceleration/internal/routing/alerts.go:47-48: the Alerts doc still says the loop "sends one event of a condition at most every limit". That is no longer true for unowned. Fix: add "or its Repeat".

[Nit] R1.4 In the description's table, the row "Level, 15-minute hold: warn, 15 min" is wrong. The first event goes out 7m30s after rows start waiting, on base and on head: IncreasingFor holds once both halves of the 15 min span rose. This PR does not change it; only the row is wrong.

[Nit] R1.6 There is no CHANGELOG.md entry. #2093 added one for the same alerts.

[Question] R1.5 AI-3373 also asks for the app's name, one Sentry issue per app, a plain-words message, and a count of rows rather than skips. This PR changes only the repeat rate. The description does not claim to close the ticket. Is it a first step, with the ticket kept open after merge? The title and branch name it, so Linear may close the ticket when this merges.

Verdict: request changes, for R1.1 (a new spell of unowned within 24 h is held back, or never sent).

Comment thread acceleration/internal/alerts/alerts.go Resolved
Comment thread acceleration/internal/alerts/alerts.go Resolved
@aliev

aliev commented Nov 19, 2026 •

Copy link
Copy Markdown
Member Author

Replies to the review's other items:

  • R1.2: fixed in 5194c50, the Alerts doc now says "at most every limit, or its Repeat".
  • R1.4: fixed in the description; the first event row now says it goes out about 7m30s after rows start waiting, before and after.
  • R1.5: title and branch stay as they are. This PR fixes only the repeat rate; the app name and one issue per app follow in AI-3373: unowned usage alert names each app #2118.
  • R1.6: added a CHANGELOG entry under Unreleased, Bug Fixes, in 5194c50.

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Delta round 2: 5194c50 merged onto main 9edddca. CI: 24 checks pass. gofmt, go vet, go test -race ./internal/alerts/ ./internal/routing/: clean.

R1.1 (thread 4630713072): fixed. I reran the round-1 probe on the condition as routing/alerts.go:66 builds it (rows wait 0-1 h and 3-5 h):

  • Base (no Repeat): second spell first sent at 3h07m30s. Head: 7m30s, then 3h07m30s. Same as base.
  • Second spell lasting to 30 h: head sends at 3h07m30s and again at 27h07m30s, 24 h after the send (round 1: 24h07m30s).
  • Items with Repeat: 24h: item a away 1-3 h goes out at 0, 3 h, 27 h; item b that never went away goes out at 0 and 24 h. So per-item forgetting works, which #2118 needs for an Items unowned.
  • Other alerts: a 48 h run of a flapping Check and an Items condition without Repeat gives 5764 events with the same md5 of message@offset (1624c93d…) on base and head.
  • Mutations of the new lines: no forget in check(), forget on Repeat == 0, forget unconditionally, wrong key, no forget in checkItems(), forget of held items, forget of all items, prefix without :, wrong key to delete: all killed. One survives, below.

R1.3 (thread 4630713084; R1.2 in my numbering): fixed. The Repeat doc at alerts.go:61-67 says a check given the loop's limit must be given the Repeat. R1.3 (routing Alerts doc), R1.4 (description row), R1.5 (CHANGELOG) are fixed as well. R1.6 stays a question: partial step, ticket stays open.

New finding below (a test gap in the new code). Verdict: request changes for that one test; no code change needed.

aliev and others added 2 commits November 20, 2026 12:37
Resolved acceleration/internal/alerts/alerts.go: the repeat interval per condition
stays, and the hold counter from main counts before the repeat check.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SWVEMob5wtaNHdUCC1msgG
@kanat

kanat commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

This branch was taken over per Kanat: main is merged in (e8ede60, a merge commit, no history rewritten).

Resolved: acceleration/internal/alerts/alerts.go conflicted with AI-3775 (#2417). The hold counter router_alert_holds_total still counts at every check, before the repeat check; Ali's per-condition Repeat (l.repeat()) and the forget of a spell's last send are kept. go vet with and without the integration tag is clean; internal/alerts and internal/routing pass, with -race and with integration.

N7 is covered by 49098cf (TestAnItemOfAConditionWithoutARepeatKeepsTheLimitAcrossSpells). On the merged code it fails under if condition.Repeat != 0 { -> if true { in checkItems.

The failing check (integration (api), 11-20) was in TestConnectorsSuite and TestToolOutputRetentionSuite, not alerts; main's runs of that workflow fail as well (other tests), and both suites pass locally on this head. CI has to run again on the new head.

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

VERDICT: GO

Delta round 3: e8ede60 (Ali's 49098cf plus the merge of main c2a4067). Checked: gofmt, go vet (with and without -tags integration), go test -race ./internal/alerts ./internal/routing, and -tags integration on both packages with my own test database.

N7 (thread 4641863031): fixed. TestAnItemOfAConditionWithoutARepeatKeepsTheLimitAcrossSpells (alerts_test.go:175). On the merged code, I changed checkItems's if condition.Repeat != 0 { to if true {. That test failed, and so did TestTheEventsSentAndTheirLimitAreAsTheyWere. Restored.

Earlier findings: R1.1 and R1.3 were closed in round 2. N7 was the only open one, and it is closed now. R1.6 (CHANGELOG) is covered by the entry in this PR.

Merge conflict in alerts.go (git show --remerge-diff e8ede60): resolved correctly.

  • Main's router_alert_holds_total is kept in both paths. check() creates the counter before the !held branch, so the series exists at 0, and increments it before the repeat check. checkItems() adds len(held) before the forget.
  • Ali's per-condition Repeat is kept: the forget when a condition stops holding, the forget of items that went away, and l.repeat(condition) in both paths.
  • Ali's local holds would have shadowed the package counter holds, so it is now still. No conflict marker is left.
  • I broke each of these on the merged head and each break fails a test: checkItems Add removed, check() Inc removed (compiled as _ = counter), check() forget removed, check() repeat(condition) replaced with Limit. All 5 mutations were killed.

Tests: ./internal/alerts passes with -race and with -tags integration. ./internal/routing passes with -race. With -tags integration -p 1, the full package passed in 3 of 5 runs. The other two runs failed TestWriterSuite/TestAStuckHolderGivesUpAndEveryRouterStillCountsWhatWaits (shipper_test.go:67, a test with a 1 s sweep timeout). The machine load was about 47 at the time. This delta does not touch the shipper. TestWriterSuite passed 3 of 3 runs on its own, and the next two full runs passed.

CI (gh pr checks, read once): the integration jobs and go were still pending on the new head. Analyze (python), Analyze (actions), labeler and GitGuardian pass. The orchestrator waits for the rest.

No new findings.

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving on the reviewer's GO (take-over of Ali's PR per Kanat; delta review #2115 (review)).

@kanat
kanat merged commit e75990b into main Nov 25, 2026
13 checks passed
@kanat
kanat deleted the fix/ai-3373-unowned-alert-repeat branch November 25, 2026 22:02
kanat added a commit that referenced this pull request Nov 25, 2026
UnownedUsage moves to the Requests repository (main split Store); the
unowned condition keeps per-item names and the 24 h Repeat of #2115.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SWVEMob5wtaNHdUCC1msgG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants