Skip to content

Commit f1007e9

Browse files
committed
fix(coderd): name stream setup failures and correct the stream docs
A failed stream setup now says it failed instead of reading as a disabled feature, and a test covers the pubsub subscription failure. The 400 for a version above the chat's says how to recover after a database restore. The docs no longer claim every chat change advances snapshot_version, and the migration guide nests the reconnect steps, runs each tool call once, and refetches a discarded page.
1 parent cdf4789 commit f1007e9

11 files changed

Lines changed: 103 additions & 60 deletions

File tree

‎coderd/apidoc/docs.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎coderd/exp_chats.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ func (api *API) clearChatReadCursor(ctx context.Context, chatID uuid.UUID) error
36883688
// @Description
36893689
// @Description Each WebSocket message is a JSON array of events.
36903690
// @Description
3691-
// @Description The server increases a chat's `snapshot_version` by 1 each time it commits a change to the chat.
3691+
// @Description The server increases a chat's `snapshot_version` by 1 each time it commits a change to the chat's messages, queue, or status.
36923692
// @Description Each change has the `snapshot_version` of the commit that made it.
36933693
// @Description Only the newest messages page, which `GET /api/v2/chats/{chat}/messages` returns when you set neither `before_id` nor `after_id`, includes the chat's `snapshot_version`.
36943694
// @Description The server reads `snapshot_version` before the messages and the queue, so a change that it commits between those reads is in the page, and the stream sends that change again.
@@ -3757,12 +3757,12 @@ func (api *API) streamChat(rw http.ResponseWriter, r *http.Request) {
37573757
return
37583758
}
37593759
}
3760-
// A chat's snapshot version never decreases, so a cursor above it was
3761-
// never issued for this chat.
3760+
// A chat's snapshot version decreases only when the database is restored,
3761+
// so a cursor above it is from before a restore or was never issued.
37623762
if snapshotVersion > chat.SnapshotVersion {
37633763
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
37643764
Message: "Invalid snapshot_version parameter.",
3765-
Detail: fmt.Sprintf("snapshot_version %d is above the chat's snapshot version %d.", snapshotVersion, chat.SnapshotVersion),
3765+
Detail: fmt.Sprintf("snapshot_version %d is above the chat's snapshot version %d. Request the chat's newest messages page again and open the stream with its snapshot_version.", snapshotVersion, chat.SnapshotVersion),
37663766
})
37673767
return
37683768
}
@@ -3772,7 +3772,8 @@ func (api *API) streamChat(rw http.ResponseWriter, r *http.Request) {
37723772
snapshot, events, cancelSub, ok := api.chatDaemon.SubscribeAuthorized(ctx, chat, r.Header, afterMessageID, snapshotVersion)
37733773
if !ok {
37743774
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
3775-
Message: "Chat streaming is not available.",
3775+
Message: "Failed to open the chat stream.",
3776+
Detail: "Retry the request, or check the coderd logs for this chat.",
37763777
})
37773778
return
37783779
}

0 commit comments

Comments
 (0)