# Tensor Header Desk — implementation contract

Identity: `work:tensor-header-desk:v1`, version 0.1.0. Frozen before inspector implementation, 2026-11-05 Asia/Muscat. Original tool, code and synthetic fixtures: Renchao Wu, Apache-2.0. Format mathematics and Safetensors are established work, not a new format or training result.

Inspect only the first eight bytes and at most 1,048,576 bytes of JSON header of a local selected file. Use its complete byte length to check payload coverage, never read or execute tensor payloads for the inspection. JSON integers are lexically parsed to exact BigInt unsigned 64-bit quantities. Sequential shape products and multiplication by dtype bits reject u64 overflow even if a later zero dimension would erase it. Scalar shape [] is one element. Empty tensors need zero bytes; all ranges sort by (start, end), including empty ranges, and must cover the complete payload without holes or overlaps. Subbyte types require total bit count divisible by eight. No global dtype-alignment constraint is invented.

Limits: 1 MiB header, 10,000 tensors, JSON nesting 32. Limits and unknown dtype are `outside-profile`, not proof of corruption. Duplicate decoded JSON keys at any depth and noncanonical dimension/offset integer spellings are `policy-rejected`, never silently overwritten. Reject invalid UTF-8, unpaired escaped surrogates and BOM. Unknown tensor fields are retained in a warning and ignored for layout, following the installed reference if confirmed. Metadata must be a string map or null; null compatibility will be verified independently. Leading JSON whitespace is accepted with a compatibility warning because current Rust source explicitly accepts it although the repository README says the header starts with `{`. Record reference differences rather than changing labels to force agreement.

Results: `layout-ok`, `invalid`, `policy-rejected`, `outside-profile`; diagnostics carry code, severity, location and concrete values. Retain every tensor descriptor in header order when the JSON/schema can be parsed; don't hide malformed entries from the table. Invalid findings take precedence over policy and unsupported findings; outside-profile never becomes layout-ok. Report exact byte offsets, counts and sizes as decimal strings. SHA-256 identifies only the prefix+header bytes read, explicitly excludes the tensor data and is not authenticity or integrity verification of the whole file. Payload edits can pass unchanged header checks. Metadata may contain arbitrary private strings; render via textContent, no HTML; export only by explicit user download. No storage, analytics, upload or remote inference.

Demo: serialize exact F64 weights and bias from the already accepted original Apache-2.0 CPU Character Router model, preserving its source identity and source model/manifest hashes. Include copied original model and license/NOTICE, verify every reloaded scalar. This creates no new fit or model identity. Corrupted copies are synthetic demonstrations, with every byte alteration recorded. The inspector is a distinct tooling identity.

Tests: own deterministic valid/malformed corpus plus randomized small shapes/ranges; installed official safetensors 0.8.0 metadata-reader differential, all discrepancies classified; exact demo reload; parser tests including unsafe integers/prototype keys/duplicates/depth/UTF8/surrogates/offsets/overflow; bounded Blob read instrumentation and async generation/Clear guards; native CUA uploads and report downloads for good, altered-payload, truncated, overlap, unknown dtype, invalid JSON; failed replacement and Clear remove previous report; desktop/375/390 layouts, keyboard and long names. Independent total-output review on a copied frozen package before release. No publication during this production batch.

Primary sources actually read through official CUA: https://github.com/huggingface/safetensors (redirects to https://github.com/safetensors/safetensors), README format/notes; https://github.com/safetensors/safetensors/blob/main/safetensors/src/tensor.rs sections read_metadata, validate, Dtype and tests on 2026-11-05. Main is a moving reference; packaged differential pins the installed version. No upstream code or prose copied into the implementation.
