Formal
Specification

The complete Context Fabric Standard specification for implementers. Schemas, wire formats, protocols, and conformance requirements.

Version 0.1.0 Draft 2026-01-15

Specification Status

CFS 0.1 is a draft specification. The primitives are stable, but wire formats and protocol details may change before 1.0. Implementations should expect breaking changes.

Core Schemas

All CFS primitives are defined with precise schemas. Implementations MUST validate against these schemas. Canonical encoding uses Protocol Buffers with deterministic serialization.

Record

message Record {
  string record_id = 1;        // Stable unique ID (UUIDv7 recommended)
  string tenant_id = 2;        // Tenant isolation boundary
  repeated string labels = 3;  // Type classification
  map<string, Value> props = 4; // Key-value properties
  Timestamp created_at = 5;    // System time of creation
  bytes integrity = 6;         // SHA-256 of canonical encoding
}

record_id: MUST be globally unique, MUST NOT change after creation.

integrity: Hash of deterministic protobuf encoding excluding this field.

Link

message Link {
  string link_id = 1;          // Unique link identifier
  string type = 2;             // Relationship predicate from registry
  string source = 3;           // Source record_id
  string target = 4;           // Target record_id
  map<string, Value> props = 5; // Relationship attributes
  Interval valid = 6;          // When this relationship was true
  Interval system = 7;         // When this was known (append-only)
  string assertion_id = 8;     // Provenance reference
  bytes integrity = 9;
}

message Interval {
  Timestamp from = 1;          // Inclusive start
  Timestamp to = 2;            // Exclusive end (MAX for open)
}

valid: Application time - when the relationship was true in reality.

system: Transaction time - when this record entered the system.

View

message View {
  string view_id = 1;
  Query base_query = 2;        // Records/links to include
  FieldMask field_mask = 3;    // Which properties are visible
  repeated string policy_refs = 4; // Governing policies
  RefreshMode refresh_mode = 5;
  Timestamp expires_at = 6;    // Optional cache expiry
}

enum RefreshMode {
  LIVE = 0;      // Always current
  CACHED = 1;    // May be stale within TTL
  SNAPSHOT = 2;  // Point-in-time frozen
}

Tool

message Tool {
  string tool_id = 1;
  string name = 2;
  string description = 3;
  Schema input_schema = 4;     // JSON Schema for inputs
  Schema output_schema = 5;    // JSON Schema for outputs
  repeated string required_permissions = 6;
  repeated SideEffect side_effects = 7;
  AuditLevel audit_level = 8;
}

message SideEffect {
  string type = 1;             // create, update, delete, external
  string resource_pattern = 2; // What's affected
}

enum AuditLevel {
  MINIMAL = 0;   // ID + timestamp only
  STANDARD = 1;  // + inputs/outputs summary
  FULL = 2;      // Complete input/output capture
}

Receipt

message Receipt {
  string receipt_id = 1;       // Unique, immutable
  Principal actor = 2;         // Who performed action
  Action action = 3;           // What was done
  repeated string targets = 4; // What was affected
  Timestamp timestamp = 5;     // System time
  map<string, string> context = 6; // Request ID, session, etc.
  bytes prev_hash = 7;         // Chain to previous receipt
  bytes integrity = 8;         // Hash for tamper detection
}

message Principal {
  string id = 1;
  PrincipalType type = 2;      // HUMAN, AGENT, SERVICE, SYSTEM
  string auth_context = 3;     // How authenticated
}

enum Action {
  READ = 0;
  WRITE = 1;
  INVOKE = 2;
  APPROVE = 3;
  SYNC = 4;
}

Policy

message Policy {
  string policy_id = 1;
  Effect effect = 2;           // ALLOW or DENY
  PrincipalMatcher principal = 3;
  ResourceMatcher resource = 4;
  repeated Condition conditions = 5;
  int32 priority = 6;          // Higher = evaluated first
  Interval valid = 7;          // When policy applies
}

enum Effect {
  ALLOW = 0;
  DENY = 1;
}

message Condition {
  string attribute = 1;        // e.g., "time.hour"
  string operator = 2;         // e.g., "between"
  repeated Value operands = 3;
}

Gate

message Gate {
  string gate_id = 1;
  repeated Requirement requirements = 2;
  repeated string unlocks = 3; // Capabilities/resources gated
  GateStatus status = 4;
  repeated Evidence evidence = 5;
  Timestamp expires_at = 6;    // When unlock lapses
}

message Requirement {
  string id = 1;
  string description = 2;
  Query check = 3;             // How to verify
  bool satisfied = 4;
}

message Evidence {
  string requirement_id = 1;
  string receipt_id = 2;       // Proof of satisfaction
  Timestamp verified_at = 3;
}

enum GateStatus {
  LOCKED = 0;
  PENDING = 1;    // Some requirements met
  UNLOCKED = 2;
}

Wire Formats

Canonical Encoding

