Repository navigation
feat(chatd): make events wake-ups due when a watched child is done - #345
Conversation
Each chatd Server gets one waker. Chat state updates poke it in-process, it arms a timer at the earliest next_run_at and sweeps every minute. A plain SELECT lists due wake-ups, and each delivery locks the chat and then the wake-up row (FOR UPDATE SKIP LOCKED, status active) and re-checks it is unchanged. This replaces the 15 second claim loop and its lease. Events wake-ups still poll every 15 seconds. Refs #294
A delivery that finds its chat busy writes nothing. Poking the chat again would list the same wake-up and spin until the chat turns idle; the end of the turn pokes instead. Refs #294
…iven-waker-b9396e7f # Conflicts: # coderd/database/forkdb/forkdbmock/forkdbmock.go # coderd/database/forkdb/querier.go
The final SELECT of ListDueChatWakeups filtered chat_wakeups by an OR of two IN lists, which Postgres answers with a sequential scan. Join the due and upcoming ids instead, and extend the plan test to the sweep.
Move the readiness rule of child watches into the view chat_wakeup_ready_watches. ListReadyChatWakeupWatches reads it, and ListDueChatWakeups makes an events wake-up due before its expiry when it has a ready child_done watch with no failed send. A poke for a chat also lists the wake-ups that watch it as a child, so the end of a child's turn delivers the parent's wake-up at once. Child-only wake-ups no longer poll every 15 seconds: their run time is the final poll at the expiry. Processes poll every 15 seconds and pull requests every minute. Drop chat_wakeups.lease_expires_at, which nothing reads since the waker replaced the claim; the migration changes no wake-up's status or run time.
…/ws-294-state-driven-waker-b9396e7f # Conflicts: # coderd/database/forkdb/chat_wakeups.sql.go
@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. |
A replica of the previous version may still hold a claim on a wake-up during a deploy. Clearing its lease in UpdateChatWakeupRun makes that replica's FinishChatWakeupClaim match no row, so it cannot overwrite the result of the new waker.
…/ws-294-state-driven-waker-b9396e7f
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e71d9238b1
ℹ️ 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. Delightful! 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". |
…/ws-294-state-driven-waker-b9396e7f
@codex review |
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@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". |
…iven-waker-b9396e7f # Conflicts: # coderd/database/forkdb/chat_wakeups.sql.go # coderd/database/forkdb/chat_wakeups_test.go # coderd/database/forkdb/querier.go # coderd/database/forkdb/queries/chat_wakeups.sql # coderd/x/chatd/ARCHITECTURE.md # coderd/x/chatd/fork_wait_for_events.go # coderd/x/chatd/fork_waker_internal_test.go # coderd/x/chatd/fork_wakeups.go
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@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". |
…iven-waker-b9396e7f
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@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". |
…iven-waker-b9396e7f
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\n@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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 44142b9 as 344810f, on main 05bc672. Gates:
Rollback: this PR drops Not exercised: the full chatd suite locally (fork-ci covered it), a live migration on the daily server, and |
Part 2 of 2 for #294. It builds on #344, merged into
mainas 7c10f9f, which added the state-driven waker. This PR is now based onmain. This part takeswait_for_eventschild watches off the 15 second poll.Closes #294
What changes
01a1e008-..._chat_wakeup_ready_watches:chat_wakeup_ready_watches, which holds the one readiness rule for watches. The rule was moved unchanged fromListReadyChatWakeupWatches: the watch is open, its wake-up is active, its chat would not queue a message, and either an event fired or the child is done.chat_wakeups.lease_expires_at. Nothing has read the column since feat(chatd): deliver chat wake-ups from a state-driven waker #344 removed the claim.ListReadyChatWakeupWatchesreads the view.ListDueChatWakeupsmakes an events wake-up due before its expiry when it has a readychild_donewatch with no failed send. The rule is not copied: the query reads the same view.upcomingexcludes rows that are already due.expires_at, whichwait_for_eventsalways sets.eventsPollInterval, which replaceswakeupPollInterval). Pull requests still poll every minute.Hot loop guard
A ready watch makes its wake-up due until the watch is delivered. Before the expiry, a delivery always consumes a ready, non-failed
child_donewatch. The exceptions:Failed sends are filtered by
failed_at IS NULL.fired_atis not set by anything yet (#295, #296), so the due query only countschild_donerows.Tests
All run locally under
flock ~/.fork-go.lock:go test ./coderd/x/chatd/... -count=1: ok.go test -race ./coderd/x/chatd/ -run 'Wak|WaitForEvents|Process|PullRequest|Events|Schedule': ok.go test ./coderd/database/forkdb/... -count=1: ok.go test ./coderd/database/dbauthz/ -run 'TestMethodTestSuite|Fork': ok.go test ./coderd/ -run 'TestForkChatLoopErrors|TestForkChatWakeups|TestForkChatWakeupStatus|TestForkChatWakeupAudit|TestForkChatOrganizationWakeupCaps': 7 tests pass.CHATDMIG_TEST_DATABASE_URL=... go test ./coderd/database/migrations/chatdmig/...: ok.chatdmig check: exit 0.make lint/go/new-code: 0 issues.lint/emdash,lint/markdown,lint/architecture,lint/migrations: ok.New tests:
TestWakerDeliversWhenChildFinishes(Quartz): a parent waits on a running child. The child's turn ends through chatstate, and the parent gets the message with no clock advance. Negative control: without ther.child_chat_idscope in the due query it fails, then reverted.TestListDueChatWakeupsReadyEvents: due when the child is done before the expiry; not due when the child runs, the send failed, the wake-up expired or the parent is busy; the child scope;upcomingexcludes due rows.TestListReadyChatWakeupWatchesPlanchecks both statements for sequential scans with 10,000 finished wake-ups.TestWakeupEventsDeliversOncePerChildnow asserts that a child-only wake-up runs next at its expiry and that a delivery keeps that run time.git grep -n 'wakeupPollInterval\|lease_expires_at\|ClaimDueChatWakeups'outside migrations finds only thepluginsandexternal_auth_linkscolumns of the same name. Nothing forchat_wakeupsis left.Deploy notes
lease_expires_at, and the chatdmig runner does not reject the unknown node, so the old binary starts and then fails on each wake-up read and write.main. The waker of feat(chatd): deliver chat wake-ups from a state-driven waker #344 already ignores the lease column.Not verified
lint/typos: thetyposbinary is not installed in this workspace.