Skip to content

make_id

autogen.beta.network.ids.make_id #

make_id()

Return a fresh, best-effort time-ordered 32-char hex string.

The leading 8 bytes are the big-endian nanosecond wall clock; the trailing 8 bytes are random for uniqueness. Two ids minted in the same clock tick share the time prefix and so sort only by their random suffix — fine for ids that need only uniqueness (agent, channel, endpoint, request). Anything that must sort in strict creation order — envelope ids, which the delivery cursor and reconnect replay compare by sort order — must come from :class:_MonotonicIds instead.

(uuid.uuid7 would give strict ordering but exists only on 3.14+, and uuid.uuid4 is unordered, so neither is a portable basis.)

Source code in autogen/beta/network/ids.py
def make_id() -> str:
    """Return a fresh, best-effort time-ordered 32-char hex string.

    The leading 8 bytes are the big-endian nanosecond wall clock; the
    trailing 8 bytes are random for uniqueness. Two ids minted in the same
    clock tick share the time prefix and so sort only by their random
    suffix — fine for ids that need only uniqueness (agent, channel,
    endpoint, request). Anything that must sort in *strict* creation order
    — envelope ids, which the delivery cursor and reconnect replay compare
    by sort order — must come from :class:`_MonotonicIds` instead.

    (``uuid.uuid7`` would give strict ordering but exists only on 3.14+,
    and ``uuid.uuid4`` is unordered, so neither is a portable basis.)
    """
    return time.time_ns().to_bytes(8, "big").hex() + os.urandom(8).hex()