Heartbeat And Triggers

Last updated: May 18, 2026

Heartbeat Loops & Wakeup Triggers

The dLAN Assistant operates on a "Pulse and Trigger" architecture. Heartbeats provide proactive, interval-based intelligence, while Wakeups provide reactive, event-driven responses.


💓 Heartbeat Loops (assistant/heartbeat.go)

These routines maintain system health and provide "Background Thinking" - waking specific agents at intervals to check for pending work.

Agent-Specific Work Loops

Loop Agent Interval Purpose Triggered By
Nikki Work Nikki 4 hours Checks Kanban board for new tasks, proactive reminders to Master Dan triggerNikkiWorkLoop()
Liz Work Lenore 4 hours Checks Liz's task board, offers proactive support triggerLizWorkLoop()
Project Manager ProjectManager 4 hours AntFarm swarm maintenance, project health triggerProjectManager()
Company Manager CEO 16 hours Business Hive operations, employee tasks triggerCompanyManager()
Team Heartbeat TeamManager 6 hours Wakes permanent teams with default tasks triggerTeamHeartbeat()

System Heartbeats

Loop Interval Purpose
Mission Control 2 min Server telemetry/status cache refresh
Sub-agent Resumption 30 min Re-hydrate stalled sub-agents after restart
Memory Cleanup Weekly Mechanical hygiene of memory files
Playbook Discovery 3 days Analyze chat patterns for repeatable workflows
Notes Fix Weekly (Fri 3am) Task board structural maintenance
Async Cleanup Daily (3am) Clean stale background agents

Security & Monitoring Heartbeats

Loop Agent Interval Purpose
Forensic Audit Architect 8 hours Scans infrastructure for anomalies
Strategic Snapshot Architect Daily Generates permanent history record
Self-Evolution Architect 4 hours Analysis of system improvements
CCTV Polling RoboCop 2 min Real-time Reolink event detection
Overnight Check RoboCop Daily (07:45) Security audit of previous night
GitLab Monitor Gilfoyle 5m day / 60m night Detect pushes, 3 AM Security Ritual
Posture Audit MrRobot 48 hours Full container package/CVE scan
Financial Anomaly CryptoTrader 10 min BTC movements >2% (threshold reduced from 5% on May 18)
Shamanic Pulse Murloc 24 hours (was 5h) WoW player level-ups, server health. Includes isHostReachable('wow.dlan') check — skips pulse if server unreachable. Initial warmup: 15min.

Quiet Hour Focus

Nikki and Lenore work loops respect quiet hours (20:00-08:00):

// Work loops skip execution during quiet hours
if isQuietHour() {
    return // Skip Nikki/Lenore work loop checks
}

Heartbeat Optimization (April 2026)

Optimization Description
Interval Increases Faster intervals during day, slower during quiet hours
Quiet Hour Throttling System tasks throttled between 20:00-08:00
Task Consolidation Multiple small tasks consolidated into fewer executions
Schedule Alignment Hardcoded system tasks aligned to 8 AM schedule

🔄 Background Services (Other Polling Systems)

Telemetry Poller (assistant/telemetry_poller.go)

  • Interval: 5 minutes
  • Purpose: Polls all system modules to keep dashboard/AI context updated
  • Polled Systems:
    • Proxmox (CPU, RAM, containers)
    • cPanel dashboard (hosting stats)
    • CoinStats (crypto prices)
    • Pelican (network stats)
    • Virtdash (virtualization)

GitLab Poller (assistant/gitlab_poller.go)

  • Trigger: Called by Gilfoyle heartbeat (5m day / 60m night)
  • Purpose: Detects GitLab pushes, queues for 3 AM Security Ritual
  • State: Persisted to assistant/logs/gitlab_poller_state.json
  • Features: Batches multiple pushes, tracks event IDs

CCTV Monitor (assistant/cctv_monitor.go)

  • Interval: 2 minutes (polling)
  • Triggers: Doorbell press, Person detection, Motion anomalies
  • Action: Summons RoboCop for analysis
  • Overnight Check: Daily at 07:45

⚡ Wakeup Triggers (assistant/wakeup.go)

The wakeup system is a Unified Event Router that provides reactive, near-instantaneous responses to external events. It runs on port 7142.

Event Sources & Handlers

