Skip to content
open.blog documentation
open.blog

ADR 0165: A suggestion's stored details are held to a bound below the column's check, measured as Postgres measures them

Context#

The submission is bounded at 12 KiB as sent, and details has a check of octet_length(details::text) <= 16384. A link is stored percent-encoded and re-written, so a CJK address of three bytes a character is nine bytes stored, and Postgres writes jsonb text with a space after every : and ,. A suggestion that passed the 12 KiB check could therefore exceed 16 KiB when stored and fail its insert, every time, with a 502.

Decision#

  • A submission whose stored details would exceed 11 KiB is refused with tooLarge, by both Submission::from_json and the browser's readSuggestionSubmissionJson, at the same point, so the form says it is too long and the function stores nothing. The size is measured as Postgres measures details::text: the compact JSON plus one byte for every : and , outside a string, of exactly {type, url?, hints?, about?, contact?}. 11 KiB leaves the room eight links need at their widest (ADR 0162), and a test sums them.
  • A shared fixture case (links of three-byte characters that percent-encoding makes too large for the stored row) holds both sides to it; tests/fixtures/future-suggestion-submissions.json is regenerated by the Rust side.
  • The whole stored record is read under 32 KiB, not 16 KiB. A record is the text (the row's body, at most 8,000 bytes), details (under its own 16 KiB check) and the name, receipt and revision (about 1.5 KiB), so a text of four-byte characters with links at the details bound made a record of 18.5 KiB that was stored and then refused on reading. The columns already bound each part; MAX_JSON_BYTES is now their sum with room to spare, one limit, so every accepted submission still reads back after eight links and a clarification. A shared fixture case and a test with eight widest links and a clarification hold it.

View this page's source