tensorfs 0.3.55__tar.gz → 0.3.56__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tensorfs might be problematic. Click here for more details.

Files changed (145) hide show
  1. {tensorfs-0.3.55 → tensorfs-0.3.56}/Cargo.lock +2 -2
  2. {tensorfs-0.3.55 → tensorfs-0.3.56}/Cargo.toml +1 -1
  3. {tensorfs-0.3.55 → tensorfs-0.3.56}/PKG-INFO +1 -1
  4. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/carrier.rs +123 -88
  5. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/fingerprint.rs +27 -22
  6. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/journal.rs +3 -2
  7. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/source.rs +0 -1
  8. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/providers.rs +24 -20
  9. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/store.rs +3 -3
  10. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/hub.rs +57 -32
  11. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/tests.rs +89 -0
  12. tensorfs-0.3.56/crates/tensorfs-core/tests/foreign_json.rs +141 -0
  13. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-py/src/store.rs +1 -1
  14. {tensorfs-0.3.55 → tensorfs-0.3.56}/pyproject.toml +1 -1
  15. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/Cargo.toml +0 -0
  16. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/build.rs +0 -0
  17. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/examples/h3-swiglu-layout.md +0 -0
  18. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/examples/optional-cache-backfill.md +0 -0
  19. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/examples/resident-conversion.md +0 -0
  20. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/examples/resident_conversion_profile.rs +0 -0
  21. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/asset_update.rs +0 -0
  22. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/b64.rs +0 -0
  23. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/ckpt.rs +0 -0
  24. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/conform.rs +0 -0
  25. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/fetch.rs +0 -0
  26. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/ingest.rs +0 -0
  27. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/main.rs +0 -0
  28. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/rd.rs +0 -0
  29. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/repo.rs +0 -0
  30. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/snap.rs +0 -0
  31. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/bin/tfs/watch.rs +0 -0
  32. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/cache_roots.rs +0 -0
  33. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/canon.rs +0 -0
  34. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/capability.rs +0 -0
  35. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/catalog.rs +0 -0
  36. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/cbor.rs +0 -0
  37. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/checkpoint.rs +0 -0
  38. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/checkpoint_root.rs +0 -0
  39. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/corpus.rs +0 -0
  40. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived/adoption.rs +0 -0
  41. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived/companion_tests.rs +0 -0
  42. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived/estimate.rs +0 -0
  43. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived/graft_tests.rs +0 -0
  44. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived/progress.rs +0 -0
  45. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived/resume_tests.rs +0 -0
  46. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived/retention.rs +0 -0
  47. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived/roots.rs +0 -0
  48. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/derived.rs +0 -0
  49. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/dtype.rs +0 -0
  50. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/durability.rs +0 -0
  51. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/err.rs +0 -0
  52. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/fetch.rs +0 -0
  53. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/fill.rs +0 -0
  54. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/fit.rs +0 -0
  55. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/gc.rs +0 -0
  56. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/header.rs +0 -0
  57. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/home.rs +0 -0
  58. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ids.rs +0 -0
  59. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/convert.rs +0 -0
  60. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/gguf.rs +0 -0
  61. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/h3_lora.rs +0 -0
  62. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/mod.rs +0 -0
  63. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/preflight.rs +0 -0
  64. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/stamp.rs +0 -0
  65. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/ingest/transaction.rs +0 -0
  66. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/jcs.rs +0 -0
  67. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/lib.rs +0 -0
  68. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/limits.rs +0 -0
  69. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/machine.rs +0 -0
  70. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/manifest.rs +0 -0
  71. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/meta.rs +0 -0
  72. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/project.rs +0 -0
  73. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/read.rs +0 -0
  74. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/receipt.rs +0 -0
  75. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/reclaim.rs +0 -0
  76. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/registry.rs +0 -0
  77. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/relation.rs +0 -0
  78. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/repo_cache/identity.rs +0 -0
  79. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/repo_cache.rs +0 -0
  80. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/repository.rs +0 -0
  81. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/sha256.rs +0 -0
  82. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/source_artifact.rs +0 -0
  83. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/spec.rs +0 -0
  84. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/staging.rs +0 -0
  85. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/stats.rs +0 -0
  86. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/storage.rs +0 -0
  87. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/api.rs +0 -0
  88. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/http.rs +0 -0
  89. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/http_reuse_tests.rs +0 -0
  90. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/ledger.rs +0 -0
  91. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/mod.rs +0 -0
  92. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/policy.rs +0 -0
  93. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/prefix.rs +0 -0
  94. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/pull.rs +0 -0
  95. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/push.rs +0 -0
  96. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/ranged.rs +0 -0
  97. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/transport/speculate.rs +0 -0
  98. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/src/vectors.rs +0 -0
  99. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/checkpoint_roots.rs +0 -0
  100. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fetch_url_progress.rs +0 -0
  101. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fit.rs +0 -0
  102. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fixtures/repo_apply/blobs.jsonl +0 -0
  103. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fixtures/repo_apply/expected_list.jsonl +0 -0
  104. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fixtures/repo_apply/expected_repository.json +0 -0
  105. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fixtures/repo_apply/expected_rows.jsonl +0 -0
  106. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fixtures/repo_apply/header.cbor +0 -0
  107. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fixtures/repo_apply/manifest.json +0 -0
  108. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/fixtures/repo_apply/mutation.json +0 -0
  109. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/h3_lora.rs +0 -0
  110. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/h3_swiglu.rs +0 -0
  111. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/home.rs +0 -0
  112. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/import_tree.rs +0 -0
  113. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/instrument_profiles.rs +0 -0
  114. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/liveness.rs +0 -0
  115. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/qwen_image21_profile.rs +0 -0
  116. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/read_plan.rs +0 -0
  117. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/reclaim.rs +0 -0
  118. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/reclaim_run.rs +0 -0
  119. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/repo_cache.rs +0 -0
  120. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/repo_store.rs +0 -0
  121. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/resident_admission.rs +0 -0
  122. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/sha256_backends.rs +0 -0
  123. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/sharded_cas.rs +0 -0
  124. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/source_artifacts.rs +0 -0
  125. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/source_plan.rs +0 -0
  126. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/source_prefixes.rs +0 -0
  127. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/source_preflight.rs +0 -0
  128. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/staging.rs +0 -0
  129. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/store_boundaries.rs +0 -0
  130. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/tensor_schema.rs +0 -0
  131. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/trust_index.rs +0 -0
  132. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/version.rs +0 -0
  133. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-core/tests/write_through.rs +0 -0
  134. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-py/Cargo.toml +0 -0
  135. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-py/src/docs.rs +0 -0
  136. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-py/src/errors.rs +0 -0
  137. {tensorfs-0.3.55 → tensorfs-0.3.56}/crates/tensorfs-py/src/lib.rs +0 -0
  138. {tensorfs-0.3.55 → tensorfs-0.3.56}/python/tensorfs/__init__.py +0 -0
  139. {tensorfs-0.3.55 → tensorfs-0.3.56}/python/tensorfs/_derived_channel.py +0 -0
  140. {tensorfs-0.3.55 → tensorfs-0.3.56}/python/tensorfs/_ext.pyi +0 -0
  141. {tensorfs-0.3.55 → tensorfs-0.3.56}/python/tensorfs/_source_channel.py +0 -0
  142. {tensorfs-0.3.55 → tensorfs-0.3.56}/python/tensorfs/_tensors.py +0 -0
  143. {tensorfs-0.3.55 → tensorfs-0.3.56}/python/tensorfs/derived.py +0 -0
  144. {tensorfs-0.3.55 → tensorfs-0.3.56}/python/tensorfs/errors.py +0 -0
  145. {tensorfs-0.3.55 → tensorfs-0.3.56}/python/tensorfs/py.typed +0 -0