Endpoint Source Trigger Action
/api/events/youtube YouTube PubSubHubbub New video on subscribed channel Notify agent, fetch video details
/api/events/ha Home Assistant State changes, voice commands Trigger automation, query agent
/api/events/vonage/inbound Vonage SMS Inbound SMS from tracked numbers Route to agent, send SMS reply
/api/wakeup Generic API POST with agent/user/platform/task Wake any agent for custom tasks
UniFi polling UniFi Controller Device presence changes Welcome home / Goodbye triggers
CCTV events Reolink NVR Doorbell, person detection Summon RoboCop for analysis

1. UniFi Presence (Arrival/Departure)

  • Source: UniFi Controller API polling every 3 minutes
  • Logic: Detects MAC address of tracked devices (Dan, Liz)
  • Debounce: 10 min for arrival, 30 min for departure
  • Action: Triggers "Welcome Home" briefings with persona-aware greetings

User Routing:

User Device Patterns Agent Platform Contact
Dan dan, iphone, ipad Nikki WhatsApp 235244066201726@lid
Liz liz, iphone Lenore WhatsApp 95129247461586@lid

2. YouTube PubSubHubbub

  • Endpoint: /api/events/youtube
  • Source: YouTube channel subscriptions via PubSubHubbub
  • Action: Notifies appropriate agent (typically Nikki) of new content
  • Use Case: Proactive notifications when subscribed channels upload

3. Home Assistant / Google Home

  • Endpoint: /api/events/ha
  • Source: Home Assistant automations, Google Home commands
  • Payload: { "command": "...", "user": "...", "entity_id": "...", "new_state": "..." }
  • Action: Process voice commands, state change triggers

4. Vonage Inbound SMS

  • Endpoint: /api/events/vonage/inbound
  • Source: Vonage webhook for inbound SMS
  • RBAC: Only responds to known contacts (Guest/Banned rejected)
  • Action: Routes SMS to preferred agent (default: Sasha), sends SMS reply

5. Generic Wakeup API

  • Endpoint: /api/wakeup
  • Method: POST
  • Payload:
{
  "agent": "nikki",
  "user": "dan",
  "platform": "whatsapp",
  "prompt": "Good morning! Check the servers.",
  "task_id": "optional-task-reference"
}
  • Action: Wakes any agent with custom prompt - enables external apps/servers to trigger the assistant

6. WHMCS Ticket Watcher

  • Source: WHMCS API polling (started from wakeup.go line 180)
  • Logic: Tracks last processed ticket ID, processes new tickets only
  • Action: Notifies Nova agent with deep context about new tickets
  • State: assistant/whmcs_state.json
  • Implementation: assistant/whmcs_client.go - runs as background goroutine

7. CCTV Event (RoboCop Integration)

  • Source: Reolink NVR AI Detection
  • Trigger: EventTypeDoorbell, EventTypePerson
  • Action: Captures tactical snapshot, summons RoboCop for analysis

🛠️ External Integration Examples

Wake Any Agent from External System

# Wake Nikki for a custom task
curl -X POST http://localhost:7142/api/wakeup \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "nikki",
    "user": "dan",
    "platform": "whatsapp",
    "prompt": "External trigger: Backup completed on server XYZ"
  }'

# Wake Sasha for infrastructure check
curl -X POST http://localhost:7142/api/wakeup \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "sasha",
    "user": "dan",
    "platform": "discord",
    "prompt": "Check Proxmox cluster health"
  }'

Home Assistant Integration

# automation.yaml
- alias: "AI Assistant Trigger"
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_office
  action:
    - service: http.post
      data:
        url: "http://localhost:7142/api/events/ha"
        payload:
          command: "Motion detected in office"
          user: "dan"
          entity_id: "binary_sensor.motion_office"
          new_state: "on"

⏰ Two Scheduling Systems

1. Heartbeats (Internal - No User Control)

  • Hardcoded intervals in heartbeat.go
  • Wake specific agents to check for pending work
  • Cannot be disabled by users
  • Examples: Nikki work loop, Architect audits, RoboCop CCTV

2. Scheduler (User-Configurable - scheduler.go)

  • SQLite-backed persistent task storage
  • Users can add tasks via API: /api/schedule-task
  • Supports both one-time (execute_at) and recurring (cron_spec)
  • Tasks persist across restarts
  • Dashboard shows at: Mission Control → Scheduler

