feat(copilot): add copilot_chat_messages table with dual-write rollout#4726
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Wires best-effort dual-write into existing chat message mutation paths: snapshot saves now Adds a non-blocking, on-boot 7-day catch-up sweep to close rolling-deploy gaps, plus updates/tests to cover the new dual-write helpers and adjusted DB Reviewed by Cursor Bugbot for commit b7d172b. Configure here. |
Greptile SummaryThis PR introduces a dedicated
Confidence Score: 5/5Safe to merge — the dual-write is fully best-effort, the JSONB column remains the source of truth, and the migration backfill is idempotent. All callsites correctly gate on the returned row before writing to the normalized table, preventing FK-violation noise. The catch-up sweep is fire-and-forget and bounded to 7 days. The transaction patterns in terminal-state.ts and replaceCopilotChatMessages are sound. No breaking schema changes, and all previously flagged gaps have been addressed. No files require special attention. Important Files Changed
Reviews (3): Last reviewed commit: "fix(copilot): thread chatModel through p..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b7d172b. Configure here.
b840bcc to
d187180
Compare
d187180 to
aa463df
Compare
Splits copilot chat messages out of the copilot_chats.messages JSONB column into a dedicated copilot_messages table. JSONB stays canonical during R+0 — every write path dual-writes to the new table best-effort (try/catch + log warn, never throws). Migration 0217 creates the table + indexes and inline-backfills history from JSONB so OSS self-hosters don't need to run a separate script. Write paths covered: - post.ts (user message append) - terminal-state.ts (assistant turn finalize) - update-messages/route.ts (snapshot replace) - inbox/executor.ts (background turn) - fork/route.ts (chat clone) - superuser/import-workflow/route.ts (chat import) Each call threads chatModel + streamId where relevant; ON CONFLICT DO UPDATE preserves existing stream_id / model via COALESCE. For pre-R+1 reconciliation, run: bun apps/sim/scripts/copilot-messages-reconcile.ts [--since='7 days'] Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
aa463df to
2b478fb
Compare
Summary
copilot_chat_messagestable to replace the JSONB messages array oncopilot_chats. The JSONB column is preserved indefinitely as the source of truth during rollout — no breaking schema change.0212_cynical_jack_murdock.sqlruns an inlinejsonb_array_elements ... ON CONFLICT DO NOTHINGbackfill.bun run db:migratedoes everything; no scripts required.0091_backfill_user_stats.sql,0192_invitation_unification.sql): multi-statement withgen_random_uuid(), FK with CASCADE, inlineINSERT ... SELECT ... ON CONFLICT DO NOTHING.lib/copilot/chat/messages-dual-write.ts) wired into every JSONB-mutation callsite (post, terminal-state, inbox, fork, update-messages, superuser-import). Best-effort — errors logged, never thrown.Indexes
UNIQUE (chat_id, message_id)— idempotent appends, dedup streaming retries(chat_id, created_at, id) WHERE deleted_at IS NULL— transcript load, last-N(chat_id, stream_id) WHERE stream_id IS NOT NULL— stream replay/resumeType of Change
Testing
Tested manually. Lint passes.
Checklist