The delivery policy is per subscription (L4 graph)¶
delivery_policy_t is a packed 16-bit field describing one producer→subscriber
relationship, carried in the SUBSCRIBER TLV’s SETTINGS child
(RFC-0022 §3.A).
The host sugar takes the same bits, so the two doors stay byte-identical. This example puts
two subscribers on one producer that already holds a value, and differs them by one bit.
What to notice¶
Bit 5,
durability_request, is the transient-local latch. Set, it delivers the producer’s latched last value once at subscribe time; clear (the all-zero default), the join delivers nothing. Both edges take the next write either way — the example asserts that too, so a subscribe that silently failed to register could not pass.The ablation is the point. Both subscribers sit on the same producer, holding the same value, admitted through the same door, and they differ. Before RFC-0022 a single
settings.durabilityknob on the vertex decided this for both, and this pair could not be expressed.reliability(bits 0–1) andpriority(bits 2–4) are stored and read back, not honoured. They await the transport work that would consume them — the honest shape RFC-0022 §3.E chose over moving dead per-vertex fields. Do not read this example as showing a QoS engine; it shows the one bit that is live today.Reserved bits are carried verbatim. Bits 6–15 must be written zero and ignored on read, and a policy differing only there is not the same bytes.
Storage stayed on the vertex. History depth and the pin ratio are declared owner-side through the host API and have no wire surface at all (§3.B–§3.D); the vertex’s
:settingscore namespace answersSCHEMA_NOT_FOUNDfor every flat knob name.
Source¶
1/*
2 * SPDX-License-Identifier: Apache-2.0
3 * SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
4 */
5
6/**
7 * @file
8 * @brief The delivery policy is PER SUBSCRIPTION — `durability_request` replays the
9 * producer's latched last value on join (RFC-0022 §3.A).
10 *
11 * `delivery_policy_t` is the packed 16-bit field a wire subscriber carries in its
12 * `SUBSCRIBER.SETTINGS` child; the host sugar takes the same bits. Bit 5,
13 * `kDurabilityRequest`, is the one bit the reference implementation consumes today: the
14 * requesting subscriber gets one delivery at subscribe time carrying the producer's
15 * last-known-value. Two subscribers on the SAME producer differ, which is what makes the
16 * policy per-subscription rather than per-vertex.
17 *
18 * Runs under ctest as `example_sub_durability_latch`; it self-checks and returns non-zero
19 * on any mismatch.
20 */
21
22#include <cstddef>
23#include <cstdint>
24#include <cstdio>
25
26#include "libtracer/tracer.hpp"
27
28namespace {
29
30using tr::graph::delivery_policy_t;
31using tr::graph::path_t;
32using tr::graph::role_t;
33
34/** @brief A one-byte VALUE view over @p b (one heap segment). */
35tr::view::view_t value_byte(std::uint8_t b) {
36 tr::view::segment_ptr_t seg = tr::view::heap_alloc(1);
37 seg->bytes[0] = std::byte{b};
38 return tr::view::view_t::over(std::move(seg));
39}
40
41/** @brief Record a failed expectation on @p ok and report it. */
42void check(bool& ok, bool cond, const char* what) {
43 if (!cond) {
44 std::printf(" [FAIL] %s\n", what);
45 ok = false;
46 }
47}
48
49} // namespace
50
51int main() {
52 tr::graph::graph_t g;
53 const tr::graph::vertex_handle_t src =
54 g.register_vertex(path_t("/sensor/temp"), role_t::STORED_VALUE);
55 (void)g.write(src, value_byte(0x5A)); // a last-known-value EXISTS before either join
56
57 int durable_seen = 0, plain_seen = 0;
58 std::uint8_t latched = 0;
59 auto on_durable = [&](const tr::view::rope_t& v) {
60 ++durable_seen;
61 latched = std::to_integer<std::uint8_t>(v.only().bytes()[0]);
62 };
63 auto on_plain = [&](const tr::view::rope_t&) { ++plain_seen; };
64
65 (void)g.subscribe(path_t("/sensor/temp"), on_durable,
66 delivery_policy_t{delivery_policy_t::kDurabilityRequest});
67 (void)g.subscribe(path_t("/sensor/temp"), on_plain); // all-zero policy = today's default
68 const int join_durable = durable_seen, join_plain = plain_seen;
69 const std::uint8_t join_latched = latched;
70 std::printf("on join: durable=%d (0x%02x), plain=%d\n", join_durable, join_latched, join_plain);
71
72 (void)g.write(src, value_byte(0x77));
73 std::printf("after one write: durable=%d, plain=%d\n", durable_seen, plain_seen);
74
75 bool ok = true;
76 check(ok, join_durable == 1 && join_latched == 0x5A,
77 "the request latched the current value on join");
78 check(ok, join_plain == 0, "the same producer delivered nothing to the non-requesting edge");
79 check(ok, durable_seen == 2 && plain_seen == 1, "both edges take the later write");
80 std::printf("RESULT %s\n", ok ? "ok" : "FAILED");
81 return ok ? 0 : 1;
82}
See also: graph module · protocol TLVs · communication flows.