Skip to content

feat: migrate trailing deletes to /api/chats/{id}/messages/trailing#393

Merged
arpitgupta1214 merged 1 commit intomainfrom
test
Apr 2, 2026
Merged

feat: migrate trailing deletes to /api/chats/{id}/messages/trailing#393
arpitgupta1214 merged 1 commit intomainfrom
test

Conversation

@arpitgupta1214
Copy link
Copy Markdown
Collaborator

@arpitgupta1214 arpitgupta1214 commented Apr 2, 2026

#385)

  • feat: migrate chat trailing messages delete endpoint

  • fix: add handler-level error guard for trailing delete

  • refactor: reuse existing memories helpers for trailing delete

  • refactor: reuse shared memories helpers for trailing delete

  • refactor: remove trailing delete count response

  • fix: harden trailing delete cursor and timestamp guard

  • fix: align trailing delete boundary with memories schema

Summary by CodeRabbit

  • New Features
    • Added the ability to delete trailing messages from a chat conversation starting from a specified message point, with request validation and error handling.

…385)

* feat: migrate chat trailing messages delete endpoint

* fix: add handler-level error guard for trailing delete

* refactor: reuse existing memories helpers for trailing delete

* refactor: reuse shared memories helpers for trailing delete

* refactor: remove trailing delete count response

* fix: harden trailing delete cursor and timestamp guard

* fix: align trailing delete boundary with memories schema
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recoup-api Ready Ready Preview Apr 2, 2026 3:56pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9585151f-3106-4a70-908e-96ab33c7d7cd

📥 Commits

Reviewing files that changed from the base of the PR and between 237567d and 1998165.

⛔ Files ignored due to path filters (3)
  • lib/chats/__tests__/deleteTrailingChatMessagesHandler.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
  • lib/chats/__tests__/validateDeleteTrailingMessagesQuery.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
  • lib/supabase/memories/__tests__/deleteMemories.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (5)
  • app/api/chats/[id]/messages/trailing/route.ts
  • lib/chats/deleteTrailingChatMessagesHandler.ts
  • lib/chats/validateDeleteTrailingMessagesQuery.ts
  • lib/supabase/memories/deleteMemories.ts
  • lib/supabase/memories/selectMemories.ts

📝 Walkthrough

Walkthrough

This PR introduces a new API endpoint to delete trailing messages from a chat starting from a specified message timestamp. It includes the route handler, request validation, and extends existing Supabase memory helpers to support timestamp-based and ID-based filtering of messages.

Changes

Cohort / File(s) Summary
New Trailing Messages Route
app/api/chats/[id]/messages/trailing/route.ts
Implements OPTIONS preflight handler for CORS and DELETE handler that extracts chat ID from params and delegates to the deletion handler.
Trailing Messages Handler & Validation
lib/chats/deleteTrailingChatMessagesHandler.ts, lib/chats/validateDeleteTrailingMessagesQuery.ts
Adds request validation with chat access checks, UUID parsing for from_message_id query param, and Supabase memory lookup; handler coordinates validation and deletion, returning appropriate JSON responses with CORS headers and error handling.
Supabase Memory Helpers
lib/supabase/memories/deleteMemories.ts, lib/supabase/memories/selectMemories.ts
Extends deleteMemories to accept optional fromTimestamp for conditional filtering; extends selectMemories to filter by optional memoryId parameter alongside existing room and ordering filters.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Route as API Route
    participant Validator as Validator
    participant DB as Supabase
    participant Handler as Handler
    
    Client->>Route: DELETE /api/chats/[id]/messages/trailing?from_message_id=UUID
    Route->>Handler: deleteTrailingChatMessagesHandler(request, id)
    Handler->>Validator: validateDeleteTrailingMessagesQuery(request, id)
    Validator->>DB: validateChatAccess(request, id)
    DB-->>Validator: Access granted or denied
    alt Access Denied
        Validator-->>Handler: NextResponse (error)
        Handler-->>Client: 401/403 Error
    else Access Granted
        Validator->>DB: selectMemories(id, {memoryId: UUID, limit: 1})
        DB-->>Validator: Memory found or not found
        alt Memory Not Found
            Validator-->>Handler: NextResponse (404)
            Handler-->>Client: 404 Message not found
        else Memory Found
            Validator-->>Handler: ValidatedDeleteTrailingMessagesQuery
            Handler->>DB: deleteMemories(id, {fromTimestamp})
            DB-->>Handler: true or false
            alt Deletion Failed
                Handler-->>Client: 500 Error response
            else Deletion Succeeded
                Handler-->>Client: 200 {chat_id, from_message_id}
            end
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • sweetmantech

Poem

🗑️ Trailing whispers fade away,
Timestamps mark what shouldn't stay,
Validation guards the path so true,
CORS-protected, tried and new!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@arpitgupta1214 arpitgupta1214 merged commit e99fd32 into main Apr 2, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant