Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
(`swift-json-envelope`), `formatVersion` (1), `payload`, `type` and `version`.
The digest is the SHA-256 of the payload's canonical bytes; decoding checks the
marker, fields and digest and reports `JSONEnvelopeFailure` for invalid or
damaged envelopes. Equal envelopes encode to equal bytes, and equal payloads
damaged envelopes. The schema-version API uses `Int64` on every platform,
with the same wire range 1 through 2^53 − 1.
Equal envelopes encode to equal bytes, and equal payloads
have equal digests for content addressing. Tests pin bytes and digests computed
independently.

Expand Down
64 changes: 64 additions & 0 deletions Documentation/Qualification/Release1.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,67 @@ controlled-performance gate instead of measuring it. The gate is
- Tag, GitHub release and qualification asset (maintainer instruction required).
- Developer kit update to 1.10.0: the kit pins the exact published commit and
tree, so it follows the tag.

## 2026-11-26 — WASI release gate: RED, fixed-width version candidate

The full release WASI attempt at `c2e4aea7cf63bdf8236c22cc9ba0c6a3abeb5201`, tree
`2e483c24b4efb3e7b7f73b2ce2ef76bea712a539`, did not pass.
The exact source was still the unreleased 1.10.0 preparation commit.
The source-bound return archive (86,175 bytes) has SHA-256
`95c6c09f0fcf6ef7c9a233ac70a2353352224d8f23e2bc8ccabbf6377d5820fa`.
The source-input manifest hash
`8cce0bbd3ebd2ed9a9f026bd469e1e0ef2f549d35d5bb254a8db88d0f68e7b9e`
recomputes over all 1,580 entries, and source_inputs_unchanged is true.
All eight referenced command-log SHA-256 values reconcile. Private
absolute host paths are not copied to this public record.

Actual ARM64 macOS 27.3; Swift.org 6.4.2, matching full-language WASI
SDK, WasmKit 0.3.1, Node 26.5.0, Xcode 27.2. Public inventory
and evaluated root manifest passed. Five of the six WASI subprocesses
passed; root-build-debug exited 1 while emitting the JSON module:
`JSONEnvelope.swift:30:56: integer literal '9007199254740991' overflows when stored into 'Int'`.
No WASI runtime tests or Release build occurred in this attempt.
The earlier 21 successful GitHub checks remain bound to the original
commit and do not qualify any corrected successor.

Candidate correction: the unpublished JSONEnvelope schema-version
API uses Int64 consistently (range, stored property, initializer and
exact integer decoding). The fixed formatVersion value, accepted wire
range 1...2^53-1, six members, canonical bytes, payload digest and
operational-error distinctions remain unchanged. Do not cap the range
at Int.max, clamp, or round metadata. This is an API adjustment to the
unpublished 1.10.0 surface, not a change to a previously published API.
Callers of the preparation branch using typed Int variables will need
explicit Int64 conversion. The existing generic JSONNumber constructor
and checked fixed-width integer decoder are reused.

Extend existing EnvelopeTests with six pinned version roundtrips
(1, 2^31-1, 2^31, 2^32-1, 2^32, 2^53-1), exact canonical bytes and
unchanged digest; explicit Int64 bounds, negative and overflow
rejections, and large formatVersion rejection. Existing five
test functions remain; no discovery exclusions or decreased coverage.
DocC, release notes and changelog describe the platform-independent type.

Editing-host supplemental probe: Swift 6.2.1 Linux Embedded
wasm32-unknown-none-wasm, standalone minimal range declaration.
Old ClosedRange<Int> fails with the observed overflow; corrected
ClosedRange<Int64> and stored Int64 initializer compile to a WASM
object. This is not a full-language WASI package build or a runtime
qualification. Independently verify six accepted values are exactly
representable in binary64 and the pinned payload SHA-256. Regenerate
CLI source identity from the ordered 243 input-file SHA-256 values
in the source-bound failed receipt (original identity
99a750404f5c4af53abe83fb52194c296a09e9e69387be2d4a3984b09551e327
reproduces exactly); replace only the changed non-DocC source hash.
New expected identity:
7e58faad4a37141b4fabc6bba4d684a9f6d5ea0d574d9cae92ea8d01da98a81d.
The normal generator --check on the clean corrected checkout remains
required. Native SDK typecheck and all actual envelope behavior tests
on the corrected package are pending.