Adding a scheduled task:

curl -X POST http://localhost:9999/api/schedule-task \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "nikki",
    "task": "Daily report for Master Dan",
    "cron_spec": "0 8 * * *"
  }'

📅 Actual Scheduled Tasks (from scheduler.db)

Nikki's Daily Routine

Time Task Agent
08:00 Command Briefing - System vitals, weather, traffic, calendar, todos nikki
08:30 WoW News Briefing - Run whats wow news playbook nikki
10:00 Fortress Sentry - Calendar, todos, Sasha infrastructure check nikki
11:00 Daily Pulse - Calendar (3 days), todos, news, market data (BTC/SOL) nikki
12:00 Gadgetzan Health - Run check dlan playbook via Sasha nikki
13:30 Lunchtime Briefing - Afternoon calendar, weather, market nikki
17:00 Daily Pulse (evening) - Calendar, todos, news nikki
20:00 Family Calendar - Check family calendar via get_family_calendar skutters
21:00 Tech Stack & Security - CVE/updates for Go, Ollama, Proxmox, UniFi, Win11 sasha
23:00 Good Night Briefing - UniFi, WAN speed, Proxmox, Nikki.dlan status nikki
23:30 Creative Playtime - Develop Go toys in nikki.dlan/toys nikki
00:30 (Sun) Den Maintenance - Organize files, clean temp, rotate logs nikki

Nikki's Weekly Routine

Time Day Task Agent
02:00 Mon Weekly Network Audit - Full nmap scan, Proxmox inventory, HTML report nikki
03:00 Mon Weekly Den Maintenance - Deep tidy, log cleanup nikki
08:00 Fri Morning Infrastructure (weekend edition) - morning report nikki
18:00 Fri Weekly Tech Round-up - AI, cybersecurity, gaming news - weekly tech nikki

Nikki's Nightly Routine

Time Task Agent
01:30 Security Tool Generation - Build new Go utility in /root/utilities/ nikki
02:00 Nightly Video Archive - Archive videos.html to dated file nikki
02:30 Utility Challenge - Create useful Linux utility in Go nikki
03:00 VIP Inbox Watch - Check Gmail for priority senders, urgent items nikki
07:00 YouTube Intelligence - Scan subscriptions, generate video portal HTML nikki
10:00 Daily Gmail Roundup - VIP email summary nikki

Lenore's Routine

Time Task Agent
09:00 Morning Briefing - Liz's calendar, todos, weather lenore
20:00 (Mon-Fri) Evening Prep - Tomorrow's calendar, Jira tasks, web health lenore

Sasha's Routine

Time Task Agent
15:00 dLAN Health Rollup - Today's alerts, storage, network status sasha
16:00 (Fri) Capacity Forecast - Disk/memory trend analysis, growth anomalies sasha

Nova's Routine

Time Task Agent
08:45 Jira Briefing - Top 3 overdue/high-priority tickets nova
09:00 London-Hosting Standup - Invoices, Jira tickets to WhatsApp group nova
09:00 (Sat) Weekly Status Report - Server stats, tickets to WhatsApp group nova

CEO/Business Hive

Time Task Agent
09:00 Business Audit (Morning) - Review all companies, morning reports ceo
10:00 (Mon) Project Review - Strategic review of all active projects projectmanager
22:00 Business Audit (Evening) - Organization health, owner distribution ceo

Memory/System

Time Task Agent
02:00 Memory Distillation (Dan) - Extract facts to long-term memory memorymaster
02:10 Memory Distillation (Liz) - Extract facts to long-term memory memorymaster
02:20 Memory Distillation (Jim) - Extract facts to long-term memory memorymaster
04:00 (Sun) Memory Reflection - Big tidy, assign significance, prune memorymaster

Miscellaneous

Time Task Agent
21:00 (Mon) Sasha Tech Stack - Latest releases & CVEs for Go, Ollama, Proxmox sasha

Total scheduled tasks in database: 40+


📦 Skills Import Capability

While this is a private system (not open-source) with no community marketplace, the architecture supports importing skills from external sources:

Supported Import Formats

Source Format Import Method
OpenClaw/ClawHub SKILL.md Convert to prompts/tools/{agent}/ structure
Hermes Agent JSON skills Parse and convert to tool definitions
GitHub .md skill files Clone repo, map to system format
Google Gemini Function calling schemas Convert to tool definitions

