SSyncropel Docs

Record Format

The 8-field record: wire format, canonical JSON rules, how the ID is computed, act types, data types, and common body conventions.

The 8 fields

Every record has exactly 8 fields. Seven are hashed into the ID; one (judged_by) is not.

#FieldTypeHashedDescription
1parentsstring[]yesRecord IDs this builds on. Sorted ascending. [] for a root record.
2threadstringyesThread ID: th_ + 64 hex characters.
3actorstringyesActor DID (did:sync:user:alice, did:sync:agent:dev, did:key:…, etc.).
4actstringyesOne of 8 act types (see below).
5bodyobjectyesJSON payload. The server doesn't interpret it; conventions are documented per topic.
6clockintegeryesCounter that orders records. Increases per (actor, thread). Zero or more, up to 9,223,372,036,854,775,807.
7data_typestringyesOne of 6 data types (see below).
8judged_bystring | nullnoPoints to the record whose judgment this reflects. Often null.

How the ID is computed

id = SHA-256(canonical_json(act, actor, body, clock, data_type, parents, thread))

The seven fields are written as canonical JSON (keys in alphabetical order), then hashed with SHA-256. The result is lowercase hex, 64 characters, no prefix.

The judged_by field is excluded from the hash because the same observation reviewed by two different parties is the same observation. Leaving it out keeps the ID the same across reviews, while trust can still be credited to each reviewer.

Canonical JSON encoding

The ID is computed from canonical JSON bytes. Any implementation must produce identical bytes for the same content.

Rules:

  1. Keys sorted alphabetically at every depth. {"b": 1, "a": 2} serializes as {"a":2,"b":1}.
  2. No whitespace outside of string values. No newlines, no indentation.
  3. Numbers in their shortest form. No leading zeros. No trailing zeros in fractions. No exponent unless required by magnitude.
  4. Strings use JSON escaping. Control characters U+0000 through U+001F are \uXXXX-escaped. " and \ are escaped. UTF-8 bytes pass through otherwise.
  5. Booleans and null as true, false, null.
  6. Arrays preserve element order. This matters for parents: preserve ascending sort.

Reference encoders are syncropel.canonical.canonical_json (Python SDK) and the Rust canonical::encode. Both produce identical bytes for identical content.

Thread IDs

thread_id = "th_" + SHA-256(<seed inputs>)

The th_ prefix is required. It lets code tell thread IDs from record IDs (bare 64-hex) and DIDs (did:…). The server rejects records whose thread field doesn't start with th_ followed by exactly 64 hex characters.

Seed inputs vary by creator:

  • Task threads: SHA-256(alias + nonce); the CLI generates the nonce at spl task add time.
  • Dispatch threads: SHA-256(parent_thread + target_actor + dispatch_timestamp_ms); each dispatch run has a fresh thread.
  • Reserved threads are fixed IDs built into the server:
    • th_engine_config
    • th_actor_registry
    • th_namespace_registry
    • th_instance_registry
    • th_fleet_control
    • th_consent

Don't make up a thread ID. Use one of the fixed names above, derive one with an SDK helper, or ask the server to create one.

Act types

Eight types in two groups of four.

Coordination (written by people, agents, and services)

TypePurposeTypical body fields
INTENDState a goal, open a thread.goal, task, assigned_to, domain, priority, labels, namespace
DORecord an action performed.tool, args, cancels, topic
KNOWRecord an observation, fact, or verdict.topic, observation, fulfills, verdict, judged_by_did
LEARNRecord an insight or configuration change.topic, rule, trigger, config

Effect (written by adapters and tools)

TypePurposeTypical body fields
GETRetrieve a value.key, result
PUTStore a value.key, value
CALLInvoke a tool or service.tool, cmd, provider, request, response
MAPTransform data.from, to, transform

Data types

TypeMeaning
SCALARA single value. The default for most records.
FORMULAA computation specification. The body carries an expression.
DISTRIBUTIONA probability distribution, interval, or range.
REFERENCEA pointer to outside content (a URL, a hash, or a stored file).
MORPHISMA transformation function between types. Used by MAP.
VOIDNo value. Used by pure side-effect records.

