Skip to content

Conversation

@wahyuwidgetworks
Copy link

Description:
This PR addresses a critical issue in the messages.update handler that
caused PrismaClientValidationError and led to crash loops.

The Bug:
The messages.update handler in whatsapp.baileys.service.ts was
attempting to call prismaRepository.messageUpdate.create without
ensuring the existence of a parent Message record. When an update event
arrived for a message that was not stored in the Message table (e.g.,
ephemeral messages, old messages not synced, or deleted messages), the
messageId required for the MessageUpdate relation would be missing. This
resulted in a PrismaClientValidationError with the message "Argument
Message is missing," causing the application to crash. The previous logs
showed a misleading artifact Invalid this.cache.delete() invocation, but
the core issue was the missing Prisma relation.

The Fix:

  • Guarded messageUpdate.create: Implemented a conditional check for
    the presence of message.messageId before attempting to create a
    MessageUpdate record.
  • Graceful Handling: If message.messageId is missing, the system now
    logs a warning ([WIDGET-WORKS] Skipping messageUpdate.create for key
    ...: Parent message not found.) and skips the database write,
    preventing the crash.
  • Annotation: Added // [WIDGET-WORKS] comments to the new guard logic
    for clarity and adherence to project conventions.

Impact:

  • Eliminates the persistent PrismaClientValidationError crash loops in
    the messages.update handler.
  • Ensures application stability and continued processing of message
    updates, even if the parent message is not found in the database.
  • Prevents log spam related to these errors.

Additional Notes:

  • The this.cache.delete() call within the messages.update handler is
    already wrapped in a try/catch block, providing a safety net for
    potential issues in cache deletion.
  • task.md has been updated to reflect the completion of this fix.

- Prevents PrismaClientValidationError (Argument Message is missing) when processing updates for messages not in the database.

- Adds a check for message.messageId before calling messageUpdate.create.

- Logs a warning if the parent message is missing.

- [WIDGET-WORKS] fix/cache-delete-messages-update
@wahyuwidgetworks wahyuwidgetworks merged commit 6581f44 into production-v2.3.2 Dec 2, 2025
1 check passed
wahyuwidgetworks pushed a commit that referenced this pull request Dec 12, 2025
fix: ajustar a manipulação do remoteJid na mensagem
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.

Fix cache.delete misuse in messages.update (PrismaClientValidationError crash-loop)

2 participants