Repository navigation
feat(chatd): store the answered state of descendant questions - #332
Conversation
chat_descendant_questions now stores the family root and whether the question is answered. The chatstate message insert marks the question answered in the same transaction as the user message that answers or retires it: a visible user message, the secret answer message, or a compressed context boundary. A new question clears the state. Reads of the pending question and the questions endpoint no longer scan chat_messages. The chatdmig node backfills root_chat_id from the family root and marks rows that the old rule treats as answered with answered_by = 'migrated'. Pending rows stay pending. Part of #300.
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: efca0cbbb9
ℹ️ 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".
Require answered_by on an answered row; a NULL passed the CHECK. Label a prefixed answer to a question that is not secret as message, so secret_answer means a secret question. Index root_chat_id fully, so the cascade from a deleted chat can use it. Say in ARCHITECTURE.md that the chatstate insert writes this table through a fork hook. Cover deleted, compressed and secret rows in the backfill test.
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
# Conflicts: # coderd/database/forkdb/sqlc.yaml # coderd/x/chatd/ARCHITECTURE.md
Merged origin/main (9308bf6, #330) into this branch. The node now also requires the token budget node. @codex review |
|
Codex Review: Didn't find any major issues. Swish! 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 origin/main (9f99450, #331, site only) into this branch. @codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs 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". |
fork-ci run 43619866320 on 1ce7f63 failed only in |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: befc479c03
ℹ️ 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".
|
|
To use Codex here, create an environment for this repo. |
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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 as 5f049c1 (squash, Gates on head 1490c74:
Not exercised: a live family on the daily server. The migration backfill ran only in the chatdmig test database. |
Bottom of a two PR stack for #300. The top PR, #333, wakes
wait_agenton the child's state channel.What changed
01a1da95-..._chat_descendant_questions_answeredaddsroot_chat_id,answered_atandanswered_bytochatd.chat_descendant_questions, a CHECK on the pair (an answered row must name what answered it), and an index onroot_chat_id.root_chat_idisCOALESCE(chats.root_chat_id, chats.id), because roots have a NULLroot_chat_idand children name the family root. A row that the old SQL rule treats as answered getsanswered_at = now()andanswered_by = 'migrated'. A pending row stays pending.chatstate.(*Tx).insertMessagesgets one hook line.forkRetireDescendantQuestion(inchatstate/fork_descendant_questions.go) runsRetireChatDescendantQuestionin the same transaction as the inserted user messages. It setsanswered_bytomessage(a visible user message, question not secret),secret_answer(a secret question answered by a visible message whose text starts withAnswer to ask_user_question call <id>:), orcontext_boundary(a compressed message: clear or compaction). Model-only messages and messages of a rolled back transaction leave the question pending.UpsertChatDescendantQuestiontakes the root fromchatsand clears the answered state, so a new question is pending again.GetPendingChatDescendantQuestionandListPendingChatDescendantQuestionsByRootread onlychat_descendant_questionsandchats. They no longer scanchat_messages.coderd/x/chatd/ARCHITECTURE.mddescribes the stored state.Why
Pending was derived from later chat messages on every read. That cost a
chat_messagesscan per poll and per questions endpoint call, and the rule was hard to reason about. Storing the state in the transaction of the retiring event keeps it exact.Tests
All run locally with
flock ~/.fork-go.lock:go test ./coderd/x/chatd/chatstate/ -run TestRetireDescendantQuestion -v: one case per retiring event through real chatstate transitions (visible message, promoted queued message, secret message stays pending, secret answer, clear context, compaction, model-only message, rolled back message) plus "new question resets". Each assertsanswered_atandanswered_by. Pass.go test ./coderd/database/forkdb/ -run Descendant -v: query table test, cascade delete, list by root. Pass.CHATDMIG_TEST_DATABASE_URL=... go test ./coderd/database/migrations/chatdmig/...: full suite includingTestUpgradeMatchesFreshand the newTestDescendantQuestionsAnsweredBackfill(a root and one child per branch of the old rule: visible, before plus model-only, deleted, compressed, secret visible, secret answer; rows kept,root_chat_idis the root,answered_byismigratedor NULL as the old rule says,created_atkept, and the CHECK rejects an answered row withoutanswered_by). Pass. fork-ci sets this variable, so it runs there too.go test ./coderd/ -run 'Question|Secret': includes the newNoMessageReadssubtest, which holdsLOCK TABLE chatd.chat_messages IN ACCESS EXCLUSIVE MODE, proves achat_messagesread blocks, and still gets the question from the endpoint. Pass.go test ./coderd/database/dbauthz/,go test ./coderd/x/chatd/...: pass.golangci-lint run --fix=falseon the changed packages: no finding on changed lines. New-code config with--new-from-merge-base=origin/main: 0 issues.make gen: no diff (it stops at the helm golden step because helm is not installed here).Not verified
Part of #300. The stack continues in #333.