Skip to content

perf(coderd/x/plugins): bind only new chats on each delivery - #351

Merged
ibetitsmike merged 8 commits into
mainfrom
mike/issue-305-chat-binding
Nov 16, 2026
Merged

ibetitsmike merged 8 commits into
mainfrom
mike/issue-305-chat-binding

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

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 with EnsurePluginChatBindings, an INSERT ... SELECT over 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

  • New query EnsurePluginChatBinding: the same insert as EnsurePluginChatBindings, 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).
  • The runner keeps a set of chats to bind. Its chat watch listener adds the chat of a created event (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.
  • Full binds remain where they are needed: when the runner subscribes to a user it did not follow (runner start and new links, after the subscription starts so no chat falls between), inside link.complete as before, and every 10 minutes (bindInterval) for created events that pubsub lost.
  • A user whose subscription failed gets the full bind on every scan until a subscription starts, as on main (Codex P2).
  • The subscription uses SubscribeWithErr. When pubsub reports dropped messages, the next scan (15 s) runs a full bind, so a lost created event costs one scan interval, as on main (Codex P2).
  • chat.send binds the chat it created instead of every chat.
  • Package doc in manager.go describes 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. A created event for a top-level chat of the organization binds that chat only, once. A child chat, a chat of another organization and a status_change event 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 with chat.send using the one-chat bind.

Negative control on main before this change: 40 scans with no change ran EnsurePluginChatBindings 40 times.

Commands run, all passed:

flock ~/.fork-go.lock go test ./coderd/x/plugins/... -v -count=1
flock ~/.fork-go.lock go test ./coderd/x/plugins/ -run TestRunnerBinds -race -count=20
flock ~/.fork-go.lock go test ./coderd/database/forkdb/ -run TestPlugin -v -count=1
flock ~/.fork-go.lock go test ./coderd/database/dbauthz/ -run TestForkQuerier -count=1
flock ~/.fork-go.lock go test ./coderd/ -run TestPlugin -v -count=1
flock ~/.fork-go.lock go test ./enterprise/coderd/ -run TestPlugin -v -count=1
flock ~/.fork-go.lock go test ./enterprise/dbcrypt/... -count=1
golangci-lint run on the touched packages: 0 issues

Not verified

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T00:52:39.836622Z fe47b6f Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/x/plugins/runner.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: cff5933749

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread coderd/x/plugins/runner.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: d707bbfda5

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: de4ed994d5

ℹ️ 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".

…ding

# Conflicts:
#	coderd/database/dbauthz/fork_forkdb_test.go
#	coderd/x/plugins/manager.go
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: f4c5cfcca8

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: fe47b6f5f9

ℹ️ 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".

@ibetitsmike
ibetitsmike merged commit d4ad70a into main Nov 16, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-305-chat-binding branch November 16, 2026 01:16
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head fe47b6f5f93dd6bc9a4c686f388517c447945a96 as d4ad70a, on main 027a8224a298f6e45eb8683d4c5b5c84ebec7767, with the server running that main.

Gates on this exact head:

  1. The head matched the SHA I verified (--match-head-commit).
  2. Every check run passed. fork-ci run 43781253180 passed on this head.
  3. Codex receipt for this head: perf(coderd/x/plugins): bind only new chats on each delivery #351 (comment) ("Didn't find any major issues").
  4. No unresolved review thread.
  5. 0 commits behind main.
  6. The four PR commits (ab0a894b79, cff5933749, d707bbfda5, 8976bad4d8) are unchanged since I tested them at f4c5cfcca8 (git range-diff shows all four identical). The diff of each of the 13 files between the tested head and this head equals main's own delta in that range, so the head only adds main merges.

Tests I ran on f4c5cfcca8, in a detached worktree under flock ~/.fork-go.lock:

  • go test -race -count=1 -v ./coderd/x/plugins/...: 25 top-level PASS, 0 FAIL.
  • go test -count=1 -v -run TestPlugin ./coderd/database/forkdb/: 7 PASS, 0 FAIL.
  • go test -count=1 -run TestForkQuerier ./coderd/database/dbauthz/: ok.
  • Negative control: with a full EnsurePluginChatBindings put back into every deliver(), TestRunnerBindsOnlyChangedChats failed (expected 1 full bind, got 2). The source was restored after.

The child also ran on this head: go build ./coderd/... ./enterprise/..., go test -race ./coderd/x/plugins/..., the forkdb and dbauthz tests above, go test ./enterprise/coderd/ -run TestPlugin, and go test ./coderd/ -run TestPlugin -v 3 times, all passing.

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 TestPlugins/LinkSendAndDeliver (#353) is a separate issue and did not appear in those runs. #305 stays open for lease renewal and archived binding cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant