coordinator

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package coordinator provides unified coordination between heartbeat monitoring, recovery handling, and task handover.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API provides HTTP handlers for taskqueue operations.

func NewAPI

func NewAPI(coord *Coordinator) *API

NewAPI creates a new API handler.

func (*API) HandlePendingTasks

func (a *API) HandlePendingTasks(w http.ResponseWriter, r *http.Request)

HandlePendingTasks handles GET /api/tasks/pending

func (*API) HandleTaskAssign

func (a *API) HandleTaskAssign(w http.ResponseWriter, r *http.Request)

HandleTaskAssign handles POST /api/tasks/{id}/assign

func (*API) HandleTaskHandover

func (a *API) HandleTaskHandover(w http.ResponseWriter, r *http.Request)

HandleTaskHandover handles GET /api/tasks/{id}/handover

func (*API) RegisterRoutes

func (a *API) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers API routes with the given ServeMux

type AgentInfo

type AgentInfo struct {
	Name         string
	State        AgentState
	FailCount    int
	LastCheck    time.Time
	LastResponse time.Time
	Tasks        []int // Issue numbers assigned to this agent
}

AgentInfo holds information about an agent's state.

type AgentState

type AgentState string

AgentState represents the health state of an agent.

const (
	// StateHealthy indicates the agent is responding normally.
	StateHealthy AgentState = "healthy"
	// StateUnresponsive indicates the agent is not responding.
	StateUnresponsive AgentState = "unresponsive"
	// StateRecovering indicates recovery is in progress.
	StateRecovering AgentState = "recovering"
	// StateFailed indicates recovery failed after max retries.
	StateFailed AgentState = "failed"
)

type AssignRequest

type AssignRequest struct {
	TargetAgent string `json:"target_agent"`
}

AssignRequest represents the request body for POST /api/tasks/{id}/assign

type AssignResponse

type AssignResponse struct {
	Success     bool   `json:"success"`
	IssueNumber int    `json:"issue_number"`
	AssignedTo  string `json:"assigned_to"`
}

AssignResponse represents the response for POST /api/tasks/{id}/assign

type Config

type Config struct {
	HealthCheckInterval time.Duration // Interval between health checks
	ResponseTimeout     time.Duration // Timeout for agent responses
	MaxRetries          int           // Maximum retry attempts
	BackoffBase         time.Duration // Base duration for exponential backoff
	BackoffMax          time.Duration // Maximum backoff duration
}

Config holds coordinator configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default coordinator configuration.

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

Coordinator manages the coordination between heartbeat, recovery, and task queue.

func NewCoordinator

func NewCoordinator(cfg Config, queue *taskqueue.Queue) *Coordinator

NewCoordinator creates a new coordinator.

func (*Coordinator) GetAgentState

func (c *Coordinator) GetAgentState(agentName string) (AgentInfo, bool)

GetAgentState returns the current state of an agent.

func (*Coordinator) GetAllAgents

func (c *Coordinator) GetAllAgents() map[string]AgentInfo

GetAllAgents returns all registered agents.

func (*Coordinator) GetQueue

func (c *Coordinator) GetQueue() *taskqueue.Queue

GetQueue returns the task queue.

func (*Coordinator) HandleFailure

func (c *Coordinator) HandleFailure(ctx context.Context, agentName string) bool

HandleFailure processes a failure detection for an agent. Returns true if recovery was successful.

func (*Coordinator) HandleHeartbeat

func (c *Coordinator) HandleHeartbeat(agentName string)

HandleHeartbeat processes a successful heartbeat from an agent.

func (*Coordinator) RegisterAgent

func (c *Coordinator) RegisterAgent(name string)

RegisterAgent registers an agent for monitoring.

func (*Coordinator) SetGetTasksFunc

func (c *Coordinator) SetGetTasksFunc(fn GetTasksFunc)

SetGetTasksFunc sets the function to get tasks for an agent.

func (*Coordinator) SetNotifyFunc

func (c *Coordinator) SetNotifyFunc(fn NotifyFunc)

SetNotifyFunc sets the notification function.

func (*Coordinator) SetRecoverFunc

func (c *Coordinator) SetRecoverFunc(fn RecoverFunc)

SetRecoverFunc sets the recovery function.

func (*Coordinator) UnregisterAgent

func (c *Coordinator) UnregisterAgent(name string)

UnregisterAgent removes an agent from monitoring.

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse represents an error response

type GetTasksFunc

type GetTasksFunc func(agentName string) []int

GetTasksFunc returns the tasks assigned to an agent.

type HandoverResponse

type HandoverResponse struct {
	IssueNumber   int                       `json:"issue_number"`
	Status        string                    `json:"status"`
	OriginalAgent string                    `json:"original_agent"`
	AssignedAgent string                    `json:"assigned_agent,omitempty"`
	History       []taskqueue.HandoverEvent `json:"history"`
	Context       string                    `json:"context,omitempty"`
}

HandoverResponse represents the response for GET /api/tasks/{id}/handover

type NotifyFunc

type NotifyFunc func(ctx context.Context, target, message string) error

NotifyFunc is called to send notifications.

type PendingTaskItem

type PendingTaskItem struct {
	IssueNumber    int    `json:"issue_number"`
	OriginalAgent  string `json:"original_agent"`
	Priority       int    `json:"priority"`
	CreatedAt      string `json:"created_at"`
	ContextSummary string `json:"context_summary,omitempty"`
}

PendingTaskItem represents a task in the pending list

type PendingTasksResponse

type PendingTasksResponse struct {
	Tasks []PendingTaskItem `json:"tasks"`
	Total int               `json:"total"`
}

PendingTasksResponse represents the response for GET /api/tasks/pending

type RecoverFunc

type RecoverFunc func(ctx context.Context, agentName string) error

RecoverFunc is called to attempt recovery of an agent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL