Repository navigation
perf(coderd/x/plugins): renew plugin leases without reading full rows - #360
Conversation
RenewPluginLeases renews this replica's leases and returns only id and updated_at, so a renewal reads and decrypts no plugin config. The manager reads a full row with GetPluginByID only when updated_at changed or no runner exists. AcquirePluginLeases now takes only plugins no replica holds, up to the free slots. Bindings of archived chats are kept on purpose: deleting them loses the cursor and the delivered mark, so an unarchived chat would replay its history or move to another link. A test pins that archived chats are not due and keep both. Part of #305.
@codex review |
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: 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". |
Merged main (2523de1, #357) into this branch. No conflicts. Focused tests pass again under the lock. @codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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 PR commit at
Decision: bindings of archived chats are kept, not deleted. Deleting one loses its cursor and delivered state, so an unarchived chat would replay its history or move to another link. The due query already skips archived chats, so the cost is one small row per archived chat. Not exercised: a multi-replica deployment, and live statement or decrypt counts on the deployed server. #305 stays open for #361 (restart backoff). |
Part of #305. This PR does item 2 (renew without reading rows) and closes out item 3. Item 4 (restart backoff) remains and comes in a follow-up PR stacked on this branch.
What changed
RenewPluginLeases:UPDATE plugins SET lease_expires_at = now() + lease WHERE runner_id = $1 AND enabled RETURNING id, updated_at. It returns no config, so a renewal reads and decrypts nothing.AcquirePluginLeasesnow takes only plugins no replica holds (runner_id IS DISTINCT FROM meand the lease is null or expired), limited to the free slots (MaxPlugins - renewed).Manager.reconcilerenews first, then acquires. For a renewed plugin with the sameupdated_atas its runner, it reuses the runner's plugin row: a live runner keeps running and an exited one restarts with no read. It callsGetPluginByID(decrypted through dbcrypt) only whenupdated_atchanged or no runner exists. A failed read keeps the current runner and retries on the next tick. The idle path (GetPluginLeaseSummary) is unchanged.ActionUpdateonResourceSystem, same asAcquirePluginLeases) with itsTestForkQuerierentry, dbmetrics, and a note in the dbcrypt wrapper that the renewal passes through because it returns no secret.flock ~/.fork-go.lock ./coderd/database/forkdb/generate.sh.make gendoes not run the forkdb generator.Archived chat bindings are kept, not deleted
Deleting a binding would lose its cursor and its delivered mark, so an unarchived chat would replay its whole assistant history (a chat created after the link rebinds at cursor 0) or be handed to another idle link. The due query already skips archived chats, so a kept binding costs one small row.
TestPluginChatBindingsnow pins that an archived chat is not due and that unarchiving keeps its cursor and delivered mark.Tests
All run with
flock ~/.fork-go.lock.go test -race -count=10 ./coderd/x/plugins/ -run TestManager -v: 70 PASS, 0 FAIL (7 tests x 10).go test -race -count=1 ./coderd/x/plugins/...: ok (plugins, pluginhost, sandbox).go test -count=1 ./coderd/database/forkdb -run TestPlugin -v: 7 PASS, 0 FAIL.go test -count=1 ./coderd/database/dbauthz -run TestForkQuerier: ok, includingTestForkQuerier/RenewPluginLeases.go test -count=1 ./coderd/database/dbmetrics/... ./enterprise/dbcrypt/... ./coderd/database/forkdb/...: ok.go test -count=1 ./coderd ./enterprise/coderd -run TestPlugin -v: 15 PASS, 0 FAIL.go build ./coderd/... ./enterprise/...: ok.golangci-lint run --fix=falseon the touched packages: 0 issues.gofmt -l: clean.New test
TestManagerRenewalReadsNoRows: a live runner (its first query blocks until it stops) is renewed over 4 ticks with 0GetPluginByIDcalls and 1 full row in total (the first acquire). Then a changedupdated_atgives exactly 1GetPluginByIDand a restart with the new config, and the next tick reads nothing.Negative controls
updated_atshortcut):TestManagerRenewalReadsNoRowsfails, "Should be zero, but was 3".updated_at: the same test fails, the restart never comes (TryReceive: context expired).manager.gofrom main:TestManagerRenewalReadsNoRowsfails (no renewals).AcquirePluginLeasesclause (includes own rows):TestPluginLeasesfails, "acquire skips the holder's own lease".NOT c.archivedfromGetPluginChatBindingsDue:TestPluginChatBindingsfails, "an archived chat is not delivered".Not verified