fix(coderd/x/chatd): wake after async chat-row UPDATEs commit (#25036)

The async title-generation and turn-summary goroutines launched from
processChat run autocommit UPDATEs on the chat row after finishActiveChat
has set the chat to pending and signalWake has fired. If the row lock
from one of those UPDATEs is held while acquireLoop's processOnce runs,
AcquireChats's FOR UPDATE SKIP LOCKED skips the freshly-pending chat and
returns no rows. The wake is then consumed with no acquisition, and the
chat sits in pending until the next acquireTicker (default 1s).

Wake again after each UPDATE commits. The second wake covers the race
window without changing the transaction semantics.

Closes coder/internal#1500
This commit is contained in:
Mathias Fredriksson
2026-05-07 15:53:11 +03:00
committed by GitHub
parent 20453e123e
commit 8c08aa1f6c
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -8630,6 +8630,10 @@ func (p *Server) updateLastTurnSummary(
updatedChat := chat
updatedChat.LastTurnSummary = lastTurnSummary
p.publishChatPubsubEvent(updatedChat, codersdk.ChatWatchEventKindSummaryChange, nil)
// AcquireChats uses SKIP LOCKED; re-wake so a wake racing this
// UPDATE's row lock does not strand a freshly-pending chat.
p.signalWake()
}
func (p *Server) webpushConfigured() bool {
+4
View File
@@ -262,6 +262,10 @@ func (p *Server) maybeGenerateChatTitle(
chat.Title = title
generatedTitle.Store(title)
p.publishChatPubsubEvent(chat, codersdk.ChatWatchEventKindTitleChange, nil)
// AcquireChats uses SKIP LOCKED; re-wake so a wake racing this
// UPDATE's row lock does not strand a freshly-pending chat.
p.signalWake()
return
}