Durable offset and replay layout#
Nonzero offsets use a 16-digit append ordinal, an underscore, and a 32-character lowercase hexadecimal history identifier. The ordinal advances once per committed nonempty stored frame. Payload size does not change it. A retry, rolled-back append or close-only request consumes no ordinal. Fixed widths preserve lexical ordering within every valid stream history. The protocol zero token is 0000000000000000_0000000000000000; it is the reserved beginning of every stream. Clients treat nonzero tokens as opaque.
Each generation starts its own write history. Forks inherit tokens through their anchor. Any partial source prefix is a new child frame with the child's history identifier. A new serving epoch lazily starts a fresh write history on the first subsequent append; surviving prefix tokens remain valid. Existing hot data rotates before new history is sealed, and a chunk contains only one write history. A chunk's first start token can belong to the preceding span or inherited parent.
A sealed manifest stores its first and final tokens, frame count, total payload size and one packed entry per verified block. Every ordinal strictly after the first token through the final token is a valid boundary only with that chunk's history identifier. No per-append row, offset array or byte-length array remains in Postgres after publication. Lengths and JSON element boundaries live inside verified object blocks.
Replay selects authorized generation and capped ancestry, captures staging bytes or immutable manifests in one database snapshot, and pins selected objects before releasing the snapshot. The Function expands the packed block directory and chooses a page bounded by bytes, frames and 64 immutable objects. SQL uses the maximum contributing ordinal and orders capped ancestry by logical starts, so discarded physical tails cannot hide an earlier prefix. Boundary blocks use their whole payload size as a safe planning bound. A page may include one block crossing its byte target; verified frame lengths set the final exact response boundary before headers. Matching conditional requests skip object I/O when the directory already determines that boundary. Other conditionals finish verification before comparing their exact validator.
The directory permits range addressing after planning. Putting a chunk number and physical position in the public token would still require path authorization, generation and ancestry validation, expiry handling, serving-epoch fencing, publication discovery for hot/age-sealed data, and collection protection. It would not remove a SQL request from this path. It would also add chunk-rollover rules to every writer and fork. The ordinal/history design instead removes the permanent per-append index while leaving object size, block size and response page size independent.
The critical recovery test retains append 100, discards the following history, and rewrites through 110. The abandoned token for 105 must fail both reads and acknowledgements before and after sealing; the surviving token at 100 and rewritten token at 105 must work. Provider recovery drills additionally test actual Neon branch and in-place restore APIs.