Skip to content

perf(coderd/x/plugins): stop lease polling while no plugin is enabled - #349

Merged
ibetitsmike merged 7 commits into
mainfrom
mike/issue-305-idle-leases
Nov 15, 2026
Merged

ibetitsmike merged 7 commits into
mainfrom
mike/issue-305-idle-leases

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 1). The chat binding change (item 3) is a separate PR.

Problem

The plugin lease loop ran AcquirePluginLeases, an UPDATE with RETURNING *, every 10 s on every replica, even with no plugin installed or enabled. That is 60 writes in 10 idle minutes.

Change

  • New query GetPluginLeaseSummary: counts enabled plugins and the ones this replica could lease now (its own, free or expired). It takes no lock and writes nothing.
  • Manager.reconcile reads the summary while the replica runs no plugin and calls AcquirePluginLeases only when a plugin is free to take. A replica that runs a plugin renews as before.
  • The loop uses a timer instead of a ticker. With no enabled plugin it waits for plugins:changed and checks once every 5 minutes (Options.IdleInterval) in case a message was lost. A standby replica (enabled plugin held by another replica) keeps the 10 s interval so it can take over an expired lease. A replica whose plugins:changed subscription failed also keeps 10 s.
  • The wait for the next renewal counts the time reconcile took, so a slow renewal does not push the next one past the lease expiry (Codex P1).
  • Package doc in manager.go describes the loop.

Install, patch and delete already publish plugins:changed (coderd/plugins.go), so an enabled plugin starts at once, as before.

Tests

  • TestManagerIdleIssuesNoWrites: zero plugins, quartz mock clock, 10 minutes. Two summary reads after start, no AcquirePluginLeases, no other statement (strict gomock).
  • TestManagerIdlePicksUpChanges: enable through plugins:changed while idle takes the lease at once; disable returns to the 5 minute idle interval after one 10 s check; an enable whose message was lost is found by the next idle check.
  • TestManagerStandbyWatchesLeases: a held plugin keeps the 10 s interval without writes, and an expired lease is taken.
  • TestManagerIdleWithoutSubscription: no subscription keeps 10 s.
  • TestManagerRenewalCountsReconcileTime: a renewal that takes 4 s waits 6 s for the next one, and one that takes longer than the interval fires the next at once. Fails without the fix (expected 6s, actual 10s).
  • TestPluginLeases (Postgres) checks the summary for free, held, released and disabled plugins.

Negative control on main before this change: a test with the same setup (idle manager, 60 x Advance(10s)) counted 60 AcquirePluginLeases calls in 10 minutes.

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 'TestManager' -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
golangci-lint run on the touched packages: 0 issues

Not done here

A replica that runs no plugin reads GetPluginLeaseSummary, which takes no
lock and writes nothing, and calls AcquirePluginLeases only when a plugin
is free to lease. With no enabled plugin the lease loop waits for
plugins:changed and checks once every 5 minutes. A standby replica and a
replica without the pubsub subscription keep the 10 s interval.

Part of #305.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@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-15T22:17:15.786021Z 6e5e228 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: b3f82173f1

ℹ️ 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: a2793638bb

ℹ️ 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/manager.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: e79c501064

ℹ️ 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. Keep it up!

Reviewed commit: aa579124a0

ℹ️ 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. Swish!

Reviewed commit: 7b6a953f37

ℹ️ 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. Can't wait for the next one!

Reviewed commit: bffff9f653

ℹ️ 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. Delightful!

Reviewed commit: 6e5e228aa0

ℹ️ 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 c3d59ea into main Nov 15, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-305-idle-leases branch November 15, 2026 22:46
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged at head 6e5e228aa0aba24d2c7f584266364c572336df49 as c3d59ea, on main 84ed04016bb18fa4e2a26db02aadb4a98a754302, 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 43766524331 passed on this head.
  3. Codex receipt for this head: perf(coderd/x/plugins): stop lease polling while no plugin is enabled #349 (comment) ("Didn't find any major issues").
  4. No unresolved review thread.
  5. 0 commits behind main.
  6. Tests I ran, under flock ~/.fork-go.lock:
    • On bffff9f653 (same three PR commits; git range-diff shows them identical, and the only change since is main's perf(chatd): read fork per-chat facts once per generation step #350 merge, which touches no plugin file): go test -race -count=1 -v ./coderd/x/plugins/ 10 top-level PASS, 0 FAIL; go test -count=1 -v -run TestPlugin ./coderd/database/forkdb/ 6 PASS, 0 FAIL.
    • Negative control: with manager.go back to plain Subscribe, TestManagerIdleWakesOnDroppedMessages failed after 10 s. The source was restored after.
    • On this exact head: go test -race -count=1 -v ./coderd/x/plugins/ 10 top-level PASS, 0 FAIL.

Not exercised: a live deployment with Wasm plugins enabled and disabled. The lease loop behavior is checked by unit tests with a mock clock only.

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