# Realtime contract: `.dsrt` source + `.profile` measurement

**Not in this edition.** Every clause in this document is deferred or retired, so nothing here binds a 1.0 implementation. It is kept so that its ids and the references to them resolve.


A rule file compiled with the `realtime` extension carries a
**realtime contract**: a set of caps the author guarantees the
engine will not exceed under any permitted input. The contract
lives in a sibling `.dsrt` file at compile time, gets embedded
into the produced `.dsc`, and is enforced at runtime.

Two YAML files use a shared schema:

- `foo.profile` — written by the profile binary; records what
  was observed during a workload. Pure measurement. Regenerated
  unilaterally whenever the profile binary runs.
- `foo.dsrt` — hand-authored realtime contract. Same schema as
  `.profile`. Read by the compiler when `realtime` is enabled.
  Required for any `realtime` compile to succeed.

The author's "commit point" is the compile. Once `foo.dsc` is
produced, the contract inside it is binding; subsequent edits
to `foo.dsrt` do not affect the deployed `.dsc`. To revise the
contract the author re-compiles.

This document defines the YAML schema, the `RealtimeContract` atom in compiled
`.dsc` files, the compile-time obligations of `realtime`,
and the runtime enforcement contract.

Prefix `RTCT`.

Parents:
- [RARC.4] format version discipline.
- [RBND] dialect / contract bindings.
- [LDIA] dialect mechanism (the `realtime` capability).

---

(RTCT-1)=
## The two files [RTCT.1]

*Deferred: not binding in this edition.*

(RTCT-1-1)=
[RTCT.1.1] **`foo.profile`** — emitted by the profile binary
([RTCT.5]). A full YAML document conforming to [RTCT.3] with
the `contract:` mapping populated from observed peaks
verbatim (no headroom applied) and the `measurement:`
section populated with full observations. The profile binary
overwrites any pre-existing `foo.profile` on each run; it
never touches a `.dsrt`.

