Skip to content

refactor(kio)!: move kio back into rs/kio, and pace a group no subscriber picked up yet - #9770

Merged
kixelated merged 17 commits into
mainfrom
quest/m0/kio-main
Nov 27, 2026
Merged

kixelated merged 17 commits into
mainfrom
quest/m0/kio-main

Conversation

@kixelated

@kixelated kixelated commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m0/kio-main.md, absorbs quest/m0/kio-crates-io.md, and moves kio back from kixel-ai/kio.

Problem

kio was split into kixel-ai/kio (moq-dev/moq#9675) mostly to prototype model checking. Its only consumer is moq, and little kio-only work is planned, so the split cost every kio change a two-repo dance: bump the rev, hakari, both lockfiles, nix/Cargo.nix, and the bench and demo crates. moq also pinned an old kio rev (866ef06). On kio main, the simulated scheduler (kixel-ai/kio#10) reorders polls and fails two moq-net tests.

Approach

Move. Revert #9675's removal and three-way merge kio main (ce495aa) into rs/kio, rs/kio/macros, and rs/kio/verify. Workspace path deps replace the git rev everywhere: hakari, bench crates, lockfiles, nix/Cargo.nix, and deny.toml. lab/ (the pure-machine prototype) stays in the archived repo, and quests link it at a pinned commit. kio's tooling comes along:

  • rs/kio/AGENTS.md, covering kio's rules and the Verus proof of src/log.rs.
  • nix develop .#verus and just rs verify, for the proof.
  • just rs sweep (random and pct schedules with KIO_SIM_PROBE), just rs miri-seeds, and just rs tsan. sh/rs/nightly.sh is the nightly sysroot helper that miri.sh now shares.
  • Nightly gains the sweep, miri-seeds, tsan, and a kio-verify job. The merge gate does not change.
  • kio's quests are ported into quest/, and stale links to kixel-ai/kio are updated.

Pacing (from the earlier session on this branch). Ingest's pace gate treated a group no reader had picked up yet as unwatched, so it read on past the pace window. A subscriber that picked the group up a moment later found it already a stream window ahead. Real readers always pick a group up after ingest starts, so the one-window bound held only when the reader won the race. A group not yet picked up is now owed to its track's subscribers. Its gate closes from the start and opens once its readers leave, or, before anyone picks it up, once the track's last subscriber leaves (Handle::owed, Handle::poll_unowed, Pace::hold). ReceiveCredit.tla makes a late reader's arrival fair and lets nobody drop a group they still owe. EveryPauseFits and ChargedAllowance now hold with late readers too. With this, hop 2 of two_relays_bound_their_cache_and_resume_without_a_hole holds about 986 KB on every version.

Test. draft22_cold_widening_finishes_the_largest_group expected a transient Live aggregate at start=2. The step-1 widening goes out as Absolute{group 1}. On main that update hadn't reached the publisher when step 2 checked, so the check passed against step 1's stale Live. When it lands first, the narrowing to group 3 resolves the publisher copy's time start to the newest group, group 1, so the aggregate settles at keys(1..) under every schedule. Both sessions on this branch reached this independently.

Other.

  • moq-net owns the epoch kio dropped, as moq_net::time::EPOCH.
  • The relay's DialersPhase::Open is boxed for kio's new size lint.
  • kio-macros' not_send UI snapshot is re-blessed on moq's toolchain. It matches the pre-split file.
  • sh/migrate.sh lets a newly added package bring its own MIGRATE.md, with tests. Otherwise the gate would reject kio's guides as edits outside the release cut.

Impact

  • API, breaking for kio users of moq's old pin (see rs/kio/MIGRATE.md, Unreleased):
    • Wall::MOQ_EPOCH is removed; use moq_net::time::EPOCH instead.
    • MOQ_SIM_SEED is now KIO_SIM_SEED, with no fallback.
    • Wall::from_unix_secs is const.
  • API, added: moq_net::time::EPOCH (2020-01-01T00:00:00Z) and kio's model feature (BFS checker).
  • Wire: none.
  • Behavior: relay ingest now pauses a group no subscriber has picked up yet once it passes the pace window, instead of reading on.
  • Publishing: release-plz publishes kio and kio-macros from moq again. That needs the crates.io trusted publisher moved back (see Follow-ups).
  • Gate: unchanged in scope. The new kio jobs are nightly-only.

Alternatives

  • Keep kio separate and only bump the pin, which was this PR's original scope. Rejected per the maintainer's call: kio has no other consumer.
  • Fix two_relays by attaching the test's reader before the second frame. I tried this first. It only hides the bug: real readers attach late, so the pacing fix is the root cause.
  • Fix draft22 by having the subscriber never narrow a live subscription to an absolute start. That is a behavior change and needs its own PR.
  • Sync draft22 on kio::clock::sim::idle(). It never settles in this fixture, because a periodic timer keeps re-arming.

Follow-ups

  • Maintainer: move the crates.io trusted publisher for kio and kio-macros from kixel-ai/kio to moq-dev/moq release-rs.yml (environment publish). Tracked in quest/m3/crates-trusted-publisher.md.
  • Maintainer: archive kixel-ai/kio once this lands.
  • quest/m1/owed-group-pass-over.md (added here): the pacing fix counts a group nobody picked up as owed while its track has any subscriber, so a group every subscriber's ranges pass over parks its ingest until it expires. The maintainer accepted the gap in review and planned the per-key fix with its TLA+ pass-over action.
  • workspace-hack's [build-dependencies] regain about 60 host crates now that kio is a workspace member again, the same as before the split; moving kio-macros to hakari's traversal-excludes changes nothing, so the source is elsewhere.
  • The IETF publisher maps an Absolute filter past the newest group to a time start, which a copy resolves back to the newest group, so the origin is asked for one group more than the subscriber wants. This is harmless, since the serve trims it, but worth a look alongside the subscriber narrowing above.
  • From the earlier session: moq-relay --all-features stack overflows in implementation::cluster_dials_advertise_the_relay and in bursts_cross_a_*::loopback, which also fail on main. KIO_SIM_PROBE=1 on draft22_cold_widening reports a possible lost wakeup in RunSubscribe's Serve step. quest/m4/sim-adversarial-sweep.md owns probe sweeps.

Validation

  • quest gate just ci origin/main on the head: clean, 13,990 tests passed. bench/fanout.test.py passes.
  • just rs sweep: 251 kio tests pass under random and under pct.
  • nix develop .#verus --command just rs verify: 21 verified, 0 errors.
  • two_relays_bound_their_cache… and draft22_cold_widening… under KIO_SIM_SCHEDULE random and pct, seeds 1–10 each: 40/40 passed. The draft22 fix alone also passes on main's old kio pin, and 40/40 under random and pct with seeds 1–20.
  • From the earlier session, not rerun after the move: just test interop --all, and every rs/moq-net/verify/credit TLA+ config (ReceiveCredit 404k states, ReceiveCreditSegments 462k, ReceiveCreditGuards 12.1k, plus Wide, Three, and Send).

Decisions

  • The maintainer chose to fold the move into this PR: one PR covering the move, the migration, and the fixes, and deleting kio-crates-io.md.
  • The maintainer accepted review finding Bump golang.org/x/net from 0.0.0-20220421235706-1d1ef9303861 to 0.7.0 in /cert #5 (the owed-group pass-over stall) for quest/m1/owed-group-pass-over.md rather than growing this PR.
  • Review fixes: a reader marks a group held only once it counts, and the gate reads the mark first, which closes the first-reader race; the release cut quest now checks kio and kio-macros against crates.io (kio needs 0.7.0) instead of this PR bumping versions; the fan-out bench resolves each checkout's own kio again.
  • The earlier session, with the user away, chose owed-group semantics over a read-on timeout, kept MIGRATE.md edits for the release cut, and left the verify-credit sync commit unchanged.

Caused by

  • moq-dev/moq#7388: its pace gate read on whenever a group had no reader yet, so a late reader found it a stream window ahead. Found by check: the kio scheduler.
  • moq-dev/moq#9293: draft22_cold_widening asserted a transient narrowing instead of the settled demand. Found by check: the kio scheduler.

Models

  • Size: L
  • Implementer: Claude Code, claude-opus-5-5, unknown (arm A)
  • Implementer: Claude Code, claude-opus-5-5, high

🤖 Generated with Claude Code

(Written by Claude Opus 5.5 with high)

Review

Rewritten by quest review after each round.

  • Head: 802e8f1

  • Base: origin/main at fcfa5b1

  • Risk: high, it changes .github/workflows/nightly.yml, which is always high, as are 3 more of its paths: workflows run with the repository's secrets

  • Classified: high by the always-high paths

  • Risk file: bb7b1c0de60b

  • Accepted by the maintainer: Maintainer accepted 2026-11-27: the owed-group pass-over stall is bounded by group expiry and needs a narrowing while another subscriber stays attached, while the pacing fix closes the cache bound for every late reader; the per-key owed check and its TLA+ pass-over action are planned in quest/m1/owed-group-pass-over.md.

  • Reviewer: Codex, gpt-6.2-sol, high effort

  • Session: 01a21e3e-00a8-78a3-8b90-921df496a4a4, round 2

  • Score: 10/10, All three earlier findings are fixed, and the changes since the last review introduce no new findings.

  • Rounds: 2; first round 3 (high 1, medium 2); findings 3 (high 1, medium 2): fixed 3, refuted 0, open 0

  • Findings: none

  • The last round's findings, at a532c8a:

    • Fixed: high, rs/kio/Cargo.toml:8: Release kio before publishing its MoQ dependents; The release checklist now requires checking the independent registry versions, bumping `kio` to 0.7.0, and raising the workspace dependency requirements before publication (`quest/m3/release/cut.md:25`).
    • Fixed: medium, rs/moq-net/src/model/group.rs:3583: Publish first-reader arrival atomically with group demand; Both attachment paths count the reader before marking the group held, and ingest reads the held marker before the count, closing the window where it could see the first reader as held but uncounted (`rs/moq-net/src/model/group.rs:3583`, `rs/moq-net/src/model/group.rs:3710`, `rs/moq-net/src/model/group.rs:3748`).
    • Fixed: medium, bench/run.sh:1275: Resolve the fanout harness against each baseline’s kio source; The runner rewrites each copied harness from the selected checkout’s workspace dependency, preserving Git pins and resolving local paths for their respective baselines (`bench/run.sh:1276`, `bench/fanout.py:177`).
  • Reviewer: Claude Code, claude-opus-5-5, high effort, second

  • Session: 4d896c8b-6ff0-430d-9b29-cbb20eb664a1, round 2

  • Score: 8/10, The sweep exit status, the fan-out rewrite, the drift paths, and the held/count race are all fixed; only the owed-group pass-over stall remains, and the maintainer decision deferring it can't yet be checked outside this PR's own quest file.

  • Rounds: 2; first round 5 (medium 5); findings 5 (medium 5): fixed 3, refuted 1, open 1

  • Findings, accepted by the maintainer:

    • Medium, rs/moq-net/src/model/group.rs:3711: A group every cursor skips still counts as owed and parks its ingest stream
  • The last round's findings, at a532c8a:

    • Fixed: medium, rs/justfile:414: `rs sweep` loop hides a failure on the random schedule; rs/justfile:414 now ends the loop body with `|| exit 1`, so a failing `random` schedule fails the recipe.
    • Open: medium, rs/moq-net/src/model/group.rs:3705: A group every cursor skips counts as owed and parks its ingest stream; owed()/poll_unowed() are unchanged on this point, and the maintainer acceptance appears only in quest/m1/owed-group-pass-over.md, which this PR adds, so it can't be verified from the base or a GitHub review.
    • Refuted: medium, .claude/skills/verify-credit/SKILL.md:79: verify-credit sync commit and drift path list are stale; The drift path list now includes group.rs, and rs/moq-net/verify/README.md:11 says to move the sync commit only once the model describes the code, which pre-existing unmirrored commits rule out at the base.
    • Fixed: medium, bench/run.sh:1276: Fan-out bench of a git-pinned-kio base points at a missing rs/kio; bench/run.sh:1276 again calls `fanout.py rewrite`, whose `kio_dependency_line` takes each checkout's own path/git/version kio entry before falling back to rs/kio.
    • Fixed: medium, rs/moq-net/src/model/pace.rs:62: Group reader lifecycle split between a `Pace::held` atomic and the channel's consumer count; consume/try_consume now count the reader before `hold()`, and owed/poll_unowed read `held` (SeqCst) before the count, so a writer can no longer see held with no reader while one is arriving.

kixelated and others added 15 commits November 27, 2026 05:06
Quest-Claim: a27910f86db107be
…MOQ_EPOCH

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he start

Ingest read past its window while a received group had no consumer yet, since pacing treated a group nobody holds as unwatched. A group is now owed to its track's subscribers until a reader picks it up, so its writer keeps to one window; it reads on once its readers leave or its track's last subscriber does. The credit model's late readers now pause from the start, and its allowance rules hold for them too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WIP checkpoint: reverts #9675 and imports kixel-ai/kio main (ce495aa).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s one frame

A group nobody reads yet is ingested unpaced by design, so the test's bound held only
while its reader attached before hop 2 ingested a window. kio's new scheduler runs the
relays first, so moq-transport (and moq-lite under random schedules) overshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…emand

The publisher's demand at the third narrowing follows the absolute start the widening before it sent, so it settles on group 1. The live join the test waited for was only the state before that update landed, which kio's old FIFO schedule happened to show first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under kio's new fifo schedule the publisher applies the step-1 widening
(Absolute group 1) before step 2 narrows. The old expectation of a live
join only held because that update had not landed yet; once it does, the
narrowing to group 3 resolves to the newest group, group 1, and the
aggregate never becomes a live join. Expect the state every interleaving
converges to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Move moq to kio's main and keep moq-transport relay ingest to one pacing window fix(net): pace a group no subscriber picked up yet; move to kio main Nov 27, 2026
Keeps that branch's owed-group pacing (and its TLA+), which fixes
two_relays_bound_their_cache at the root, and drops this branch's test-only
reordering of that test. kio itself comes from rs/kio rather than the
pinned git rev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title fix(net): pace a group no subscriber picked up yet; move to kio main refactor(kio)!: move kio back into rs/kio, and pace a group no subscriber picked up yet Nov 27, 2026
- A reader marks a group held only once it counts, and the gate reads the
  mark before the count, so it never opens between the two.
- `just rs sweep` fails when either schedule fails.
- The fan-out bench resolves each checkout's own kio source again, so a
  base from the git-pinned period still builds.
- verify-credit's drift command covers group.rs; kio's verify package knows
  the `model` feature; kio's AGENTS.md defers to rs/AGENTS.md on host time.
- The release cut checks kio and kio-macros against crates.io.
- quest/m1/owed-group-pass-over.md plans the accepted pass-over gap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Handoff note from a parallel session that worked this quest before the kio move landed here. I will not push to this branch.

  • Parked fix: branch quest-review/kio-main-first-reader (c054aee8cc) fixes a review finding from its round on f6e6597e94. consume and try_consume marked a group held before counting the reader, so ingest could briefly treat an arriving first reader as gone and read past the window. The fix counts the reader first, and owed/poll_unowed check held before the count. It also adds group.rs to the verify-credit history command. It cherry-picks cleanly onto a532c8a78f: git cherry-pick c054aee8cc.
  • Refuted finding: "a group every subscriber's with_range excludes stays paused and blocks the next group." moq-quic grants 100 concurrent streams by default (rs/moq-quic/src/config/transport/mod.rs:26), so only that group's own stream stalls. A pause needs a whole stream window, the paused budget caps pauses (rs/moq-net/src/transport/boxed.rs:167), and the pause ends when the group closes, expires or is evicted, or the last subscriber leaves. Per-group demand would put every subscriber's cursor in TrackState, a cost fan-out pays on every paced poll.

(Written by Claude Opus 5.5)

@kixelated
kixelated marked this pull request as ready for review November 27, 2026 20:18
@kixelated
kixelated added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 41ebd2f Nov 27, 2026
8 checks passed
@kixelated
kixelated deleted the quest/m0/kio-main branch November 27, 2026 21:15
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