All CFS data MUST be serializable to canonical Protocol Buffers for integrity verification. Deterministic serialization rules:

  • Map fields sorted by key (lexicographic)
  • Repeated fields maintain insertion order
  • Default values explicitly encoded
  • No unknown fields preserved

Transport Formats

For transport, implementations MAY use:

  • Protobuf (recommended for performance)
  • JSON (for debugging, human readability)
  • CBOR (for constrained environments)

Integrity hashes MUST be computed on the canonical protobuf encoding, regardless of transport format.

Content Addressing

Artifacts use content addressing with multihash:

multihash = <hash-function-code> + <digest-length> + <digest>

Recommended: SHA-256 (0x12) with 32-byte digest
Example: 0x1220 + 64 hex chars

Timestamps

All timestamps use protobuf google.protobuf.Timestamp:

  • Seconds since Unix epoch (UTC)
  • Nanosecond precision
  • Special value for "now": seconds=0, nanos=0
  • Special value for "forever": seconds=MAX_INT64

Protocols

Read Protocol

Querying context with bitemporal semantics:

message QueryRequest {
  Query query = 1;
  Timestamp as_of_valid = 2;   // Valid time (default: now)
  Timestamp as_of_system = 3;  // System time (default: now)
  int32 limit = 4;
  string cursor = 5;           // For pagination
  FieldMask fields = 6;        // Which properties to return
}

message QueryResponse {
  repeated Record records = 1;
  repeated Link links = 2;
  string next_cursor = 3;
  Receipt receipt = 4;         // Proof of access
}

Write Protocol (Propose → Review → Apply)

Safe writes with human-in-the-loop:

// Step 1: Propose
message ProposeRequest {
  repeated Mutation mutations = 1;
  string intent = 2;           // Why this change
  repeated string citations = 3; // Source artifacts
}

message ProposeResponse {
  string proposal_id = 1;
  Diff diff = 2;               // What would change
  repeated string affected = 3; // Impacted records
}

// Step 2: Review (external, human or policy)

// Step 3: Apply
message ApplyRequest {
  string proposal_id = 1;
  string approver = 2;         // Who approved
  string approval_ref = 3;     // Evidence of approval
}

message ApplyResponse {
  bool success = 1;
  repeated Receipt receipts = 2;
  string commit_id = 3;
}

Sync Protocol

Incremental replication between planes:

message SyncRequest {
  string source_plane = 1;
  string cursor = 2;           // Last sync position
  SyncFilter filter = 3;       // What to include
  int32 batch_size = 4;
}

message SyncResponse {
  repeated SyncEntry entries = 1;
  string next_cursor = 2;
  bool has_more = 3;
}

message SyncEntry {
  oneof entry {
    Record record = 1;
    Link link = 2;
    Artifact artifact_meta = 3;
  }
  string commit_id = 4;
  Timestamp commit_time = 5;
}

Conformance Requirements

To claim CFS conformance, implementations MUST pass the conformance test suite and meet these requirements:

MUST-001

Schema Validation

All primitives MUST validate against the core schemas.

MUST-002

Integrity Verification

Implementations MUST compute and verify integrity hashes using canonical protobuf encoding.

MUST-003

Bitemporal Semantics

Links and versioned data MUST support AS-OF queries on both valid-time and system-time axes.

MUST-004

Append-Only History

Corrections MUST append new records, never mutate existing ones. System intervals MUST only close, never reopen.

MUST-005

Receipt Generation

All reads and writes MUST produce receipts with valid actor, action, targets, and integrity hash.

MUST-006

Policy Enforcement

Views MUST respect policy filters. Denied access MUST NOT leak data through error messages or timing.

MUST-007

Sync Compatibility

Implementations MUST support import/export in the canonical format. Round-trip MUST preserve all data and integrity hashes.

SHOULD-001

Merkle Audit

Implementations SHOULD maintain a merkle tree of receipts for tamper-evident audit trails.

The conformance test suite is available at github.com/helaix/cfs-conformance. Run the suite against your implementation to verify compliance.

Extensions

CFS is extensible. Custom types, predicates, and schemas can be added through the registry mechanism.

Schema Registry

Custom record labels, link types, and property schemas are registered in a schema registry. Each entry has a namespace, version, and schema definition.

message SchemaEntry {
  string namespace = 1;        // e.g., "com.glitchy"
  string name = 2;             // e.g., "IncidentReport"
  string version = 3;          // Semver
  Schema schema = 4;           // JSON Schema
  SchemaEntry supersedes = 5;  // Previous version
}

Link Type Registry

Custom relationship predicates with cardinality and validity constraints:

message LinkType {
  string namespace = 1;
  string predicate = 2;        // e.g., "escalated_to"
  string source_label = 3;     // Required source type
  string target_label = 4;     // Required target type
  Cardinality cardinality = 5; // ONE_TO_ONE, ONE_TO_MANY, etc.
}

Versioning

Schema evolution follows these rules:

  • New optional fields: always allowed
  • Removing fields: create new version
  • Changing field types: create new version
  • Adding required fields: create new version with migration

Implementation Resources