feat(db): add quick-chat history tables and tRPC - #5536
Merged
Conversation
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Previous Review Summaries (2 snapshots, latest commit f56779c)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit f56779c)Status: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Previous review (commit 355c1ae)Status: 1 Issue Found | Recommendation: Address before merge Executive Summary
Overview
Issue Details (click to expand)WARNING
Files Reviewed (12 files)
Reviewed by grok-4.6 · Input: 53.2K · Output: 5.4K · Cached: 208.8K Review guidance: REVIEW.md from base branch |
This was referenced Aug 27, 2026
The listMessages query orders by (created_at DESC, id DESC) but paged with a created_at-only cursor, so rows sharing a timestamp could be skipped at the page boundary. Encode the last row's (created_at, id) into an opaque keyset cursor and filter with a tie-break-aware comparison.
pandemicsyn
approved these changes
Aug 27, 2026
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.
Summary
No new behavior — this level adds only the backend storage and API for quick-chat history; the visible Quick Chat experience ships in later levels.
Two new tables,
quick_chat_threadsandquick_chat_messages, store quick-chat history. Partial unique indexes enforce one thread per user in the personal scope and one per user plus organization in the organization scope. Messages cascade-delete with their thread, and the thread's user key is restrict, so account deletion removes the threads and messages explicitly in the cleanup step.Files
packages/db/src/schema.ts— adds the two Drizzle table definitions with their select and insert types; declares the unique indexesquick_chat_threads_user_personal_uidxandquick_chat_threads_user_org_uidx, and the lookup indexIDX_quick_chat_messages_thread_created_at.packages/db/src/migrations/0233_big_abomination.sql— generated DDL (23 lines) that creates both tables, the user, organization, and message foreign keys, the cascade and restrict actions, the two partial unique indexes, and the message lookup index.The
quickChatnamespace adds thegetOrCreateThread,listMessages, andappendMessagesprocedures with Zod-validated inputs, andgetOrCreateThreadre-selects the raced thread on a concurrent unique violation.listMessagespages from newest to oldest through an opaque base64url keyset cursor that carries(created_at, id), so rows that share a timestamp are never skipped.appendMessagesgives each row a strictly-increasingcreated_at, so a batch keeps its append order under the id tie-break.Files
apps/web/src/routers/quick-chat-router.ts— new router (215 lines); resolves the thread scope and checks organization membership for the organization scope; encodes and decodes the composite keyset cursor; serializes timestamps to ISO; implements the three procedures.apps/web/src/routers/root-router.ts— registersquickChaton the root router.packages/trpc/src/mobile.ts— registersquickChaton the mobile-scoped router, extending the mobile client type surface.The accepted usage feature values now include
quick-chat, so a caller can send that header and the gateway attributes usage to it. No rate-limit set changes.Files
apps/web/src/lib/feature-detection.ts— adds'quick-chat'toFEATURE_VALUES.Account soft deletion now hard-deletes a user's quick-chat threads and messages. Messages go first, selected through the user's threads, so the thread delete cannot race the message cascade and leave rows behind.
Files
apps/web/src/lib/user/index.ts— imports both tables; in the anonymization step, deletes the user's messages through a thread subquery, then deletes the user's threads.Tests: 3 files changed —
quick-chat-router.test.ts,feature-detection.test.ts, anduser/index.test.ts.Generated: 2 files —
0233_snapshot.jsonand_journal.json.Verification
No E2E report: none attached — this is a lower stacked level; the tip PR carries the E2E report and screenshots. No manual test paths were run; this level changes no UI and its behavior is covered by automated tests.
Visual Changes
Visual Changes: N/A
Reviewer Notes
Human steps: none known for this level alone.
Notes: none.
Stacked PRs — merge bottom to top. Each level shows only its own diff.
Runtime verification (E2E, user advocacy, simplify) runs on the tip PR over every level.
Every level keeps its own checks, its own bot review, and its own threads; each one is answered on its own PR.
Each level is its own deliverable: it builds and passes its own checks alone.
A finding on a level is repaired on that level, then carried upward with stack.sh forward.
quick-chat-spectator-5c48— feat(db): add quick-chat history tables and tRPC #5536 ← this PRquick-chat-spectator-5c48-s2— feat(mobile): add flagged Chat tab for gateway chats #5541quick-chat-spectator-5c48-s3— feat(mobile): add read-only review spectator transcript #5566 (tip)