Skip to content

fix(cron): agent response not sent to channel after cron job#757

Open
decker502 wants to merge 4 commits intosipeed:mainfrom
decker502:fix/cron-response-not-sent
Open

fix(cron): agent response not sent to channel after cron job#757
decker502 wants to merge 4 commits intosipeed:mainfrom
decker502:fix/cron-response-not-sent

Conversation

@decker502
Copy link

Description

Cron-triggered agent replies were silently discarded and never delivered to any channel (e.g. Telegram).

ExecuteJob calls ProcessDirectWithChannel, which bypasses the AgentLoop bus and invokes processMessage directly. The Run() loop's PublishOutbound — which is responsible for dispatching the response to the channel — never fires in this code path. The returned response was discarded with _ = response.

Before:

_ = response // Will be sent by AgentLoop  ← never is

After:

if response != "" {
    t.msgBus.PublishOutbound(bus.OutboundMessage{
        Channel: channel,
        ChatID:  chatID,
        Content: response,
    })
}

This is consistent with the deliver=true and command execution paths in the same function.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

🤖 AI Code Generation

  • 🤖 Fully AI-generated — AI (Claude) identified the root cause and wrote the fix; contributor reviewed and validated it

Related Issue

N/A — identified from production logs showing agent response generated but not received on Telegram.

Technical Context

Call chain: CronTool.ExecuteJobProcessDirectWithChannelprocessMessagerunAgentLoop → returns string. The Run() loop that normally calls PublishOutbound is never involved when ProcessDirectWithChannel is used directly.

🧪 Test Environment

  • Hardware: PC
  • OS: Debian 13.02
  • Model/Provider: Claude Sonnet 4.6
  • Channels: Telegram

Evidence

2026/02/25 10:10:32 [INFO] agent: Response: ... {agent_id=main, session_key=agent:main:main, iterations=1, final_length=369}
# → message never received on Telegram

Checklist

  • I have read CONTRIBUTING.md
  • make check passes locally
  • My change is focused and does not bundle unrelated changes
  • I have disclosed AI involvement above

decker502 and others added 4 commits February 25, 2026 09:51
…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.
@xiaket xiaket added bug Something isn't working domain: channel domain: tool labels Feb 25, 2026
Copy link

@nikolasdehor nikolasdehor left a comment

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants