Skip to content

docs(remote): write down what bounds one history reply - #861

Merged
huichen merged 1 commit into
mainfrom
docs/payload-boundary
Sep 25, 2026
Merged

huichen merged 1 commit into
mainfrom
docs/payload-boundary

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

The page byte budget (BACKWARD_HISTORY_PAGE_BYTES, 512 KiB) exists to stay under NATS's 1 MiB payload limit — but it is a soft bound, and the layers that make it safe were not written down. This records them beside the budget they belong to.

Why now

Closing a follow-up from the real-broker verification, which flagged that one sample's undeclared paged reply sat ~8.6 KB from the broker's default max_payload. Re-measured on a real nats-server v2.15.0 (--samples 3 --broker both, all three liveEqual/historyEqual: true):

sample undeclared paged (wire) headroom to 1 MiB lean, same page
1 492,311 556 KB 511,885 (1,356 entries vs 279)
2 422,480 626 KB 280,967
3 1,032,942 15,634 B 114,222 (9× smaller)

So the near-limit page is real, is relayed intact, and the trim is what keeps it away.

What the doc now says

  • The budget sheds whole oldest exchanges and stops when only the newest remains, so a single exchange larger than 512 KiB is not deferred — a page can approach the limit.
  • A lean page deliberately fills the budget (511,841 of 524,288 observed): fitting more entries is the point of trimming before the budget.
  • Oversize is an explicit error, never a silent drop: encode_reply_payload checks MAX_PLAINTEXT (1 MiB − header − tag, sized so a sealed record is exactly ≤ 1 MiB) and answers remote_reply_too_large.
  • The phone never leans on this: history/replay reads use requestReadPage (chunkedRead: true) and reassemble ≤192 KiB chunks, so no single record is near the limit.

Docs only — no code, no behavior. python3 scripts/docs/check-docs.py — 205 docs OK.

The page byte budget (512 KiB) exists to stay under NATS's 1 MiB payload
limit, but it is a soft bound: it sheds whole oldest exchanges and stops when
only the newest one is left, so a single exchange larger than 512 KiB is not
deferred. Measured on a real session, a non-chunked newest page came within
15.6 KB of the limit and was relayed intact; the same page is 114,222 bytes
for a lean client, which is what keeps it away.

Record the whole chain where the budget is described: the soft bound and its
single-exchange residual, that a lean page deliberately fills the budget
(511,841 of 524,288 observed), that oversize is an explicit
`remote_reply_too_large` rather than a silent NATS drop, and that the phone
takes the chunked path so no single record approaches the limit.

Found while closing a follow-up from the real-broker verification: the
near-limit page was worth confirming over an actual nats-server, and it passes
(three samples, liveEqual/historyEqual both true on the real broker).
@huichen
huichen enabled auto-merge (squash) September 25, 2026 22:06
@huichen
huichen merged commit 6db1684 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the docs/payload-boundary branch September 25, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant