interplane.Get Omega
Read in your language

synapse

A component of the AienOS ecosystem.

Brought by drakestapleton

branch main Branches Tags History

synapse / crates / synapse-coord / README.md

207 lines · 14318 bytes Raw Blame History Source

synapse-coord

Shared agent coordination (claims, presence, whispers) for agents working through Synapse, on the same store as the Crumb tool crumb.c. Deliverable 2 of the Crumb-Synapse workstream (ADR 0004): move shared agent coordination off Git without creating a second, invisible lock set.

Reference implementation: tools/crumb/crumb.c in aien-architecture at 29780e5 (sha256 of the file: ef0f6566fb838917a750eb898f66596b76aa15a53d7d61bedac03c4c963ee147; identical to origin/main on 2026-10-14), RFC-0002 plane from the comment "RFC-0002 common coordination plane", and docs/CRUMB_PROTOCOL_RFC_0002.md.

The problem this prevents

During the transition some agents claim through crumb in Git worktrees and some through Synapse. If each side kept its own locks, two agents could both "own" src/runtime.c and neither would know. Here both tools read and write one store under one OS lock, so a claim made by either is refused by the other, and each sees the other in sniff. scripts/crumb-coord-interop.sh proves this against the pinned C tool.

Compatibility contract with crumb.c (what is kept identical)

AspectRule (same as crumb.c)
Store rootPassed in explicitly. crumb.c uses CRUMB_COORD_ROOT, else git config crumb.coordinationRoot, else <git-common-dir>/crumb/v1. Synapse points both at one directory beside its repository store. This crate never calls Git.
Layoutdirs/<repo-relative dir>.json (dirs/_root.json for .), agents/<agent>.json (bytes outside [A-Za-z0-9._-] become _), continuations/, ledger/, lock file .lock.
Transaction lockfcntl(F_SETLKW, F_WRLCK) on <root>/.lock, whole file, held for the read-modify-write of one command. Readers (sniff) take no lock.
Durable write<record>.tmp<pid>, write, fsync, close, rename over the record, fsync the directory. Only changed records are written.
Keysnorm_path collapses ., .., //; a path that climbs above the root is refused. Target key: <dir>/<target> if it exists, else <target> from the root if it exists, else the repo-relative form when the target contains /, else <dir>/<target>. Absolute targets must lie inside the workspace.
TTLslock 1800 s, scent 3600 s, whispers kept 24 h; a claim's presence lasts max(3600, lock ttl). Expired = now - stamp > ttl, or the stamp is unparseable.
PruningEvery mutation loads every record, drops expired locks/scents/whispers, unlinks expired agent records, and writes back what changed.
RecordsByte-identical JSON: key order kept, two-space indent, ": ", trailing newline, \u007f and control bytes escaped as crumb.c does, numbers kept as written, unknown fields preserved. Strings are bytes (no UTF-8 requirement). History capped at 20.
Exit semanticsclaim on a key held by another agent: blocked with holder info (C exit 2); close by a non-holder: refused (exit 2).
Session idCRUMB_SESSION if set, else agent@host; never a PID. A caller may pass one explicitly.

What replaces branch / head / base for Synapse agents (decision)

RFC-0002 says branch, worktree, head and base are holder metadata, never identity. crumb.c writes them from Git. A Synapse agent has no Git branch, so `Holder::synapse(lane, revision, base)` fills the same fields and adds one:

FieldGit agent (crumb.c)Synapse agent (this crate)
worktreegit rev-parse --show-toplevelthe agent's workspace path or a stable absolute label (e.g. /synapse/ws/<agent>)
branchshort branch namethe Synapse lane/ref name
head12-hex short commitfirst 12 hex of the ChangesetId the agent works from
base12-hex merge-base with origin/mainfirst 12 hex of the base ChangesetId
synapse_revisionabsentfull ChangesetId hex (new, appended last)

