Skip to content

Livechat triggers: agent sender resolution is globally cached for 1 hour, causing cross-trigger sender leakage #39150

@Shreyas2004wagh

Description

@Shreyas2004wagh

Description:

Livechat trigger agent resolution is cached globally for 1 hour in the widget, causing sender/agent leakage across different trigger configurations.

A trigger action that resolves agent A can affect later trigger actions that should resolve agent B (or queue), because getAgent() reuses a single module-level cached Promise instead of caching by trigger sender context.

Steps to reproduce:

  1. Enable Livechat and create two triggers:
    • Trigger 1:
      • Condition: chat-opened-by-visitor
      • Action: send-message
      • Params: sender=custom, name=agent_one, msg=first trigger message
    • Trigger 2:
      • Condition: after-guest-registration
      • Action: send-message
      • Params: sender=custom, name=agent_two, msg=second trigger message
  2. Open /livechat as a fresh visitor and open the widget.
  3. Confirm Trigger 1 fires and message sender is agent_one.
  4. Register/send first visitor message so Trigger 2 fires.
  5. Observe Trigger 2 message sender.

Expected behavior:

Each trigger action should resolve sender/agent independently from its own action params.

For the example above, Trigger 2 should use agent_two.

Actual behavior:

Trigger 2 may reuse the cached result from Trigger 1 and still use agent_one (or stale queue result), because sender resolution is globally cached for 1 hour.

Server Setup Information:

  • Version of Rocket.Chat Server: develop (observed from current source code path)
  • License Type: N/A
  • Number of Users: N/A
  • Operating System: N/A
  • Deployment Method: Local development
  • Number of Running Instances: 1
  • DB Replicaset Oplog: N/A
  • NodeJS Version: N/A
  • MongoDB Version: N/A

Client Setup Information

  • Desktop App or Browser Version: Browser (Livechat widget)
  • Operating System: Any

Additional context

Relevant code paths:

  • packages/livechat/src/lib/triggerUtils.ts
    • Global cache: let agentPromise ...
    • TTL: agentCacheExpiry = 3600000
    • getAgent() returns the same cached promise for all actions during TTL.
  • packages/livechat/src/lib/triggers.js
    • Multiple triggers share execution path: processTriggers -> schedule -> fire.
  • packages/livechat/src/lib/triggerActions.ts
    • Both send-message and use-external-service actions call getAgent().

This creates cross-trigger contamination and stale sender behavior.

Relevant logs:

No server error is required to reproduce.
Behavior is visible in widget trigger messages (sender mismatch with configured trigger action params).

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugvalidA valid contribution where maintainers will review based on priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions