A sync is one pass. It reads the repository, merges three versions of every item, applies what came from elsewhere, then pushes what you changed. The order matters, because it explains why a conflict blocks a push, why a partial failure can leave media behind and why the counts on the toast do not always match the commits in Git.
There is no daemon and no queue worker. Either you press Sync now, a 15-minute cron run fires, a conflict resolution triggers a sync, or a build preflight asks for one. They all run the same engine, and they all take the same site lock.
Before the button: the status read
Loading the Sync screen runs a status read with no network access. It reads the stored base, exports every syncable post, page and referenced attachment, and counts what differs from the base. That is how the screen knows how many changes are ready without contacting the repository.
It also means the screen does real work on every load. Fine for hundreds of posts, noticeable for thousands. If the Sync screen feels slow, that is why, and it is not a sign that a sync is running.
The order of operations
- Snapshot. Read the branch tip with a shallow fetch, which gets the current tree without full history. Walk
items/,attachments/andenvironments/. Preserve everything else, including unrecognised JSON. An empty branch has no head; the media branch tip is read if that branch exists. - Export. Turn every syncable post and page into a document, and every attachment they reference into a record. Only referenced attachments are exported. Files over the media limit are recorded for the warning and excluded.
- Environment. Build this site’s fingerprint, stamp it with the current person and time, and compare it with the record already in the repository. It is written only when it differs.
- Conversation cards. Compare this environment with every other environment record and build the “Worth a conversation” list. This is reporting, not merging.
- Merge documents. Run the three-way merge for every document ID using the base, this site’s copy and the repository’s copy.
- Merge attachment records. Same shape, but the push set is the merge result plus the base plus this site’s records. Attachments are a shared library, so a sync never deletes one.
- Media import. Any attachment whose local file is missing or has a different blob is fetched by blob ID in chunks of 20, then written under uploads. Failures are counted as skipped and do not stop the sync.
- Apply documents. Resolve content tokens to this site’s uploads URL and attachment IDs, then apply through
wp_insert_post()orwp_update_post(). Remote deletions callwp_trash_post(). - The conflict gate. If anything is queued for review, save the base and stop. Nothing is pushed, not even unrelated posts or media.
- Push. Upload media batches of at most 4 MiB to
<branch>-media, then commit documents, attachment records and the environment as one commit on the content branch. The branch update is compare-and-swap against the snapshot head. - Update the base and mark the build stale. Save the pushed or pulled versions as the new agreed base, record the new commit and media commit, and set the applied timestamp if anything was applied, pulled, link-refreshed or deleted.
Counts and what they mean
The toast and the stored result use six numbers. They are not all the same type of record.
| Count | Meaning |
|---|---|
pulled | Documents and attachment records the repository changed that this site took. Attachment records count, so the number can be higher than the number of posts that changed. |
pushed | Documents this sync added, changed or removed in the repository. It does not count attachment-record-only changes, environment-only commits or media commits. A sync can make a commit and still report pushed: 0. |
deleted | Local deletions applied because the repository deleted the document. It does not count deletions pushed the other way. |
conflicts | Items now in the review queue. Zero means the sync was clean. |
skipped_media | Attachment records that could not be imported or fetched in this run, including missing bytes and write errors. |
pushed_at_all | Whether a content commit was made. Media and environment commits do not set it. |
The status read has its own changes count: local documents and local attachment records that differ from the base, including documents present in the base but missing locally. It does not count deleted attachments, because a sync never deletes them.
The conflict gate is site-wide
The engine checks for conflicts before it pushes and returns early if there are any. The early return reports pulled, pushed: 0, deletions, conflicts and skipped media, with pushed_at_all: false. Not one document, not one media blob and not the environment record leaves the site.
This is broader than the conflicted item. One unresolved post stops every other post from pushing too. It is blunt, and it is the reason the status band says “Nothing is pushed until you choose. Your site keeps your version meanwhile.” Treat the queue as a gate, not a list of suggestions.
Conflicted items keep their old base version, so they still look unpushed after the sync. That is intentional: the next sync will try them again once the conflict is gone.
Compare-and-swap and the single retry
The content commit is conditional on the branch still being where the snapshot found it. If someone else pushed first, the update is rejected. The engine then retries the whole sync once: it re-reads, re-merges and tries again. A second failure is reported.
The usual error text is The content repository changed while this site was syncing. Nothing is lost; the retry is working from the newer head. If it persists, sync again. The retry is broad: any push-time Git failure, including a permanent permission error or a host size limit, triggers one full retry before the error surfaces. Expect a slow failure rather than an instant one in those cases.
Locking
Only one sync runs per site at a time. The lock is a row in wp_options, created in a way that prevents two requests from both acquiring it. A lock older than 600 seconds is treated as a crashed request and replaced. A second caller gets a busy response; a build preflight turns that into a preview without a sync.
The lock is used by the Sync button, the resolve endpoint, the cron sync and the build preflight. It is local to one install, so it does not coordinate two different sites. Two sites pushing at once are handled by compare-and-swap, not by the lock. The lock also has no owner token, so a run that takes more than ten minutes can have its lock replaced while it is still working. Rare, but possible on a very large first sync.
The first sync
With an empty base, documents present on only one side are kept and pushed. Documents with the same UUID but different content become add conflicts. Independent installs generate different UUIDs per post, so the same slug on two sites normally produces two documents that coexist rather than one collision.
The first sync pushes every post, page and referenced image plus the environment record. It is the slowest sync you will run. Changing the repository or branch clears the base, so the next run is a first sync again.
Deletions
Sync represents a deletion by absence. There is no tombstone file, despite the terminology you may see elsewhere. If a document disappears from the repository, this site moves the local post to trash. If a post disappears locally, usually because someone trashed it, the next export does not include it and the next push removes it from the repository.
Trash is outside the exported statuses, so “trashed” means “deleted” as far as Sync is concerned. A published or draft post restored from trash regains its UUID and can be re-added. Attachments are different: they are never deleted by a sync, and attachment delete conflicts are dropped.
Base update and link refresh
After applying, the engine writes the next base. Conflicted items keep the old version. Non-conflicted items take the repository snapshot. Remote deletions drop out of the base. A local deletion still waiting to be pushed keeps its base so it can be pushed next time. The media pointer moves to the repository’s media tip.
One quiet extra step: base documents that still contain post tokens, and were neither conflicted nor changed locally, get their links refreshed. That follows a target slug change without re-applying unrelated edits.
Marking the build stale
If anything was applied, pulled, link-refreshed or deleted, the add-on records that content changed outside a build. The Sync screen then says content changed since the last build, or that the site has not been built yet. Publishing is blocked until a new build includes it. That timestamp is the bridge between Sync and StaticScope’s build.
Media can move before content does. Media batches are pushed before the content commit. If the content commit then fails permanently, the media branch has already advanced while the content did not land. The next successful sync will reconcile it, but do not assume a failed sync left the repository exactly as it was.
Next
- Conflicts and review: the rules behind the gate and how to clear it.
- Notices and errors: what each failure means and what to do.
- Cache and background jobs: keeping WP-Cron running.