Updates
This commit is contained in:
@@ -2,124 +2,104 @@
|
||||
|
||||
**Protocol:** `hyper-p2p-task-orchestrator/v1`
|
||||
|
||||
**Export:** `HyperP2PTaskOrchestrator`
|
||||
**Export:** `HyperP2PTaskOrchestrator`, `TASK_PROTOCOL`
|
||||
|
||||
## Overview
|
||||
|
||||
HyperP2PTaskOrchestrator Novel distributed task orchestration primitive for Bare/Pear P2P. - DAG task dependencies & priority scheduling - Ed255255 signed tasks and results for authenticity
|
||||
`HyperP2PTaskOrchestrator` manages a signed task graph with priorities, deadlines, dependency gates, execution hooks, JSON file persistence, and Protomux gossip for remote task submission. Integrates `HyperP2PVectorClock` for causal lifecycle metadata.
|
||||
|
||||
## Constructor
|
||||
|
||||
```js
|
||||
const mod = new HyperP2PTaskOrchestrator(opts)
|
||||
const orch = new HyperP2PTaskOrchestrator(opts)
|
||||
```
|
||||
|
||||
| Option | Type | Default | Description |
|
||||
|--------|------|---------|-------------|
|
||||
| `keyPair` | KeyPair | random Ed25519 | keyPair |
|
||||
| `storageDir` | `<cwd>/{module}-storage` | `<cwd>/{module}-storage` | Hypercore/Hyperbee storage root |
|
||||
| `defaultDeadlineMs` | varies | DEFAULT_DEADLINE_MS | defaultDeadline (ms) |
|
||||
| `topic` | varies | null | topic |
|
||||
| `keyPair` | `KeyPair` | random | Task signing identity |
|
||||
| `topic` | `string` | `null` | Hyperswarm topic for gossip |
|
||||
| `storageDir` | `string` | `{cwd}/hyper-p2p-task-orchestrator-storage` | `tasks.json` persistence |
|
||||
| `defaultDeadlineMs` | `number` | `300000` | Default task TTL |
|
||||
| `clock` | `HyperP2PVectorClock` | new instance | Causal clock helper |
|
||||
|
||||
## Methods
|
||||
|
||||
### `ready(—)`
|
||||
### `ready()`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:** — (none documented in method body)
|
||||
Loads storage, joins swarm when `topic` set, starts expiry cleanup interval.
|
||||
|
||||
- **Returns:** `Promise<void>`
|
||||
- **Emits:** `ready`, `p2p-ready`
|
||||
|
||||
### `submitTask(taskSpec)`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
Creates signed pending task; records dependencies.
|
||||
|
||||
- **Parameters:** `{ type, payload?, owner?, priority?, deadline?, deps? }`
|
||||
- **Returns:** `Promise<task>`
|
||||
- **Throws:**
|
||||
- `Error: Task signing failed`
|
||||
- `Error: taskSpec.type required`
|
||||
- `Error: Task signing failed`
|
||||
|
||||
### `assignTask(taskId, assignee = null)`
|
||||
### `assignTask(taskId, assignee?)`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:**
|
||||
- `Error: Task not assignable`
|
||||
- `Error: Task not found`
|
||||
Marks task `assigned` when dependencies satisfied.
|
||||
|
||||
### `completeTask(taskId, resultData = {}, success = true)`
|
||||
- **Returns:** `Promise<task | null>`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:**
|
||||
- `Error: Task not found`
|
||||
### `completeTask(taskId, resultData?, success?)`
|
||||
|
||||
### `getTask(taskId)`
|
||||
Stores result, updates status `completed` or `failed`, unblocks dependents.
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:** — (none documented in method body)
|
||||
- **Returns:** `Promise<result>`
|
||||
|
||||
### `queryTasks(filter = {})`
|
||||
### `getTask(taskId)` / `queryTasks(filter)`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:** — (none documented in method body)
|
||||
Read single task or filter by `status`, `type`, `owner`.
|
||||
|
||||
### `registerExecutionHook(taskType, handler)`
|
||||
### `registerExecutionHook(taskType, handler)` / `executeTask(taskId)`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:**
|
||||
- `Error: handler must be function`
|
||||
Register per-type executor; run when assigned.
|
||||
|
||||
### `executeTask(taskId)`
|
||||
### `getMetrics()` / `getStats()`
|
||||
|
||||
- **Returns:** `Promise`
|
||||
- **Throws:**
|
||||
- `Error: Task must be assigned`
|
||||
Returns `metrics` counters + `{ ops, errors }`.
|
||||
|
||||
### `getMetrics(—)`
|
||||
### `close()`
|
||||
|
||||
- **Returns:** `value`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `getStats(—)`
|
||||
|
||||
- **Returns:** `object`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
### `close(—)`
|
||||
Clears timers, destroys swarm, persists tasks.
|
||||
|
||||
- **Returns:** `Promise<void>`
|
||||
- **Throws:** — (none documented in method body)
|
||||
|
||||
## Task object
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `taskId` | Hex id |
|
||||
| `type` | Handler type string |
|
||||
| `status` | `pending` \| `assigned` \| `completed` \| `failed` \| `expired` |
|
||||
| `priority` | Higher runs first in queries |
|
||||
| `deadline` | Unix ms |
|
||||
| `deps` | Prerequisite task ids |
|
||||
| `signature` | Base64 Ed25519 |
|
||||
| `causal` | Vector clock snapshot at submit |
|
||||
|
||||
## Events
|
||||
|
||||
| Event | Payload |
|
||||
|-------|---------|
|
||||
| `closed` | no payload |
|
||||
| `error` | err |
|
||||
| `hook:registered` | payload object |
|
||||
| `p2p-ready` | no payload |
|
||||
| `ready` | no payload |
|
||||
| `task:assigned` | task |
|
||||
| `task:completed` | payload object |
|
||||
| `task:deps-ready` | depTask |
|
||||
| `task:error` | error |
|
||||
| `task:expired` | task |
|
||||
| `task:gossiped` | task |
|
||||
| `task:retry` | task |
|
||||
| `task:submitted` | task |
|
||||
`ready`, `p2p-ready`, `task:submitted`, `task:assigned`, `task:completed`, `task:failed`, `task:expired`, `task:retry`, `task:received`, `error`
|
||||
|
||||
## getStats()
|
||||
## Wire messages
|
||||
|
||||
Returns `{ ...this._stats }` — typically `ops`, `errors`, and module-specific counters (`created`, `relays`, `open`, `peers`, etc.).
|
||||
Library-only modules may include `mode: 'local'`.
|
||||
|
||||
## Errors
|
||||
|
||||
Stable message substrings: see [`../_shared/ERROR_CODES.md`](../../_shared/ERROR_CODES.md).
|
||||
| type | fields |
|
||||
|------|--------|
|
||||
| `task` | `task` (full signed task object) |
|
||||
|
||||
## P2P
|
||||
|
||||
When `topic` is set, `ready()` joins Hyperswarm and opens Protomux `hyper-p2p-task-orchestrator/v1`.
|
||||
Uses `initModuleSwarm` from `p2p-bare.js` with protocol `hyper-p2p-task-orchestrator/v1`.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
npm install && npm test
|
||||
npm test
|
||||
```
|
||||
|
||||
Integration: [`../../real_tests/integration/task-orchestrator-two-node.js`](../../../real_tests/integration/task-orchestrator-two-node.js)
|
||||
@@ -1,43 +1,29 @@
|
||||
# Architecture: hyper-p2p-task-orchestrator
|
||||
|
||||
**Category:** Agents & workflows
|
||||
**Category:** `agents-workflows` · **Protocol:** `hyper-p2p-task-orchestrator/v1`
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
App[Application] --> Mod[HyperP2PTaskOrchestrator]
|
||||
Mod --> Mux[Protomux hyper-p2p-task-orchestrator/v1]
|
||||
Mux --> Swarm[Hyperswarm]
|
||||
```
|
||||
## Role
|
||||
|
||||
## Sequence (P2P)
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant App
|
||||
participant Mod as Module
|
||||
participant SW as Hyperswarm
|
||||
participant Peer
|
||||
App->>Mod: ready(topic)
|
||||
Mod->>SW: join(topic)
|
||||
SW->>Peer: connection
|
||||
Mod->>Peer: gossip / Protomux
|
||||
Peer-->>Mod: onmessage
|
||||
Mod-->>App: emit(event)
|
||||
```
|
||||
Signed DAG task orchestration with file persistence, dependency tracking, expiry/retry loop, and task gossip.
|
||||
|
||||
## Wire messages
|
||||
|
||||
| type | fields | direction | behavior |
|
||||
|------|--------|-----------|----------|
|
||||
| `task` | task | gossip | Handled in onmessage / gossipSend |
|
||||
| type | direction | fields | behavior |
|
||||
|------|-----------|--------|----------|
|
||||
| `task` | gossip | `task` | Insert into `tasks` map; emit `task:received` |
|
||||
|
||||
## State model
|
||||
|
||||
- In-memory `Map` / `Set` structures for hot path
|
||||
- Optional Hyperbee/Hypercore persistence when `storageDir` or `memoryOnly` is configured
|
||||
- `close()` tears down swarm, timers, and clears ephemeral state
|
||||
| Map | Content |
|
||||
|-----|---------|
|
||||
| `tasks` | taskId → task record |
|
||||
| `results` | taskId → result blob |
|
||||
| `dependencies` | taskId → Set of dep ids |
|
||||
| `reverseDeps` | depId → dependent task ids |
|
||||
| `executionHooks` | taskType → async handler |
|
||||
|
||||
Cleanup interval marks expired tasks, retries up to `MAX_RETRIES` (3).
|
||||
|
||||
## Composition
|
||||
|
||||
Composes with: `hyper-p2p-agent-memory`, `hyper-p2p-workflow-graph`.
|
||||
|
||||
`hyper-p2p-vector-clock` for causal fields; `hyper-p2p-activity-queue` for local scheduling; capabilities for gated execution.
|
||||
|
||||
Reference in New Issue
Block a user