Repository navigation
perf(coderd/x/plugins): bind only new chats on each delivery - #351
Conversation
Delivery ran EnsurePluginChatBindings, a full rebind of every chat of every linked user, on each 15 s scan and on each chat watch event. A runner now binds all chats once when it follows a new user and once every 10 minutes as a fallback. A created chat watch event, sent for a new or unarchived chat, binds that one chat through EnsurePluginChatBinding, and chat.send binds the chat it created. Part of #305.
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. |
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab0a894b79
ℹ️ 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".
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb577f838c
ℹ️ 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".
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
@codex review |
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
…ding # Conflicts: # coderd/database/dbauthz/fork_forkdb_test.go # coderd/x/plugins/manager.go
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
@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
The child also ran on this head: Not exercised: a live plugin on the deployed server, and a real pubsub outage (the drop and subscription failure paths are covered by unit tests only). The flaky |
Part of #305 (item 3). The idle lease loop change (item 1) is #349. The two PRs are independent and both based on
main.Problem
deliver()started withEnsurePluginChatBindings, anINSERT ... SELECTover every top-level chat of every linked user. Delivery runs on every 15 s scan and on every chat watch event of a linked user, so each runner rebound every chat 40 times in 10 minutes with nothing changed, and once more for each status or title event.Change
EnsurePluginChatBinding: the same insert asEnsurePluginChatBindings, for one chat, with the same cursor rules (a chat newer than the link starts at 0, an older one at its newest message), and the same filters (top-level, not archived, same organization).createdevent (sent for a new chat and for an unarchived one) when it is top-level and in the plugin's organization, then wakes delivery as before.deliver()binds only that set and keeps a chat whose bind failed for the next delivery.link.completeas before, and every 10 minutes (bindInterval) for created events that pubsub lost.main(Codex P2).SubscribeWithErr. When pubsub reports dropped messages, the next scan (15 s) runs a full bind, so a lostcreatedevent costs one scan interval, as onmain(Codex P2).chat.sendbinds the chat it created instead of every chat.manager.godescribes when chats are bound.Archived chats keep their binding; the issue's idea of deleting them is not done, because an unarchived chat would then be bound again with a cursor of 0 and replay its history.
Tests
TestRunnerBindsOnlyChangedChats: the first scan follows the linked user and runs one full bind; 40 more scans (10 minutes) run none. Acreatedevent for a top-level chat of the organization binds that chat only, once. A child chat, a chat of another organization and astatus_changeevent bind nothing. A failed bind is retried on the next delivery. A newly linked user gets one full bind. While Subscribe fails, every scan runs a full bind, and the first scan after it succeeds runs the last. A dropped-messages error makes the next scan run one full bind. The last two checks fail without their fixes (expected 6, actual 4; expected 8, actual 7).TestPluginChatBindingOneChat(Postgres): only the named chat is bound; child, other organization and archived chats are not; a chat older than the link starts at its newest message; a second call changes nothing.TestPlugins/LinkSendAndDeliver(existing, real Postgres and plugin host) passes withchat.sendusing the one-chat bind.Negative control on
mainbefore this change: 40 scans with no change ranEnsurePluginChatBindings40 times.Commands run, all passed:
Not verified
perf(coderd/x/plugins): stop lease polling while no plugin is enabled #349 and perf(coderd/x/plugins): bind only new chats on each delivery #351 both edit the package doc in
manager.goandfork_forkdb_test.go, so whichever merges second needsmainmerged in first.A chat watch message lost without a pubsub drop report still waits for the 10 minute fallback bind, and a reply that finished meanwhile is skipped.
mainhas the same race inside its 15 s window.The 10 minute fallback bind in
runner.runhas no test of its own;bindAllis covered through the scan path.No end-to-end test creates a chat in the UI for a linked user and checks that its reply reaches the plugin; the unit test covers the event handling and the Postgres test covers the query.
Items 2 and 4 of plugins: the runtime polls with nothing to run and rebinds every chat every 15 s #305 are not in this PR.