Skip to content

fix: a schema refusal ends the snapshot subscription; callers stop matching on ZodError - #9376

Merged
kixelated merged 9 commits into
mainfrom
quest/m1/json-snapshot-refusal
Nov 22, 2026
Merged

kixelated merged 9 commits into
mainfrom
quest/m1/json-snapshot-refusal

Conversation

@kixelated

@kixelated kixelated commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m1/json-snapshot-refusal.md, found by #9344.

Summary

A value that fails a Snapshot.Consumer's schema is a hard failure: next()/latest() reject and the reader's subscription ends, for the hang catalog and every other schema consumer. The two callers that told that rejection apart by matching err instanceof z.core.$ZodError and read on, @moq/room's subscribeJson and the MoQ Boy demo's #runStatus (demo/boy/src/game.ts, which the quest didn't name), drop the match and treat any rejection as the end. No skip path, no warning, and @moq/json has no logging.

This makes the quest's own goal mostly moot: the consumer already rejected on a schema failure, so there is no distinction to expose in its API. All that remained was the instanceof branches (they are gone), a docstring line saying a refusal rejects, and tests pinning it.

Impact

  • Public API: none; js/json/api/index.api.md is unchanged. No wire change.
  • Behavior change (no !): @moq/room metadata and the MoQ Boy status loop no longer survive a schema-failing value; it ends that track's subscription (the last valid value stays, and the other metadata track is unaffected). Migration: a caller that must keep reading past an invalid value reads without a schema and validates itself. js/json/MIGRATE.md is left to the release cut.

Validation

  • snapshot.test.ts: a value that fails the schema rejects latest() with a ZodError.
  • room/src/metadata.test.ts and demo/boy/src/game.test.ts exercise the real consumer through the callers: after a refused value the last valid one stays and a later valid value is never read; the boy loop ends the same way for a track error.
  • just check passes (biome, js build and tests of changed packages, dead-code, API report, quest).

Decisions

  • ✅ Hard fail, per the maintainer: a schema refusal ends the subscription (rejected: skip with a console.warn, an out.refused signal, an opt-in flag). Callers never match on ZodError.
  • Rust moq-json unchanged: its decode errors are one Error::Json(String) and no Rust caller reads past one.
  • The quest is finished by this PR rather than rewritten, since nothing remains.

Caused by

Models

Size: S
Implementer: Claude, claude-sonnet-5-5, unknown effort (arm B)
Implementer: Claude Code, claude-sonnet-5-5, unknown effort (iterate, S, arm B)

Review

Rewritten by quest review after each round.

  • Head: 326f25f

  • Base: origin/main at 040a566

  • Risk: medium, Could break: `@moq/room` metadata and the demo's status loop now end a track's subscription on a schema-failing value instead of warning and reading on, so a malformed publish stops later updates for that track, for users of the shipped room package; the API signatures and wire format are unchanged, and a revert fully undoes it (the `@moq/json` change is only a doc comment and a test).

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session 9209aa31-8a61-492b-bf8c-371b251e450b

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a20424-d0bc-7823-af6b-1dfcc55c2aa0, round 2

  • Score: 10/10, Both read loops now reliably close their subscriptions on exit, resolving the prior finding without introducing new issues in the reviewed changes.

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

  • Findings: none

  • The last round's findings, at 0ab1f0d:

    • Fixed: medium, js/room/src/metadata.ts:295: Close the consumer when the read loop fails; Both read loops now call consumer.close() in a finally block while retaining effect cleanup to unblock pending reads, and Consumer.close() is idempotent and closes its track subscription.

