Skip to content

fix: diagnose cron message delivery delay#690

Open
dorey-agent[bot] wants to merge 3 commits into
mainfrom
fix/cron-message-delivery-delay
Open

fix: diagnose cron message delivery delay#690
dorey-agent[bot] wants to merge 3 commits into
mainfrom
fix/cron-message-delivery-delay

Conversation

@dorey-agent
Copy link
Copy Markdown
Contributor

@dorey-agent dorey-agent Bot commented May 17, 2026

Motivation

Cron-triggered agent messages (unsolicited session/update notifications) are delayed until the user sends a new message. The output appears buffered — it only flushes when the next incoming message triggers activity.

Solution

Two-pronged approach:

1. Diagnostic tracing (to identify the exact buffering point)

Added info-level tracing at key delivery points:

  • ChannelsManager: when event arrives from orchestrator
  • ChannelsManager: when notification is sent to channel subprocess
  • Channel harness: when deliverMessage is received from stdin
  • Presenter actor: when render() is called on the adapter

2. Reproduction infrastructure

  • Added unsolicited_delay_ms and unsolicited_message options to agent-mock
  • Added flow test when_agent_sends_unsolicited_notification_then_delivered_without_user_ping

The flow test passes with debug-http channel, confirming the core delivery path (orchestrator → channels manager → channel subprocess → harness → presenter → adapter) works correctly for unsolicited notifications.

This means the production bug is Telegram-specific — likely one of:

  • session_chat_map race (session not registered when unsolicited message arrives)
  • Rate limiter dropping the render
  • Docker attach stdout buffering

Testing

  • when_agent_sends_unsolicited_notification_then_delivered_without_user_ping — passes
  • All existing flow tests pass

Next Steps

Deploy this build and check logs when cron fires to identify which layer delays delivery.

[ai-assisted]

dorey-agent[bot] added 2 commits May 17, 2026 01:17
Add info-level tracing at key points in the message delivery chain to
identify where cron-triggered messages get buffered:

1. ChannelsManager: when event arrives from orchestrator
2. ChannelsManager: when notification is sent to channel subprocess
3. Channel harness: when deliverMessage is received from stdin
4. Presenter actor: when render() is called on the adapter

This will help identify whether the delay is in:
- Orchestrator → ChannelsManager routing
- ChannelsManager → channel subprocess stdin
- Channel subprocess stdin → harness dispatch
- Presenter actor → adapter render
Add unsolicited_delay_ms and unsolicited_message options to agent-mock
that send a session/update notification after a prompt completes without
being prompted again. This simulates cron-triggered agent output.

Add flow test that verifies unsolicited notifications are delivered to
the channel without requiring a new user message. The test passes with
debug-http channel, confirming the core delivery path works correctly.

The production bug is likely Telegram-specific (session_chat_map race
or Docker attach buffering).
@dorey-agent dorey-agent Bot requested a review from donbader as a code owner May 17, 2026 01:28
The Docker attach demux task writes agent stdout/stderr chunks to
DuplexStream via write_all() but never flushes. While DuplexStream
itself makes data immediately available, adding explicit flush ensures
downstream readers (the SDK transport's BufReader) see each chunk
without delay.

This is a defensive fix for the cron message delivery delay — when an
agent sends a small unsolicited notification (e.g., from a cron job),
the data must be immediately available to the SDK's line reader rather
than potentially sitting in any intermediate buffer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants