From 8c08aa1f6c6c42ad6f11c6a2dad88f0dd2bc32d9 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Thu, 7 May 2026 15:53:11 +0300 Subject: [PATCH] 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 --- coderd/x/chatd/chatd.go | 4 ++++ coderd/x/chatd/quickgen.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/coderd/x/chatd/chatd.go b/coderd/x/chatd/chatd.go index 3978b4e462..9338dda90f 100644 --- a/coderd/x/chatd/chatd.go +++ b/coderd/x/chatd/chatd.go @@ -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 { diff --git a/coderd/x/chatd/quickgen.go b/coderd/x/chatd/quickgen.go index e76545527e..13a7feba70 100644 --- a/coderd/x/chatd/quickgen.go +++ b/coderd/x/chatd/quickgen.go @@ -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 }