fix(cron): deliver reminders directly as bot messages instead of rout…#118
fix(cron): deliver reminders directly as bot messages instead of rout…#118
Conversation
…ing through agent When deliver=true, send Payload.Message straight to the channel without agent processing. This fixes reminders appearing as fake user messages followed by an unnecessary agent reply. Also auto-set deliver=true when cron jobs are created from chat context (channel + chatID available), so reminders always deliver correctly without requiring the LLM to explicitly set the deliver flag.
viettranx
left a comment
There was a problem hiding this comment.
Review
Hướng đi đúng
Reminder nên gửi thẳng ra channel, không cần qua agent loop — fix đúng vấn đề "fake user message + unnecessary agent reply".
Vấn đề cần xem lại
1. Mất media attachment khi direct delivery
Code cũ có appendMediaToOutbound(&outMsg, result.Media) — gửi media từ agent response. PR mới bypass agent hoàn toàn nên direct delivery không bao giờ gửi được media. Nếu reminder chỉ text thuần thì OK, nhưng nên ghi comment giải thích rõ.
2. Auto deliver=true quá aggressive
if !deliver && channel != "" && to != "" {
deliver = true
}Mọi cron job tạo từ chat context sẽ luôn deliver trực tiếp, kể cả khi LLM cố tình set deliver=false (ví dụ: cron job cần agent xử lý logic phức tạp, query dữ liệu rồi mới trả lời).
→ Đề xuất: phân biệt "LLM không truyền deliver" vs "LLM truyền deliver=false". Dùng check key existence trong jobObj thay vì check !deliver:
if _, hasDeliver := jobObj["deliver"]; !hasDeliver && channel != "" && to != "" {
deliver = true
}3. Auto-fill channel/to bỏ gate deliver
Trước: chỉ fill khi deliver=true. Sau: fill luôn cho tất cả cron jobs. Kết hợp với auto-deliver → mọi cron job từ chat context đều thành direct delivery. Cần cân nhắc nếu có use case cron job chạy agent logic mà vẫn cần biết channel info.
4. Comment hữu ích bị xóa
Trong gateway_cron.go, các comment "Infer peer kind...", "Resolve channel type...", "Block until the scheduled run completes" giúp hiểu flow — nên giữ lại.
viettranx
left a comment
There was a problem hiding this comment.
Review
Good direction
Reminders should be sent directly to the channel without agent loop processing — this correctly fixes the "fake user message + unnecessary agent reply" behavior.
Issues to address
1. Media attachments lost on direct delivery
The old code calls appendMediaToOutbound(&outMsg, result.Media) to forward media from the agent response. The new direct delivery path bypasses the agent entirely, so media can never be attached. If reminders are text-only this is fine, but worth a comment explaining the limitation.
2. Auto deliver=true is too aggressive
if !deliver && channel != "" && to != "" {
deliver = true
}Every cron job created from chat context will always deliver directly, even when the LLM intentionally sets deliver=false (e.g. a cron job that needs agent processing — query data, run logic, then respond).
→ Suggestion: distinguish "LLM didn't pass deliver" vs "LLM explicitly set deliver=false". Check key existence instead of value:
if _, hasDeliver := jobObj["deliver"]; !hasDeliver && channel != "" && to != "" {
deliver = true
}3. Auto-fill channel/to no longer gated by deliver
Before: only filled when deliver=true. After: filled unconditionally for all cron jobs. Combined with auto-deliver above → every cron job from chat context becomes direct delivery. Consider whether there are use cases where agent-processed cron jobs still need channel info for context.
The auto-fill itself is reasonable (agent may need channel context), but combined with auto-deliver it changes behavior significantly.
4. Useful comments removed
Several helpful comments in gateway_cron.go were removed:
- "Infer peer kind from the stored session metadata..."
- "Resolve channel type for system prompt context"
- "Block until the scheduled run completes"
These help readers understand the flow — consider keeping them.
…ing through agent
When deliver=true, send Payload.Message straight to the channel without agent processing. This fixes reminders appearing as fake user messages followed by an unnecessary agent reply.
Also auto-set deliver=true when cron jobs are created from chat context (channel + chatID available), so reminders always deliver correctly without requiring the LLM to explicitly set the deliver flag.