Skip to content

Tolerate unknown IChange $type via PeekThenConcreteChangeConverter#80

Merged
hahn-kev merged 7 commits into
mainfrom
feat/unknown-change-type-converter
Jul 20, 2026
Merged

Tolerate unknown IChange $type via PeekThenConcreteChangeConverter#80
hahn-kev merged 7 commits into
mainfrom
feat/unknown-change-type-converter

Conversation

@hahn-kev-bot

@hahn-kev-bot hahn-kev-bot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replace STJ JsonPolymorphic on IChange with PeekThenConcreteChangeConverter: known $type values deserialize via cached concrete JsonTypeInfo; unknown values become OpaqueChange (raw JSON preserved for round-trip).
  • Emit serialize-only synthetic $type on registered concrete change types from CrdtConfig, and skip snapshot apply for changes that do not support NewEntity (opaque/unknown creates).
  • Add unit coverage for happy-path, opaque, and $type-first requirements.

Test plan

  • dotnet test src/SIL.Harmony.Tests --filter ChangeConverterTests
  • dotnet test src/SIL.Harmony.Tests (full suite)
  • Confirm sync/round-trip of a commit containing a known change plus an unregistered $type keeps the unknown payload and does not throw
  • Confirm older clients skip applying opaque creates without dropping the change from history

Summary by CodeRabbit

  • New Features
    • Added support for preserving and round-tripping unrecognized change types without losing their original payload.
    • Mixed commits containing both known and unknown changes can now be deserialized safely.
  • Bug Fixes
    • Snapshot processing no longer fails when commits contain unsupported/unknown changes; such changes are kept in history while snapshot creation is skipped.
    • Enforced a consistent JSON format requiring the change type discriminator to appear first.
  • Tests
    • Added coverage for known/unknown change JSON round-tripping and discriminator ordering rules.

hahn-kev and others added 3 commits July 10, 2026 14:19
Co-authored-by: Cursor <cursoragent@cursor.com>
Unknown $type values will be held as OpaqueChange once the converter owns discrimination.

Co-authored-by: Cursor <cursoragent@cursor.com>
CrdtConfig owns IChange discrimination with synthetic $type on write; SnapshotWorker skips opaque creates.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@hahn-kev, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8106e813-6362-428e-994d-8eaee14df579

📥 Commits

Reviewing files that changed from the base of the PR and between 1b398e8 and 5f0a869.

📒 Files selected for processing (2)
  • src/SIL.Harmony/CrdtConfig.cs
  • src/SIL.Harmony/SnapshotWorker.cs
📝 Walkthrough

Walkthrough

The PR replaces interface-level polymorphic JSON handling with a custom converter, adds OpaqueChange for unknown discriminators, preserves unknown payloads during serialization, skips unsupported opaque entity creation, and adds round-trip and JSON-shape tests.

Changes

Change serialization and replay

Layer / File(s) Summary
Discriminator mapping and serializer metadata
src/SIL.Harmony/Changes/Change.cs, src/SIL.Harmony/CrdtConfig.cs, src/SIL.Harmony/Changes/PeekThenConcreteChangeConverter.cs
CrdtConfig builds discriminator maps and injects synthetic $type properties, while IChange delegates polymorphic handling to the custom converter.
Known and opaque change conversion
src/SIL.Harmony/Changes/PeekThenConcreteChangeConverter.cs, src/SIL.Harmony/Changes/OpaqueChange.cs
The converter validates $type ordering, deserializes registered types, stores unknown payloads in OpaqueChange, and reserializes preserved JSON.
Replay behavior and converter tests
src/SIL.Harmony/SnapshotWorker.cs, src/SIL.Harmony.Tests/ChangeConverterTests.cs
Snapshot application skips unsupported new-entity changes, and tests cover known and unknown round-tripping, mixed commits, preservation, and discriminator ordering.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CommitJson
  participant CrdtConfig
  participant PeekThenConcreteChangeConverter
  participant SnapshotWorker
  CommitJson->>CrdtConfig: Create serializer options and discriminator maps
  CommitJson->>PeekThenConcreteChangeConverter: Deserialize change JSON
  PeekThenConcreteChangeConverter->>PeekThenConcreteChangeConverter: Match first $type discriminator
  PeekThenConcreteChangeConverter->>CommitJson: Return known concrete change
  PeekThenConcreteChangeConverter->>CommitJson: Return OpaqueChange with raw JSON
  SnapshotWorker->>OpaqueChange: Check SupportsNewEntity()
  SnapshotWorker->>SnapshotWorker: Skip unsupported opaque creation
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately highlights the main change: unknown IChange $type values are handled by PeekThenConcreteChangeConverter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/unknown-change-type-converter

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/SIL.Harmony/CrdtConfig.cs`:
- Around line 49-65: Update BuildChangeDiscriminatorMaps to construct the
reverse discriminator map in a local dictionary alongside knownChanges, populate
both fully within the loop, then assign the completed map to
_changeTypeDiscriminators immediately before returning. Do not publish the field
until all entries have been validated and added.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 00791495-bffd-4c2a-baae-784dde3c8328

📥 Commits

Reviewing files that changed from the base of the PR and between 01efe25 and 2d008f7.

📒 Files selected for processing (8)
  • .gitignore
  • AGENTS.md
  • src/SIL.Harmony.Tests/ChangeConverterTests.cs
  • src/SIL.Harmony/Changes/Change.cs
  • src/SIL.Harmony/Changes/OpaqueChange.cs
  • src/SIL.Harmony/Changes/PeekThenConcreteChangeConverter.cs
  • src/SIL.Harmony/CrdtConfig.cs
  • src/SIL.Harmony/SnapshotWorker.cs

Comment thread src/SIL.Harmony/CrdtConfig.cs Outdated
hahn-kev and others added 2 commits July 16, 2026 10:22
_changeTypeDiscriminators was assigned before its loop finished populating
it, so a concurrent JsonTypeModifier callback (invoked lazily by STJ on
arbitrary threads) could observe a partially-built dictionary. Build into a
local and assign the field once, so readers only ever see null or a complete
map.

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

@myieye myieye 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.

Just some improvement ideas/suggestions, but the feature looks solid

Comment thread src/SIL.Harmony/SnapshotWorker.cs Outdated
Comment thread src/SIL.Harmony/Changes/PeekThenConcreteChangeConverter.cs Outdated
Comment thread src/SIL.Harmony/Changes/PeekThenConcreteChangeConverter.cs
Comment thread src/SIL.Harmony/CrdtConfig.cs Outdated
Comment thread src/SIL.Harmony/CrdtConfig.cs Outdated
hahn-kev and others added 2 commits July 17, 2026 08:58
Co-authored-by: Tim Haasdyk <myieye@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@hahn-kev
hahn-kev merged commit aae2ee0 into main Jul 20, 2026
7 checks passed
@hahn-kev
hahn-kev deleted the feat/unknown-change-type-converter branch July 20, 2026 07:52
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.

3 participants