Skip to content

Fix block note attachment persistence - #79020

Closed
chubes4 wants to merge 42 commits into
WordPress:trunkfrom
chubes4:fix/72717-notes-unsaved-attachment
Closed

chubes4 wants to merge 42 commits into
WordPress:trunkfrom
chubes4:fix/72717-notes-unsaved-attachment

Conversation

@chubes4

@chubes4 chubes4 commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

What?

Fixes top-level Block Notes becoming detached when the editor is reloaded before the user manually saves the post.

Why?

Creating a top-level note persists its comment immediately, but its block attachment lives in post_content as metadata.noteId and, for inline notes, a core/note marker. Previously those changes could remain only in editor memory, so the durable comment reopened as detached.

Persisting the attachment must not save unrelated dirty post edits or replace the collaborative document lineage.

How?

  1. Capture the selected block's location and saved-state identity before applying the local note mutation.
  2. Queue the targeted repair with normal sync saves for the same room.
  3. When the repair runs, re-read the latest persisted entity and refuse the repair if the saved block path no longer identifies the intended occurrence.
  4. Apply metadata.noteId and any inline core/note marker to the loaded sync-manager CRDT document.
  5. Persist the repaired post_content and _crdt_document together through /wp-sync/v1/save, then ingest the returned entity into core-data.

There is no fallback to a full post save, so unrelated dirty edits remain unsaved. Occurrence-aware matching handles duplicate and contentless blocks, while divergent paths fail safely.

Testing Instructions

Clean post:

  1. Open a post and add a Block Note without making other edits.
  2. Reload without manually saving.
  3. Confirm the note remains attached to the original block.

Dirty post safety:

  1. Make an unrelated content edit.
  2. Add a Block Note.
  3. Reload without manually saving.
  4. Confirm the note remains attached and the unrelated edit was not persisted.

Automated coverage includes duplicate contentless blocks, inline markers, divergent dirty paths, failed-repair behavior, CRDT peer lineage, and competing sync-save ordering.

Evidence

Fixes #72717.

AI assistance

  • AI assistance: Yes
  • Tool: OpenCode
  • Used for: Implementation, repository-native regression coverage, adversarial corpus hardening, and verification. Chris remains responsible for review and submission.

@github-actions

github-actions Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: chubes4 <extrachill@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: desrosj <desrosj@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the [Package] Editor /packages/editor label Jun 8, 2026
@chubes4
chubes4 marked this pull request as draft June 8, 2026 19:33
@chubes4
chubes4 marked this pull request as ready for review June 8, 2026 19:41
@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended Needs Decision Needs a decision to be actionable or relevant labels Jun 9, 2026
@Mamaduka

Mamaduka commented Jun 9, 2026

Copy link
Copy Markdown
Member

Thanks, @chubes4!

The problem isn't unique to block notes; it affects any block attribute that hasn't been saved. I was hoping we could piggyback on the new RTC functionality and have some kind of method to fix these missing items.

While similar band-aid fixes work, they're not ideal and introduce an odd pattern in the public codebase.

I did a surface-level review, and here are some potential issues:

  • Persisting other block data from blocks without the user's direct action.
  • Running the whole thing inside the useSelect and for the block-editor store, which is the most active store in the project.

I like the exploration, but I don't think this is the right way to solve the problem.

@chubes4

chubes4 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@Mamaduka Thanks! I'll take it back to the lab.

This PR resulted from experiments with deterministic benchmarking. It feels like a promising way to diagnose and prove complex WordPress problems like this.

I'll try another approach and push an updated attempt later.

@chubes4
chubes4 requested a review from nerrad as a code owner June 10, 2026 11:00
@github-actions github-actions Bot added [Package] Core data /packages/core-data [Package] Sync /packages/sync labels Jun 10, 2026
@chubes4

chubes4 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the push here. I reworked this away from the Notes-specific save path.

The updated approach adds a private core-data repair path that persists targeted block attribute changes for a sync-enabled entity. Notes now only supplies the metadata.noteId mutation; core-data applies it to the saved block tree and writes repaired post_content together with _crdt_document, so the REST content and sync snapshot stay aligned without saving unrelated dirty editor edits.

I also expanded the reusable Homeboy/WP Codebox coverage to prove the behavior beyond the happy path: clean live note creation, dirty same-block text, dirty structural insertion before the target block, and rapid double note creation preserving all note IDs. The focused build/lint/unit checks and those trace profiles pass locally on the updated branch.

@adamsilverstein
adamsilverstein requested review from Mamaduka and t-hamano and removed request for nerrad July 20, 2026 16:52
@adamsilverstein

Copy link
Copy Markdown
Member

@chubes4 looks like the persistEntityBlockAttributes test is failing, could you take a look?

@chubes4

chubes4 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@adamsilverstein Yes, taking a look and also fuzzing this with adversarial scenarios. Will push an update soon. Thank you!

@chubes4

chubes4 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@adamsilverstein The remaining Core-backport check is a false positive from the changed phpunit/tests/collaboration/wpSyncSaveServer.php fixture. The production server change is under lib/experimental/collaboration/, which .github/workflows/check-backport-changelog.yml explicitly excludes from Core sync.

Could a maintainer add No Core Sync Required? This matches the existing RTC precedents in #78891 and #80469; #78891 changed this same sync-save server, core-data/sync packages, and collaboration PHPUnit fixture under that label. A Core PR would otherwise ship only generated JS while omitting the experimental PHP endpoint.

References:

# Conflicts:
#	packages/core-data/src/private-actions.js
@adamsilverstein adamsilverstein added the No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core label Jul 23, 2026
@adamsilverstein

Copy link
Copy Markdown
Member

Could a maintainer add No Core Sync Required?

Added.

@chubes4

chubes4 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@adamsilverstein Thank you! This became a rabbit hole. Once I started fuzzing it, bugs popped up all over the place. I fixed a ton of them. Still would like to run a few more tests. This gets complicated quick when you have a lot of users on the page.

@chubes4

chubes4 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@adamsilverstein The additional multi-user/adversarial testing is complete at current head e9fbb4a49fa.

Final exact-head campaign

  • Public corpus and review: homeboy-rigs#699, revision 52ad4a0.
  • Campaign: gutenberg-79020-21-case-e9fbb4a-r7, seed 1.
  • Result: 21 passed, 0 failed, 0 errored, 0 skipped.
  • Recorded build provenance: component_git_sha = e9fbb4a49fa132ef5f5f06d3694a4416305fc311; the required core-data/editor/block build assets were already present, so the workload neither hydrated dependencies nor rebuilt a different tree.
  • Total case execution: 1,386,443 ms (23m06s).
  • Result SHA-256: 8973cd4d097e3082e6651f88e8e36f02148424ddf75e7216a8373ce775bf95ae.
  • Case-log SHA-256: ecc18d690bf9c113e1d76d7222822285399a418f76ceae2633260bea8dc5cb8f.
  • Replay SHA-256: 4eb94a926e8154166d3188fd6f32fc5eeeb1356f2f90d93838e3f43690831393.

The 21 operations cover missing/saved anchors; clean, dirty, nested, repeated, and inline creation; invalid/ambiguous/empty saved content; store coherence; seeded repair/save ordering; CRDT peer lineage; forced repair recovery; overlapping repairs; pending inline edits; 12 independently authenticated authors; conditional content/CRDT atomicity; and independent PHP-worker/MariaDB-session atomicity.

Reproduction from the corpus PR checkout with this built Gutenberg checkout:

homeboy extension setup wordpress
HOMEBOY_COMPONENT_PATH=/path/to/gutenberg \
HOMEBOY_WORDPRESS_HELPER_MANIFEST="$HOME/.config/homeboy/extensions/wordpress/lib/helper-manifest.js" \
WP_CODEBOX_RUNTIME_MODULE="$HOME/.cache/homeboy/wp-codebox/source/packages/runtime-core/dist/index.js" \
HOMEBOY_SEED=1 \
node WordPress/gutenberg/fuzz/gutenberg-notes-unsaved-attachment.mjs

Together with the green Gutenberg-native CI at this head, no fuzz finding remains open.

# Conflicts:
#	packages/editor/src/components/collab-sidebar/hooks.js
@t-hamano

Copy link
Copy Markdown
Contributor

Let's punt this to 7.2.

@t-hamano t-hamano moved this from 🔎 Needs Review to 🦵 Punted to 7.2 in WordPress 7.1 Editor Tasks Aug 10, 2026
@chubes4

chubes4 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

I split this work into six focused draft PRs so each synchronization invariant can be reviewed and landed independently:

  1. #81715: targeted CRDT persistence snapshots
  2. #81714: conflict-safe CRDT snapshot saves
  3. #81716: atomic synchronized entity saves
  4. #81717: queued revision-aware CRDT persistence
  5. #81719: targeted block-attribute repair
  6. #81718: Block Notes attachment integration

The drafts target trunk because contributor fork branches cannot be used as base refs in upstream PRs. Please review them in order; each later cumulative diff shrinks to its own layer as the preceding PRs merge.

The original review findings and adversarial evidence remain recorded in this PR. The replacement stack preserves those fixes and adds one focused Gutenberg-native Playwright regression per layer, with the Block Notes integration retaining the attachment scenarios requested in the review.

AI assistance: GPT-5.6 Sol via OpenCode assisted with splitting the implementation, adding repository-native regression coverage, and verifying the replacement stack. Chris reviewed and is responsible for the submitted changes.

@chubes4 chubes4 closed this Aug 16, 2026
@github-project-automation github-project-automation Bot moved this from 🔎 Needs Review to ✅ Done in WordPress 7.2 Editor Tasks Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting Needs Decision Needs a decision to be actionable or relevant No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Package] Core data /packages/core-data [Package] Editor /packages/editor [Package] Sync /packages/sync [Type] Bug An existing feature does not function as intended

Projects

Development

Successfully merging this pull request may close these issues.

New notes (unnested) are not properly attached to a block when post is not saved

4 participants