Repository navigation
fix: a schema refusal ends the snapshot subscription; callers stop matching on ZodError - #9376
Conversation
Quest-Claim: 677c4b61c345e88b
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>
There was a problem hiding this comment.
✅ 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.Consumervalidates itself: decodes raw JSON with a schema-lessDecoder, thensafeParses 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, andlatest()still skips to the newest group.- Config
trackgainsname: used only to label the warning. EveryTrack.ConsumerandTrack.Produceralready has it, and the API report is updated. - Callers simplified:
@moq/roomsubscribeJsonand the MoQ Boy#runStatusloop 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.claude-opus-5-5 | 𝕏
|
Warning Review limit reachedYou'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. View limit details
No actionable comments were generated in the recent review. WalkthroughSnapshot.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 Merge Risk:
|
…matching on ZodError Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
ℹ️ 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.Consumervalidation: removedsafeParse, theconsole.warn, and thenamefield on configtrack. The schema goes back to theDecoder, and the API report matchesmainagain. - 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.tscase pinslatest()rejecting with aZodError. 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
subscribeJsondocs: they now say that a non-matching value ends the subscription.
claude-opus-5-5 | 𝕏
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes: the delta since the prior pullfrog review.
- Fixed stale comment:
demo/boy/src/game.tsnow says a rejection, whether a schema failure or a track error, ends the status loop. This applies the earlier suggestion unchanged.
claude-sonnet-5-5 | 𝕏

Finishes quest/m1/json-snapshot-refusal.md, found by #9344.
Summary
A value that fails a
Snapshot.Consumer'sschemais 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 matchingerr instanceof z.core.$ZodErrorand read on,@moq/room'ssubscribeJsonand 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/jsonhas 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
instanceofbranches (they are gone), a docstring line saying a refusal rejects, and tests pinning it.Impact
js/json/api/index.api.mdis unchanged. No wire change.!):@moq/roommetadata 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 aschemaand validates itself.js/json/MIGRATE.mdis left to the release cut.Validation
snapshot.test.ts: a value that fails the schema rejectslatest()with aZodError.room/src/metadata.test.tsanddemo/boy/src/game.test.tsexercise 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 checkpasses (biome, js build and tests of changed packages, dead-code, API report, quest).Decisions
console.warn, anout.refusedsignal, an opt-in flag). Callers never match onZodError.moq-jsonunchanged: its decode errors are oneError::Json(String)and no Rust caller reads past one.Caused by
@moq/roommatched onZodErrorto tell a refused value from a failure (found by reviewer, fix(js): hang catalog/CMAF, watch rotation, and room metadata bugs #9344)ZodErrormatchModels
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 reviewafter 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-371b251e450bReviewer: Codex, gpt-6.1-sol, medium effort
Session:
01a20424-d0bc-7823-af6b-1dfcc55c2aa0, round 2Score: 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:
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.