kixelated and others added 6 commits November 22, 2026 00:03
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…to the release cut

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A snapshot consumer reports a schema refusal without callers matching on errors fix(json): a snapshot consumer refuses a schema failure itself Nov 22, 2026
@kixelated
kixelated marked this pull request as ready for review November 22, 2026 08:24
pullfrog[bot]
pullfrog Bot previously approved these changes Nov 22, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Approach: sound. Applying the schema with safeParse inside Snapshot.Consumer makes a refusal a result rather than an error, which removes both instanceof z.core.$ZodError matches at the source instead of giving callers a new error type to match on. An error thrown inside the schema (the catalog's UnsupportedVersion refine) still propagates, and a test pins that.

Reviewed changes: I reviewed all 6 commits: the consumer change, its callers, the API report, and the new tests.

  • Snapshot.Consumer validates itself: decodes raw JSON with a schema-less Decoder, then safeParses it. A failing value is warned about and skipped, and the loop waits for the next frame with the decoder state left as it was. A later delta can therefore repair it, and latest() still skips to the newest group.
  • Config track gains name: used only to label the warning. Every Track.Consumer and Track.Producer already has it, and the API report is updated.
  • Callers simplified: @moq/room subscribeJson and the MoQ Boy #runStatus loop drop their try/catch. A rejection now means a real failure, so the loop ends.
  • Tests: cover a refused snapshot repaired by a later frame of its group, latest() waiting through a refused group, and a schema that throws still rejecting the read.

ℹ️ The hang catalog watch() docs still promise a throw on any failed validation

The JSDoc on watch() in js/hang/src/catalog/root.ts (around line 259) says it throws "on an update that fails validation". After this PR, that holds only for errors thrown inside RootSchema, such as UnsupportedVersion, and for the post-parse checkRenditions and checkResolvable checks. A structurally malformed catalog is now warned about and skipped. In js/watch, that leaves the broadcast loading instead of erroring. The PR body already calls this out as intended, so this is only about the doc wording.

Technical details
# `watch()` JSDoc overstates when it throws

## Affected sites
- js/hang/src/catalog/root.ts:259 — "Throws {@link UnsupportedVersion}, {@link DuplicateRendition}, or {@link EscapingBroadcast} on an update that fails validation."

## Required outcome
- The doc says that a catalog failing `RootSchema` structurally is skipped with a warning, so the previous catalog stays current. It also says the listed errors still end the iteration.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e95e60a1-7855-4055-9013-4e8a5d12be43
Commits

Reviewing files that changed from the base of the PR and between d5dabf2 and 399987d.

Files selected for processing: 6

  • demo/boy/src/game.test.ts
  • demo/boy/src/game.ts
  • js/json/src/snapshot/consumer.ts
  • js/json/src/snapshot/snapshot.test.ts
  • js/room/src/metadata.test.ts
  • js/room/src/metadata.ts

No actionable comments were generated in the recent review.

Walkthrough

Snapshot.Consumer now validates decoded values against its optional schema. It warns and skips invalid values while continuing to read, and returns valid parsed values. New tests cover skipped values and schema exceptions. The demo status loop and metadata subscription loop no longer catch errors from reads and continue. The consumer track configuration now requires both subscribe and name.

Merge Risk: Minimal · previous review d5dab

Schema-invalid snapshot values are now skipped by the consumer itself, so callers no longer need to catch schema errors. No merge-blocking risk was identified in the supplied changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title names the main behavior change: a schema refusal now ends the snapshot subscription, and callers no longer match on ZodError. The changeset matches this. The consumer rejects on schema failu…
Description check Passed The description is specific and on-topic. It explains that a schema failure in Snapshot.Consumer now ends the subscription, and it says the @moq/room subscribeJson and MoQ Boy #runStatus callers drop …
Full details: Title check

Explanation

The title names the main behavior change: a schema refusal now ends the snapshot subscription, and callers no longer match on ZodError. The changeset matches this. The consumer rejects on schema failure, the room and MoQ Boy callers drop the ZodError match, and the quest file is deleted. The title is clear and specific, and it fits the changes in the summaries and objectives.

Full details: Description check

Explanation

The description is specific and on-topic. It explains that a schema failure in Snapshot.Consumer now ends the subscription, and it says the @moq/room subscribeJson and MoQ Boy #runStatus callers drop their ZodError matching. It also lists the files affected, the behavior change, validation steps, and the deferred MIGRATE.md update. This matches the changeset described in the raw summary.

Finishing Touches

Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 10d7a8d8-982c-46ab-8f2f-15158b1abff0
Commits

Reviewing files that changed from the base of the PR and between 0c5b90d and d5dabf2.

Files selected for processing: 7

  • demo/boy/src/game.test.ts
  • demo/boy/src/game.ts
  • js/json/api/index.api.md
  • js/json/src/snapshot/consumer.ts
  • js/json/src/snapshot/snapshot.test.ts
  • js/room/src/metadata.ts
  • quest/m1/json-snapshot-refusal.md
Files with no reviewable changes: 1

  • quest/m1/json-snapshot-refusal.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

…matching on ZodError

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title fix(json): a snapshot consumer refuses a schema failure itself fix: a schema refusal ends the snapshot subscription; callers stop matching on ZodError Nov 22, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues. One stale comment is flagged inline.

Approach: sound, and simpler than the previous revision. Decoder.decode() already parses against the schema and throws, so a refusal now ends the subscription like any other failed read. That removes the ZodError matches without adding a skip path or new API. The prior note about the hang catalog watch() JSDoc no longer applies, because a structurally invalid catalog throws again.

Reviewed changes: I reviewed the reversal from skip-with-warning to a hard failure since d5dabf2.

  • Restored Snapshot.Consumer validation: removed safeParse, the console.warn, and the name field on config track. The schema goes back to the Decoder, and the API report matches main again.
  • Documented the refusal: the class docs now say that a schema failure rejects the read and the caller ends the subscription.
  • Replaced the tests: a single snapshot.test.ts case pins latest() rejecting with a ZodError. The room test checks that the refused track ends while the other track keeps updating. The MoQ Boy test is parameterized so that a schema failure and a track error both end the loop with the last valid status kept.
  • Updated subscribeJson docs: they now say that a non-matching value ends the subscription.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Comment thread demo/boy/src/game.ts Resolved
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes: the delta since the prior pullfrog review.

  • Fixed stale comment: demo/boy/src/game.ts now says a rejection, whether a schema failure or a track error, ends the status loop. This applies the earlier suggestion unchanged.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit e01b49b Nov 22, 2026
5 checks passed
@kixelated
kixelated deleted the quest/m1/json-snapshot-refusal branch November 22, 2026 20:41
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