Skip to content

fix(ws): broadcast cron job results to WebSocket clients in real-time#1099

Open
nimitbhardwaj wants to merge 1 commit intoRightNow-AI:mainfrom
nimitbhardwaj:fix#1088/websocket-scheduled
Open

fix(ws): broadcast cron job results to WebSocket clients in real-time#1099
nimitbhardwaj wants to merge 1 commit intoRightNow-AI:mainfrom
nimitbhardwaj:fix#1088/websocket-scheduled

Conversation

@nimitbhardwaj
Copy link
Copy Markdown

Summary

Fixes #1088 — Scheduled task results now appear in the web UI in real-time via WebSocket push, without requiring a page refresh.

Problem

When a cron job fires, the result was only delivered to configured channels (Telegram, etc.) via cron_deliver_response. WebSocket clients had no mechanism to receive these results — they had to refresh the page to see cron output.

Solution

Backend

  • WS Connection Registry: Added global tracking of WebSocket connections per agent (ws.rs). Connections register on connect and deregister on disconnect.
  • CronJobExecuted Event: New SystemEvent::CronJobExecuted variant emitted by cron_run_job after the agent loop completes.
  • WS Broadcaster: start_ws_cron_broadcaster() subscribes to the kernel event bus and broadcasts to all active WebSocket connections for the relevant agent.
  • Dual Delivery: Cron results still go to channels via cron_deliver_response (unchanged), and now also broadcast to WebSocket.

Frontend

  • Added handler for type: "message" events from server — these display as user messages (left side) with [Scheduled: job_name] label.

Testing

  1. Create a schedule (e.g., every 1 min: "Tell the user 'Hello World'")
  2. Open web UI and connect to agent via WebSocket
  3. Observe cron trigger message appears on left, response on right, in real-time
  4. Multiple browser tabs all receive the broadcast

Breaking Changes

None.

Fixes RightNow-AI#1088 - scheduled task results now appear in web UI without page
refresh.
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.

OpenFang v0.6.0 When you schedule a task, it reaches the agent, but the result isn't displayed in the CHAT!!!!

1 participant