fix(cron): agent response not sent to channel after cron job#757
fix(cron): agent response not sent to channel after cron job#757decker502 wants to merge 4 commits intosipeed:mainfrom
Conversation
…prevent connection drops
…WithChannel ProcessDirectWithChannel bypasses the AgentLoop bus, so the Run() loop's PublishOutbound never fires. The response was silently discarded with _ = response, causing cron-triggered agent replies to never reach the Telegram channel. Fix by explicitly calling PublishOutbound with the response when non-empty, consistent with the deliver=true and command execution paths.
nikolasdehor
left a comment
There was a problem hiding this comment.
This is a well-analyzed bug fix with three focused improvements:
1. Cron response delivery (the main fix):
The root cause is clearly explained: ProcessDirectWithChannel bypasses the AgentLoop bus, so PublishOutbound never fires. The fix explicitly publishes the outbound message. This is correct and consistent with the deliver=true path mentioned in the PR description.
2. Atomic cron store writes:
The saveStoreUnsafe change to write-temp-then-rename is a good defensive fix. os.Rename is atomic on the same filesystem, preventing partial writes on crash. Minor note: on some filesystems and cross-device scenarios os.Rename can fail, but for storePath + ".tmp" this is always the same directory so it is fine.
3. Telegram transport hardening:
Adding TCP keepalive (30s) and explicit timeouts to the Telegram HTTP transport is a good improvement for long-poll stability. The refactoring to always use a custom transport (rather than only when proxy is configured) is cleaner.
One minor observation: the response != "" check in ExecuteJob means that if a cron job legitimately returns an empty response, it silently succeeds without any notification. That might be fine (no point sending an empty message), but worth documenting.
LGTM — clean, focused, well-documented fix.
Description
Cron-triggered agent replies were silently discarded and never delivered to any channel (e.g. Telegram).
ExecuteJobcallsProcessDirectWithChannel, which bypasses theAgentLoopbus and invokesprocessMessagedirectly. TheRun()loop'sPublishOutbound— which is responsible for dispatching the response to the channel — never fires in this code path. The returned response was discarded with_ = response.Before:
After:
This is consistent with the
deliver=trueand command execution paths in the same function.Type of Change
🤖 AI Code Generation
Related Issue
N/A — identified from production logs showing agent response generated but not received on Telegram.
Technical Context
Call chain:
CronTool.ExecuteJob→ProcessDirectWithChannel→processMessage→runAgentLoop→ returnsstring. TheRun()loop that normally callsPublishOutboundis never involved whenProcessDirectWithChannelis used directly.🧪 Test Environment
Evidence
Checklist
make checkpasses locally