From ec4c6ea705796bd75ac74a6894faa8179f3f8396 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:58:08 -0700 Subject: [PATCH 1/2] chore(quest): claim quest/m1/release-audit/ietf-timestamps.md Quest-Claim: 7d3b6692616093d7 From ac237c8148445f050f45b5c1a25b2caba87a4e69 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:59:11 -0700 Subject: [PATCH 2/2] fix(net): convert IETF object timestamps with Timestamp.as `encodeObjectTime` scaled with its own multiply and divide, which lost precision at the same scale (a NANO 9007199254740985 went out as ...984) and wrote values past 2^53 that its own decoder rejects, such as 10^10 ms at nanosecond scale. Use `Timestamp.as`, as Lite does: exact at the same scale, and a RangeError before anything is written when the converted value leaves the range a Timestamp holds. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EeyiEy5FWz3z44DYZVo7vU --- js/net/src/ietf/object.test.ts | 32 +++++++++++++++++++++++ js/net/src/ietf/object.ts | 4 ++- quest/m1/release-audit/README.md | 3 +-- quest/m1/release-audit/ietf-timestamps.md | 30 --------------------- 4 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 js/net/src/ietf/object.test.ts delete mode 100644 quest/m1/release-audit/ietf-timestamps.md diff --git a/js/net/src/ietf/object.test.ts b/js/net/src/ietf/object.test.ts new file mode 100644 index 00000000000..ba6cec1acdb --- /dev/null +++ b/js/net/src/ietf/object.test.ts @@ -0,0 +1,32 @@ +import { expect, test } from "bun:test"; +import { Cursor } from "../stream.ts"; +import { Timescale, Timestamp } from "../time.ts"; +import { decodeObjectTime, encodeObjectExtensions } from "./object.ts"; +import { Version } from "./version.ts"; + +const VERSION = Version.DRAFT_17; + +/** `timestamp` written at `timescale` and read back. */ +async function roundtrip(timestamp: Timestamp, timescale: Timescale): Promise { + const properties = await encodeObjectExtensions(timestamp, timescale, VERSION); + return decodeObjectTime(new Cursor(properties, VERSION), timescale); +} + +test("a same-scale timestamp is written exactly, up to the largest a Timestamp holds", async () => { + for (const value of [0, 1, 9_007_199_254_740_985, Number.MAX_SAFE_INTEGER]) { + const read = await roundtrip(new Timestamp(value, Timescale.NANO), Timescale.NANO); + expect(read?.value).toBe(value); + } +}); + +test("a timestamp is converted to the track's scale", async () => { + expect((await roundtrip(Timestamp.fromMillis(1234), Timescale.NANO))?.value).toBe(1_234_000_000); + expect((await roundtrip(Timestamp.fromMicros(1_500), Timescale.MILLI))?.value).toBe(2); +}); + +test("a conversion past what a Timestamp holds is refused before anything is written", async () => { + // 10^10 ms is 10^16 ns, past 2^53. + await expect(encodeObjectExtensions(Timestamp.fromMillis(10_000_000_000), Timescale.NANO, VERSION)).rejects.toThrow( + RangeError, + ); +}); diff --git a/js/net/src/ietf/object.ts b/js/net/src/ietf/object.ts index e7b068b795f..1ffcdc09c74 100644 --- a/js/net/src/ietf/object.ts +++ b/js/net/src/ietf/object.ts @@ -59,7 +59,9 @@ async function encodeObjectTime( timescale: Timescale, version: IetfVersion, ): Promise { - const value = Math.round((timestamp.value * timescale) / timestamp.scale); + // The shared conversion: exact at the same scale, and refused before anything is written when + // the result leaves the range a Timestamp, and so the receiver, can hold. + const value = Math.round(timestamp.as(timescale)); await encodeObjectPropertyType(w, PROP_TIMESTAMP, 0n, version); await w.u62(BigInt(value)); } diff --git a/quest/m1/release-audit/README.md b/quest/m1/release-audit/README.md index 58c4f100770..a0794130601 100644 --- a/quest/m1/release-audit/README.md +++ b/quest/m1/release-audit/README.md @@ -83,7 +83,7 @@ network-impairment performance result is implied by these checks. ## Required -The 21 children comprise 17 reproduced or source-confirmed findings, three +The 20 children comprise 16 reproduced or source-confirmed findings, three contract/lifetime investigations, and one security-review pointer. Each child records whether its behavior is new on main or inherited from release. @@ -104,7 +104,6 @@ child records whether its behavior is new on main or inherited from release. - [Release finished FFI codecs](/quest/m1/release-audit/ffi-finished.md) - preserving finished tracks does not preserve drained encoders and scratch buffers - [Release HLS server state](/quest/m1/release-audit/hls-shutdown.md) - final server drop retires its watchers while publishers remain live - [Retire expiry metadata](/quest/m1/release-audit/expiry-index.md) - empty deadline entries do not accumulate with historical read budgets -- [Preserve IETF timestamps](/quest/m1/release-audit/ietf-timestamps.md) - JS encoding uses exact same-scale conversion and rejects unsupported values before sending - [Settle Go reservation release](/quest/m1/release-audit/go-reservation.md) - investigate prompt allocation release through the public wrapper - [Settle finite HLS import](/quest/m1/release-audit/hls-finite.md) - initially ended playlists have an explicit and tested start position - [Settle HLS timestamp resets](/quest/m1/release-audit/hls-discontinuity.md) - unchanged-map discontinuities preserve timeline identity or are explicitly refused diff --git a/quest/m1/release-audit/ietf-timestamps.md b/quest/m1/release-audit/ietf-timestamps.md deleted file mode 100644 index 2c7cc900434..00000000000 --- a/quest/m1/release-audit/ietf-timestamps.md +++ /dev/null @@ -1,30 +0,0 @@ -# [S] Preserve timestamp conversion rules in JS IETF objects - -## Goal - -The JS IETF object encoder preserves exact same-scale timestamps and refuses -unrepresentable conversions before emitting data its receiver rejects. - -## Plan - -P2 inherited correctness defect at main 1d43c096e0. -`js/net/src/ietf/object.ts::encodeObjectTime` multiplies and divides Numbers -directly, bypassing Timestamp.as and its same-scale shortcut and range check. -A valid NANO timestamp 9007199254740985 roundtrips as 9007199254740984 through -IETF. The normal conversion, Lite path, and native same-scale conversion -preserve it. This becomes reachable around 104 days on a nanosecond timeline. - -Converting Timestamp.fromMillis(10_000_000_000) to the IETF nanosecond scale -also emits 10^16 ticks, exceeding the JS Timestamp range. Its own decoder -rejects the result, whereas Timestamp.as and Lite reject the conversion -before sending. These are local encoder/decoder reproductions using valid -API inputs, not end-to-end transport tests. - -Use the shared timestamp conversion contract in IETF framing. Test exact -same-scale boundaries, supported conversions, and refusal before encoding -out-of-range results. Keep supported wire values unchanged; report any -observable error-behavior change. No new timestamp API is needed. - -## Related - -- [Binding timestamps](/quest/m1/binding-timestamps.md) - exact values through language bindings, separate from JS protocol encoding