ROS 2 transient-local durability lets a publisher retain samples for subscriptions that join after those samples were written. It is useful for a robot's current operating mode, a map revision, a calibration identifier, or another value that a restarting consumer needs immediately. The policy does not create an unlimited topic archive. The living publisher is responsible for the retained history, the history and depth policies bound what can remain, resource limits still apply, and the subscriber must request compatible durability to receive old samples.

Publisher-local retention

The official ROS 2 QoS documentation defines transient local by making the publisher responsible for persisting samples for late-joining subscriptions. That local responsibility distinguishes it from a separate database or a durable service that outlives the writer. When the original publisher is destroyed or its process exits, application code must not assume another process will preserve its transient-local cache.

This makes publisher lifetime part of the interface. A map server that publishes map_revision=17 with transient-local durability can serve that value to a compatible subscriber that starts later while the publisher and its retained history remain available. If the server exits and restarts without republishing revision 17, a new subscriber has no basis for expecting the previous process's cache.

If the value must survive publisher restart, store it in an authoritative application data source and republish it after recovery. Transient local can improve startup behavior; it should not be the only persistence mechanism for configuration that must survive process or host loss.

History and depth bound the cache

QoS policies combine into a profile. KEEP_LAST retains up to the configured depth for each applicable history scope. A transient-local publisher with KEEP_LAST depth 1 offers the latest retained sample, not every prior update. With depth 3, at most the relevant last three samples are requested from the history policy, subject to middleware resource limits and other constraints.

KEEP_ALL means retain all samples subject to the underlying middleware's resource limits. It does not mean infinite memory. A publisher that updates a keyed state or sends large messages can reach limits long before an operator thinks of the topic as high rate. The system needs an explicit capacity budget: number of instances, samples per instance, payload size, update rate, and expected late-join window.

Depth also changes the meaning of startup data. For a current-mode topic, depth 1 may be exactly right. For a short sequence of initialization records, the subscriber may require several samples in order. If those records have a transactional meaning, a topic cache alone may be insufficient because joining in the middle of a bounded sequence can yield an incomplete state.

Both endpoints participate

Durability follows the ROS 2 requested-versus-offered compatibility model. A volatile publisher cannot satisfy a subscription that requests transient local, so the endpoints do not communicate. A transient-local publisher can communicate with a volatile subscription, but that subscription receives new messages only. To obtain both old and new messages in the documented compatibility table, the publisher and subscription both use transient local.

This is a common source of misleading tests. A publisher is configured as transient local, a command-line or diagnostic subscriber starts later with volatile durability, and no historical sample appears. The absence does not prove that the publisher failed to retain data. It can be the expected behavior of the subscriber's request. Capture the actual requested and offered profiles before changing network or discovery settings.

Other policies still matter. Reliability, history, depth, lifespan, deadline, and liveliness remain separate decisions. Compatible durability does not override an incompatibility elsewhere in the QoS profile. A retained sample can also become unavailable for reasons outside transient-local durability, such as history eviction, resource constraints, or configured lifespan expiration.

Design state topics deliberately

Use transient local for state that has a clear meaning when replayed to a new consumer. Include a revision, generation, or epoch in the payload so the subscriber can compare the retained value with its own state. If the value can become unsafe or irrelevant with age, include application freshness data and define an explicit rejection rule.

Avoid using transient local for commands with irreversible side effects. A late subscriber receiving an old command can mistake historical delivery for a new instruction. ROS 2's service profile deliberately uses volatile durability to reduce the risk that a restarted server receives stale requests. Topics carrying commands need a similar application-level decision about replay, identity, expiration, and idempotency.

Separate snapshots from event streams. A snapshot topic can use depth 1 and a complete state object. An event stream may use volatile delivery plus a durable application log, sequence numbers, and a recovery query. Trying to reconstruct a complete robot state from a small transient-local event cache creates ambiguous startup behavior.

Test the late-join boundary

Create a publisher with a recorded QoS profile and publish uniquely numbered samples. Start a matching transient-local subscriber after publication and verify which sequence numbers arrive. Repeat with depths 1, 3, and a deliberately constrained resource configuration. Confirm that the received history matches the documented capacity rather than the total number ever published.

Start a volatile subscriber late. It should match a transient-local publisher for new traffic but should not be treated as a consumer of retained history. Then request transient local from a subscriber against a volatile publisher and verify the incompatible-QoS evidence. This distinguishes history behavior from a discovery or topic-name problem.

Restart the subscriber while leaving the publisher alive; retained samples should still be eligible for the compatible late joiner. Next restart the publisher and do not republish. Verify that a fresh subscriber does not magically recover the former process's cache. Finally, restart the publisher and explicitly restore and republish authoritative state, showing that recovery comes from application persistence rather than a presumed immortal QoS cache.

Observe more than message arrival

Log the publisher identity, writer process lifetime, requested and offered QoS, history kind, depth, payload revision, publication time, subscriber start time, and whether each sample was historical or newly published if the implementation exposes that distinction. Track incompatible-QoS events and resource-limit diagnostics. A screenshot showing one value after startup does not establish which mechanism delivered it.

For each state topic, document the fallback when no retained value arrives. A robot can wait for a current sample, query a service, load a signed local configuration, or enter a restricted mode. Silence should be a defined condition rather than implicit permission to use an unknown previous value.

Transient local answers a narrow question: can this publisher offer eligible retained history to a compatible late-joining subscription while that publisher and cache are available? It does not promise unlimited depth, survival across publisher restart, application freshness, or safe command replay. Treat writer lifetime, history capacity, endpoint compatibility, and recovery behavior as parts of one explicit startup contract.