Repository navigation
feat: add chat wake-up tables and queries - #82
Conversation
Adds the fork-chat-wakeups experiment and the storage for chat wake-ups: a chatdmig node with chatd.chat_wakeups and chatd.chat_wakeup_runs, forkdb queries to create, list, pause, cancel and claim due wake-ups with a lease (FOR UPDATE SKIP LOCKED), run records unique per occurrence and daily run counts, with their dbauthz and dbmetrics wrappers. Refs #11.
|
@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: bc3a7f3f7f
ℹ️ 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".
…ke-up InsertChatWakeupRun now selects chat_id and organization_id from the wake-up and authorizes on the wake-up's chat, so a caller cannot record a run of one chat's wake-up against another chat. Adds the chatd architecture TODO for the new state.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d59e2abaee
ℹ️ 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".
chat_wakeups gets organization_id, copied from the chat by InsertChatWakeup, so organization-scoped lists and caps need no join. A wake-up run now takes its organization from the wake-up.
|
@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". |
…chema # Conflicts: # coderd/database/dbauthz/fork_forkdb.go # coderd/database/dbmetrics/fork_forkdb.go # coderd/database/forkdb/forkdbmock/forkdbmock.go # coderd/database/forkdb/querier.go # coderd/database/forkdb/sqlc.yaml
|
@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". |
Closing and reopening only to make GitHub recompute the merge ref against current main ( |
The merge ref now points at current main ( |
Merge evidence for head
|
Part of #11.
Adds the storage for chat wake-ups: the
fork-chat-wakeupsexperiment, a chatd graph node with two tables, and the forkdb queries a worker and the wake-up tools need. Nothing calls them yet. The worker,schedule_wakeupand/loop,wait_for_events, caps, the API and the UI come in the next PRs of the stack.Why upstream removed automations (scope item 0)
Upstream removed its chat automations in coder#30412 (merged 2026-10-11). I read the PR body, both commits, every PR comment, the 16 reverted stack PRs it lists, and searched the upstream issues. None of them says why. Reason not stated. The PR body only covers what it removes and the upgrade consequences. Two of upstream's design notes shaped this design:
FOR UPDATE SKIP LOCKED, and run records are unique per occurrence.Schema (node
01a1c28c-…_chat_wakeups, inchatd)chat_wakeups: one row per wake-up of a chat, with the chat'sorganization_idcopied on insert.delay,interval,cronorevents, with the prompt each run sends.active,paused,completedorcanceled, with a reason.next_run_at, pluslease_expires_atfor the worker that claimed the row.max_runsandrun_count.chat_wakeup_runs: one row per delivery attempt.(wakeup_id, run_key), where the run key is the scheduled time or an event key.wakeup_idforeign key isON DELETE SET NULL, so deleting a wake-up does not reset the daily caps that count its runs.Queries and authorization
ClaimDueChatWakeupsclaims due active rows with a lease underFOR UPDATE SKIP LOCKED, so replicas never claim the same row.FinishChatWakeupClaimsucceeds only for the current lease holder.InsertChatWakeupandInsertChatWakeupRuntake the organization (and, for a run, the chat) from the parent row, so a caller cannot file a row under another chat or organization.InsertChatWakeupRunreturns no row when that occurrence already ran.UpsertChatTodos. Three worker-only queries span chats (claim, run status, organization count). They authorize on site-widerbac.ResourceChat, which the chatd subject already has and members do not. No new RBAC resource, grant or scope.Validation
go build ./...,go vet,chatdmig check, and the tests ofchatdmig,forkdb,dbauthz,dbmetricsandcodersdk. All passed. Rerunningforkdb/generate.shgives no drift.SKIP LOCKED, the lease filter, the lease match on finish,ON CONFLICT, or thedeliveredfilter, or switching the runs FK toCASCADE. Each break failed its test.fork-chat-wakeupsonly when the flag is set.Size
About 700 hand-written lines. 150 of them are mechanical (dbmetrics pass-throughs and the dbauthz test table), and about 300 are tests. Generated, not counted:
chat_wakeups.sql.go,models.go,querier.go,forkdbmock, apidoc,typesGenerated.ts.