Repository navigation
perf(coderd): read a chat family's descendants in one statement for the chat tree and list_agents - #366
Conversation
…de, settle and spawn
…ons while settling an archive
…he chat tree and list_agents
@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: 1c515d7261
ℹ️ 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".
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 778e0e567a
ℹ️ 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".
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review\n\nThe architecture TODO is intentional per AGENTS.md line 75 and is already flagged for the author. Please review the rest of the change. |
# Conflicts: # coderd/x/chatd/fork_family_reads_internal_test.go
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review\n\nRestacked on |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 238401c22f
ℹ️ 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".
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review\n\nThe chat tree finding is answered in its thread: both callers pass only root chats. |
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd835876e2
ℹ️ 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".
Deleting a family root sets root_chat_id and the promoted child's parent_chat_id to NULL, so the root_chat_id predicate returned only one level below the promoted root. GetDescendantChatsByRootIDs now walks parent_chat_id with a recursive CTE, and list_agents starts the walk at the listed chat.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 194c5da5db
ℹ️ 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 one-level list_agents call walked up to 64 levels and discarded every row below the direct children. GetDescendantChatsByRootIDs now takes a max_depth, capped at 64.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 849d942f9c
ℹ️ 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".
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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. Bravo. 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. 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". |
fork-ci run 43974407705 on 8011e07 failed only in TestForkWorkflowLiveLogs/StopLinesBypassTheEchoSuppression ( |
Merged at head Gates on this exact head:
Tests I ran on
Review notes: the Codex P2 about a family whose root was deleted was a real regression, because both chat foreign keys are ON DELETE SET NULL. It is fixed with a recursive CTE over Not exercised: a running server and the sidebar UI. |
Part of #302. This is the second PR of a stack. #365 (items 1 to 3) merged as 5e28a43, and this PR is now based on
mainwithmainmerged in. It covers item 4 of the issue, the chat tree. The wait_agent item follows in #367, which is based on this one.What changed
With
fork-nested-subagentson, a chat family's descendants are read in one statement instead of one query per level.GetDescendantChatsByRootIDsincoderd/database/forkdb/queries/chat_tree.sql. It walksparent_chat_iddown from the given chats with a recursive CTE that stops at the caller'smax_depth(capped at 64, likeGetChatSubtreeIDs), served byidx_chats_parent_chat_id. It does not useroot_chat_id, so a family whose root was deleted (both foreign keys areON DELETE SET NULL) still returns its whole subtree. The archive filter applies at each step of the walk, so an archived chat's subtree is never walked. It has the row shape,has_unreadand archive filter of upstream'sGetChildChatsByParentIDs. dbauthz uses the same per-row post-filter as upstream (fetchWithPostFilter, read action), and dbmetrics observes it.forkdb.DescendantsByLevelkeeps only rows whose parent was reached from the roots, level by level, each level in the query'screated_at DESCorder. A chat that the archive filter or authorization drops therefore still hides its own subtree, and the output order is the one the per-level walk produced.coderd/fork_chat_tree.go:forkEmbeddedChildChats(chat list and single-chat GET of a root) runs that one query. With the experiment off it is still upstream's single direct-children query.coderd/x/chatd/fork_list_agents.go:listDescendantChatsreads the listed chat's subtree in one statement that stops at the requested depth (one level forchat_idwithoutrecursive), still unarchived only. list_agents stays limited to the caller's subtree, since thechat_iddescendant check is unchanged.forkdb.ChatsExpanded.Chat()converts the new row todatabase.Chat.sqlc.yamlmaps thechats_expandedenum and JSON columns to the upstream types.coderd/x/chatd/ARCHITECTURE.md: the fork list_agents bullet (from feat(coderd/x/chatd): list a chat's descendants with list_agents #278) now says thatchat_idandrecursiveread the listed chat's subtree in oneGetDescendantChatsByRootIDsstatement, followingparent_chat_idthrough unarchived chats only. No upstream line changed.Tests
coderd/fork_chat_tree_test.goTestForkChatTreeStatements: counts the queries through a wrapped store. For a root with child, grandchild and great-grandchild, the single-chat GET and the chat list each run oneGetDescendantChatsByRootIDsand noGetChildChatsByParentIDs, and embed the family level by level. A grandchild the member cannot read hides its own child. An archived child hides its unarchived subtree from the unarchived list. After the root of a 4-level family is deleted, the GET of the promoted root runs one statement and embeds its child and grandchild.coderd/x/chatd/fork_list_agents_internal_test.goTestForkListAgentsAfterRootDeleted: after the root of a 4-level family is deleted, recursive list_agents from the promoted root returns its child and the deepest chat.coderd/x/chatd/fork_family_reads_internal_test.goTestForkListDescendantsStatements: list_agents over a root with 20 descendants on 2 levels, from the root and from a child, runs exactly oneGetDescendantChatsByRootIDs. It also checks the subtree cut, the one-level listing and that an archived child hides its subtree.coderd/database/forkdb/chat_tree_test.go: each row equals upstream's row for the same chat, the archive filter, a legacy child withoutroot_chat_id, a family whose root was deleted, themax_depthbound, another family left out,DescendantsByLevelorder, the hidden parent rule and the depth limit, andChatsExpanded.Chat()copying every column.coderd/database/dbauthz/fork_forkdb_test.go: the new query's authorization.Negative controls: with the old per-level walk put back,
TestForkChatTreeStatementsfails with 4GetChildChatsByParentIDsfor the GET, andTestForkListDescendantsStatementsfails withGetChildChatsByParentIDs: 3instead of oneGetDescendantChatsByRootIDs. With the earlierroot_chat_id OR parent_chat_idpredicate put back, the deleted-root cases fail inTestForkChatTreeStatements(only the promoted root's child is embedded),TestForkListAgentsAfterRootDeletedandTestGetDescendantChatsByRootIDs.Plan:
EXPLAIN ANALYZEon 100,000 chats usesidx_chats_parent_chat_idin both arms of the recursive CTE andchats_pkeyfor the join tochats_expanded.Commands run:
go test ./coderd/ -run 'TestForkChat|TestChat' -count=1: okgo test ./coderd/x/chatd/ ./coderd/database/forkdb/... -count=1: okgo test ./coderd/database/dbauthz/ -run TestForkQuerier -count=1: okgolangci-lint run --fix=false ./coderd/ ./coderd/x/chatd/ ./coderd/database/forkdb/...: nothing reported in the changed filesNot verified
make lintwas not run.golangci-lint run --fix=falseon the changed packages reports nothing in the changed files.