Skip to content

The memory model

The shared-memory transport uses two bounded rings between cell monitors. The memory model defines which monitor may write each region, when a frame becomes visible, when a slot may be reused, and what survives a process failure.

Ring ownership

flowchart LR
  subgraph CALLER["CALLER MONITOR"]
    direction TB
    CP["Call producer"]
    CC["Completion consumer"]
  end
  subgraph MEMORY["SHARED MEMORY"]
    direction TB
    CR[("Call ring<br/>bounded SPSC")]
    RR[("Completion ring<br/>bounded SPSC")]
  end
  subgraph OWNER["OWNER MONITOR"]
    direction TB
    OC["Call consumer"]
    OP["Completion producer"]
  end
  CP -->|"release publication"| CR
  CR -->|"acquire observation"| OC
  OP -->|"release publication"| RR
  RR -->|"acquire observation"| CC

Each ring has one producer and one consumer. The caller monitor produces calls and consumes completions; the owner monitor consumes calls and produces completions. Ring control fields are separated onto 64-byte cache lines and use 64-bit sequence numbers. Capacity is a power of two between 2 and 4096 slots.

Each ring backing has 128 control bytes followed by 160 bytes per slot. A slot contains an 8-byte sequence, a 128-byte compact header and 24 inline payload bytes.

Ring-control memory remains monitor-owned. Cell code may write only a buffer generation for which it holds the current write right. Attachments read by another cell are sealed and mapped read-only.

Publishing and releasing a slot

A producer acquires the consumer's prior release before reusing a slot. It writes the complete header and payload, then publishes the slot with a release operation. The consumer acquires that publication before reading any frame bytes. It releases the slot only after the frame and receiving-end correlation guards accept the observation.

The sequence number distinguishes successive uses after the array index wraps. The full sequence establishes whether a frame is current. The receiving monitor validates the header before it decodes a payload, including version, kind, flags, grant and channel generations, ordinals, deadline, lengths and attachment counts. A channel is retired before its 64-bit sequence can itself overflow and reuse an old sequence value.

When frame or correlation validation fails, the consumer leaves its position and the slot's release sequence unchanged. It invalidates the ring and reports the applicable typed malformed-frame or unmatched-correlation fact. Later access observes peer closure, and bytes following a refused frame stay outside decoding.

Failure and race behaviour

Event Result
Producer dies before publication The unpublished reservation is ignored; authority accounting reconciles it.
Consumer dies after observing a call The observation remains recorded for the nucleus to classify.
Cancellation races with completion Both remain correlated facts; nucleus state decides terminality independently of arrival order.
Completion arrives late or twice The typed transport fault is reported; credit remains settled exactly once.
Cell or peer dies The channel generation is invalidated before its rings are reset.
An attachment is released It is authoritatively released, zeroed, and assigned a new generation before reuse.

Reset preserves epoch isolation. Slot reinitialisation begins only after reservation accounting has settled.

Protocol bounds

The reference channel's control-frame envelope is limited to 16 MiB and 16 attachments. A shared-memory slot carries 24 inline payload bytes; larger values use sealed attachments. Each request ring, completion ring and pending-correlation set is limited to 4096 entries. Completed-correlation tombstones are bounded by ring capacity. These are protocol ceilings: the channel grant may allow less, and a free ring slot authorises no call.

The same typed observations describe malformed frames, unmatched correlations, peer closure, delivery loss and backpressure on both transports. See Semantic equivalence and Credit backpressure.