Repository navigation
perf(coderd/x/chatd): pack path cache, one linkable plugins query, subscribe before a step wait - #370
Conversation
… in one query, and subscribe before waiting on a step Part of #307 (items 4, 7 and 8).
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: 40d265778f
ℹ️ 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".
…p deadline across wait restarts The pack path cache holds the two latest commits per pack, so a step still pinned to the previous commit keeps its paths. awaitStepChild caps each wait at the step deadline and stops restarting once it passed, so a child that changes state often cannot hold waitStep past the step timeout. Part of #307.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15549fbe6e
ℹ️ 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".
The two-slot cache dropped the commit of a step pinned to it once the pack moved twice, and the next read stored the current files under the old commit. The cache now keeps every commit read in the last hour and drops the others when a new commit is stored.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0417bd9930
ℹ️ 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".
…moved past The resource table holds only a pack's current files. A miss for a pinned commit now reads the pack commit after the files, caches them only when it still matches, and returns no paths otherwise, so the files of a newer commit are never used as the pinned commit's.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6d92082844
ℹ️ 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".
…drop idle pack entries
@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: Didn't find any major issues. Can't wait for the next one! 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 @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5700f4243
ℹ️ 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".
A cold replica stores one commit per enabled pack, and a sweep on every store scanned the whole cache once per pack. The step deadline test now runs on a mock clock instead of a 300 ms wall-clock deadline.
Pushed @codex review |
|
Codex Review: Didn't find any major issues. 🎉 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:
Not exercised: a running server with real plugin packs, and many replicas sweeping the cache. |
Part of #307: items 4, 7 and 8. Items 2, 3 and 6 are in #368, item 1 is in #369, and item 5 is covered by #294.
Changes
Item 4: pack path cache.
packPathsincoderd/x/chatd/fork_plugin_gate.gokept one entry per (pack, commit) and never dropped old commits. It now keeps one entry per pack ID (packPathsEntry) that maps each commit to its paths and last read. A store sweeps every pack, at most once per minute (packPathsSweepEvery), so a cold replica that reads many packs does not scan the cache once per pack. The sweep works so: a commit not read for an hour (packPathsIdle) is dropped, and an entry left with no commits is removed withCompareAndDelete, so a deleted pack's entry goes away too. A step reads its pinned commit each time it filters pack rows, so a step still pinned to an older commit keeps its paths while newer steps read newer commits. Memory per pack is the commits read in the last hour.plugin_pack_resourcesholds only a pack's current files, so on a misspackPathsreads the pack commit and its files in one statement, the new forkdb queryGetPluginPackCommitPaths(plugin_packs LEFT JOIN plugin_pack_resources), and caches them only when that commit is the pinned commit. One statement means both come from one snapshot. When the pack moved past the pinned commit, the gate fails closed for that step (no paths, nothing cached) instead of using a newer commit's files under the old commit. Onmainsuch a read returned and cached the newer files.Item 7: linkable plugins.
GET /api/experimental/users/me/pluginsread the user's organizations and then ranGetPluginsByOrganizationIDper organization, which also selected and decryptedconfig. It now runs one forkdb query,GetLinkablePluginsByUserID, that joinsorganization_membersand liveorganizations, keeps enabled plugins, and selects noconfig. The chats grant filter stays in Go. dbauthz (ResourceSystemread, likeGetPluginUserLinksByUserID) and dbmetrics wrappers are added. dbcrypt needs nothing because the row has no config.Item 8: first notification.
waitStepcalledawaitSubagentCompletion, which reads the child and then subscribes, so a child that ended its turn in between was seen only at the 5 s fallback tick. The new fork helperawaitStepChildinfork_workflow.gosubscribes to the child's state channel first, then callsawaitSubagentCompletion, and restarts it when a state change arrives, so the restarted call reads the child at once. Each wait is capped at the time left before the step deadline and the restarts stop once it passed, so a child that changes state often still returns control towaitStep, which fails the step afterworkflowStepTimeout. Upstreamsubagent_operations.gois unchanged.Tests
TestPackPathsCacheOnePerPack(each install moves the pack commit and its files; one cache entry across c1 to c3; c1 is still served from the cache after the pack moved to c4; once every commit is an hour idle, reading c3 keeps it and storing c4 drops c1 and c2; a read of dropped c1 fails closed and caches nothing; a store within a minute of the last sweep does not sweep; a deleted pack's entry is dropped on the next sweep)-race -count=3)a store soon after a sweep does not sweep. The line numbers of the mutations below were taken ata5700f4243, before the gate test moved them by about 6 lines.TestPluginPackResources(GetPluginPackCommitPaths: one row per file, a NULL path for an empty pack, no row for a deleted pack)TestLinkablePluginsOneQuery(coderdtest with a counting store, member of 4 orgs)coderd/plugins.gofrom main: FAIL,no query per organizationexpected 0 actual 4TestGetLinkablePluginsByUserID(member orgs only, disabled and deleted org excluded, order)TestWorkflowWaitStepSeesFirstNotification(store ends the child's turn on the first completion check and returns the stale row; mock clock never fires the fallback tick)-count=30 -racefork_workflow.gofrom main: FAIL,waitStep missed the notification...after 10 sTestWorkflowAwaitStepChildKeepsDeadline(store publishes a state change on every check of a running child; mock clock, deadline 1 s ahead; the test waits for restarts, then advances the clock to the deadline)-race -count=3awaitStepChild kept restarting past the step deadlineafter 10 sCommands, all under
flock ~/.fork-go.lock:go test ./coderd/ -run 'TestLinkablePluginsOneQuery|TestPlugins' -count=1: ok (TestPlugins, TestPluginsAudit, TestPluginsDisabled, TestLinkablePluginsOneQuery PASS)go test ./coderd/x/chatd/ -run 'Workflow|Subagent|Pack|Plugin' -count=1 -v: ok, 282 PASS, 0 FAILgo test ./coderd/database/forkdb/... ./coderd/database/dbmetrics/... ./enterprise/dbcrypt/... -count=1: okgo test ./coderd/database/dbauthz/ -run 'TestForkQuerier|TestMethodTestSuite' -count=1: ok, includesTestForkQuerier/GetLinkablePluginsByUserIDandTestForkQuerier/GetPluginPackCommitPathsgolangci-lint run --fix=false --new-from-rev=origin/mainon the changed packages: 0 issues;gofmt -l: cleanNot verified
awaitStepChildre-runs the descendant check and one chat read per state change of the step child. That cost was not measured.