Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/taskdeck-web/src/api/chatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const chatApi = {
return data
},

async getSession(sessionId: string): Promise<ChatSession> {
const { data } = await http.get<ChatSession>(`/llm/chat/sessions/${encodeURIComponent(sessionId)}`)
async getSession(sessionId: string, options?: { skipRetry?: boolean }): Promise<ChatSession> {
const { data } = await http.get<ChatSession>(`/llm/chat/sessions/${encodeURIComponent(sessionId)}`, options)
return data
},

Expand Down
4 changes: 3 additions & 1 deletion frontend/taskdeck-web/src/composables/useAutomationChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ export function useAutomationChat() {

async function refreshSelectedSession(sessionId: string) {
try {
const result = await chatApi.getSession(sessionId)
// The send already succeeded and its messages are retained locally. A
// failed reconciliation must not hold continuation behind read retries.
const result = await chatApi.getSession(sessionId, { skipRetry: true })
if (isDisposed || requestedSessionId !== sessionId || selectedSession.value?.id !== sessionId) return
localMessagesBySession.delete(sessionId)
sessionWriteGenerations.set(sessionId, (sessionWriteGenerations.get(sessionId) ?? 0) + 1)
Expand Down
8 changes: 8 additions & 0 deletions frontend/taskdeck-web/src/tests/api/chatApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ describe('chatApi', () => {
})
})

it('can fail fast for a post-send reconciliation read', async () => {
const failure = new Error('Refresh unavailable')
vi.mocked(http.get).mockRejectedValue(failure)

await expect(chatApi.getSession('session/1', { skipRetry: true })).rejects.toBe(failure)
expect(http.get).toHaveBeenCalledWith('/llm/chat/sessions/session%2F1', { skipRetry: true })
})

it('loads provider health', async () => {
const healthPayload = {
isAvailable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ describe('useAutomationChat', () => {
chat.messageContent.value = 'new instruction'
await chat.handleSendMessage()

expect(chatApiMocks.getSession).toHaveBeenNthCalledWith(1, 's1')
expect(chatApiMocks.getSession).toHaveBeenLastCalledWith('s1', { skipRetry: true })
expect(chat.sendingMessage.value).toBe(false)
expect(chat.selectedSession.value?.recentMessages.map((message) => message.content)).toEqual([
'older instruction',
'No board linked',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ describe('chatApi — integration (mocked HTTP)', () => {
expect(result.recentMessages).toHaveLength(2)
expect(result.recentMessages[0].role).toBe('User')
expect(result.recentMessages[1].role).toBe('Assistant')
expect(http.get).toHaveBeenCalledWith('/llm/chat/sessions/session-1')
expect(http.get).toHaveBeenCalledWith('/llm/chat/sessions/session-1', undefined)
})

it('URL-encodes special characters in the session ID', async () => {
vi.mocked(http.get).mockResolvedValue({ data: makeChatSession({ id: 'session/special' }) })

await chatApi.getSession('session/special')

expect(http.get).toHaveBeenCalledWith('/llm/chat/sessions/session%2Fspecial')
expect(http.get).toHaveBeenCalledWith('/llm/chat/sessions/session%2Fspecial', undefined)
})

it('propagates 404 when session does not exist', async () => {
Expand Down
Loading