Next: run complete WASI lane on the corrected source, preserve RED
evidence, require native, Linux, safety, platform-floor, composition,
docs and archive evidence on the exact final release commit, review
the applicability of the documented 1.10-only performance exception
to that final source, verify public API and assets, then tag/publish
only the qualified commit. No release or product admission performed.
3 changes: 2 additions & 1 deletion Documentation/ReleaseNotes/1.10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ The digest is the SHA-256 of the payload's canonical bytes. Decoding accepts any
strict spelling, checks the marker, the six members, the format version, the
fields and the digest, and reports `JSONEnvelopeFailure` for invalid or damaged
records. Equal envelopes encode to equal bytes, and equal payloads have equal
digests. Format version 1 is fixed. Stores built on
digests. Format version 1 is fixed. Schema versions use `Int64` on every platform and retain the
same range 1 through 2^53 − 1, including wasm32. Stores built on
[Swift-SQLite](https://github.com/ThorFuchs/Swift-SQLite) are the intended users;
Swift-JSON itself adds no persistence.

Expand Down
18 changes: 9 additions & 9 deletions Sources/JSON/Codec/JSONEnvelope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public struct JSONEnvelope: Sendable, Equatable {
public static let formatVersion = 1
/// The largest accepted ``type`` length in UTF-8 bytes.
public static let maximumTypeBytes = 256
/// The accepted ``version`` range: the positive integers that binary64 represents exactly.
public static let versions: ClosedRange<Int> = 1...9_007_199_254_740_991
/// The accepted ``version`` range: 1 through 2^53 − 1, independent of platform word size.
public static let versions: ClosedRange<Int64> = 1...9_007_199_254_740_991

/// The caller's name for the kind of payload, such as `mcp.task`.
public let type: String
/// The schema version of ``type`` that the payload follows.
public let version: Int
/// The schema version of ``type`` that the payload follows, stored as a platform-independent integer.
public let version: Int64
/// The enveloped value.
public let payload: JSON

Expand All @@ -46,7 +46,7 @@ public struct JSONEnvelope: Sendable, Equatable {
/// - type: A non-empty name for the kind of payload, at most 256 UTF-8 bytes.
/// - version: The payload's schema version, from 1 through 2^53 − 1.
/// - payload: The value to envelope.
public init(type: String, version: Int, payload: JSON) throws {
public init(type: String, version: Int64, payload: JSON) throws {
guard !type.isEmpty, type.utf8.count <= Self.maximumTypeBytes else { throw JSONEnvelopeFailure.invalidType }
guard Self.versions.contains(version) else { throw JSONEnvelopeFailure.invalidVersion }
self.type = type; self.version = version; self.payload = payload
Expand Down Expand Up @@ -134,7 +134,7 @@ public struct JSONEnvelope: Sendable, Equatable {
}
guard case .string(format) = try member("format", meter: &meter) else { throw JSONEnvelopeFailure.invalidFormat }
guard case .number(let formatVersion) = try member("formatVersion", meter: &meter) else { throw JSONEnvelopeFailure.invalidFormat }
guard try integer(formatVersion, meter: &meter) == Self.formatVersion else {
guard try integer(formatVersion, meter: &meter) == Int64(Self.formatVersion) else {
throw JSONEnvelopeFailure.unsupportedFormatVersion
}
guard case .string(let type) = try member("type", meter: &meter) else { throw JSONEnvelopeFailure.invalidType }
Expand All @@ -152,9 +152,9 @@ public struct JSONEnvelope: Sendable, Equatable {
return .init(result: envelope, statistics: meter.statistics())
}

/// The integer value, or nil when the number is not an integer that fits `Int`.
private static func integer(_ number: JSONNumber, meter: inout JSONWorkMeter) throws -> Int? {
do { return try number.integer(as: Int.self, meter: &meter) }
/// The exact integer value, or nil when it does not fit `Int64`.
private static func integer(_ number: JSONNumber, meter: inout JSONWorkMeter) throws -> Int64? {
do { return try number.integer(as: Int64.self, meter: &meter) }
catch let failure as JSONFailure where failure.category == .conversion { return nil }
}
private static func digest(of bytes: [UInt8], meter: inout JSONWorkMeter) throws -> String {
Expand Down
3 changes: 2 additions & 1 deletion Sources/JSON/Documentation.docc/VersionedEnvelopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Format version 1 is one RFC 8785 canonical object with exactly six members:

- `format` is always `swift-json-envelope`; `formatVersion` is always `1`.
- `type` is a non-empty string of at most 256 UTF-8 bytes; `version` is an
integer from 1 through 2^53 − 1.
integer from 1 through 2^53 − 1. Swift stores `version` as `Int64`, including
on wasm32; the accepted range and canonical wire bytes are platform independent.
- `digest` is `sha256:` followed by the lowercase hexadecimal SHA-256 of the
payload's canonical bytes.

Expand Down
2 changes: 1 addition & 1 deletion Sources/JSONCLIEngine/CLIBuildIdentity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// Generated by Scripts/generate_cli_identity.py; excludes this file.
// SHA-256 of the ordered Package.swift + Sources content manifest (DocC catalogs excluded), not a Git commit.
package enum CLIBuildIdentity {
package static let revision = "sha256:99a750404f5c4af53abe83fb52194c296a09e9e69387be2d4a3984b09551e327"
package static let revision = "sha256:7e58faad4a37141b4fabc6bba4d684a9f6d5ea0d574d9cae92ea8d01da98a81d"
package static let kind = "source-sha256"
}
25 changes: 24 additions & 1 deletion Tests/JSONTests/EnvelopeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ private let taskEnvelope = #"{"digest":"sha256:87245ae1c062ec8fd5e2ab1ac60fbc44f
("[1]", .invalidFormat), ("{}", .invalidFormat),
(replacing(#""formatVersion":1"#, #""formatVersion":2"#), .unsupportedFormatVersion),
(replacing(#""formatVersion":1"#, #""formatVersion":1.5"#), .unsupportedFormatVersion),
(replacing(#""formatVersion":1"#, #""formatVersion":2147483648"#), .unsupportedFormatVersion),
(replacing(#""formatVersion":1"#, #""formatVersion":9223372036854775808"#), .unsupportedFormatVersion),
(replacing(#""formatVersion":1"#, #""formatVersion":"1""#), .invalidFormat),
(replacing(#""mcp.task""#, #""""#), .invalidType),
(replacing(#""mcp.task""#, "7"), .invalidType),
(replacing(#""version":3"#, #""version":0"#), .invalidVersion),
(replacing(#""version":3"#, #""version":-9223372036854775808"#), .invalidVersion),
(replacing(#""version":3"#, #""version":9223372036854775807"#), .invalidVersion),
(replacing(#""version":3"#, #""version":9223372036854775808"#), .invalidVersion),
(replacing(#""version":3"#, #""version":3.5"#), .invalidVersion),
(replacing(#""version":3"#, #""version":9007199254740992"#), .invalidVersion),
(replacing(#""version":3"#, #""version":99999999999999999999"#), .invalidVersion),
Expand All @@ -79,9 +84,27 @@ private let taskEnvelope = #"{"digest":"sha256:87245ae1c062ec8fd5e2ab1ac60fbc44f
#expect(throws: JSONEnvelopeFailure.invalidType) { try JSONEnvelope(type: "", version: 1, payload: .null) }
#expect(throws: JSONEnvelopeFailure.invalidType) { try JSONEnvelope(type: String(repeating: "é", count: 129), version: 1, payload: .null) }
_ = try JSONEnvelope(type: String(repeating: "é", count: 128), version: 1, payload: .null)
for version in [0, -1, 9_007_199_254_740_992, .max] {
let rejectedVersions: [Int64] = [0, -1, .min, 9_007_199_254_740_992, .max]
for version in rejectedVersions {
#expect(throws: JSONEnvelopeFailure.invalidVersion) { try JSONEnvelope(type: "t", version: version, payload: .null) }
}
// The envelope wire contract is independent of the host's Int width.
// Exercise values below, at and beyond the wasm32 signed-integer ceiling.
let accepted: [Int64] = [1, 2_147_483_647, 2_147_483_648, 4_294_967_295, 4_294_967_296, 9_007_199_254_740_991]
let versions: ClosedRange<Int64> = JSONEnvelope.versions
#expect(versions == 1...9_007_199_254_740_991)
for version in accepted {
let value = try JSONEnvelope(type: "mcp.task", version: version, payload: parse(#"{"id":7,"state":"done"}"#))
let pinned = taskEnvelope.replacingOccurrences(of: #""version":3}"#, with: "\"version\":\(version)}")
let encoded = try value.encode()
#expect(encoded.data == Data(pinned.utf8))
#expect(encoded.digest == taskDigest)
let decoded = try decode(pinned)
let decodedVersion: Int64 = decoded.version
#expect(decodedVersion == version)
#expect(decoded == value)
#expect(try decoded.encode() == encoded)
}
// A number binary64 cannot spell exactly is refused unless rounding is chosen on both sides.
let inexact = try JSONEnvelope(type: "t", version: 1, payload: parse("[0.10000000000000001]"))
#expect { try inexact.encode() } throws: { ($0 as? JSONFailure)?.code == .inexactConversion }
Expand Down