The extra field is only appended; every field crumb.c reads keeps its meaning, so crumb.c's displays (held by X [branch], BLOCKED ... on branch ...) stay readable. crumb.c's JSON model keeps unknown fields, and the interop script checks that crumb.c rewriting the same directory record keeps synapse_revision (I5). The crate takes strings, not synapse_core::ChangesetId, so it has no dependency on Synapse internals.

Store identity: catching split coordination roots (issue #15)

The two tools agree on one store only by configuration (CRUMB_COORD_ROOT / crumb.coordinationRoot for crumb.c, --store or the path given to CoordStore here). A wrong root used to fail silently: each tool granted a claim on the same file in its own store.

Crash safety

Hostile store files (issue #58)

Anyone who can write into the shared store can plant a FIFO, a device, a symlink to /dev/zero or a huge file under a record name. Every store file this crate reads (dirs/**/*.json, agents/*.json, STORE_ID, and the .lock file a mutation opens) goes through one bounded read (src/record.rs):

A refusal is CoordError::RefusedRecord { path, reason } with reason one of Symlink, NotRegular("fifo" | "socket" | "char device" | ...) or TooLarge { limit }. It is handled exactly like a corrupt record: the operation fails, nothing is written, the file is left as found, and the D3 pre-submit advisory reports CoordinationStatus::Unavailable. The scope is store-wide, because every mutation and sniff load every record: a FIFO planted at dirs/sub/x.json also fails claim . other/y.c. The error names the file; an operator moves it aside to restore the store. Mutations also refuse to rename over a non-regular file and to write a record over the cap; their temporary file is created fresh with O_EXCL | O_NOFOLLOW. Directory listing never opens an entry: it uses the entry type, does not walk symlinked directories, and ignores names that do not end in .json.

crumb.c at 29780e5 has the same defect (a FIFO dirs/*.json hangs its sniff and claim); that fix belongs in aien-architecture and is out of scope here.

What coordination state is not

Coordination state is ephemeral. It is never written into Synapse history, is **never an evidence receipt, and is **never an authority: a claim is advisory, it does not grant publication or merge rights (AEGIS stays the sole publication authority). Nothing in this crate touches synapse-store, changesets or refs.

Known differences and limits

Using it

let store = CoordStore::open("/path/beside/synapse/store/crumb/v1");
let ws = Workspace::with_oracle("/synapse/ws/agent-7",
    Holder::synapse("lane/main", &changeset_hex, &base_hex), Box::new(NoOracle));
match store.claim(&ws, "agent-7", ".", "crates/x/src/lib.rs", "refactor", None)? {
    ClaimOutcome::Claimed { key } => { /* work */ }
    ClaimOutcome::Blocked { key, holder } => { /* someone else owns it */ }
}

The synapse-coord binary mirrors crumb claim|update|whisper|close|sniff lines and exit codes for scripts: synapse-coord --store DIR --top WS [--synapse LANE REV BASE] claim ....

Verification

Mission message board (issue #83)

synapse_coord::board (CLI synapse-coord board ...) is a separate, durable per-mission board for agent findings, questions, answers and handoffs: one fsynced journal (group commit: concurrent posts share their flushes) with a 64-byte commit table, per-topic and per-addressee id indexes, tag registration (board register <tag>; addressing only, never authentication), subscriptions, per-tag cursors with at-least-once delivery, and best-effort wake datagrams so a waiting agent does not poll. It lives under its own root with its own BOARD_ID and changes nothing in the coordination store's records or verbs. Board content is untrusted data. Design, crash rules and CLI: docs/SWARM_BOARD.md. Tests: tests/board_core.rs, tests/board_cli.rs, tests/durability.rs.

Migration

This crate is existing Rust. Under the pure-Omega directive (rule 3) it receives only minimal fixes of production defects, such as the board durability repairs of crumb924 (aien-sovereign-core-mv#928 review rounds), and no new features, verbs or dependencies. Its successor is an Omega (.om) board for the swarm-bridge port: om/swarm-bridge in aien-sovereign-core-mv (crumb924), tracked in Linear DRA-460 (follow-up of DRA-97). The board's recovery contract and the regressions in tests/durability.rs are the behaviour that successor must reproduce.