@@ -439,7 +439,7 @@ checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
439
439
 
440
440
  [[package]]
441
441
  name = "tensorfs-core"
442
- version = "0.3.55"
442
+ version = "0.3.56"
443
443
  dependencies = [
444
444
  "fs2",
445
445
  "libc",
@@ -454,7 +454,7 @@ dependencies = [
454
454
 
455
455
  [[package]]
456
456
  name = "tensorfs-py"
457
- version = "0.3.55"
457
+ version = "0.3.56"
458
458
  dependencies = [
459
459
  "pyo3",
460
460
  "tensorfs-core",
@@ -3,5 +3,5 @@ resolver = "2"
3
3
  members = ["crates/tensorfs-core", "crates/tensorfs-py"]
4
4
 
5
5
  [workspace.package]
6
- version = "0.3.55"
6
+ version = "0.3.56"
7
7
  edition = "2021"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tensorfs
3
- Version: 0.3.55
3
+ Version: 0.3.56
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Rust
@@ -7,12 +7,10 @@
7
7
  //! 1. **Refuse before allocation.** The 8-byte length prefix is compared with the cap AND
8
8
  //! with the file's real length before `Vec::with_capacity` is ever reached. A header
9
9
  //! claiming 2^63 bytes costs one `read_exact` of 8 bytes.
10
- //! 2. **One JSON reader.** The foreign header goes through `canon::parse` — the same
11
- //! bounded, integer-only, ASCII-only, duplicate-key-refusing reader every canonical
12
- //! document uses. A second tolerant parser at the border is exactly the drift this repo
13
- //! is built against. The foreign header is NOT required to be canonically ENCODED (it is
14
- //! someone else's file, pretty-printed as they please); it is required to be inside the
15
- //! canonical GRAMMAR.
10
+ //! 2. **The format's own grammar.** A foreign header is someone else's RFC 8259 JSON, read
11
+ //! by the bounded, duplicate-key-refusing `jcs` reader: any UTF-8, any escape, any number
12
+ //! inside the interoperable range. Only what TensorFS consumes is typed; foreign metadata
13
+ //! it cannot carry is dropped, never a reason to refuse the carrier.
16
14
  //! 3. **Geometry is arithmetic, not trust.** Every tensor's declared byte run must equal
17
15
  //! `checked_prod(shape) x sizeof(dtype)`, must lie inside the file, and must not overlap
18
16
  //! its neighbour. A lying header is refused by multiplication, never by a failed read.
@@ -22,9 +20,9 @@ use std::fs::File;
22
20
  use std::io::{Read, Seek, SeekFrom};
23
21
  use std::path::{Path, PathBuf};
24
22
 
25
- use crate::canon::{self, as_arr, as_str, Fields, Value};
26
23
  use crate::dtype::{checked_bytes, Dtype};
27
24
  use crate::err::{refuse, Code, Refusal, Result};
25
+ use crate::jcs::{self, Json};
28
26
  use crate::limits;
29
27
 
30
28
  fn io(what: impl AsRef<str>, e: std::io::Error) -> Refusal {
@@ -34,6 +32,78 @@ fn io(what: impl AsRef<str>, e: std::io::Error) -> Refusal {
34
32
  }
35
33
  }
36
34
 
35
+ fn kind(v: &Json) -> &'static str {
36
+ match v {
37
+ Json::Null => "null",
38
+ Json::Bool(_) => "bool",
39
+ Json::Num(_) => "number",
40
+ Json::Str(_) => "string",
41
+ Json::Arr(_) => "array",
42
+ Json::Obj(_) => "object",
43
+ }
44
+ }
45
+
46
+ fn object<'a>(what: &str, v: &'a Json) -> Result<&'a [(String, Json)]> {
47
+ match v {
48
+ Json::Obj(m) => Ok(m),
49
+ o => refuse(
50
+ Code::WRONG_TYPE,
51
+ format!("{what}: expected object, got {}", kind(o)),
52
+ ),
53
+ }
54
+ }
55
+
56
+ fn array<'a>(what: &str, v: &'a Json) -> Result<&'a [Json]> {
57
+ match v {
58
+ Json::Arr(a) => Ok(a),
59
+ o => refuse(
60
+ Code::WRONG_TYPE,
61
+ format!("{what}: expected array, got {}", kind(o)),
62
+ ),
63
+ }
64
+ }
65
+
66
+ fn string<'a>(what: &str, v: &'a Json) -> Result<&'a str> {
67
+ match v {
68
+ Json::Str(s) => Ok(s),
69
+ o => refuse(
70
+ Code::WRONG_TYPE,
71
+ format!("{what}: expected string, got {}", kind(o)),
72
+ ),
73
+ }
74
+ }
75
+
76
+ fn uint(what: &str, v: &Json) -> Result<u64> {
77
+ match v {
78
+ Json::Num(n) if *n >= 0.0 && n.fract() == 0.0 => Ok(*n as u64),
79
+ o => refuse(
80
+ Code::WRONG_TYPE,
81
+ format!("{what}: expected non-negative integer, got {}", kind(o)),
82
+ ),
83
+ }
84
+ }
85
+
86
+ fn field<'a>(what: &str, entry: &'a [(String, Json)], name: &str) -> Result<&'a Json> {
87
+ entry
88
+ .iter()
89
+ .find(|(k, _)| k == name)
90
+ .map(|(_, v)| v)
91
+ .ok_or_else(|| Refusal {
92
+ code: Code::MISSING_FIELD,
93
+ detail: format!("{what}: missing {name:?}"),
94
+ })
95
+ }
96
+
97
+ /// Foreign metadata is advisory. Strings and integers are carried as text; anything else is
98
+ /// dropped rather than refused.
99
+ fn metadata(v: &Json) -> Option<String> {
100
+ match v {
101
+ Json::Str(s) => Some(s.clone()),
102
+ Json::Num(n) if *n >= 0.0 && n.fract() == 0.0 => Some((*n as u64).to_string()),
103
+ _ => None,
104
+ }
105
+ }
106
+
37
107
  // ---------------------------------------------------------------- the closed dialect set
