[PR #6710] [CLOSED] fix(model): read null safetensors __metadata__ as absent #7395

Closed
opened 2026-11-01 21:47:33 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6710
Author: @Sriram-PR
Created: 10/23/2026
Status: ❌ Closed

Base: main ← Head: fix/safetensors-null-metadata


📝 Commits (1)

  • 58117be fix(model): read null safetensors metadata as absent

📊 Changes

3 files changed (+46 additions, -3 deletions)

View changed files

📝 docs/model-artifacts.md (+2 -1)
📝 src/model/SafetensorsHeader.ts (+13 -2)
📝 tests/boundary/model/modelArtifact.test.ts (+31 -0)

📄 Description

Summary

inspect_model_artifact rejects a safetensors file whose header has "__metadata__": null with file_format_rejected ("Safetensors header requires unsigned integer declarations"). The reference reader declares that field as Option<HashMap<String, String>> (HashMetadata in safetensors/src/tensor.rs), so null is valid there and the same bytes load fine with safetensors itself.

Fixes #6656

Problem and expected behavior

Smallest trigger: the issue's 82-byte file, one U8 tensor x with shape [1] and "__metadata__": null. On main a281455f, ModelArtifactService.inspect with detail: "complete" fails as above; the same file with __metadata__ left out or set to {"a":"b"} passes. The header JSON reader in SafetensorsHeader.ts has no case for null, so it falls into the integer branch. Expected: no metadata rows and the tensor reported as usual.

Change and scope

  • HeaderJson now parses the null literal.
  • A root __metadata__ of null is skipped like a missing one.
  • objectOf rejects null explicitly (typeof null is "object"), so null anywhere else still fails like it does in the reference reader: a tensor entry, a metadata value, a shape dimension, offsets or dtype.
  • docs/model-artifacts.md notes that null __metadata__ reads as absent.
  • Not included: other JSON literals (true, false, floats). The reference reader rejects those in every header position too.

Contribution scope: ordinary fix within existing boundaries; no scope decision needed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: HeaderJson and readSafetensorsHeader in src/model/SafetensorsHeader.ts.
  • Contribution scope fit and linked maintainer decision: not applicable (bug fix, #6656).
  • CLI and MCP/tool-catalog contract: none; a previously rejected valid file is now inspected.
  • Provider, bridge, target-format, or platform compatibility: safetensors headers with null __metadata__ are now accepted.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/model/modelArtifact.test.ts adds reads null safetensors __metadata__ as absent, as the reference reader does (no metadata rows, tensor x U8 [1]) and three rows in the file_format_rejected table: null tensor entry, null metadata value, null shape dimension.
  • Base reproduction: the issue's file fails on main a281455f through ModelArtifactService.inspect. The new test fails on main's source with:
    Error: Cannot open artifact: Safetensors header requires unsigned integer declarations
    Caused by: ModelFormatFailure: Safetensors header requires unsigned integer declarations
    
  • User-visible CLI/MCP output: the issue's file now reports tensor x (U8, shape ["1"], byte length 1) and an empty metadata list.
  • Remaining proof gaps: I checked the reference behavior from the safetensors source (Option field) and didn't run the Python package here.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/model/modelArtifact.test.ts: 87 passed (the new positive test fails on main's source)
  • npm run test:focused -- tests/acceptance/modelArtifactCli.test.ts tests/process-global/modelHostReadFailure.test.ts: 12 passed
  • npm run check:fast: typecheck and lint passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux x64, Node 24.18.0.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; the parser still rejects null everywhere the reference does.

Author readiness

Human owner: @Sriram-PR

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/6710 **Author:** [@Sriram-PR](https://github.com/Sriram-PR) **Created:** 10/23/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/safetensors-null-metadata` --- ### 📝 Commits (1) - [`58117be`](https://github.com/morluto/rea/commit/58117be4f99332a009192d527adbf4fb6e39bdef) fix(model): read null safetensors __metadata__ as absent ### 📊 Changes **3 files changed** (+46 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/model-artifacts.md` (+2 -1) 📝 `src/model/SafetensorsHeader.ts` (+13 -2) 📝 `tests/boundary/model/modelArtifact.test.ts` (+31 -0) </details> ### 📄 Description ## Summary `inspect_model_artifact` rejects a safetensors file whose header has `"__metadata__": null` with `file_format_rejected` ("Safetensors header requires unsigned integer declarations"). The reference reader declares that field as `Option<HashMap<String, String>>` (`HashMetadata` in `safetensors/src/tensor.rs`), so null is valid there and the same bytes load fine with safetensors itself. Fixes #6656 ## Problem and expected behavior Smallest trigger: the issue's 82-byte file, one U8 tensor `x` with shape `[1]` and `"__metadata__": null`. On main a281455f, `ModelArtifactService.inspect` with `detail: "complete"` fails as above; the same file with `__metadata__` left out or set to `{"a":"b"}` passes. The header JSON reader in `SafetensorsHeader.ts` has no case for `null`, so it falls into the integer branch. Expected: no metadata rows and the tensor reported as usual. ## Change and scope - `HeaderJson` now parses the `null` literal. - A root `__metadata__` of null is skipped like a missing one. - `objectOf` rejects null explicitly (`typeof null` is `"object"`), so null anywhere else still fails like it does in the reference reader: a tensor entry, a metadata value, a shape dimension, offsets or dtype. - `docs/model-artifacts.md` notes that null `__metadata__` reads as absent. - Not included: other JSON literals (`true`, `false`, floats). The reference reader rejects those in every header position too. Contribution scope: ordinary fix within existing boundaries; no scope decision needed. ## Contract and boundary impact - Semantic owner and earliest changed stage: `HeaderJson` and `readSafetensorsHeader` in `src/model/SafetensorsHeader.ts`. - Contribution scope fit and linked maintainer decision: not applicable (bug fix, #6656). - CLI and MCP/tool-catalog contract: none; a previously rejected valid file is now inspected. - Provider, bridge, target-format, or platform compatibility: safetensors headers with null `__metadata__` are now accepted. - Evidence, artifact, provenance, or reconstruction contract: none. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `tests/boundary/model/modelArtifact.test.ts` adds `reads null safetensors __metadata__ as absent, as the reference reader does` (no metadata rows, tensor `x` U8 `[1]`) and three rows in the `file_format_rejected` table: null tensor entry, null metadata value, null shape dimension. - Base reproduction: the issue's file fails on main a281455f through `ModelArtifactService.inspect`. The new test fails on main's source with: ``` Error: Cannot open artifact: Safetensors header requires unsigned integer declarations Caused by: ModelFormatFailure: Safetensors header requires unsigned integer declarations ``` - User-visible CLI/MCP output: the issue's file now reports tensor `x` (`U8`, shape `["1"]`, byte length 1) and an empty metadata list. - Remaining proof gaps: I checked the reference behavior from the safetensors source (`Option` field) and didn't run the Python package here. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:focused -- tests/boundary/model/modelArtifact.test.ts`: 87 passed (the new positive test fails on main's source) - `npm run test:focused -- tests/acceptance/modelArtifactCli.test.ts tests/process-global/modelHostReadFailure.test.ts`: 12 passed - `npm run check:fast`: typecheck and lint passed ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: Linux x64, Node 24.18.0. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none; the parser still rejects null everywhere the reference does. ## Author readiness Human owner: @Sriram-PR - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:47:33 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7395
No description provided.