Skip to content

Commit b7d172b

Browse files
waleedlatif1claude
andcommitted
fix(copilot): thread chatModel through post + terminal-state dual-writes
The user-message append path (post.ts) and assistant-finalize path (terminal-state.ts) were calling appendCopilotChatMessages without chatModel, leaving the model column NULL on every interactive turn. post.ts now projects model from .returning(...); terminal-state.ts adds model to the in-tx SELECT and surfaces it through a closure. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a47ca82 commit b7d172b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

apps/sim/lib/copilot/chat/post.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,13 @@ async function persistUserMessage(params: {
331331
updatedAt: new Date(),
332332
})
333333
.where(eq(copilotChats.id, chatId))
334-
.returning({ messages: copilotChats.messages })
334+
.returning({ messages: copilotChats.messages, model: copilotChats.model })
335335

336336
if (updated) {
337-
await appendCopilotChatMessages(chatId, [userMsg], { streamId: userMessageId })
337+
await appendCopilotChatMessages(chatId, [userMsg], {
338+
streamId: userMessageId,
339+
chatModel: updated.model ?? null,
340+
})
338341
}
339342

340343
const messagesAfter = Array.isArray(updated?.messages) ? updated.messages : undefined

apps/sim/lib/copilot/chat/terminal-state.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export async function finalizeAssistantTurn({
4949
},
5050
async (span) => {
5151
let appendedAssistantMessage: PersistedMessage | undefined
52+
let chatModel: string | null = null
5253
const result = await db.transaction(async (tx) => {
5354
const where = userId
5455
? and(eq(copilotChats.id, chatId), eq(copilotChats.userId, userId))
@@ -58,11 +59,13 @@ export async function finalizeAssistantTurn({
5859
messages: copilotChats.messages,
5960
conversationId: copilotChats.conversationId,
6061
workspaceId: copilotChats.workspaceId,
62+
model: copilotChats.model,
6163
})
6264
.from(copilotChats)
6365
.where(where)
6466
.for('update')
6567
.limit(1)
68+
chatModel = row?.model ?? null
6669

6770
const messages: Record<string, unknown>[] = Array.isArray(row?.messages) ? row.messages : []
6871
span.setAttribute(TraceAttr.ChatExistingMessageCount, messages.length)
@@ -154,6 +157,7 @@ export async function finalizeAssistantTurn({
154157
if (appendedAssistantMessage) {
155158
await appendCopilotChatMessages(chatId, [appendedAssistantMessage], {
156159
streamId: userMessageId,
160+
chatModel,
157161
})
158162
}
159163

0 commit comments

Comments
 (0)