Skip to main content

Local Device Architecture

This document describes the technical architecture of local device support, including communication protocols, heartbeat mechanisms, and security design.


πŸ— Architecture Overview​

System Components​

Communication Architecture​

The following diagram shows how local devices communicate with the Wegent system:


πŸ“‘ WebSocket Protocol​

Event Types​

EventDirectionDescription
device:registerDevice β†’ BackendDevice registration
device:heartbeatDevice β†’ BackendHeartbeat keepalive
task:executeBackend β†’ DeviceTask dispatch
task:progressDevice β†’ BackendTask progress
task:completeDevice β†’ BackendTask completion

Message Format​

// device:register
{
"event": "device:register",
"data": {
"device_id": "uuid-xxx",
"name": "Darwin - MacBook-Pro.local",
"max_slots": 5
}
}

// device:heartbeat
{
"event": "device:heartbeat",
"data": {
"device_id": "uuid-xxx",
"running_task_ids": ["task-1", "task-2"]
}
}

// task:execute
{
"event": "task:execute",
"data": {
"subtask_id": "subtask-xxx",
"prompt": "User message",
"context": {}
}
}

πŸ’“ Heartbeat Mechanism​

Sequence Diagram​

Timing Parameters​

ParameterValueDescription
Heartbeat Interval30 secondsDevice sends heartbeat
Online TTL90 secondsRedis key expiration
Monitor Interval60 secondsBackend checks expired devices
Offline Threshold3 missed heartbeatsDevice marked as offline

Running Task Tracking​

Each heartbeat contains currently running task IDs, used for:

  • Real-time slot usage tracking
  • Orphaned task detection
  • Automatic cleanup on disconnection

πŸ”„ Task Execution Flow​

Task State Transitions​


πŸ” Security Mechanisms​

Authentication Flow​

Security Features​

FeatureDescription
JWT AuthenticationWebSocket connections require valid token
Token Expiration7-day expiry, requires periodic refresh
User IsolationDevices can only execute tasks from their owner
Hardware BindingDevice ID generated from hardware identifiers

User Isolation​

Each device session is bound to a user:

  • Devices can only receive tasks from their registered owner
  • Prevents cross-user task execution
  • Subtasks validated against user namespace

Data Privacy​

When using local devices:

  • Code stays local: Source code is never uploaded to cloud
  • Local execution: All processing happens on user's machine
  • Result streaming: Only output text is transmitted
  • No persistent storage: Cloud doesn't store local files

πŸ”§ Device ID Generation​

The Executor automatically generates a stable device ID based on the following priority:

  1. Cached ID: Stored in ~/.wegent-executor/device_id (if exists)
  2. Hardware UUID:
    • macOS: System hardware UUID
    • Linux: /etc/machine-id
    • Windows: MachineGuid from registry
  3. Fallback: MAC address or random UUID

This ensures devices maintain consistent identity across restarts.


πŸ“Š Concurrency Control​

Slot Management​

Each device supports up to 5 concurrent tasks:

  • Slot usage tracked in real-time via heartbeats
  • Device shows "busy" when all slots are occupied
  • Tasks queue if busy device is selected

Load Balancing​



πŸ’¬ Get Help​

Need help?

  • πŸ“– Check the FAQ
  • πŸ› Submit a GitHub Issue
  • πŸ’¬ Join community discussions