Skip to content

Add message channel reset command#16266

Merged
charlesBochet merged 10 commits intomainfrom
add-messsage-channel-reset-command
Dec 4, 2025
Merged

Add message channel reset command#16266
charlesBochet merged 10 commits intomainfrom
add-messsage-channel-reset-command

Conversation

@neo773
Copy link
Copy Markdown
Member

@neo773 neo773 commented Dec 2, 2025

In this PR, we are adding a new command to reset a message channel.

We are also refactoring a bit cursor reset as we had multiple implementations at different places in the code base

@neo773 neo773 requested a review from charlesBochet December 2, 2025 18:48
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Dec 2, 2025

Greptile Overview

Greptile Summary

Adds a new CLI command messaging:reset-channel to reset message channel sync state and clear all associated data for full resync. The command supports resetting a single channel or all channels in a workspace.

  • Creates comprehensive reset functionality that clears sync cursors, deletes message associations, removes cache entries, and resets sync state
  • Properly integrates with existing MessagingMessageCleanerService for deletion operations
  • Includes detailed logging throughout the process
  • Handles both single-channel and bulk operations

Minor optimization opportunity: the resetMessageChannel method retrieves the message channel repository again even though it's already available from the calling method.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The implementation follows established patterns in the codebase, integrates well with existing services, and handles edge cases appropriately. There's one minor inefficiency with redundant repository retrieval, but this doesn't affect functionality or introduce bugs.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-server/src/modules/messaging/message-cleaner/commands/messaging-reset-channel.command.ts 4/5 New command for resetting message channels - retrieves repository redundantly within resetMessageChannel method
packages/twenty-server/src/modules/messaging/message-cleaner/messaging-message-cleaner.module.ts 5/5 Adds new command to module providers - straightforward registration

Sequence Diagram

sequenceDiagram
    participant CLI as CLI Command
    participant CMD as MessagingResetChannelCommand
    participant ORM as TwentyORMGlobalManager
    participant MCS as MessagingMessageCleanerService
    participant Cache as CacheStorageService
    participant DB as Database Repositories

    CLI->>CMD: run(options)
    CMD->>ORM: getRepositoryForWorkspace(messageChannel)
    ORM-->>CMD: messageChannelRepository
    
    alt Single Channel
        CMD->>DB: findOne(messageChannelId)
        DB-->>CMD: messageChannel
        CMD->>CMD: resetMessageChannel()
    else All Channels
        CMD->>DB: find() all channels
        DB-->>CMD: messageChannels[]
        loop For each channel
            CMD->>CMD: resetMessageChannel()
        end
    end
    
    Note over CMD,DB: resetMessageChannel operations
    CMD->>ORM: getRepositoryForWorkspace(messageChannelMessageAssociation)
    ORM-->>CMD: associationRepository
    CMD->>DB: find associations
    DB-->>CMD: associations[]
    
    alt Has message associations
        CMD->>MCS: deleteMessagesChannelMessageAssociationsAndRelatedOrphans()
        MCS->>DB: delete associations, orphan messages, orphan threads
    end
    
    CMD->>Cache: del(messages-to-import cache key)
    CMD->>ORM: getRepositoryForWorkspace(messageFolder)
    ORM-->>CMD: messageFolderRepository
    CMD->>DB: update(syncCursor = null)
    CMD->>DB: update channel(syncCursor, syncStage, syncStatus, etc.)
    CMD-->>CLI: Success
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +105 to +109
const messageChannelRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageChannelWorkspaceEntity>(
workspaceId,
'messageChannel',
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: messageChannelRepository is already retrieved in the run method and could be passed as a parameter to avoid redundant database calls

Suggested change
const messageChannelRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageChannelWorkspaceEntity>(
workspaceId,
'messageChannel',
);
private async resetMessageChannel(
workspaceId: string,
messageChannel: MessageChannelWorkspaceEntity,
messageChannelRepository: Repository<MessageChannelWorkspaceEntity>,
): Promise<void> {
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/twenty-server/src/modules/messaging/message-cleaner/commands/messaging-reset-channel.command.ts
Line: 105:109

Comment:
**style:** `messageChannelRepository` is already retrieved in the `run` method and could be passed as a parameter to avoid redundant database calls

```suggestion
  private async resetMessageChannel(
    workspaceId: string,
    messageChannel: MessageChannelWorkspaceEntity,
    messageChannelRepository: Repository<MessageChannelWorkspaceEntity>,
  ): Promise<void> {
```

How can I resolve this? If you propose a fix, please make it concise.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 2, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:48106

This environment will automatically shut down when the PR is closed or after 5 hours.

Copy link
Copy Markdown
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comment but approving

@charlesBochet charlesBochet changed the title Add messsage channel reset command Add message channel reset command Dec 4, 2025
@charlesBochet charlesBochet merged commit 8716cb2 into main Dec 4, 2025
51 of 52 checks passed
@charlesBochet charlesBochet deleted the add-messsage-channel-reset-command branch December 4, 2025 13:25
@twenty-eng-sync
Copy link
Copy Markdown

Hey @charlesBochet! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

@greptile-apps greptile-apps bot mentioned this pull request Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants