release: persist assistant message after chat workflow (#609)
Merged
SW
6mo ago+506+506+012345678901234567890123456789-11-11-01234567890123456789
Summary
Releases PR #609 from `test` → `main`.
- Closes the silent-data-loss gap: assistant messages now land in `chat_messages` after the chat workflow finishes
- Threads a workflow-body-generated `assistantMessageId` through `runAgentStep` → `toUIMessageStream.generateMessageId` so the upsert isn't keyed on an empty string (matches open-agents' pattern, resume-aware for tool-call turns)
- Bumps `chats.last_assistant_message_at` alongside `updated_at` so the sidebar unread badge (`getChatSummaries.hasUnread`) fires correctly
Test plan
- 3176 unit tests passing (16 new across `persistAssistantMessage`, `runAgentStep`, `runAgentWorkflow`, `generateAssistantMessageId`)
- Preview UI verification — fresh chat on PR preview shows the assistant `OK` reply after a hard page refresh (renders from the shared `chat_messages` table via open-agents' Drizzle query)
- REST verification — `GET /api/sessions/{sid}/chats` returns `lastAssistantMessageAt` populated and `hasUnread: true` after workflow finish
- Post-merge: sanity check on `sandbox.recoupable.com` against `https://api.recoupable.com\`
🤖 Generated with Claude Code
Summary by cubic
Persist the assistant’s final reply to chat_messages after each chat workflow to prevent silent data loss on refresh and keep conversation history intact. Also threads a stable assistant message id and updates chats.last_assistant_message_at so unread badges work.
- Bug Fixes
- Added a fire-and-forget
persistAssistantMessagestep to upsert the assistant reply and touchupdated_at/last_assistant_message_at. - Generate a durable
assistantMessageIdonce per run (as a step) and pass it throughrunAgentSteptotoUIMessageStream.generateMessageId; reuse the id when resuming tool-call turns. - Capture the final
responseMessageviatoUIMessageStream.onFinishand return it fromrunAgentStepfor persistence. - Expanded tests across workflow, step, and persistence to cover id threading, resume behavior, and idempotent inserts.
- Added a fire-and-forget