Send the MatchClaim table to the server as bytes and answer it as aligned arrays behind a JSON header#
Status: accepted · Date: 2026-11-21
Context#
POST /api/match-claims takes a package’s match_claims.parquet together
with the manifest it belongs to, reads the table with timetoalign, checks
it against the manifest with TimeToShare’s table checks and answers with
the columns of decision 0029 (MatchClaimColumns) and every row’s beliefs,
from which the editor computes the belief filter’s row mask. Decision 0029
fixes the arrays and the encoding of a value; this record fixes the bytes
of the request and of the answer.
The requirements:
No new dependency on either side. FastAPI reads a multipart form only through
python-multipart, which the server does not have.No copy and no parse of the arrays in the browser: the answer of 250,000 MatchClaims is about 30 MB of numbers, which typed arrays view where
Response.arrayBuffer()put them. A typed array’s offset must be a multiple of its element size, eight bytes for a double or an int64.No copy of the picked file in the browser: the request is built from the
Filethe user picked without reading it.Self-describing: a client refuses an answer it does not understand instead of misreading it.
Considered options#
A multipart form: standard, but needs
python-multiparton the server (requirement 1).JSON with the file in Base64 (request) or with number lists (answer): a copy of the file and a parse of every number (requirements 2 and 3).
Apache Arrow IPC for the answer: the columnar format pyarrow writes, but reading it in the browser takes the
apache-arrowpackage (requirement 1), and its buffers are not the arrays of decision 0029.A length prefix and plain bytes, both ways: the request is a
Blobof a four-byte prefix, the manifest’s text and the pickedFile; the answer is a four-byte prefix, a JSON header naming the arrays and the arrays themselves, each at a multiple of eight bytes.
Decision#
The last option, both ways little-endian, with media type
application/octet-stream.
The request is three parts, back to back:
Bytes |
Holds |
|---|---|
0 to 3 |
the manifest’s length |
4 to 4 + |
the manifest file’s text, UTF-8, in any serialization TimeToShare reads, IDs written |
the rest |
the Parquet file, unchanged |
The answer (200) is:
Bytes |
Holds |
|---|---|
0 to 3 |
the header’s length |
4 to 4 + |
the header, compact JSON in UTF-8 |
from |
the arrays, |
The header is {format, version, rows, timelines, actors, beliefs, arrays}: format is "tilie-match-claims", version is 1; rows the
number of MatchClaims; timelines [{id, number_type}], every timeline a
row names, by bare ID sorted by code point, each with its axis’s number
type as the manifest states it; actors every actor holding a belief,
each the IRI timetoalign compares it as (expanded under the manifest’s
@context, every prefix it declares; timetoalign’s belief_context and
actor_iri), so a compact and an absolute spelling of one actor are one
entry, sorted by code point; beliefs the belief words in TimeToShare’s order,
["true", "false", "unlikely"]; arrays maps each array’s name to
[offset, length], its offset from base (a multiple of 8) and its
number of entries. Padding after an array is zero bytes.
Array |
Entries |
Element |
Holds |
|---|---|---|---|
|
bytes |
|
the claim IDs in row order, UTF-8, joined by U+000A (an ID holds no control character) |
|
|
|
the index of the side’s timeline in |
|
|
|
decision 0029’s |
|
|
|
decision 0029’s |
|
|
|
1 where the row has that anchor |
|
|
|
where each row’s beliefs start in the two arrays below; the last entry is their number |
|
beliefs |
|
per belief its actor’s index in |
|
beliefs |
|
per belief its word’s index in |
A row’s beliefs are those of its own provenance, or those of the file’s
provenance (TimeToShare’s timetoshare:provenance metadata) when the file
states it, which the checks allow only for a table whose rows state none.
The arrays are listed in the order above; a client reads them by name.
Refusals answer JSON, as the server’s other routes: 422
{"detail": {"path", "message"}} for a body that cannot be split, a
manifest that cannot be read (path timetoshare’s) or that timetoalign
refuses to read as a bundle (its message), or bytes that are no Parquet
file; a table TimeToShare’s checks refuse adds problems, every
problem the checks find as {code, row, column, message}, message being
the first one’s; 501 for a server whose timetoshare cannot check tables or
read manifests, or whose timetoalign cannot read the table.
The client (@timetoalign/tilie-client, matchClaims) refuses an answer
whose header is no such object, whose format or version differ, whose
beliefs are not those three words, or whose arrays are missing, out of
bounds, misaligned or of another length than their name requires; it
views every array where it lies, decodes the claim IDs with one
TextDecoder call and one split, and refuses to run on a big-endian
platform. The row mask is computed from the beliefs on the client
(beliefMask, the believer expanded under the same @context as the
actors), so the same answer serves every believer and filter.
Maintenance and dependencies#
No dependency enters: struct, json and numpy (which timetoalign
requires) on the server, Blob, DataView, typed arrays and
TextDecoder in the browser. The server’s tests decode the answer to the
TimeToShare fixture tables/0.2.0 with their own reader of this layout
and compare every array; scripts/record_answers.py writes that
answer, with the answers of the client’s other routes, into the client’s
tests, which decode it and compare the same
values, written out from the fixture by hand.
Primary sources: https://fetch.spec.whatwg.org/#body-mixin
(arrayBuffer()), https://tc39.es/ecma262/#sec-typedarray-objects (a
view’s offset a multiple of its element size), https://w3c.github.io/FileAPI/#blob-section
(a Blob of parts reads the picked file without copying it in script),
https://www.rfc-editor.org/rfc/rfc8259 (JSON).
Consequences#
An answer of 250,000 MatchClaims costs one JSON parse of a header of a few
hundred bytes, one decode and split of the IDs, and no copy of the arrays.
A later layout raises version; a client refuses a version it does not
know. The exit cost is local: the server’s encoder and the client’s
decoder are the two readers of this layout.
Decision 0031 adds the routes that read a MatchClaim’s provenance and record a belief; both take this request behind their parameters.
Review date#
2027-05-21, or when the table reaches the browser without the server.