*see also:* [RTCT.3](#RTCT-3), [RTCT.5](#RTCT-5)

(RTCT-1-2)=
[RTCT.1.2] **`foo.dsrt`** — the realtime contract. Same schema
as `.profile`. Hand-authored — the author starts by copying
`foo.profile` to `foo.dsrt`, then edits the `contract:`
section to apply whatever headroom and rounding the author
elects. Subsequent edits track the author's intent, not the
profile output.

(RTCT-1-3)=
[RTCT.1.3] **Mode independence.** The `.dsrt` does not declare
`rt_mode`. The mode under which the profile *measured* the
rules is recorded in `measurement.rt_mode`; the contract
itself is mode-agnostic — it caps the engine in whichever
mode it runs.

(RTCT-1-4)=
[RTCT.1.4] **Profile-binary obligation.** The profile binary
MUST refuse to write to any path ending in `.dsrt` —
`DS_ERR_RTCT_PROFILE_REFUSES_DSRT`. This guards the
"hand-authored only" invariant.

---

(RTCT-2)=
## Workflow [RTCT.2]

*Deferred: not binding in this edition.*

(RTCT-2-2)=
[RTCT.2.2] **The commit point is step 7.** The author commits
to the contract by compiling with `realtime`. From that
point forward the `.dsc` is authoritative; the `.dsrt` on
disk is no longer consulted by anything.

(RTCT-2-3)=
[RTCT.2.3] **The `.dsrt` is a plain text file.** Its existence in the compile working directory
at compile time is the act of commitment.

---

(RTCT-3)=
## YAML schema [RTCT.3]

*Deferred: not binding in this edition.*

(RTCT-3-1)=
[RTCT.3.1] A conforming `.dsrt` or `.profile` file is a UTF-8
YAML 1.2 document with the layout in [RTCT.3.2]. The compiler
parses only the top-level `contract:` mapping ([RTCT.4.1]); the
runtime sees the contract via the embedded `RealtimeContract` atom and
never reads any YAML file. The other sections are informational
and SHOULD be present in profile-binary output but MAY be
omitted, regenerated, or deleted by the author at any time.

*see also:* [RTCT.3.2](#RTCT-3-2), [RTCT.4.1](#RTCT-4-1)

(RTCT-3-2)=
[RTCT.3.2] Canonical file layout. Note the file order:

  1. `contract:` — what the compiler reads
  2. `measurement:` — what the profile binary observed
  3. `provenance:` — which `.ds` / dialect this pairs with

```yaml
# ╔══════════════════════════════════════════════════════════════╗
# ║ foo.dsrt — realtime contract for foo.ds                     ║
# ║                                                             ║
# ║ The compiler reads ONLY the `contract:` mapping below.      ║
# ║ Every other section is informational — runtime never sees   ║
# ║ it.                                                         ║
# ║                                                             ║
# ║ Values under `contract:` are CAPS. The runtime enforces     ║
# ║ them. Exceeding one of the counted caps REFUSES that        ║
# ║ operation with DS_ERR_CONTRACT_BREACH and leaves the engine ║
# ║ usable; exceeding pump_wcet_ns HALTS THE TIER with          ║
# ║ DS_ERR_CONTRACT_WCET_HALT and the engine does not reopen    ║
# ║ (RTCT.7.2, RTCT.7.3). The author guarantees these caps will ║
# ║ not be exceeded under any permitted input.                  ║
# ╚══════════════════════════════════════════════════════════════╝


# ── COMPILER READS THIS ──────────────────────────────────────────
contract:
  wm_max:             <int>      # max simultaneous facts
  agenda_cap:         <int>      # max queued activations
  max_fires_per_pump: <int>      # pump fire upper bound
  token_pool_cap:     <int>      # total tokens across all betas
  intern_cap:         <int>      # interned-string slots
  intern_bytes_cap:   <int>      # interned-string byte capacity
  cache_cap:          <int>      # max live cache keys
  cache_bytes_cap:    <int>      # cache value byte capacity
  json_depth_cap:        <int>   # optional; lowers Json depth (max 16)
  json_node_cap:         <int>   # optional; lowers Json nodes per value (max 256)
  json_string_bytes_cap: <int>   # optional; lowers Json string bytes (max 16384)
  json_text_bytes_cap:   <int>   # optional; lowers Json text per parse (max 24576)
  pump_wcet_ns:       <int>      # per-pump wall-clock ceiling

  nodes:                           # one entry per network node
    - node_id:  <int>
      kind:     alpha | beta | term
      capacity: <int>

  series:                          # one entry per series backend
    - series_id: <int>
      capacity:  <int>


# ── COMPILER IGNORES EVERYTHING BELOW ────────────────────────────

measurement:                       # profile-binary output
  ds_version:     "<string>"
  recorded_at:    "<RFC 3339 UTC>"
  rt_mode:        rt | non-rt
  pump_count:     <int>
  workload_label: "<string>"

  wm:
    peak:           <int>
    asserts_total:  <int>
    retracts_total: <int>

  agenda:
    peak: <int>

  timing:
    pump_pmin_ns:  <int>
    pump_pmean_ns: <int>
    pump_p99_ns:   <int>
    pump_pmax_ns:  <int>

  memory:
    init_bytes:    <int>
    runtime_bytes: <int>          # MUST be 0 for RT-clean

  intern:
    peak:       <int>
    bytes_peak: <int>

  fire_rate:
    per_pump_peak: <int>
    per_pump_p99:  <int>

  schemas:
    - id:        <int>
      name:      "<string>"
      fact_peak: <int>

  nodes:
    alpha:
      - id:             <int>
        matched_peak:   <int>
        hash_load_peak: <float>
    beta:
      - id:          <int>
        tokens_peak: <int>
    terminal:
      - id:                  <int>
        rule:                "<string>"
        firings_total:       <int>
        fires_per_pump_peak: <int>

  series:
    - series_id:    <int>
      backend:      "<string>"
      samples_peak: <int>


provenance:                        # which source/dialect this pairs with
  ds_basename:        "<string>"
  dialect_tier:       "<string>"
  dialect_extensions: [<sorted strings>]
```

(RTCT-3-3)=
[RTCT.3.3] **`contract:` field requirements** (compile-time
enforced):

  - All scalar fields listed in [RTCT.3.2] under `contract:`
    MUST be present and ≥ 1 (zero is rejected as
    `DS_ERR_CONTRACT_INVALID`; the engine has no zero-sized
    legitimate state).
  - There MUST be exactly one entry in `contract.nodes:` for
    each alpha, beta, and terminal node in the loaded rule
    network; `node_id` values MUST match the compiler-assigned
    IDs; missing entry or unknown node_id is
    `DS_VALIDATE_COMPILE_CONTRACT_INCOMPLETE`.
  - There MUST be exactly one entry in `contract.series:` for
    each series backend in the rule set.
  - `kind` MUST be one of `alpha`, `beta`, `term`.
  - All capacity fields are uint32; values exceeding 2^31-1
    are rejected (`DS_ERR_CONTRACT_INVALID`).

These requirements are **compile-time** only (the source-level
`.dsrt` contract); the per-node coverage rule above is *not* a
runtime check and MUST NOT be cited for load-time rejection
(see [RTCT.6.7.6]). The `.dsrt` **source** schema is unchanged
by the compact encoding: an author still writes one
`contract.nodes:` entry per node. The compiler MAY compact the
*compiled* `RealtimeContract` atom per [RTCT.6.7]; this is invisible
at the source level and changes neither the logical contract
nor its hash.

*see also:* [RTCT.3.2](#RTCT-3-2), [RTCT.6.7](#RTCT-6-7), [RTCT.6.7.6](#RTCT-6-7-6)

(RTCT-3-4)=
[RTCT.3.4] **Banner text is non-normative.** The decorative
header block at the top of [RTCT.3.2] is provided by the
profile binary as a courtesy and may be deleted, edited, or
reformatted in any `.dsrt` without affecting compile or
hash. The hash covers only the `contract:` mapping per
[RBND.4b].

---

*see also:* [RBND.4b](#RBND-4b), [RTCT.3.2](#RTCT-3-2)

(RTCT-4)=
## Compile-time obligations [RTCT.4]

*Deferred: not binding in this edition.*

(RTCT-4-1)=
[RTCT.4.1] **Contract lookup.** When a compile resolves a
dialect that includes the `realtime` extension, the compiler
must take the contract from exactly one place:

1. the contract file the invocation names, when it names one
   ([RCLI.1.9]);
2. otherwise `<dsdir>/<basename>.dsrt`, where `<dsdir>` is the
   directory containing the source file and `<basename>` is the
   source file's basename minus the `.ds` extension. Exact
   filename match only.

A source read from standard input has no `<dsdir>`, so it has a
contract only by (1). The compiler must not consult search paths
or environment variables, and must not fall back from (1) to (2):
a named contract that cannot be read is a usage error
([RCLI.3.1]).

*see also:* [RCLI.1.9](#RCLI-1-9), [RCLI.3.1](#RCLI-3-1)

(RTCT-4-2)=
[RTCT.4.2] **Missing `.dsrt`** is `DS_VALIDATE_COMPILE_MISSING_DSRT`,
a hard compile error. The compiler MUST NOT proceed to emit
a `.dsc`.

(RTCT-4-3)=
[RTCT.4.3] **`realtime` absent.** A `.ds` file whose
resolved dialect does NOT include `realtime` MUST NOT carry
a `.dsrt`. If a sibling `<basename>.dsrt` exists without
`realtime` enabled, the compile MUST fail with
`DS_VALIDATE_COMPILE_DSRT_WITHOUT_REALTIME` — the `.dsrt` is
useless and probably a leftover from an earlier `realtime`
configuration; surfacing as an error guards against silent
ineffectiveness.

(RTCT-4-4)=
[RTCT.4.4] **Parse, validate, canonicalize, embed.** Given a
valid `<basename>.dsrt`, the compiler MUST:

  1. Parse the YAML.
  2. Validate `contract:` against [RTCT.3.3].
  3. Cross-check `contract.nodes:` IDs against the
     compiled rule network's actual node IDs.
  4. Compute the canonical serialization per [RBND.4b].
  5. Compute `rt_config_sha256` (SHA-256 of canonical bytes).
  6. Emit a `RealtimeContract` atom into the `.dsc` carrying the contract
     values plus the hash ([RTCT.6.1]).
  7. Populate the `DscHeader` `rt_config_sha256` field with
     the same value (binding spine, per RBND.2).

*see also:* [RBND.2](#RBND-2), [RBND.4b](#RBND-4b), [RTCT.3.3](#RTCT-3-3), [RTCT.6.1](#RTCT-6-1)

(RTCT-4-5)=
[RTCT.4.5] **No silent rounding.** Whatever integer values the
author wrote in `contract:` are embedded verbatim. The
compiler does not round, normalize, or sanitize.

---

(RTCT-5)=
## Profile binary [RTCT.5]

*Deferred: not binding in this edition.*

(RTCT-5-1)=
[RTCT.5.1] The profile binary is a separate build of the
runtime with `-DDS_PROFILE=1` and is the *only* program
permitted to emit `.profile` files. It loads a `.dsc` (same
loader path as the production runtime) and executes a
caller-provided workload while recording high-water marks
and timing data.

(RTCT-5-2)=
[RTCT.5.2] **Mode selection.** The profile binary runs in
either `rt` or `non-rt` mode, controlled by an explicit CLI
flag (`--rt` / `--non-rt`). Both modes:

  - load the `.dsc` normally and read the `RealtimeContract` atom if
    present;
  - record measurements identically;
  - emit a `.profile` file whose `measurement.rt_mode`
    field reflects the chosen mode.

(RTCT-5-3)=
[RTCT.5.3] **RT-mode behaviour.** When the binary runs in
`rt` mode against a `.dsc` carrying a contract, all caps
defined in [RTCT.7] are enforced exactly as in the
production runtime. A contract breach during a profile
capture is a fatal runtime error (`DS_ERR_CONTRACT_BREACH`)
and aborts the capture; the partial `.profile` MAY be
written but is marked
`measurement.aborted_on_contract_breach: true` if so.

*see also:* [RTCT.7](#RTCT-7)

(RTCT-5-4)=
[RTCT.5.4] **Non-RT-mode behaviour.** When the binary runs
in `non-rt` mode, caps are not enforced — pool growth is
permitted and observed. This is the path for capturing
*what the engine actually wants* before the author has set
caps, supporting the [RTCT.2] iteration loop.

*see also:* [RTCT.2](#RTCT-2)

(RTCT-5-5)=
[RTCT.5.5] **Output path.** The profile binary writes to a
caller-supplied path. The path MUST end in `.profile`;
any other extension — particularly `.dsrt` — is
`DS_ERR_RTCT_PROFILE_REFUSES_DSRT`. Output overwrites any
pre-existing file at that path.

(RTCT-5-6)=
[RTCT.5.6] **`contract:` population.** The emitted
`.profile` MUST contain a `contract:` section whose values
are the observed peaks verbatim (per-field correspondences
in [RTCT.3.2]). This makes `cp foo.profile foo.dsrt` a
valid starting point — the resulting `.dsrt` is a valid
contract that exactly fits the observed workload (no
headroom). The author edits up from there.

---

*see also:* [RTCT.3.2](#RTCT-3-2)

(RTCT-6)=
## `RealtimeContract` atom in `.dsc` [RTCT.6]

*Deferred: not binding in this edition.*

(RTCT-6-1)=
[RTCT.6.1] **Identity and framing.** `RealtimeContract` is field **128** of
`proto/atom.proto#Atom`'s `body` oneof, and that field number is its
wire identity ([RFCS.16.1], [RDSC.7.1]). Framing is
the container's, two levels, both protobuf ([RFCS.19.1]) — there is no
ASCII magic and no big-endian length. Its body is
a `RealtimeContract` protobuf message (see [RTCT.6.2]).

*defined in:* [proto/atom.proto#Atom](#proto-atom-proto-Atom)  —  *see also:* [RDSC.7.1](#RDSC-7-1), [RFCS.16.1](#RFCS-16-1), [RFCS.19.1](#RFCS-19-1), [RTCT.6.2](#RTCT-6-2)

(RTCT-6-2)=
[RTCT.6.2] **Body proto** (`proto/realtime_contract.proto`):

```proto
message RealtimeContract {
  uint32 wm_max               = 1;
  uint32 agenda_cap           = 2;
  uint32 max_fires_per_pump   = 3;
  uint32 token_pool_cap       = 4;
  uint32 intern_cap           = 5;
  uint32 intern_bytes_cap     = 6;
  uint64 pump_wcet_ns         = 7;
  repeated NodeCap   nodes    = 8;    // LEGACY per-node list; ascending node_id.
                                      // Emitted only when a producer chooses the
                                      // legacy encoding (see [RTCT.6.7.5]).
  repeated SeriesCap series   = 9;    // ascending series_id
  bytes  rt_config_sha256     = 10;   // 32 raw bytes, the canonical hash

  // Compact node-cap encoding (gated on realtime; see [RTCT.6.7]).
  uint32 node_count        = 11;      // covered network nodes (cross-check)
  uint32 default_node_cap  = 12;      // capacity for every covered node not overridden
  repeated NodeCapOverride node_overrides  = 13;   // sparse, ascending node_id
  repeated uint32          node_caps_packed = 14 [packed = true];  // dense fallback

  // Cache caps (gated on realtime; see [RTCT.6.8]).
  uint32 cache_cap         = 15;      // max live cache keys (<= 2^31-1)
  uint64 cache_bytes_cap   = 16;      // cache value byte capacity (<= 2^63-1)

  // Json caps (see [RTCT.6.10]); 0 = the fixed maximum of [LGRA.5.8.6].
  uint32 json_depth_cap        = 17;
  uint32 json_node_cap         = 18;
  uint32 json_string_bytes_cap = 19;
  uint32 json_text_bytes_cap   = 20;
}

message NodeCap {
  uint32 node_id   = 1;
  string kind      = 2;                // "alpha"|"beta"|"term"
  uint32 capacity  = 3;
}

message NodeCapOverride {
  uint32 node_id   = 1;
  uint32 capacity  = 2;
}

message SeriesCap {
  uint32 series_id = 1;
  uint32 capacity  = 2;
}
```

The `nodes` (field 8) legacy list and the compact fields (11–14) are two
encodings of the same logical per-node capacity map; a contract uses **exactly
one** ([RTCT.6.7]). `node_count`/`default_node_cap`/`node_overrides`/
`node_caps_packed` carry no `kind` — the runtime derives each node's kind from
its `AlphaNode`/`BetaNode`/`TerminalNode` atom ([RBND.4b.8]).

*defined in:* [proto/realtime_contract.proto#RealtimeContract](#proto-realtime_contract-proto-RealtimeContract)  —  *see also:* [LGRA.5.8.6](#LGRA-5-8-6), [RBND.4b.8](#RBND-4b-8), [RTCT.6.10](#RTCT-6-10), [RTCT.6.7](#RTCT-6-7), [RTCT.6.7.5](#RTCT-6-7-5), [RTCT.6.8](#RTCT-6-8)

(RTCT-6-3)=
[RTCT.6.3] **Cardinality.** A `.dsc` produced by a `realtime`
compile MUST contain exactly one `RealtimeContract` atom. A `.dsc`
produced by a non-`realtime` compile MUST NOT contain a
`RealtimeContract` atom.

(RTCT-6-4)=
[RTCT.6.4] **Position.** The `RealtimeContract` atom appears between the
`DscHeader` header atom and the first per-module group — the first
`DsSource` atom ([RDSC.16.3.5]). Its absolute position within that
range is not specified.

*see also:* [RDSC.16.3.5](#RDSC-16-3-5)

(RTCT-6-5)=
[RTCT.6.5] **Load-time refusal.** A runtime loading a `.dsc`
whose dialect resolves `realtime`:

  - MUST find a `RealtimeContract` atom; absence is
    `DS_ERR_CONTRACT_MISSING`.
  - MUST decode the body without error;
    `DS_ERR_CONTRACT_INVALID` on malformed payload.
  - MUST cross-check the embedded `rt_config_sha256` against
    a recomputation over the **materialized logical contract**
    ([RBND.4b.8]) — for the compact encoding ([RTCT.6.7]) this
    means expanding `default_node_cap`/`node_overrides`/
    `node_caps_packed` to the per-node list first; mismatch is
    `DS_ERR_CONTRACT_INVALID`.
  - MUST cross-check the embedded `rt_config_sha256` against
    `DscHeader.rt_config_sha256` (the binding-spine
    duplicate); mismatch is `DS_ERR_BND_INCOMPLETE`.

*see also:* [RBND.4b.8](#RBND-4b-8), [RTCT.6.7](#RTCT-6-7)

(RTCT-6-6)=
[RTCT.6.6] **Stored contract.** On successful load the engine
keeps the decoded contract in private state for the lifetime
of the engine instance, accessible to runtime cap checks
([RTCT.7]) and to artifact emitters (FS, `.dsr`) per
[RBND.2.3].

*see also:* [RBND.2.3](#RBND-2-3), [RTCT.7](#RTCT-7)

(RTCT-6-7)=
[RTCT.6.7] **Compact node-cap encoding.** The per-node token
capacities of [RTCT.6.2] MAY be carried in a compact encoding
in place of the legacy `nodes` list (field 8). This is a pure
wire-size optimization gated on the `realtime` capability —
the `RealtimeContract` atom is `realtime`-only ([RTCT.6.3]) — and the logical
contract and its `rt_config_sha256` ([RBND.4b]) are identical to
the uncompacted encoding ([RBND.4b.8]).

*see also:* [RBND.4b](#RBND-4b), [RBND.4b.8](#RBND-4b-8), [RTCT.6.2](#RTCT-6-2), [RTCT.6.3](#RTCT-6-3)

(RTCT-6-7-1)=
[RTCT.6.7.1] A `RealtimeContract` carries its per-node capacities
in **exactly one** of two encodings:

  - **legacy** — `nodes` (8) non-empty; fields 11–14 unset/zero.
  - **compact** — `nodes` (8) empty; `node_count` (11) set;
    capacities given by `default_node_cap` (12) +
    `node_overrides` (13), **or** by `node_caps_packed` (14).

A body with both `nodes` (8) non-empty and any of fields 11–14
set is `DS_ERR_CONTRACT_INVALID`.

(RTCT-6-7-2)=
[RTCT.6.7.2] **Node basis.** "Covered nodes" are the alpha,
beta, and terminal nodes of the loaded network, enumerated in
**ascending node_id** order. The id space is the
compiler-assigned ids ([RTCT.3.3]); it need not be contiguous.
`node_count` MUST equal the number of covered nodes; mismatch
is `DS_ERR_CONTRACT_INVALID`. **Degenerate case:** a network
with zero covered nodes encodes `node_count = 0`, empty
`node_overrides`, empty `node_caps_packed`, and
`default_node_cap = 0`; it is the compact image of an empty
legacy `nodes` list and hashes identically.

*see also:* [RTCT.3.3](#RTCT-3-3)

(RTCT-6-7-3)=
[RTCT.6.7.3] **default + overrides.** When `node_caps_packed`
is empty, a covered node's capacity is the `capacity` of the
matching `node_overrides` entry (keyed by `node_id`), else
`default_node_cap`. `node_overrides` MUST be in strictly
ascending `node_id` order and every `node_id` MUST be a covered
node; a duplicate, out-of-order, or unknown `node_id` is
`DS_ERR_CONTRACT_INVALID`.

(RTCT-6-7-4)=
[RTCT.6.7.4] **packed.** When `node_caps_packed` is non-empty,
`default_node_cap` MUST be 0 and `node_overrides` empty. The
array has exactly `node_count` entries; the *i*-th entry is the
capacity of the *i*-th covered node in the ascending
enumeration of [RTCT.6.7.2]. A length ≠ `node_count` is
`DS_ERR_CONTRACT_INVALID`.

*see also:* [RTCT.6.7.2](#RTCT-6-7-2)

(RTCT-6-7-5)=
[RTCT.6.7.5] **Producer choice.** A conforming compiler MUST
emit the smallest valid encoding among {legacy,
default+overrides, packed} by serialized byte length, ties
broken in that order. The choice is deterministic: identical
logical contracts MUST produce byte-identical atoms.

(RTCT-6-7-6)=
[RTCT.6.7.6] **Old-reader rejection (structural, no minor
gate).** A runtime implementing this clause MUST accept both
encodings. A runtime built *before* this clause rejects a
compact contract **without needing to know about it**, via the
load-time hash recompute it already performs ([RTCT.6.5] /
[RDSC.16.3.3] step 3 / [RBND.4b]): it decodes the compact body
as a legacy body with an empty `nodes` list, recomputes the
canonical hash over that empty list, and the result cannot
equal the stored `rt_config_sha256` (computed over the *N*-node
logical contract, `N > 0`), so the contract is
`DS_ERR_CONTRACT_INVALID`. No version gate and no
field-presence sniffing are required. The `node_count = 0` case
([RTCT.6.7.2]) is the sole contract an old reader accepts —
correctly, as it hashes identically under either encoding.
(`[RTCT.3.3]`'s per-node coverage rule is **compile-time** —
`DS_VALIDATE_COMPILE_CONTRACT_INCOMPLETE` — and MUST NOT be cited
for runtime rejection.)

*see also:* [RBND.4b](#RBND-4b), [RDSC.16.3.3](#RDSC-16-3-3), [RTCT.3.3](#RTCT-3-3), [RTCT.6.5](#RTCT-6-5), [RTCT.6.7.2](#RTCT-6-7-2)

(RTCT-6-7-7)=
[RTCT.6.7.7] **Capacity bounds.** As in [RTCT.3.3], all
capacity values are uint32 ≤ 2³¹−1; a value exceeding that
bound is `DS_ERR_CONTRACT_INVALID`.

*see also:* [RTCT.3.3](#RTCT-3-3)

(RTCT-6-8)=
[RTCT.6.8] **Cache caps.** `cache_cap` (field 15, max live
cache keys — `uint32` ≤ 2³¹−1 per [RTCT.6.7.7]) and `cache_bytes_cap`
(field 16, cache value byte capacity — **`uint64` ≤ 2⁶³−1**: a byte
capacity warrants 64-bit headroom where a count cap does not, the high
bit staying reserved to mirror [RTCT.6.7.7]) bound the engine-owned cache
([LSTO.4.7]) in the `realtime` / `constspace` slab budget, enforced
per [RTCT.7.1] with breach ⇒ `DS_ERR_CONTRACT_BREACH`. A value over its
bound is `DS_ERR_CONTRACT_INVALID`.

*see also:* [LSTO.4.7](#LSTO-4-7), [RTCT.6.7.7](#RTCT-6-7-7), [RTCT.7.1](#RTCT-7-1)

(RTCT-6-8-1)=
[RTCT.6.8.1] **Canonical hash — omit-when-zero.** The caps join the
`ds.contract.v1` canonical serialization ([RBND.4b]) **only when
non-zero.** A cap-free contract therefore serializes byte-identically to
its form from before the cache caps existed: its `rt_config_sha256` is unchanged and no
existing `.dsrt` binding is revved. A contract that **declares** a cache
cap gets the extra canonical lines; a runtime predating the caps then
recomputes a mismatching hash and rejects the file ([RDSC.16.3.3]) — the
same reject-don't-skip gate. The Python
`canonical_bytes` and the C `emit_canonical` MUST apply omit-when-zero
identically.

*see also:* [RBND.4b](#RBND-4b), [RDSC.16.3.3](#RDSC-16-3-3)

(RTCT-6-9)=
[RTCT.6.9] **The fault-fact pool is not a contract field.** Its size is the
program's fault-fact site count ([LERR.9.10]), which the artefact header carries
for every program, under `realtime` or not. `RealtimeContract` carries no field
for it, a `.dsrt` cannot declare it, and it does not join the
`ds.contract.v1` canonical serialization ([RBND.4b]). The pool is allocated
separately from `wm_max`.

---

*see also:* [LERR.9.10](#LERR-9-10), [RBND.4b](#RBND-4b)

(RTCT-6-10)=
[RTCT.6.10] **`Json` caps.** `json_depth_cap` (field 17), `json_node_cap`
(field 18), `json_string_bytes_cap` (field 19) and `json_text_bytes_cap`
(field 20), all `uint32`, lower the four fixed `Json` limits of [LGRA.5.8.6]
for the tier. `0`, the proto3 default and omitted on the wire, means the fixed
maximum. A non-zero value above its fixed maximum is `DS_ERR_CONTRACT_INVALID`:
a contract may lower a limit and may not raise one. A value over a lowered limit
is refused as one over the fixed limit is ([LGRA.5.8.6]).

*defined in:* [proto/realtime_contract.proto#RealtimeContract](#proto-realtime_contract-proto-RealtimeContract)  —  *see also:* [LGRA.5.8.6](#LGRA-5-8-6)

(RTCT-7)=
## Runtime enforcement [RTCT.7]

*Deferred: not binding in this edition.*

(RTCT-7-7)=
[RTCT.7.7] Per-cap enforcement points. Each entry below
defines the operation that touches the cap and the
comparison; the error returned on breach is uniform across
every row and is stated once in [RTCT.7.2]. Caps are enforced
identically in `rt` and `non-rt` engine modes when a contract
is present; the only difference between modes is pre-
allocation strategy and other RT invariants per [RTCT.12].

**The `Enumerator` column is the binding to `proto/bounds_error.proto#CapName`,
and it is carried rather than derived.** The two spellings do not correspond by
any rule: `agenda_cap` is `CAP_AGENDA`, `token_pool_cap` is `CAP_TOKEN_POOL`,
and `nodes[i].capacity` is `CAP_NODE_CAPACITY`. A gate normalising one into the
other would be a regex nobody can read, wrong in a way only a fixture would
catch, and silent
when it matched nothing. Stating the enumerator makes the reconciliation a set
difference instead.

`CAP_UNSPECIFIED` is deliberately absent from [RTCT.7.1]. It is the protobuf
zero, refused at load, and denotes no cap; `styl_5_9_2_cap_name.sql` excludes it
on the proto side for that reason, exactly as the validate registry excludes
`DS_VALIDATE_UNSPECIFIED`.

*see also:* [RTCT.12](#RTCT-12), [RTCT.7.1](#RTCT-7-1), [RTCT.7.2](#RTCT-7-2)

(RTCT-7-1)=
[RTCT.7.1]

| Cap                          | Enumerator               | Enforced where                                                     | Breach condition                                                                                              |
|------------------------------|--------------------------|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| `wm_max`                     | `CAP_WM_MAX`             | a WM assert                                                        | live fact count + 1 > `wm_max`                                                                                |
| `agenda_cap`                 | `CAP_AGENDA`             | agenda push in beta/terminal activation                            | activations queued + 1 > `agenda_cap`                                                                         |
| `max_fires_per_pump`         | `CAP_MAX_FIRES_PER_PUMP` | the pump fire loop                                                 | fires this pump + 1 > `max_fires_per_pump`                                                                    |
| `token_pool_cap`             | `CAP_TOKEN_POOL`         | beta join token allocation                                         | live tokens + 1 > `token_pool_cap`                                                                            |
| `intern_cap`                 | `CAP_INTERN`             | intern table insert                                                | interned strings + 1 > `intern_cap`                                                                           |
| `intern_bytes_cap`           | `CAP_INTERN_BYTES`       | intern table byte accounting                                       | interned bytes + N > `intern_bytes_cap`                                                                       |
| `pump_wcet_ns`               | `CAP_PUMP_WCET_NS`       | pump-completion timing                                             | observed pump elapsed ns > `pump_wcet_ns`                                                                     |
| `nodes[i].capacity`          | `CAP_NODE_CAPACITY`      | per-node memory (alpha matches, beta tokens, terminal activations) | per-node count + 1 > capacity for the node's kind                                                             |
| `series[i].capacity`         | `CAP_SERIES_CAPACITY`    | series backend append                                              | backend's stored-sample count + 1 > capacity, for an aggregation whose "At capacity" is refuse ([LSER.13.14]) |
| a slot's declared `capacity` | `CAP_VALUE_CAPACITY`     | a fact assert or emit writing the slot ([LSTR.11.3])               | value length in codepoints > `capacity`                                                                       |
| `cache_cap`                  | `CAP_CACHE`              | `cache` write of a new key (dispatcher)                            | live cache keys + 1 > `cache_cap`                                                                             |
| `cache_bytes_cap`            | `CAP_CACHE_BYTES`        | `cache` write value accounting                                     | cache value bytes + N > `cache_bytes_cap`                                                                     |

*checks:* `tla×10` `idris×4`  —  *see also:* [LSER.13.14](#LSER-13-14), [LSTR.11.3](#LSTR-11-3)

(RTCT-7-2)=
[RTCT.7.2] **Breach semantics, for a cap decided on a count the engine
holds.** The breach returns `DS_ERR_CONTRACT_BREACH` from the API call that
triggered the check. The engine MUST NOT mutate state on a breaching
call (the assert / push / fire / append does not happen).
Subsequent calls work normally — the engine is not
"poisoned" — but the operation that breached is rejected.

**Ten of [RTCT.7.1]'s eleven caps are that shape.** `pump_wcet_ns` is not: it
is decided on a measurement taken after the work has already happened, so there
is no operation left to refuse and no intact state to carry forward. It halts
the tier ([RTCT.7.3]).

*checks:* `tla×8`  —  *see also:* [RTCT.7.1](#RTCT-7-1), [RTCT.7.3](#RTCT-7-3)

(RTCT-7-3)=
[RTCT.7.3] **A `pump_wcet_ns` breach halts the tier.** Pump timing is measured
at pump completion. On a breach the engine **must** emit an `EngineError`
carrying `ENGINE_FAULT_PUMP_WCET` and halt the tier — rung 7 of [LERR.1] — and
**must** return `DS_ERR_CONTRACT_WCET_HALT` from the pump that breached. From
there the halt is every `EngineError`'s halt ([NCBK.2.9]): the integrator **must
not** resume service, the engine's state is undefined ([LERR.1.4.7]), and each
later call but the few that clause leaves valid is refused with
`DS_ERR_ENGINE_HALTED`.

**Exceeding the worst-case execution time is a system failure, not a refused
operation.** Ten of [RTCT.7.1]'s caps decide **before** the work happens, so
the operation does not begin and the engine is intact ([RTCT.7.2]). This one
decides **after**. The engine cannot interrupt a pump mid-execution, so by the
time the breach is known the tier has already missed the deadline it exists to
keep — and a real-time tier that has overrun is one whose timing contract no
longer holds, for that pump and for every pump after it. There is no state in
which continuing is safe, which is what puts this cap on rung 7 rather than
rung 2 ([LERR.1.5]).

**This cap reads a measurement, and it is the only one of the eleven that
does.** The other ten compare a count the engine holds; this one compares an
elapsed wall-clock time, which is a property of the host rather than of the
program. Two live runs of one event trace against one contract therefore
disagree about whether the cap was breached whenever their elapsed times fall
either side of it — a loaded host halts where an idle one does not. **No clause
promises that two live runs agree on this cap**, and one that did could not be
honoured by any engine.

**That is not a determinism failure, because [LDET.1.1] scopes the guarantee to
the event trace rather than to live reality.** Live execution is where the
measurement is taken; the trace is what the guarantee is about. Two live runs
at different speeds produce two different traces — one that halts here and one
that does not — and each replays faithfully as itself.

**A trace recording this fault ends with it**, because the tier halted: the
`EngineError` is the last record on the trace ([RFCS.3.1]). A replayer drives
the trace to that point, comparing every atom before it, and stops. The
terminal fault is the recorded run's cause of death rather than an observable
the replay must reproduce, so a replaying host that would not itself have
breached does not report a divergence ([LFST.9.2.1]).

```{admonition} This is the one recorded compare atom a replay does not compare
:class: warning
[LFST.9.3.1] forbids the compare acquiring an exclusion list, and this is not
one. An exclusion list narrows the comparison **within** a run that continues,
so the un-compared thing goes unnoticed while everything after it is still
checked. A terminal fault has nothing after it: the trace ends, and there is no
remainder whose verification it could weaken. The replay reports what it found
rather than passing over it.
```

**No requirement here is written against where a recording ends.** A recording
is evidence of how far one run got, and a run ends for reasons that are the
engine's and for reasons that are not; a host losing power mid-pump ends a trace
as surely as a fault does. Nothing in a recording attests that it is complete
([RFCS.19.8]), so a requirement written against its end would be a requirement
about the power supply.

*checks:* `idris×2`  —  *see also:* [LDET.1.1](#LDET-1-1), [LERR.1](#LERR-1), [LERR.1.4.7](#LERR-1-4-7), [LERR.1.5](#LERR-1-5), [LFST.9.2.1](#LFST-9-2-1), [LFST.9.3.1](#LFST-9-3-1), [NCBK.2.9](#NCBK-2-9), [RFCS.19.8](#RFCS-19-8), [RFCS.3.1](#RFCS-3-1), [RTCT.7.1](#RTCT-7-1), [RTCT.7.2](#RTCT-7-2)

(RTCT-7-4)=
[RTCT.7.4] **No "soft" mode.** There is no environment
variable, runtime flag, or build option that downgrades
`DS_ERR_CONTRACT_BREACH` to a warning. The author
guaranteed the bounds; the engine enforces them. Soft mode
would invite contracts that aren't honest, which is
exactly what this spec exists to prevent.

(RTCT-7-5)=
[RTCT.7.5] **`realtime` absent.** A `.dsc` whose dialect
does not include `realtime` carries no `RealtimeContract` atom and
therefore no caps. The engine treats every per-cap check
as unconditionally satisfied. The engine remains in
"unbounded pools" mode and pool growth proceeds normally.
This is the path for development, debugging, and non-RT
deployments.

---

(RTCT-7-6)=
[RTCT.7.6] **RT-safety is checked at LOAD, not at evaluation.** A `.dsc` whose
dialect resolves `realtime` **must** be refused at load if it contains a call
to an operation the runtime does not hold to be RT-safe — bounded time, bounded
space, no allocation. The refusal is a load error, alongside the other
capability refusals, and names the operation.

**Why load and not first fire.** A per-activation check discovers the breach
only when the offending rule happens to fire, which may be days in. Until then
the artefact has been accepted, `ds_engine_go_live` has succeeded, and the
deployment reads as conforming — so the failure arrives as a trap in the field
rather than as a refusal at deploy, on the one profile whose entire purpose is
that its costs are known **before** it runs.

It also cannot be reconciled with the contract itself. `[RTCT.7.2]` enforces
caps against declared bounds, and a WCET bound over a rule set containing an
unbounded operation is not a bound that was ever satisfiable. Admitting the
artefact and trapping later asserts a guarantee the artefact cannot keep.

**The set of RT-safe operations is the runtime's to declare and is not an
author surface.** An author writes the same language under `realtime`; what
changes is which of it the profile admits, which is `[LCAP]`'s model and not a
second dialect.

---

*see also:* [RTCT.7.2](#RTCT-7-2)

(RTCT-7-8)=
[RTCT.7.8] **Capability refusal is a load error.** An artefact whose rules can
reach a builtin that is not `rt_safe` ([IRET.13.3]) **must be refused at load**
under `realtime`, with `DS_ERR_RT_UNSAFE`. It must not be accepted and then
declined per-activation.

**Why the load and not the activation.** A realtime contract is a promise made
before the engine runs. An artefact accepted at load and refused mid-cycle has
already been promised for, and the integrator learns the promise was unkeepable
at the first fact that reaches the rule — which may be long after go-live and
is not reproducible from the artefact alone. Refusing at load makes the
contract checkable when it is offered.

**Which component performs the check is not specified here.** The compiler
knows every builtin a rule can reach and the loader holds the registration
table, so either can answer; what this clause fixes is that the answer arrives
**before any fact is processed**, and that the artefact is rejected rather than
degraded.

This is rung 1 of `[LERR.1]` — nothing is abandoned because nothing has
started. It is not a `TypeError`: a `TypeError` abandons one activation, and an
artefact that cannot honour `realtime` is not a per-activation condition.

*see also:* [IRET.13.3](#IRET-13-3), [LERR.1](#LERR-1)

(RTCT-8)=
## Relation to the binding spine [RTCT.8]

*Deferred: not binding in this edition.*

(RTCT-8-1)=
[RTCT.8.1] The contract is the source of every value that
[RBND.4b] canonical RT-config serialization hashes. `.dsrt`
content + the compiler's canonicalization rules produces a
`rt_config_sha256` that:

  - is embedded in the `RealtimeContract` atom body ([RTCT.6.2] field 10);
  - is duplicated into `DscHeader.rt_config_sha256` ([RDSC.3]);
  - flows into every artifact the engine produces (fact
    stream `StreamHeader`, DAP trace `.dsr` meta) per [RBND.2];
  - is cross-checked at every load-pairing per [RBND.5].

*see also:* [RBND.2](#RBND-2), [RBND.4b](#RBND-4b), [RBND.5](#RBND-5), [RDSC.3](#RDSC-3), [RTCT.6.2](#RTCT-6-2)

(RTCT-8-2)=
[RTCT.8.2] Two `.dsc` files share `rt_config_sha256` iff
their `contract:` sections are byte-equal under the
canonical serialization. Different sources, different
basenames, different authors — if the canonical bytes
match, the hash matches. The hash is content-addressed.

(RTCT-9)=
## Error codes [RTCT.9]

*Deferred: not binding in this edition.*

(RTCT-9-1)=
[RTCT.9.1] Compile-side errors are issued by the compiler
and are not part of the runtime `ds_status_t` space
([LERR.8]) — they carry no number and appear in no band:

```
DS_VALIDATE_COMPILE_MISSING_DSRT             /* realtime without sibling .dsrt */
DS_VALIDATE_COMPILE_DSRT_WITHOUT_REALTIME    /* .dsrt present, realtime not */
DS_VALIDATE_COMPILE_CONTRACT_INCOMPLETE      /* missing node/series entry, missing required scalar */
```

*see also:* [LERR.8](#LERR-8)

(RTCT-9-1-1)=
[RTCT.9.1.1] **Reserved names.** `DS_ERR_COMPILE_MISSING_DSRT`,
`DS_ERR_COMPILE_DSRT_WITHOUT_REALTIME` and
`DS_ERR_COMPILE_CONTRACT_INCOMPLETE` are out of use and **never
reused** ([STYL.2.8.7]).

A compiler diagnostic does not take the `DS_ERR_` prefix: that prefix is the
runtime status registry's ([LERR.8.1]), for values an integrator receives from
a call and compares against, and the diagnostics above are raised as strings,
reachable by no caller.

*see also:* [LERR.8.1](#LERR-8-1)

(RTCT-9-2)=
[RTCT.9.2] Runtime errors are the -710 band, defined by [NERR.12.1] and [NERR.18]:

```
DS_ERR_CONTRACT_BREACH                  -710
DS_ERR_CONTRACT_MISSING                 -711   /* realtime DSC with no RealtimeContract atom */
DS_ERR_CONTRACT_INVALID                 -712   /* malformed RealtimeContract payload / hash mismatch */
DS_ERR_RTCT_PROFILE_REFUSES_DSRT        -713   /* profile binary asked to write to .dsrt */
DS_ERR_CONTRACT_WCET_HALT               -714   /* pump exceeded pump_wcet_ns; tier halted */
```

*see also:* [NERR.12.1](#NERR-12-1), [NERR.18](#NERR-18)

(RTCT-9-3)=
[RTCT.9.3] Binding errors (`DS_ERR_BND_*`) surface through
band 700 unchanged per [RBND.7].

---

*see also:* [RBND.7](#RBND-7)

(RTCT-11)=
## Cache seed [RTCT.11]

*Deferred: not binding in this edition.*

(RTCT-11-1)=
[RTCT.11.1] A **cache seed** ([IARC.12]) is a setup-only
write of the engine-owned cache. It must be issued **before** `go_live`; after
the engine goes live the runtime must reject it with `DS_ERR_RT_LIVE`, as for any
state-shaping operation forbidden in the live phase. A seed performs no
allocation or blocking beyond the store write itself, so it does not bear on the
live-phase timing contract.

*see also:* [IARC.12](#IARC-12)

(RTCT-11-2)=
[RTCT.11.2] A seed is a **cap-counted** write: it is charged against `cache_cap`
/ `cache_bytes_cap` exactly as a rule `cache` write is, enforced at the store
before any mutation ([RTCT.7.1]). A breach returns `DS_ERR_CONTRACT_BREACH` and
leaves the cache unchanged — restoring a snapshot larger than the configured
caps fails loudly at setup rather than silently truncating.

---

*see also:* [RTCT.7.1](#RTCT-7-1)

(RTCT-10)=
## One contract per program, fixed at compile time [RTCT.10]

- **A `.ds` file pairs with at most one `.dsrt`.** Two rule files needing similar
  contracts each carry their own.
- **The contract is fixed at compile time and frozen into the
  `.dsc`.** The runtime never adjusts it, and there is no
  renegotiation protocol. Changing a cap means recompiling.

Choosing the headroom values themselves is an engineering judgement
this spec does not make; it governs the contract once chosen.

*Deferred: not binding in this edition.*

(RTCT-12)=
## The T_wcet bound [RTCT.12]

`pump_wcet_ns` ([RTCT.3.2]) is the number a `.dsrt` commits to. This section
is where that number comes from: the structural bound on a pump cycle, the
bound on the mutations between cycles, and the method by which a platform's
coefficients are established.

Every parameter below is a deployment-time constant once `engine->live`
([NRTM.5.2]).

*Deferred: not binding in this edition.*

*see also:* [NRTM.5.2](#NRTM-5-2), [RTCT.3.2](#RTCT-3-2)

(RTCT-12-1)=
### Structural formula — one pump cycle [RTCT.12.1]

The worst-case execution time of one pump cycle is bounded by:

```
T_run = c_alpha  × R × N_max
      + c_beta   × max_fires × k_max
      + c_agenda × max_fires × log2(max_fires)
      + c_fire   × max_fires × A_max
      + c_ttl    × expired_max × log2(N_max)
      + c_cache  × cap_keys
```

| Term | Big-O | Meaning |
|---|---|---|
| `c_alpha × R × N_max` | O(R × N_max) | alpha dispatch per newly asserted fact × R alpha nodes matching that schema × N_max worst-case activations |
| `c_beta × max_fires × k_max` | O(max_fires × k_max) | beta join propagation per activation, bounded by the token budget |
| `c_agenda × max_fires × log₂(max_fires)` | O(M log M) | agenda heap insert/pop for M = max_fires activations |
| `c_fire × max_fires × A_max` | O(max_fires × A_max) | firing loop: max_fires activations, each with A_max actions |
| `c_ttl × expired_max × log₂(N_max)` | O(expired × log N) | deadline-heap drain plus the fact-retract cascade |
| `c_cache × cap_keys` | O(cap_keys) | the cache-expiry sweep at pump entry ([NSTG.2.4.2]) |

The cache term is **linear in the cap, not in the number of expiries**: the
sweep looks at every entry to find the expired ones, so a deployment pays for
the cache it permitted rather than the one it used. A large `cap_keys` with a
nearly empty cache still costs a full walk each pump. Sizing the cap is
therefore a WCET decision, not only a memory one.

Every parameter derives statically from the `.dsc` and the deployment-time
`N_max` declaration. The `c_*` coefficients are hardware-dependent and must be
measured per platform ([RTCT.12.4]).

*see also:* [NSTG.2.4.2](#NSTG-2-4-2), [RTCT.12.4](#RTCT-12-4)

(RTCT-12-2)=
### Mutations between pump cycles [RTCT.12.2]

[RTCT.12.1] bounds the pump. In LIVE the same discipline binds the
mutations that happen between pump calls:

```
T_assert(fact)  = c_wm_insert
                + c_dlheap × log N_ttl          (if the fact has a TTL)
                + c_alpha × A_s × T             (alpha test + insert)
                + c_beta_right × matched × T_j  (for EQ-join betas)
                + c_beta_right × L_β × T_j      (for non-indexed betas)
                + c_agenda × log A              (activation insertion)

T_retract(fact) = c_wm_remove
                + c_dlheap × log N_ttl          (if the fact had a TTL)
                + c_alpha × A_s                 (alpha memory remove)
                + c_beta_ridx × joined × k      (ridx-based retract)
                + c_tms × n_ids                 (if a logical fact)

T_tick_ttl(expired) = c_dlheap × expired × log N_max   (`dynamic_ttl`, heap)
                    + T_retract × expired

T_tick_ttl(expired) = c_fifo × (expired × log n_ttl_schemas + n_ttl_schemas)   (default FIFO queue)
                    + T_retract × expired
```

The full-cycle bound is therefore:

```
T_wcet = T_init_cycle                     (clock cache refresh, budget reset)
       + n_asserts  × T_assert
       + n_retracts × T_retract
       + T_tick_ttl(max_expired_per_tick) (default) or T_tick_ttl(expired_max)
       + T_run(max_fires)                 ([RTCT.12.1])
```

`T_init_cycle` is O(1); `n_asserts` and `n_retracts` are bounded by `N_max`.

Under `linear_scan: false` with default TTL every parameter is a compile-time constant —
`max_expired_per_tick` derives per [LDTL.7.2], `F_max` / `A_max` / `E_rhs` are
`.dsc` topology constants, and `n_ttl_schemas` is fixed at load. The formula
then evaluates to a single fixed number: **`T_wcet` is O(1) in `N_max`** under
that configuration. [LDTL.7.1]–[LDTL.7.4] carry the derivation.

*see also:* [LDTL.7.1](#LDTL-7-1), [LDTL.7.2](#LDTL-7-2), [LDTL.7.4](#LDTL-7-4), [RTCT.12.1](#RTCT-12-1)

(RTCT-12-3)=
### Establishing the coefficients for a platform [RTCT.12.3]

The `c_*` coefficients in [RTCT.12.1] and [RTCT.12.2] are hardware-dependent. A
deployment must measure them on its **target** hardware; a figure measured on a
development host is not a bound for a device.

The method:

1. Measure the pump on the target, under the gate's own thresholds, to obtain
   that platform's numbers.
2. Regenerate the latency and allocation evidence below from those
   measurements.
3. Drive the measurement with an **adversarial** workload, not a representative
   one — several rules, several new facts per cycle, and a sweep over `N_max`.
   A workload chosen to be typical measures the typical case, which is not what
   `pump_wcet_ns` promises.

What the charts must establish, and why each is a proof rather than a
visualisation:

| Evidence | What it proves |
|---|---|
| Latency CCDF, log-log, all `N_max` | a hard cutoff at pmax with **no long tail**. A tail is the signature of allocation or GC on the pump path. |
| Per-cycle latency trace | a fill phase followed by a flat plateau. Flatness proves no hidden state accumulation and no periodic spike. |
| pmax vs `N_max` | for single-pattern rules pmax is approximately constant in `N_max` — WM size does not drive pump latency. Join rules add the beta term of [RTCT.12.1]. |
| Allocation count per cycle | zero allocations across every config and cycle, **beside a non-RT control run showing non-zero**. Without the control the zero is indistinguishable from a dead counter. |

That last row is the one that carries the contract. A zero-allocation result with
no positive control is not evidence ([STYL.5.10.5] states the same principle for
gates).

*see also:* [RTCT.12.1](#RTCT-12-1), [RTCT.12.2](#RTCT-12-2)

(RTCT-12-4)=
### Zero-allocation and intern-stability obligations [RTCT.12.4]

The bound in [RTCT.12.1] holds only if the pump path allocates nothing. Two
properties must be verified on every build, not asserted:

**Zero allocation.** A pump cycle must call `malloc` / `calloc` / `realloc`
exactly zero times when RT mode is active, the pools are ready, and the RT
tables were pre-sized after all schemas and rules were loaded. The engine
verifies this by intercepting the allocator through the linker's `--wrap`
mechanism, so the count is observed rather than reasoned about.

For two-pattern join rules the guarantee holds while the left-memory size per
beta node at right-activate time is at most `DS_RIDX_INLINE`. A configuration
that may exceed that bound must pre-allocate its heap tokens during INIT.

**Intern stability.** The string-intern resize count must not change during a
pump cycle. This is structural rather than incidental: locking the intern table
at pre-size time makes interning return `DS_ERR_OOM` instead of growing,
and in LIVE the engine only looks up strings interned at load time. A cycle that
interns a new string has left the bound.

Both are enforced in CI against the `pump_wcet_ns` cap ([RTCT.3.2],
[RTCT.7.1]); a pump exceeding it halts the tier with
`DS_ERR_CONTRACT_WCET_HALT` ([RTCT.7.3]). There is no environment-variable override and no
soft mode — a different timing budget is a different `.dsrt`, and therefore a
different `.dsc` ([RARC.4]).

*see also:* [RARC.4](#RARC-4), [RTCT.12.1](#RTCT-12-1), [RTCT.3.2](#RTCT-3-2), [RTCT.7.1](#RTCT-7-1), [RTCT.7.3](#RTCT-7-3)

