Repository navigation
perf(coderd/x/chatd): read family statuses in one statement for cascade, settle and spawn - #365
Conversation
…de, settle and spawn
@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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e0714cc14
ℹ️ 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".
…ons while settling an archive
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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: the cascade now passes Not exercised: a running server or the UI; archive settle timing under real worker leases. |
Part of #302. This is the bottom PR of a stack. It covers items 1 to 3 of the issue. The chat tree and wait_agent items follow in PRs based on this one.
What changed
GetChatSubtreeIDsnow also returns each descendant's status.forkInterruptDescendantsskips idle descendants from that result and interrupts the active ones by ID. It no longer reads each descendant withGetChatByID.InterruptChatlocks the chat by ID and checks the transition against the locked row, so the stale status in the row is only a filter. I kept the filter in Go so the other callers of the query (lockSubtreeForArchive,archive_agent) keep the same rows and order.settleChatsForArchiveinterrupts the top chat once, which cascades leaves first. Each later wake runssettleArchivePass: oneGetChatSubtreeIDsfor the current subtree of the top chat, so a child spawned during the settle is covered, and oneGetChatsByIDsfor the top chat and that subtree. It then interrupts every active member again, except aninterruptingmember that a worker still owns, which only waits for that worker. An unownedinterruptingmember is interrupted again, so the transition finishes it inline. Before, each wake ran the whole cascade again and then oneGetChatByIDper member.loadSubagentSpawnParentChatno longer validates the parent before it reloads it. The check on the reloaded parent still fails fast before prompt hooks run. The check in the creation transaction stays the deciding one, with the lock order from perf(coderd/x/chatd): count subagent capacity in one statement and lock per family #359 unchanged: owner check share locks, root share lock, then the family admission lock. Spawn now reads the limits, the depth and the live count twice instead of three times.Tests
New file
coderd/x/chatd/fork_family_reads_internal_test.go:TestForkInterruptCascadeStatements: a leaf interrupt runs oneGetChatSubtreeIDsand noGetChatByID. A root with 20 idle descendants over 3 levels runs exactly one statement. With 2 active descendants, there is still noGetChatByID, and both reachinterrupting.TestForkArchiveSettlePassStatements: one pass over a root with 20 descendants runs exactly oneGetChatSubtreeIDsand oneGetChatsByIDs, both while a member is interrupting and once it is settled. An owned interrupting member is not interrupted again.TestForkArchiveSettlePassCoversLateAndUnownedMembers: a pass interrupts a running grandchild that was not in the family when the settle began, and finishes an unowned interrupting child. It fails when the pass skips every interrupting member or does not reread the subtree.TestForkSpawnValidationReads: aspawn_agentcall from a depth 1 child, counted inside and outside the creation transaction, reads the limits, the depth and the live count twice each. The counter only counts reads from the validation, not from capacity admission or the orchestration prompt.coderd/database/forkdb/chat_subtree_test.gonow checks the status column.Negative controls: I put back the old per-descendant read, the per-member status read and the pre-reload validation, and the new tests failed:
GetChatByID: 20for the idle family and for the active one,GetChatByID: 20instead of oneGetChatsByIDsfor the settle pass, and 3 instead of 2 for spawn. The leaf case passes either way, since a leaf has no descendants to read.Commands run:
go test ./coderd/x/chatd/ -count=1: okgo test ./coderd/database/forkdb/ -count=1: okgo test ./coderd/database/dbauthz/ -run 'Fork|Subtree' -count=1: okNot verified
make lintwas not run.golangci-lint run --fix=falseoncoderd/x/chatdandcoderd/database/forkdbreports nothing in the changed files.