Skip to content

feat(json): ValueWriter stamps value-track updates itself - #99

Merged
Frando merged 1 commit into
mainfrom
Frando/value-writer
Nov 16, 2026
Merged

Frando merged 1 commit into
mainfrom
Frando/value-writer

Conversation

@Frando

@Frando Frando commented Nov 16, 2026

Copy link
Copy Markdown
Member

Value tracks are timed since the moq bump in #94: every update carries a
timestamp, and moq-net refuses a group that starts at or before the group
before it (TimestampMismatch). A scalar value starts a new group on every
changed update, so two updates in the same millisecond fail, and every
caller had to keep its own monotonic clock.

This adds ValueWriter<T> in a small new crate, moq-ext-json, and
returns it from Node::publish_value and LocalBroadcast::value_track.

  • update(&v) stamps from the moq clock. A stamp that is not past the last
    one becomes one tick after it, so updates never collide.
  • The stamp is taken and the frame written under one lock, so clones on
    different threads stay ordered.
  • update_at(&v, at) takes a caller's time, mutate edits in place,
    finish ends the track, and the track finishes when the last clone
    drops.
  • A burst of N updates within one tick runs N-1 ticks ahead of the clock
    until updates slow down.

It lives in its own crate because iroh-live-node and moq-ext-publisher do
not depend on each other. The facade re-exports it as
iroh_live::ValueWriter. The reading side is unchanged.

Breaking: publish_value and value_track return a ValueWriter instead
of a raw snapshot producer. docs/migration.md has the before and after.

Tests cover ties, a clock stepping back, a burst of 100 updates, clones on
two threads, update_at before the previous group, and finish on the last
drop.

🤖 Generated with Claude Code

A latest-value JSON track is timed, and moq-net refuses a group that
starts at or before the group before it. A scalar value starts a group
with every change, so two changes in the same millisecond failed when
the caller stamped them with `Timestamp::from(Instant::now())`, and every
application needed its own stamp counter and a drop guard that finishes
the track.

The new `moq-ext-json` crate adds `ValueWriter<T>`. It wraps the moq-json
snapshot producer, stamps each update from the moq clock at the track's
timescale, and moves a stamp that does not pass the previous one a tick
past it, so stamps strictly increase. Clones share the track and the
stamps, and stamp and write under one lock, so clones on several threads
cannot reorder them. The last clone to drop finishes the track.
`update_at` takes an explicit time, `mutate` edits in place, and
`producer()` hands out the underlying producer for refresh and cut.

`Node::publish_value` and `LocalBroadcast::value_track` return the
writer, and `iroh-live-node`, `moq-ext-publisher` and the `iroh-live`
facade re-export it. The type lives in its own crate because the node
and the publisher do not depend on each other. Nothing changes on the
wire or on the read side.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Frando
Frando merged commit 2705f0c into main Nov 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant