Prevent Studio Code from overwriting manual editor changes with stale content - #4210
Draft
sejas wants to merge 5 commits into
Draft
Prevent Studio Code from overwriting manual editor changes with stale content#4210sejas wants to merge 5 commits into
sejas wants to merge 5 commits into
Conversation
…ing pages Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…or-image-changes
…or-image-changes
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…pped image Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
How AI was used in this PR
Proposed Changes
When a user manually edits a page in the WordPress editor (for example, replacing placeholder images with real ones) and later asks Studio Code for a content-only tweak, the agent could push a stale locally saved copy of the page back over the live content, silently reverting the user's manual changes.
This happened because the agent's working copy of a page is a local scratch file (
<site>/tmp/page-<slug>.html) that persists across turns and sessions, and applying content is a fullpost_contentoverwrite — nothing ever re-read the live content first. The live database row (where editor saves land) is the only copy of the user's manual edits.This PR closes that gap at the instruction layer:
block-contentskill gains a mandatory "Editing Existing Content" recipe: before any edit to an existing page/post, the agent must hydrate a fresh working copy from the livepost_content(with a byte-count echo so an empty read from a wrong post ID is caught instead of applied), edit that fresh copy, and validate + apply in the same work burst. Stale scratch files from earlier tasks/sessions must never be the starting point.wpcom-remote-managementskill applies the equivalent rule to remote sites: fetch current raw content (context=edit) before updating, and treat staged payload files as single-use.wp_update_postinwp_slash()so editor-authored markup containing backslash escapes (common in block-attribute JSON) survives the hydrate → apply round trip instead of being corrupted.User impact: manual editor changes survive subsequent Studio Code content edits, on both local sites (Playground and native PHP runtimes) and connected WordPress.com sites.
This is a prompt/skill-level fix. A deterministic tool-level guard (compare-and-swap on apply, blocking blind
post_contentoverwrites inwp_cli) is planned as a follow-up.Testing Instructions
Unit tests:
npm test -- apps/cli/ai/tests(newskills-content.test.tsplus new assertions insystem-prompt.test.tspin the load-bearing wording).Agent eval:
npm run eval -- --filter-pattern "hydrates from live content"— newstale-content-hydrationcase reproduces the bug end-to-end: an out-of-band image swap must survive a subsequent heading-only edit, and the agent must re-read live content before applying.Manual repro:
hydrated N bytes) before the edit, and the real image survives alongside the new heading.Pre-merge Checklist