Repository navigation
perf(coderd/x/chatd): count notify_user sends in a fork table - #369
Conversation
The hourly notify_user limit counted notification_messages by a JSON payload field, with no index that serves it. It now counts rows of the fork table chat_user_notifications, indexed on (chat_id, created_at). notify_user and sent wake-up pause notifications insert a row, and dbpurge deletes rows older than a day. Part of #307.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df1720ad80
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…se sends DeleteOldChatUserNotifications deletes at most 1000 rows per tick through a new created_at index. A pause notification whose send failed counts toward the notify_user limit, since the enqueuer may have queued some deliveries before the error. Part of #307.
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
The parallel subtests shared a 10s context of the parent and failed with context deadline exceeded when they waited for a slot longer than that.
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…-count # Conflicts: # coderd/database/forkdb/sqlc.yaml
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Merged at head Gates on this exact head:
Tests I ran on
Review notes: the hourly Not exercised: a running server sending real notifications, and two replicas racing on the limit. |
Part of #307 (item 1).
What changed
The hourly
notify_userlimit countednotification_messagesrows bypayload->'data'->>'chat_id', which no index serves, so every call scanned the user's custom notifications. It now counts a fork table.01a1e3cc..._chat_user_notifications: tablechat_user_notifications (id, chat_id, created_at)with indexes on(chat_id, created_at)and(created_at). No index is added to an upstream table.forkdb/queries/chat_user_notifications.sql:InsertChatUserNotification,CountChatUserNotificationsSince(chat_id, since)andDeleteOldChatUserNotifications(at mostlimit_countrows older than a day). The oldnotification_messagescount inchat_wakeups.sqlis removed.notify_userinserts a row once the call passes the limit, before the enqueue, so a send that fails after it queued some deliveries still counts.docs/fork/pstack-adapter.mddocuments.created_atindex.docs/fork/pstack-adapter.md: code citations updated.TestInTx(forkdb, unchanged logic): each parallel subtest now makes its own context. They shared one 10s context of the parent and failed withcontext deadline exceededin chat-tests run 43851884892 when they waited longer than that for a slot. This is a test-only fix for a flake thatmainhas too.Notifications sent before the node runs are not backfilled, so each chat may send one more full hour of them once after the deploy. A backfill would scan
notification_messagesat startup, which is what this change avoids.Tests
All run with
flock ~/.fork-go.lock.go test ./coderd/database/forkdb/... ./coderd/database/dbpurge/ ./coderd/database/dbmetrics/ -count=1: ok.go test ./coderd/database/dbauthz/ -run TestForkQuerier -count=1: ok.CHATDMIG_TEST_DATABASE_URL=... go test ./coderd/database/migrations/chatdmig/... -count=1: ok.go run ./coderd/database/migrations/chatdmig/cmd/chatdmig check: exit 0.go test ./coderd/x/chatd/ -run 'Fork|Notify|Wakeup|Loop|WaitForEvents' -count=1: ok, 481 PASS lines.golangci-lint run --fix=false --new-from-rev=origin/mainon the changed packages: 0 issues.gofmt -l: clean.New or changed tests:
TestCountChatUserNotificationsSince(forkdb): counts per chat and window, and asserts withEXPLAINthat the plan reads onlychat_user_notificationswith no Seq Scan.TestDeleteOldChatUserNotifications(dbpurge): rows older than a day go, newer rows stay.TestNotifyUserTool: after 10 sends, deleting the user'snotification_messagesdoes not lift the limit; moving the fork rows back an hour does.TestWakeupCaps/WakeupsOfCappedChatNotifyOnce: two capped wake-ups send one pause notification and record one row.TestDeleteOldChatUserNotificationsBatch(forkdb): a batch of 2 deletes 2, then 1, then 0 of 3 old rows and keeps the recent one; with 10,000 recent rows theEXPLAINof the delete has no Seq Scan. Ran-count=20: ok, and the full forkdb package 6 times in a row: ok.TestWakeupCaps/FailedPauseNotificationCounts: an enqueuer that fails still leaves one row.Negative controls (fix reverted, test failed, fix restored):
notify_user:TestNotifyUserToolFAIL.TestCountChatUserNotificationsSinceFAIL (Seq Scan in the plan).TestDeleteOldChatUserNotificationsFAIL.TestWakeupCaps/WakeupsOfCappedChatNotifyOnceFAIL (expected 1, actual 0).created_atindex removed from the node:TestDeleteOldChatUserNotificationsBatchFAIL (Seq Scan in the plan).TestDeleteOldChatUserNotificationsBatchFAIL (expected 2, actual 3).err != nil || len(ids) == 0returns):TestWakeupCaps/FailedPauseNotificationCountsFAIL (expected 1, actual 0).Not verified