Skip to content

fix(format2): freeze the format-2 specification and escape the stored writer version - #254

Merged
gouyt13 merged 2 commits into
dev/0.9from
fix/format2-spec-freeze
Nov 19, 2026
Merged

gouyt13 merged 2 commits into
dev/0.9from
fix/format2-spec-freeze

Conversation

@gouyt13

@gouyt13 gouyt13 commented Nov 19, 2026

Copy link
Copy Markdown
Member

Summary

0.9 is the first release that writes index format 2. Once it ships, its reader binds every later format-2 file (the order and overlap checks run before the reader looks up a section's kind, so they also bind optional sections added later), so docs/formats.md must state exactly what the reader enforces. Two commits:

1. docs(format2): freeze the specification.

  • Layout rule. The old text ("empty sections take no bytes and may share an offset. Table entries are in non-decreasing offset order") allowed an empty section at the start of, or inside, the previous section, for example A@192 size 100 then B@192 size 0; the reader rejects that ("overlaps the previous section or is out of order"), and the writer never produces it. The rule now states what reader and writer do: each section starts at or after the end of the previous table entry; an empty section takes no bytes, several may share an offset, and the next section may start at it. Under this rule section ends never decrease, so the existing "the file ends where ... the last section ends" sentence is exact.
    • Changing the reader instead was considered and rejected: it would add a special case (tracking the largest non-empty end) for a layout no writer needs. The planned RaBitQ-SSD integration writes sections sequentially and needs nothing more.
  • Drops the "draft" status and closes the open question (the header is not a blob).
  • Header growth is per release within version 2 (the text said "a later version may append fields", but any version other than 2 is rejected).
  • States reader behavior the text implied otherwise: the checksum of a known section is verified exactly when checksummed is set; a known kind is read whatever its required bit.
  • Reading step 5 lists the per-entry checks in the reader's order.
  • The list of replaced IVF layouts adds RBFQRAW1 and the unversioned layout; stale proposal wording (hnsw_levels, quant raw-array plan, golden test) is updated.
  • New test PlacesEmptySectionsByTheLayoutRule pins the rule.

2. fix(format2): escape the stored writer version in error messages.
Readers do not validate writer_version, but two FormatError messages embed it. A byte outside printable ASCII reached Python's error conversion, which decodes messages as UTF-8, so loading such a file raised UnicodeDecodeError instead of rabitqlib.FormatError (reproduced with an unknown incompat bit and 0xFF in writer_version). The messages now show those bytes, and backslashes, as \xNN; Reader::writer_version() still returns the stored bytes. No other file-derived string reaches a format-2, IVF, HNSW, SymphonyQG or blob error message.

Found during a pre-release check of dev/0.9.

Testing

Local, Linux x86-64, GCC 14.3, Release, RABITQ_ENABLE_NATIVE_OPTIMIZATION=OFF:

  • ctest --no-tests=error: 612 passed, 1 skipped (ThreadCount.BoundParallelForUsesRuntimePlacementAndPropagatesErrors, also skipped without the change).
  • Python suite against the package installed from this branch (Python 3.13): 1206 passed, 2 skipped. New test_non_ascii_writer_version_still_raises_format_error; the same file raised UnicodeDecodeError with the previous build.
  • EscapesTheStoredWriterVersionInMessages fails without the fix. PlacesEmptySectionsByTheLayoutRule fails if the reader exempts empty sections from the order check (the reader then accepts the file).
  • ./scripts/check-format.sh, full ./scripts/check-tidy.sh (clang-tidy 23), ./scripts/check-python.sh, mkdocs build --strict, git diff --check.

0.9 is the first release that writes index format 2, and its reader binds
every later file, so the specification must state what the reader
enforces. The layout rule now says what reader and writer do: each section
starts at or after the end of the previous table entry, so an empty section
shares its offset only with entries after it; the earlier text also allowed
an empty section inside or at the start of the previous one, which the
reader rejects. Also: drop the draft status and close the open question
(the header is not a blob); header growth is per release within version 2;
readers check the checksum of known sections exactly when checksummed is
set and read known kinds whatever their required bit; reading step 5 lists
the checks in the reader's order; the replaced IVF layouts include RBFQRAW1
and the unversioned one; stale proposal wording is removed. A test pins the
layout rule for empty sections.
Readers do not validate writer_version, but two FormatError messages embed
it. A byte outside printable ASCII reached Python's error conversion, which
decodes messages as UTF-8, so loading such a file raised UnicodeDecodeError
instead of rabitqlib.FormatError. The messages now show those bytes, and
backslashes, as \xNN; Reader::writer_version() still returns the stored
bytes. The specification says readers do not validate the field.
@github-actions github-actions Bot added the release:fixed Release category managed from the PR title label Nov 19, 2026
@gouyt13
gouyt13 merged commit c456f31 into dev/0.9 Nov 19, 2026
26 checks passed
@gouyt13
gouyt13 deleted the fix/format2-spec-freeze branch November 19, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fixed Release category managed from the PR title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant