Skip to content

Sync: Add cron cleanup for stale CRDT document post meta#75466

Draft
pkevan wants to merge 1 commit intotrunkfrom
pkevan/rtc-meta-cleanup-cron
Draft

Sync: Add cron cleanup for stale CRDT document post meta#75466
pkevan wants to merge 1 commit intotrunkfrom
pkevan/rtc-meta-cleanup-cron

Conversation

@pkevan
Copy link
Contributor

@pkevan pkevan commented Feb 12, 2026

What?

Closes #75311

Adds a daily WP-Cron event that cleans up stale sync post meta left behind by real-time collaboration sessions.

Why?

When real-time collaboration sessions end (e.g. browser closed, network lost), sync_awareness_ and sync_update_ post meta can be left behind indefinitely. Over time this can accumulate unnecessary data in the database.

How?

A new Gutenberg_Sync_Cleanup class registers a daily cron event (wp_sync_cleanup) that:

  1. Queries all post meta with sync_ meta
  2. Checks the timestamp stored within the meta_value
  3. If the timestamp is greater than the wp_sync_cleanup_expiration, deletes the relevant meta values.

The expiration period is configurable via the wp_sync_cleanup_expiration filter. The cron event is properly unscheduled on plugin deactivation.

Testing Instructions

  1. Create a post enable RTC and edit collaboratively.
  2. Verify the cron event is scheduled: wp_next_scheduled( 'wp_sync_cleanup' ) returns a timestamp
  3. Trigger the cleanup manually: do_action( 'wp_sync_cleanup' )
  4. Posts which have not been recently edited should have their older sync_ meta removed
  5. Posts which have been recently edited should retain their sync_ meta
  6. In order to check 4 & 5, you may need to query the DB to confirm.
  7. Run PHPUnit tests: phpunit phpunit/experimental/class-gutenberg-sync-cleanup-test.php
@pkevan pkevan added [Feature] Real-time Collaboration Phase 3 of the Gutenberg roadmap around real-time collaboration [Type] Iteration Scoped iteration of an effort from a tracking issue or overview issue ideally for a major release. labels Feb 12, 2026
@github-actions
Copy link

Flaky tests detected in 2d3275b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/21945161833
📝 Reported issues:

@chriszarate
Copy link
Contributor

Hi @pkevan, I've updated the issue with clarification. Our target should not be the _crdt_document post meta, which contains the persisted CRDT document. This post meta is useful over the entire lifetime of the post, to prevent duplicate updates during collaborative sessions.

Our targets are the sync updates generated by the default sync provider, which are also separately stored in post against a special post type.

@pkevan
Copy link
Contributor Author

pkevan commented Feb 13, 2026

Hi @pkevan, I've updated the issue with clarification. Our target should not be the _crdt_document post meta, which contains the persisted CRDT document. This post meta is useful over the entire lifetime of the post, to prevent duplicate updates during collaborative sessions.

Our targets are the sync updates generated by the default sync provider, which are also separately stored in post against a special post type.

Thanks - I got confused here! I've updated the PR description to reflect the change in functionality based on this.

Introduces a daily WP-Cron event that removes stale sync_update_* and
sync_awareness_* post meta from the wp_sync_storage post. Each update
envelope's timestamp is checked against a configurable expiration period
(default 7 days via wp_sync_cleanup_expiration filter). The cron event
is unscheduled on plugin deactivation.
@pkevan pkevan force-pushed the pkevan/rtc-meta-cleanup-cron branch from 6e87805 to 5cc4c0b Compare February 23, 2026 09:01
@pkevan pkevan added the No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core label Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Real-time Collaboration Phase 3 of the Gutenberg roadmap around real-time collaboration No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Iteration Scoped iteration of an effort from a tracking issue or overview issue ideally for a major release.

2 participants