feat: make workspaceAgentAddChatContext use the chatd state machine#26112
Open
hugodutka wants to merge 1 commit into
Open
feat: make workspaceAgentAddChatContext use the chatd state machine#26112hugodutka wants to merge 1 commit into
hugodutka wants to merge 1 commit into
Conversation
8fa644f to
aef0c15
Compare
efdf24f to
1627cf8
Compare
1627cf8 to
d0f134b
Compare
aef0c15 to
6c84888
Compare
johnstcn
reviewed
Jun 8, 2026
Comment on lines
+2606
to
+2634
| if errors.Is(err, chatstate.ErrMessageQueueFull) { | ||
| var queueFull *chatstate.MessageQueueFullError | ||
| detail := "" | ||
| if errors.As(err, &queueFull) { | ||
| detail = fmt.Sprintf("Maximum %d messages can be queued.", queueFull.Max) | ||
| } | ||
| httpapi.Write(ctx, rw, http.StatusTooManyRequests, codersdk.Response{ | ||
| Message: "Message queue is full.", | ||
| Detail: detail, | ||
| }) | ||
| return | ||
| } | ||
| if errors.Is(err, chatstate.ErrInvalidState) { | ||
| httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{ | ||
| Message: "Chat is in an invalid state.", | ||
| }) | ||
| return | ||
| } | ||
| if errors.Is(err, chatstate.ErrTransitionNotAllowed) { | ||
| httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{ | ||
| Message: "Chat is not in a state that accepts new context.", | ||
| Detail: err.Error(), | ||
| }) | ||
| return | ||
| } | ||
| if errors.Is(err, chatstate.ErrChatNotFound) { | ||
| writeAgentChatError(ctx, rw, errChatNotFound) | ||
| return | ||
| } |
Member
There was a problem hiding this comment.
suggestion, non-blocking: maybe rewrite this as a switch?
Comment on lines
+2856
to
+2872
| func agentChatContextStateMessage( | ||
| content pqtype.NullRawMessage, | ||
| modelConfigID uuid.UUID, | ||
| ownerID uuid.UUID, | ||
| apiKeyID string, | ||
| ) chatstate.Message { | ||
| return chatstate.Message{ | ||
| Role: database.ChatMessageRoleUser, | ||
| Content: content, | ||
| Visibility: database.ChatMessageVisibilityBoth, | ||
| ModelConfigID: uuid.NullUUID{UUID: modelConfigID, Valid: modelConfigID != uuid.Nil}, | ||
| CreatedBy: uuid.NullUUID{UUID: ownerID, Valid: ownerID != uuid.Nil}, | ||
| ContentVersion: chatprompt.CurrentContentVersion, | ||
| APIKeyID: sql.NullString{String: apiKeyID, Valid: apiKeyID != ""}, | ||
| } | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
suggestion, non-blocking: this is only used in one place, just inline it for clarity.
Comment on lines
+2587
to
+2589
| if len(sendResult.InsertedMessages) == 0 { | ||
| return nil | ||
| } |
Member
There was a problem hiding this comment.
This seems like an error case? We're trying to send a message, but the result was that nothing was sent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 6 of the chatd refactor. Originally not included in the RFC - I wasn't aware that
workspaceAgentAddChatContextexisted. It seems to be an internal endpoint that the workspace agent can call to inject additional context into the chat. I don't think it's used in production today, but I refactored it either way.Previous PR in the stack: #26111