Skip to content

feat: expose pending update and pending delete set from transactions - #129

Open
jcannon98188 wants to merge 1 commit into
y-crdt:mainfrom
jcannon98188:feature/pending-update-bindings
Open

jcannon98188 wants to merge 1 commit into
y-crdt:mainfrom
jcannon98188:feature/pending-update-bindings

Conversation

@jcannon98188

Copy link
Copy Markdown
Contributor

Summary

Adds C# bindings for the pending update and pending delete set that yffi exposes through ytransaction_pending_update and ytransaction_pending_ds.

When an update arrives before the updates it depends on, yrs holds it back instead of integrating it. These bindings let callers see what is waiting and what is missing, for example to request the missing data from a peer.

Changes

New public API on Transaction:

  • PendingUpdate() returns a PendingUpdate?, or null if nothing is pending.
    • Missing is a StateVector with the minimum client clocks that must arrive before the update can be applied.
    • Update is the pending update as lib0 v1 encoded bytes.
  • PendingDeleteSet() returns a DeleteSet?, or null if all deletions have been applied. It reuses the existing DeleteSet type.

Internals:

  • TransactionChannel gains the P/Invoke entry points ytransaction_pending_update, ytransaction_pending_ds, ypending_update_destroy and ydelete_set_destroy.
  • A new PendingUpdateNative struct mirrors yffi's YPendingUpdate.
  • Native memory is copied into managed objects and then freed in a finally block, so the native structs are released even if reading fails.

The signatures and struct layouts come from libyrs.h at release-v0.19.1, the version pinned in build-binaries.yml.

Tests

New PendingTests:

  • An empty doc returns null for both methods.
  • Applying an update whose dependency is missing produces a pending update with a non-empty Update and Missing vector. Applying the dependency afterwards clears it.
  • Applying a deletion whose target content hasn't arrived produces a pending delete set with ranges.

I ran the unit suite against a yrs.dll built locally from release-v0.19.1, and all of it passes.

Notes

  • PendingUpdate.Missing depends on StateVector reading its clocks correctly. That bug is fixed separately on fix/state-vector-clocks and is not part of this PR. Until it merges, the clock values in Missing are wrong. The tests here only assert that they are non-zero, so they pass either way.
  • The change is additive and does not alter any existing public API.

🤖 Generated with Claude Code


public uint UpdateLength { get; }

public byte[] Update()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is weirdly named. It should e ReadUpdate or so

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to make this change, but Update() is more in line with the DeleteSetNative that this pairs with. Which exposes Clients() and Ranges(). Your call though. Let me know.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

perhaps their are all named badly, but Update sounds like an action.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would you prefer PendingUpdate() instead? Seems closest to the intended field without being an action?

Bind ytransaction_pending_update and ytransaction_pending_ds, exposed as
Transaction.PendingUpdate() and Transaction.PendingDeleteSet().

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jcannon98188
jcannon98188 force-pushed the feature/pending-update-bindings branch from 2a568d4 to 4d4a1f8 Compare October 11, 2026 16:29
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.

2 participants