38
108
 
39
109
  /// What a carrier CALLS its element types, mapped into the closed cozytensors enum. A
@@ -274,16 +344,8 @@ pub fn read_header(path: &Path) -> Result<SourceHeader> {
274
344
  /// be exactly what the runs declare, which is the only honest reading when there is no file
275
345
  /// to measure. Every other check is identical.
276
346
  pub fn parse_header(bytes: &[u8], data_start: u64, file_len: Option<u64>) -> Result<SourceHeader> {
277
- let v = canon::parse(bytes, limits::CARRIER_HEADER_MAX_BYTES)?;
278
- let entries = match &v {
279
- Value::Obj(m) => m,
280
- o => {
281
- return refuse(
282
- Code::WRONG_TYPE,
283
- format!("carrier header: expected object, got {}", o.kind()),
284
- )
285
- }
286
- };
347
+ let v = jcs::parse(bytes, limits::CARRIER_HEADER_MAX_BYTES)?;
348
+ let entries = object("carrier header", &v)?;
287
349
  if entries.len() > limits::MAX_TENSORS {
288
350
  return refuse(
289
351
  Code::COUNT_CAP,
@@ -304,21 +366,12 @@ pub fn parse_header(bytes: &[u8], data_start: u64, file_len: Option<u64>) -> Res
304
366
 
305
367
  for (key, ev) in entries {
306
368
  if key == "__metadata__" {
307
- for (mk, mv) in canon::as_obj("carrier", "__metadata__", ev)? {
308
- out.metadata.push((
309
- mk.clone(),
310
- match mv {
311
- Value::Str(s) => s.clone(),
312
- // Foreign metadata is decoded as flat strings under a strict schema
313
- // or discarded. A nested blob is not silently carried forward.
314
- o => {
315
- return refuse(
316
- Code::WRONG_TYPE,
317
- format!("__metadata__.{mk}: expected string, got {}", o.kind()),
318
- )
319
- }
320
- },
321
- ));
369
+ if let Json::Obj(pairs) = ev {
370
+ for (mk, mv) in pairs {
371
+ if let Some(value) = metadata(mv) {
372
+ out.metadata.push((mk.clone(), value));
373
+ }
374
+ }
322
375
  }
323
376
  continue;
324
377
  }
@@ -328,14 +381,28 @@ pub fn parse_header(bytes: &[u8], data_start: u64, file_len: Option<u64>) -> Res
328
381
  format!("carrier key length {} out of bounds", key.len()),
329
382
  );
330
383
  }
331
- let mut f = Fields::new("carrier.tensor", ev)?;
332
- let offsets = as_arr("carrier.tensor", "data_offsets", f.req("data_offsets")?)?;
333
- let dtype = foreign_dtype(key, as_str("carrier.tensor", "dtype", f.req("dtype")?)?)?;
334
- let shape = as_arr("carrier.tensor", "shape", f.req("shape")?)?
384
+ // The one grammar limit that is TensorFS's own: a CozyTensors key is printable ASCII.
385
+ if !key.bytes().all(|b| (0x20..=0x7e).contains(&b)) {
386
+ return refuse(
387
+ Code::KEY_GRAMMAR,
388
+ format!(
389
+ "carrier key {key:?} is not printable ASCII; a CozyTensors key cannot name it"
390
+ ),
391
+ );
392
+ }
393
+ let f = object("carrier.tensor", ev)?;
394
+ let offsets = array(
395
+ "carrier.tensor.data_offsets",
396
+ field("carrier.tensor", f, "data_offsets")?,
397
+ )?;
398
+ let dtype = foreign_dtype(
399
+ key,
400
+ string("carrier.tensor.dtype", field("carrier.tensor", f, "dtype")?)?,
401
+ )?;
402
+ let shape = array("carrier.tensor.shape", field("carrier.tensor", f, "shape")?)?
335
403
  .iter()
336
- .map(|x| canon::as_uint("carrier.tensor", "shape", x))
404
+ .map(|x| uint("carrier.tensor.shape", x))
337
405
  .collect::<Result<Vec<u64>>>()?;
338
- f.done()?;
339
406
 
340
407
  if offsets.len() != 2 {
341
408
  return refuse(
@@ -343,8 +410,8 @@ pub fn parse_header(bytes: &[u8], data_start: u64, file_len: Option<u64>) -> Res
343
410
  format!("{key}: data_offsets holds {} values, not 2", offsets.len()),
344
411
  );
345
412
  }
346
- let begin = canon::as_uint("carrier.tensor", "data_offsets", &offsets[0])?;
347
- let end = canon::as_uint("carrier.tensor", "data_offsets", &offsets[1])?;
413
+ let begin = uint("carrier.tensor.data_offsets", &offsets[0])?;
414
+ let end = uint("carrier.tensor.data_offsets", &offsets[1])?;
348
415
  if end < begin {
349
416
  return refuse(
350
417
  Code::CARRIER_GEOMETRY,
@@ -510,45 +577,21 @@ fn locate_shard(index_path: &Path, shards: Shards<'_>, name: &str) -> Result<Pat
510
577
  pub fn read_sharded(index_path: &Path, shards: Shards<'_>) -> Result<(SourceHeader, Vec<u8>)> {
511
578
  let index_bytes =
512
579
  std::fs::read(index_path).map_err(|e| io(format!("read {}", index_path.display()), e))?;
513
- let v = canon::parse(&index_bytes, limits::CARRIER_HEADER_MAX_BYTES)?;
514
- let top = match &v {
515
- Value::Obj(m) => m,
516
- o => {
517
- return refuse(
518
- Code::WRONG_TYPE,
519
- format!("shard index: expected object, got {}", o.kind()),
520
- )
521
- }
522
- };
523
- let mut weight_map: Option<&Vec<(String, Value)>> = None;
580
+ let v = jcs::parse(&index_bytes, limits::CARRIER_HEADER_MAX_BYTES)?;
581
+ let top = object("shard index", &v)?;
582
+ let mut weight_map: Option<&[(String, Json)]> = None;
524
583
  let mut index_meta: Vec<(String, String)> = Vec::new();
525
584
  for (k, ev) in top {
526
- match k.as_str() {
527
- "weight_map" => weight_map = Some(canon::as_obj("shard index", "weight_map", ev)?),
528
- "metadata" => {
529
- for (mk, mv) in canon::as_obj("shard index", "metadata", ev)? {
530
- let s = match mv {
531
- Value::Str(s) => s.clone(),
532
- Value::Int(n) => n.to_string(),
533
- o => {
534
- return refuse(
535
- Code::WRONG_TYPE,
536
- format!(
537
- "shard index metadata.{mk}: expected string or uint, got {}",
538
- o.kind()
539
- ),
540
- )
541
- }
542
- };
543
- index_meta.push((mk.clone(), s));
585
+ match (k.as_str(), ev) {
586
+ ("weight_map", _) => weight_map = Some(object("shard index weight_map", ev)?),
587
+ ("metadata", Json::Obj(pairs)) => {
588
+ for (mk, mv) in pairs {
589
+ if let Some(value) = metadata(mv) {
590
+ index_meta.push((mk.clone(), value));
591
+ }
544
592
  }
545
593
  }
546
- other => {
547
- return refuse(
548
- Code::WRONG_TYPE,
549
- format!("shard index: unknown top-level field {other:?}"),
550
- )
551
- }
594
+ _ => {}
552
595
  }
553
596
  }
554
597
  let weight_map = match weight_map {
@@ -568,7 +611,7 @@ pub fn read_sharded(index_path: &Path, shards: Shards<'_>) -> Result<(SourceHead
568
611
  std::collections::HashMap::with_capacity(weight_map.len());
569
612
  let mut names: Vec<&str> = Vec::new();
570
613
  for (k, v) in weight_map {
571
- let name = as_str("shard index", "weight_map value", v)?;
614
+ let name = string("shard index weight_map value", v)?;
572
615
  if name.is_empty() {
573
616
  return refuse(
574
617
  Code::KEY_GRAMMAR,
@@ -656,18 +699,10 @@ pub fn read_sharded(index_path: &Path, shards: Shards<'_>) -> Result<(SourceHead
656
699
  end: virtual_base + t.end,
657
700
  });
658
701
  }
659
- for (mk, mv) in &h.metadata {
660
- match out.metadata.iter().find(|(k, _)| k == mk) {
661
- Some((_, prev)) if prev == mv => {}
662
- Some((_, prev)) => {
663
- return refuse(
664
- Code::CARRIER_GEOMETRY,
665
- format!(
666
- "shard metadata {mk:?} disagrees across shards ({prev:?} vs {mv:?})"
667
- ),
668
- )
669
- }
670
- None => out.metadata.push((mk.clone(), mv.clone())),
702
+ // Advisory metadata that differs across shards is kept as both values, never refused.
703
+ for pair in &h.metadata {
704
+ if !out.metadata.contains(pair) {
705
+ out.metadata.push(pair.clone());
671
706
  }
672
707
  }
673
708
  out.header_bytes += h.header_bytes;
@@ -16,7 +16,7 @@
16
16
  //! only under other components refuses by naming them.
17
17
 
18
18
  use super::carrier::SourceHeader;
19
- use crate::canon::{as_arr, as_obj, as_str, Fields, Value};
19
+ use crate::canon::{as_arr, as_str, Fields, Value};
20
20
  use crate::dtype::Dtype;
21
21
  use crate::err::{refuse, Code, Result};
22
22
  use crate::header::{tensor_schema_digest_of, tensor_schema_value};
@@ -867,7 +867,7 @@ pub fn validate_source_member_prefix(prefix: &str) -> Result<()> {
867
867
  }
868
868
 
869
869
  /// Decoded `__metadata__` facts the border is willing to carry as EVIDENCE STAMPS. Foreign
870
- /// JSON is decoded through this strict list or discarded — it never survives as itself.
870
+ /// JSON is decoded through this list; a value it cannot carry is discarded.
871
871
  pub fn evidence_stamps(h: &SourceHeader) -> Result<Vec<(String, String)>> {
872
872
  const KEPT: [&str; 5] = [
873
873
  "modelspec.architecture",
@@ -883,13 +883,10 @@ pub fn evidence_stamps(h: &SourceHeader) -> Result<Vec<(String, String)>> {
883
883
  {
884
884
  return refuse_bnb("__metadata__.quantization_config");
885
885
  }
886
- if KEPT.contains(&k.as_str()) {
887
- if v.len() > limits::MAX_NAME_BYTES {
888
- return refuse(
889
- Code::SIZE_CAP,
890
- format!("__metadata__.{k}: stamp value over the byte cap"),
891
- );
892
- }
886
+ if KEPT.contains(&k.as_str())
887
+ && v.len() <= limits::MAX_NAME_BYTES
888
+ && v.bytes().all(|b| (0x20..=0x7e).contains(&b))
889
+ {
893
890
  out.push((k.clone(), v.clone()));
894
891
  }
895
892
  }
@@ -897,8 +894,9 @@ pub fn evidence_stamps(h: &SourceHeader) -> Result<Vec<(String, String)>> {
897
894
  Ok(out)
898
895
  }
899
896
 
900
- /// What a `.comfy_quant` marker actually says, decoded through the SAME bounded reader as
901
- /// everything else. It never survives into the canonical header.
897
+ /// What a `.comfy_quant` marker actually says. The payload is ComfyUI's JSON, read by the
898
+ /// bounded RFC 8259 reader; fields other than the two below are ignored. It never survives
899
+ /// into the canonical header.
902
900
  #[derive(Debug, Clone, PartialEq, Eq)]
903
901
  pub struct ComfyQuant {
904
902
  /// The carrier format the producer named, e.g. `float8_e4m3fn`.
@@ -924,13 +922,23 @@ pub fn decode_comfy_quant(key: &str, bytes: &[u8]) -> Result<ComfyQuant> {
924
922
  format!("{key}: marker payload {} B over the text cap", bytes.len()),
925
923
  );
926
924
  }
927
- // The payload is a NUL-padded JSON blob inside a U8 tensor. Take the text, then the one
928
- // bounded reader; every field but the two below is discarded by construction.
925
+ // The payload is a NUL-padded JSON blob inside a U8 tensor.
929
926
  let end = bytes.iter().position(|b| *b == 0).unwrap_or(bytes.len());
930
- let v = crate::canon::parse(&bytes[..end], limits::MAX_DOC_TEXT_BYTES)?;
931
- let fields = as_obj("comfy_quant", key, &v)?;
927
+ let v = crate::jcs::parse(&bytes[..end], limits::MAX_DOC_TEXT_BYTES)?;
928
+ let crate::jcs::Json::Obj(fields) = &v else {
929
+ return refuse(
930
+ Code::WRONG_TYPE,
931
+ format!("{key}: marker payload is not a JSON object"),
932
+ );
933
+ };
932
934
  let format = match fields.iter().find(|(k, _)| k == "format") {
933
- Some((_, x)) => as_str("comfy_quant", "format", x)?.to_string(),
935
+ Some((_, crate::jcs::Json::Str(format))) => format.clone(),
936
+ Some(_) => {
937
+ return refuse(
938
+ Code::WRONG_TYPE,
939
+ format!("{key}: marker `format` is not a string"),
940
+ )
941
+ }
934
942
  None => {
935
943
  return refuse(
936
944
  Code::MISSING_FIELD,
@@ -942,14 +950,11 @@ pub fn decode_comfy_quant(key: &str, bytes: &[u8]) -> Result<ComfyQuant> {
942
950
  .iter()
943
951
  .find(|(k, _)| k == "full_precision_matrix_mult")
944
952
  {
945
- Some((_, crate::canon::Value::Bool(b))) => *b,
946
- Some((_, o)) => {
953
+ Some((_, crate::jcs::Json::Bool(b))) => *b,
954
+ Some(_) => {
947
955
  return refuse(
948
956
  Code::WRONG_TYPE,
949
- format!(
950
- "{key}: full_precision_matrix_mult is a bool, got {}",
951
- o.kind()
952
- ),
957
+ format!("{key}: full_precision_matrix_mult is not a bool"),
953
958
  )
954
959
  }
955
960
  None => false,
@@ -163,11 +163,12 @@ fn field(hash: &mut Sha256, value: &[u8]) {
163
163
  /// journalled part instead of re-reading the carrier is sound.
164
164
  ///
165
165
  /// Deliberately NOT a function of the output: the whole point is to know the plan before any
166
- /// weight byte has been converted.
166
+ /// weight byte has been converted. Nor of the TensorFS build: an upgraded or differently
167
+ /// built pod resumes the same plan. Changing a converter's output bytes renames it or bumps
168
+ /// the domain tag below.
167
169
  pub fn plan_digest(plan: &Plan, headers: &[(PathBuf, &SourceHeader)]) -> String {
168
170
  let mut hash = Sha256::new();
169
171
  field(&mut hash, b"tensorfs.conversion-journal/2");
170
- field(&mut hash, crate::IMPLEMENTATION_SHA256.as_bytes());
171
172
  field(&mut hash, plan.converter.as_bytes());
172
173
  field(&mut hash, plan.class_name.as_bytes());
173
174
  for (path, header) in headers {
@@ -1091,7 +1091,6 @@ fn digest_field(hash: &mut crate::sha256::Sha256, value: &[u8]) {
1091
1091
  fn request_digest(request: &PrepareModelSource, _registry_bytes: &[u8]) -> String {
1092
1092
  let mut hash = crate::sha256::Sha256::new();
1093
1093
  digest_field(&mut hash, b"tensorfs.model-source-preparation/2");
1094
- digest_field(&mut hash, crate::IMPLEMENTATION_SHA256.as_bytes());
1095
1094
  digest_field(&mut hash, request.source_selection_digest.as_bytes());
1096
1095
  for row in &request.profiles {
1097
1096
  digest_field(&mut hash, row.slot.as_bytes());
@@ -460,11 +460,15 @@ fn list_selected_observed(
460
460
  );
461
461
  }
462
462
  members.sort_by(|left, right| left.member.cmp(&right.member));
463
+ members.dedup();
463
464
  if members
464
465
  .windows(2)
465
466
  .any(|pair| pair[0].member == pair[1].member)
466
467
  {
467
- return refuse(Code::DUPLICATE_KEY, "the source lists one member twice");
468
+ return refuse(
469
+ Code::DUPLICATE_KEY,
470
+ "the source lists one member twice with different facts",
471
+ );
468
472
  }
469
473
  Ok(members)
470
474
  }
@@ -1391,6 +1395,7 @@ pub fn resolve_files(
1391
1395
  }
1392
1396
  let mut names = files.to_vec();
1393
1397
  names.sort();
1398
+ names.dedup();
1394
1399
  if names
1395
1400
  .iter()
1396
1401
  .any(|name| !member_path(name) || crate::manifest::check_path(name).is_err())
@@ -1400,12 +1405,6 @@ pub fn resolve_files(
1400
1405
  "ordinary file selection requires exact member paths",
1401
1406
  );
1402
1407
  }
1403
- if names.windows(2).any(|pair| pair[0] == pair[1]) {
1404
- return refuse(
1405
- Code::DUPLICATE_KEY,
1406
- "ordinary file selection names one member twice",
1407
- );
1408
- }
1409
1408
  let ledger = Ledger::new();
1410
1409
  let policy = endpoints.policy(uri);
1411
1410
  let listed =
@@ -2251,7 +2250,7 @@ mod tests {
2251
2250
  Code::KEY_GRAMMAR,
2252
2251
  ),
2253
2252
  (
2254
- r#"{"files":[{"id":92696,"name":"a.safetensors"},{"id":92696,"name":"b.safetensors"}]}"#,
2253
+ r#"{"files":[{"id":92696,"name":"a.safetensors","hashes":{"SHA256":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}},{"id":92696,"name":"b.safetensors","hashes":{"SHA256":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"}}]}"#,
2255
2254
  Code::DUPLICATE_KEY,
2256
2255
  ),
2257
2256
  ] {
@@ -2272,6 +2271,23 @@ mod tests {
2272
2271
  assert_eq!(refusal.code, code);
2273
2272
  handle.join().unwrap();
2274
2273
  }
2274
+ // A provider that lists one file twice with the same facts lists it once.
2275
+ let listing = r#"{"files":[{"id":92696,"name":"a.safetensors"},{"id":92696,"name":"a.safetensors"}]}"#;
2276
+ let (base, _, handle) = origin(1, move |_| ok_body(listing.as_bytes(), "application/json"));
2277
+ let endpoints = Endpoints {
2278
+ civitai: base,
2279
+ allow_local: true,
2280
+ ..Endpoints::default()
2281
+ };
2282
+ let members = list(
2283
+ &SourceUri::Civitai { version: 777 },
2284
+ &endpoints,
2285
+ &Anonymous,
2286
+ Deadline::none(),
2287
+ )
2288
+ .unwrap();
2289
+ assert_eq!(members.len(), 1);
2290
+ handle.join().unwrap();
2275
2291
  }
2276
2292
 
2277
2293
  /// The credential is scoped to the host that holds it. A relative redirect stays on
@@ -2557,18 +2573,6 @@ mod tests {
2557
2573
  Code::PATH_ILLEGAL
2558
2574
  );
2559
2575
  }
2560
- assert_eq!(
2561
- resolve_files(
2562
- &uri,
2563
- &["config.json".into(), "config.json".into()],
2564
- &Endpoints::default(),
2565
- &Anonymous,
2566
- Deadline::none()
2567
- )
2568
- .unwrap_err()
2569
- .code,
2570
- Code::DUPLICATE_KEY
2571
- );
2572
2576
  }
2573
2577
 
2574
2578
  #[test]
@@ -447,9 +447,9 @@ impl Store {
447
447
  Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
448
448
  Err(error) => return Err(io("stat TensorFS catalog", error)),
449
449
  }
450
- let store = open_validated(root)?;
451
- store.trust.validate()?;
452
- Ok(store)
450
+ let trust = crate::catalog::Trust::of(root);
451
+ trust.validate()?;
452
+ open_validated(root)
453
453
  }
454
454
  }
455
455