Coordination and Events
This page explains how work starts, runs and stays coordinated when one prompt and one answer are not enough. Each part below is a kit: plug in only what your job needs (Build an Environment). The Kit…
This page explains how work starts, runs and stays coordinated when one prompt and one answer are not enough. Each part below is a kit: plug in only what your job needs (Build an Environment). The Kit Catalog links each kit's full settings.
#Events
A kit saves each change together with the events that describe it, in one store transaction: both are saved or neither is. The event log is append-only, and each event gets a sequence number (seq).
The bus (port bus@1) delivers the log to every kit that listens: bus-inproc inside one process, bus-postgres (Enterprise) across processes. Each kit has its own cursor and gets each event it listens to at least once, in seq order. A kit chooses in kit.json (events.delivery) where it starts and what a failed handler does:
| Setting | Values | Default |
|---|---|---|
startAt | beginning replays the whole log the first time; latest starts at the end (kits that start work, like intake). | beginning |
onFailure | block retries the event and holds everything after it (kits that keep a view of history, like diagnostics). dead-letter retries up to maxAttempts (default 5), then sets it aside (kits that react). | block |
neusym events <dir> --failures lists failed deliveries, and --redeliver tries the set-aside events again.
The kernel stamps each event with its actor, its cause, and its depth: the number of event hops from the work that started the chain. Kits cannot set these. A commit deeper than the kernel's maxEventDepth (default 8) fails with EVENT_DEPTH_EXCEEDED, so events that keep causing each other stop.
#How work starts
A person or program starts work directly: neusym run, the server's POST /tasks, or your own code. Everything else goes through a kit.
Outside events come in through intake. By default it accepts only registered producers. It admits each (source, eventId) once, refuses an event older than one it already took for the same intentKey, and marks the payload untrusted (tainted). The server's signed POST /webhooks/:source route goes through it (Deployment).
Intake's trigger rules (triggers) turn events into tasks. A prompt may name only the fields the kernel stamped, like {{taskId}}; the payload reaches the task as tainted context. With intake and worker-pool loaded (and contextIssuer: [worker-pool] granted), this rule asks a reviewer to check every finished task:
kitConfigs:
tasks:
allowedCreateRoles: [reviewer]
worker-pool:
allowedRoles: [reviewer] # this pool serves the reviewer queue
intake:
triggers:
- id: review-answers
on: task.changed
where:
payload.status: completed
payload.workerRole: { $exists: false } # skip the reviewer's own tasks
prompt: "Check the answer of task {{taskId}}."
workerRole: reviewerAfter neusym run ./my-env "How many invoices are overdue?":
$ neusym tasks ./my-env
task_…01a [queued] role=reviewer Check the answer of task task_…008.
task_…008 [completed] How many invoices are overdue?
$ neusym events ./my-env
seq time type source depth actor caused by run task
5 2026-11-30T13:29:59.190Z task.changed tasks 0 cli - run_…i task_…008
6 2026-11-30T13:29:59.197Z intake.accepted intake 1 cli evt_…014 run_…i task_…008
7 2026-11-30T13:29:59.200Z task.changed tasks 1 cli evt_…014 run_…i task_…008Event 5 is the first task finishing; events 6 and 7, one hop deeper, admit the reviewer task. neusym work ./my-env runs it. A rule that fires on its own tasks (payload.status: queued and nothing else) stops at the depth limit:
✗ kit:intake on task.changed #21 · set aside after 5 attempt(s) · Event "intake.accepted" from "intake" would be 9 hops from the work that started its chain; the limit is 8. Events that keep causing each other are refused here.When an event needs a judgment call, a router (event-router, Enterprise) picks where it goes. A rule route matches the event and creates its task at once. A semantic_llm route, or a hybrid one whose rule does not match, queues a check task instead: a model must pick one route id from a closed list and sees the payload only as tainted context. Below minConfidence, the event goes to a person by default. Each decision is published as route.decided, route.ignored or route.escalated.
A goal (goals) records what the work is for, finite or continuous. The planner (planner) turns a goal into steps with dependencies, run up to maxParallelSteps at a time (default 1), with outputs passed between steps ($fromStep), fan-out (forEach), retries and up to two replans. A continuous goal gets a check task every checkIntervalMs (default one minute). Revising a goal stops plans made for the old version. CLI: neusym goals create <dir> --title <text> --kind continuous, then neusym plans create <dir> --goal <goalId>.
Timers (scheduler) are durable, one-shot or repeating: plan checks, approval expiry, and, with waitTool on, an agent pausing its own run (scheduler.wait). Like worker-pool, scheduler acts for every tenant, so it needs the contextIssuer grant.
#How work runs
A task runs on the environment's one executor (port executor@1; swapping it):
| Executor | What it runs |
|---|---|
harness | A model loop: model, tools, model. Agent definitions are versioned, and each run is pinned to the setup it started with. |
cli-executor | An external agent CLI (through a cli-harness@1 driver) inside a runner@1 session, such as a Docker container. Changed files come back as a tree-delta archive, saved as untrusted evidence. |
procedure-executor | No model: one registered tool per task, chosen by worker role, with the task's procedureInput as arguments. |
A task may name a workerRole (one that tasks lists in allowedCreateRoles) and then waits in the queue tasks:<role>. worker-pool serves the roles in its allowedRoles; neusym work runs queued tasks and due timers until none are left. A run that throws is retried from its checkpoint up to maxAttempts (default 3), then fails with RETRIES_EXHAUSTED. If a worker loses its job lease, another takes the job over and the old run stops with LEASE_LOST (resilience also checks this before every step). Environment folders that share one store can serve different roles, each with its own level and kits.
#Several agents on one job
Leases (blackboard) keep parallel workers out of each other's files. Before changing files, a worker leases paths: exclusive, shared-read or symbol-write. A clash is refused (RESOURCE_LOCK_CONFLICT); when waiting would close a cycle, the youngest run gets DEADLOCK_YIELD and gives way. Leases expire and end with their task. Runs can also freeze an interface contract (writes to it fail with CONTRACT_FROZEN) and leave notes for the other runs' context. cli-executor takes the lease in a task's procedureInput.lease first, and a changed file outside it fails the run (CLI_LEASE_SCOPE_VIOLATION).
With delegation, a task hands work to other agents, alone or in batches, and waits for all or any. Children share the parent's budget scope and taint, nesting stops at maxDepth (default 2), and children still running are halted when the parent fails.
Parallel cli-executor runs each return an archive of their changes. A later task can start from several (applyArchiveArtifactIds), or sandbox.integrate_archives can merge them, check that exported symbols still agree, and run one allowlisted command on the result. When two archives change one file, archiveConflictStrategy decides: fail (the default) refuses, text-merge-3way merges lines, and ast-merge-3way (the default of integrate_archives) merges part by part. Despite its name, ast-merge-3way builds no syntax tree. Plain code in contracts/runner (mergeStructured3Way) splits each file into top-level parts: JSON keys, JavaScript and TypeScript imports and named declarations, top-level units of Python, Go, Rust, YAML and SQL. Other files get the line merge. Two archives that change the same part fail with SESSION_ARCHIVE_CONFLICT.
#Long-running work
Three kits keep a long task on track. examples/coding-benchmark runs one task with and without them (README).
| Kit | Problem | What it does |
|---|---|---|
working-state | The agent loses track after many steps | Keeps a ledger per goal or task (known, tried, next, never) plus an operator-set goal summary, and adds it to each new run's context (again after old turns are compacted). What the model writes stays marked untrusted. |
convergence | The agent repeats an approach that failed | Fingerprints each attempt and feeds back EXPECTED / SAW / FENCE / DEAD ENDS. When one fingerprint repeats maxSameSawRepeats times (default 2), the next step is refused with HALT_SAME_SAW_REPEATED. |
constraints (in kits/reasoning) | Key rules get lost in long prompts | Keeps versioned one-line rules (never, always, required_check, split_rule), matched by worker role or leased path, and adds them to the context. A required_check becomes a check completion-gate runs before the task closes. |
#Across systems (Enterprise)
A saga (saga, level execute) undoes a change that spans several systems. Each step is registered with the tool that undoes it. When the task fails, or an operator runs neusym sagas compensate, the undo calls run in reverse order through tool-gateway and operation-journal. A step whose call may still land waits in needs_reconciliation.
a2a-bridge connects other agent runtimes over the Agent-to-Agent (A2A v1.0) protocol. Inbound tasks are admitted once per external id and marked tainted. Outbound, the a2a.delegate tool reaches only peers listed in peers, can pin a peer's Agent Card hash (cardSha256), caps spend per peer (maxCostUsd), and returns untrusted output.
What tainted and untrusted content may not do is in Authority and Safety. How kits declare ports and events is in Architecture.