Skip to content

fix(whatsapp): resolve reaction UUID targets#691

Merged
namastex888 merged 1 commit into
devfrom
fix/whatsapp-reaction-uuid-target-dev
Jun 1, 2026
Merged

fix(whatsapp): resolve reaction UUID targets#691
namastex888 merged 1 commit into
devfrom
fix/whatsapp-reaction-uuid-target-dev

Conversation

@namastex888
Copy link
Copy Markdown
Contributor

Summary

  • Promote the WhatsApp reaction UUID target fix to dev
  • Resolve internal Omni message UUIDs to provider-native external IDs before plugin send
  • Fail closed for UUID targets when target chat/message scope cannot be verified
  • Add regression coverage for UUID happy path, missing chat/message, cross-chat mismatch, and external-ID fallback

Test Plan

  • bunx biome check packages/api/src/routes/v2/messages.ts packages/api/src/routes/v2/__tests__/messages-send-reaction.test.ts
  • bun test packages/api/src/routes/v2/__tests__/messages-send-reaction.test.ts packages/cli/src/__tests__/react-context.test.ts
  • bun run --filter @omni/api typecheck
  • bun run --filter @automagik/omni build:server
  • pre-push full suite on the sibling felipe PR branch: 3963 pass / 292 skip / 0 fail
  • dogfood: reacted between Felipe's two WhatsApp instances using an Omni UUID; async reaction record indexed without fallback text duplication

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2a402299-5921-4e7a-9d51-49a0b906aad7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/whatsapp-reaction-uuid-target-dev

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces changes to resolve Omni message UUIDs to channel-native external IDs when sending message reactions, adding helper functions resolveReactionTarget and getReactionTargetByOmniId along with comprehensive unit tests. Feedback on the changes highlights an issue in getReactionTargetByOmniId where checking the chatId mismatch inside the try block and catching it in the same block can lead to unintended error handling behavior; moving this check outside the try-catch block is recommended to ensure consistent error wrapping and context enrichment.

Comment on lines +172 to +198
async function getReactionTargetByOmniId(
services: Services,
instanceId: string,
chatId: string,
messageId: string,
): Promise<Awaited<ReturnType<Services['messages']['getByExternalId']>>> {
try {
const target = await services.messages.getById(messageId);
if (target.chatId !== chatId) {
throw new OmniError({
code: ERROR_CODES.NOT_FOUND,
message: `Reaction target message not found: ${messageId}`,
context: { instanceId, chatId, messageId },
recoverable: false,
});
}
return target;
} catch (error) {
if (error instanceof OmniError) throw error;
throw new OmniError({
code: ERROR_CODES.NOT_FOUND,
message: `Reaction target message not found: ${messageId}`,
context: { instanceId, chatId, messageId },
recoverable: false,
});
}
}
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.

medium

In the current implementation of getReactionTargetByOmniId, throwing an error inside the try block and catching it in the same catch block leads to a bug where error instanceof OmniError is true for the newly thrown error, which is then immediately rethrown. Furthermore, if getById throws a NotFoundError (which extends OmniError), it is rethrown directly without the enriched context (instanceId, chatId, messageId) and the specific error message.

Moving the chatId mismatch check outside of the try-catch block resolves both issues, ensuring that any message-not-found error is consistently wrapped with the rich context and specific error message.

async function getReactionTargetByOmniId(
  services: Services,
  instanceId: string,
  chatId: string,
  messageId: string,
): Promise<Awaited<ReturnType<Services['messages']['getById']>>> {
  let target: Awaited<ReturnType<Services['messages']['getById']>>;
  try {
    target = await services.messages.getById(messageId);
  } catch (error) {
    throw new OmniError({
      code: ERROR_CODES.NOT_FOUND,
      message: "Reaction target message not found: " + messageId,
      context: { instanceId, chatId, messageId },
      recoverable: false,
    });
  }

  if (target.chatId !== chatId) {
    throw new OmniError({
      code: ERROR_CODES.NOT_FOUND,
      message: "Reaction target message not found: " + messageId,
      context: { instanceId, chatId, messageId },
      recoverable: false,
    });
  }

  return target;
}

@namastex888 namastex888 force-pushed the fix/whatsapp-reaction-uuid-target-dev branch from dcb66bc to e7ec629 Compare June 1, 2026 19:25
@namastex888
Copy link
Copy Markdown
Contributor Author

Addressed the Gemini review feedback: narrowed UUID target lookup error handling so only NotFoundError is converted to the reaction-target 404, unexpected lookup/system errors now propagate, and tests now mock NotFoundError plus cover the non-masked unexpected-error path. Re-ran targeted gates and pre-push suite after force-pushing the amended commit.

@namastex888 namastex888 merged commit 7a89dff into dev Jun 1, 2026
10 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