-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Description
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:
- 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
- Condition:
- Trigger 2:
- Condition:
after-guest-registration - Action:
send-message - Params:
sender=custom,name=agent_two,msg=second trigger message
- Condition:
- Trigger 1:
- Open
/livechatas a fresh visitor and open the widget. - Confirm Trigger 1 fires and message sender is
agent_one. - Register/send first visitor message so Trigger 2 fires.
- 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.
- Global cache:
packages/livechat/src/lib/triggers.js- Multiple triggers share execution path:
processTriggers -> schedule -> fire.
- Multiple triggers share execution path:
packages/livechat/src/lib/triggerActions.ts- Both
send-messageanduse-external-serviceactions callgetAgent().
- Both
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).