Import Process

  1. Skill Discovery: Find skill in external format (SKILL.md, JSON, GitHub)
  2. Format Conversion: Map to internal tool definition format:
    # tool_name
    ## Description
    ...
    ## Parameters
    {"type": "object", ...}
    ## Access
    MasterAdmin, Partner
    
  3. Tool Implementation: Create shell script or Go handler for execution
  4. RBAC Gating: Set appropriate access roles
  5. Live Injection: No restart needed - tools loaded from filesystem

Example: Converting OpenClaw Skill

# OpenClaw SKILL.md format:
# # skill_name
# ## What it does
# ## Triggers
# ## Actions

# Convert to dLANDiscord tool format:
# assistant/prompts/tools/shared/skill_name.md

This enables the system to leverage the broader AI agent ecosystem's skill libraries without maintaining a public marketplace.


Session Reliability (April 2026)

Planner Session get_capabilities Fix

Issue: WhatsApp-initiated planner sessions failed because LLMs returned empty/text responses without calling get_capabilities. Scheduled/playbook sessions worked because they forced the call in code.

Fix: ProcessReActLoop in planner.go now forces get_capabilities for ALL planner sessions regardless of source (WhatsApp, scheduled, playbook, etc.).

Location: assistant/planner.goProcessReActLoop initial tool injection

Shared Tools Full Definitions

Issue: shared_tools capability returned only tool names, not full definitions.

Fix: GetSystemCapabilities in assistant.go now returns complete Tool structs with name, description, and parameters.


🚀 System Startup (main.go)

These services start when the application boots:

Service File Purpose
StartHeartbeat heartbeat.go 18 heartbeat loops for proactive tasks
StartWakeupSystem wakeup.go UniFi presence detection
StartWakeupServer wakeup.go Port 7142 event router API
NewScheduler scheduler.go SQLite-backed cron scheduler
ScheduleBusinessReports business.go Scheduled business reports
StartTelegramBot telegram.go Telegram bot integration
StartWoWChecker wowcheck.go WoW character monitoring
StartInternalChecks internalcheck.go Health monitoring

Boot Sequence

// main.go line ~174
assistant.StartHeartbeat()      // All heartbeat loops
assistant.StartWakeupSystem()   // UniFi presence polling
assistant.StartWakeupServer()   // Port 7142 API

// Scheduler
scheduler, err := assistant.NewScheduler("./scheduler.db")
scheduler.Start()
assistant.GlobalScheduler = scheduler

// Observability
observabilityDB, err := assistant.NewObservabilityDB("./observability.db")
assistant.GlobalObservabilityDB = observabilityDB

Best Practices

  • Isolation: When adding new heartbeat, assign to relevant agent persona for clean telemetry
  • Adaptive Polling: Background tasks should slow at night (except security rituals)
  • Error Handling: Heartbeat loops must use recover() or clean error logging to prevent crashes
  • Capability Injection: Ensure planner agents have access to system capabilities before planning
  • External Triggers: Use /api/wakeup for any external system integration needs
  • RBAC: Always validate user roles in event handlers (Guest/Banned rejected)

Panic Recovery (May 18, 2026)

All heartbeat and scheduler goroutines are now wrapped with safeGo() — a helper that wraps recover() + debug.Stack() logging. This prevents silent goroutine deaths:

  • All 18 heartbeat loops now use safeGo() for panic recovery
  • Main scheduler goroutine has recover() at line 665 in scheduler.go
  • Per-tick recovery around checkAndExecuteDueTasks() calls
  • SQLite WAL mode enabled on scheduler DB (busy_timeout=5000) to prevent SQLITE_BUSY errors

This fixed the May 18 scheduler crash that stopped all scheduled tasks.


Key Files

File Purpose
assistant/heartbeat.go All heartbeat loop implementations (18 loops)
assistant/wakeup.go Unified event router (port 7142), UniFi presence
assistant/wakeup.go WHMCS ticket watcher (runs as goroutine)
assistant/scheduler.go SQLite-backed cron scheduler (user tasks)
assistant/telemetry_poller.go System telemetry polling (5 min)
assistant/gitlab_poller.go GitLab push detection (called by Gilfoyle)
assistant/robocop.go CCTV event handling
assistant/cctv_monitor.go Reolink NVR integration

Cross-References