Clock rules

  • Monotonically increasing per (actor, thread). Cannot go backwards.
  • Starts at 0 for an actor's first record on a thread.
  • Gaps allowed: 0, 1, 5, 7 is valid. Gaps don't mean records are missing; the actor usually wrote elsewhere in between.
  • Per-actor per-thread. Two actors on the same thread each have independent clock sequences.
  • A repeated clock returns DUPLICATE_CLOCK. This makes retries safe. If you see it, your client's clock is wrong or another writer is active. Increase the clock and retry.
  • Clocks are i64. Values from 0 to 9,223,372,036,854,775,807 are valid. You will not run out in normal use.

Wire format

On the HTTP API, records are JSON. The 8 fields appear at the top level:

{
  "parents": [],
  "thread": "th_a1b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4e5f67890",
  "actor": "did:sync:user:alice",
  "act": "INTEND",
  "body": {
    "goal": "Deploy the authentication service v2",
    "namespace": "acme-corp/auth/prod"
  },
  "clock": 0,
  "data_type": "SCALAR",
  "judged_by": null
}

The response always echoes the stored record plus an id field:

{
  "parents": [],
  "thread": "th_a1b2c3d4…",
  "actor": "did:sync:user:alice",
  "act": "INTEND",
  "body": { "goal": "…", "namespace": "…" },
  "clock": 0,
  "data_type": "SCALAR",
  "judged_by": null,
  "id": "a1b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4e5f67890"
}

You never send the id. It is the result of the hash, shown for convenience.

Common body conventions

The server doesn't interpret body, but these conventions are stable.

Opening a task thread:

{
  "act": "INTEND",
  "body": {
    "task": true,
    "alias": "TASK-0334",
    "goal": "Docs depth pass",
    "assigned_to": "did:sync:agent:dev",
    "domain": "code",
    "priority": "high",
    "labels": ["foundation", "docs"],
    "namespace": "default"
  }
}

Closing a thread with a verdict:

{
  "act": "KNOW",
  "body": {
    "fulfills": "3292991f311ea69ce02fa290c7517d0bd20658d0f4d379ffdeb39b52180f87ec",
    "verdict": "accept",
    "summary": "All deliverables shipped; build clean."
  },
  "judged_by": "3292991f311ea69ce02fa290c7517d0bd20658d0f4d379ffdeb39b52180f87ec"
}

A routing rule (LEARN on th_engine_config):

{
  "act": "LEARN",
  "thread": "th_engine_config",
  "body": {
    "topic": "routing_rule",
    "name": "code-to-dev",
    "expression": "record.act == 'INTEND' && record.body.domain == 'code'",
    "target": "did:sync:agent:dev",
    "priority": 100
  }
}

A correction record:

{
  "act": "KNOW",
  "body": {
    "topic": "correction",
    "supersedes": "<bad_record_id>",
    "reason": "value was wrong; correct value is X"
  },
  "parents": ["<bad_record_id>"]
}

A cancellation:

{
  "act": "DO",
  "body": {
    "cancels": "<intend_id>",
    "reason": "requirements changed"
  }
}

See CEL expressions for the full set of topics the workspace recognizes, and the body.kind grammar for the structure the SDK enforces on body.kind in integration records.

What the server checks when you write a record

The server checks a short list:

  1. All 8 fields present with the correct types.
  2. thread matches ^th_[0-9a-f]{64}$.
  3. actor is a syntactically valid DID. Unknown actors are allowed; invalid syntax is rejected.
  4. act is one of the 8 types.
  5. data_type is one of the 6 types.
  6. clock is a non-negative i64.
  7. parents is a sorted-ascending array of valid record IDs (64-hex each).
  8. body.namespace (if present) passes the namespace rules: every parent namespace must exist and be active.

The server does not check:

  • Whether body makes sense. It doesn't check that body.fulfills names a real record, that body.topic is a known topic, or that body fits the declared data_type. Readers handle that.
  • Signatures. They apply to sharing between workspaces; local records are not signed.
  • Duplicate content (apart from duplicate clocks). Two records that differ only in clock are two separate records, and that is allowed.

Errors

The POST /v1/records endpoint returns structured JSON errors:

CodeMeaning
INVALID_SHAPE8 fields missing, wrong types, or malformed thread/actor/act/data_type.
DUPLICATE_CLOCKAnother record with the same (actor, thread, clock) already exists. Retry with clock+1.
NAMESPACE_REJECTEDbody.namespace (or an ancestor) is missing or not active in the registry.
AUTH_REQUIREDauth.required=true and no valid bearer token was presented.
FORBIDDENA CEL permission rule denied the write.

Error responses include the failing field and, where applicable, a recovery hint. See API reference for the full error shape.

Where to go next

On this page