Skip to content

Inside Step 5 the sync with main

Ilia edited this page Nov 9, 2026 · 1 revision

A reviewed branch whose pull request conflicted with main used to go on to the preview, to QA and to the merge as if nothing were wrong, and then wait: the merge offer said "it conflicts with main — resolve them and push", and the merge wait asked GitHub every half minute, for hours, about a merge nobody could make. The conflict is known long before that, and for nothing: git merge-tree --write-tree merges in memory and names the files, with no session and no GitHub call (merge_conflicts in sclaude/lib/tree/sync.sh).

So remind_prod asks it at three points:

  • before the preview — QA should look at the code that will merge, not at the branch alone;
  • after QA's yes, before the pull request is handed over — main moves while QA works, and a hand-off taken back a moment later would flip the board, the pull request and its summary for nothing;
  • while the merge is waited for, every SYNC_POLL seconds (two minutes), since the wait is a fetch — of an open pull request only: a merged one has its branch deleted on GitHub, and the stale ref left here could conflict with the main its merge moved.

The branch asked about is origin's tip, which is what the pull request merges, and also the tree's own commits when origin lacks them: whoever merges main here merges those too. A merge under way in the tree — a sync broken off mid-way, or one by hand — is never clean, whatever origin's tip says: its files may hold conflict markers, and the preview would deploy them. Its unmerged files are the conflict, and the session finishes it.

A conflict opens the sync session, 5-sync/<slug> (5-sync(2) for a second one): the review step's rules, sonnet at medium effort (SYNC_MODEL in sync.sh, a narrower job than a review round's), the prompt sclaude/prompts/sync.md. It merges origin/main into the branch — a merge, never a rebase: the branch is under review, and a force push is refused anyway — resolves each conflict keeping both sides' intent, checks the result as the project's CLAUDE.md says, and pushes. sclaude then checks for itself that no merge is under way, the tree is clean, the branch merges cleanly with main and is pushed. Only then does the run go on: from before the preview it simply continues, and the changed tree is deployed; from after QA, or from the wait, it starts over, so the preview, its regression and QA (qa_retest) see the new code. QA is not asked again when the branch's own product is what they passed (qa_product_same): each commit's change against the main it stands on, less the paths that are not the product (NO_DEPLOY: .sclaude, docs, .github, .githooks, *.md), compared as text — bytes, whitespace and binaries included, renames found, only line numbers and blob ids dropped. Main's edits to lines the branch does not touch leave the yes standing; a change of the function header above the branch's lines does not, nor anything that cannot be read: in doubt, QA looks again. A session that ends otherwise stops the run, and the feature shows 5/7 sync in the menu until sclaude <feature> finishes it; its conversation is resumed then. On the maps such a sync stands still on the block it ran ahead of: its S drawn in the colour of a wait on you (stalled in process_position.py), the command in its note — while the pull request is open; merged or closed, there is nothing left to sync.

Like a step's session, the sync writes what got in its way into the friction log (<include:friction> in sync.md), and once its end is recorded a friction review follows, keyed by its run (sync-2), its row in the issue naming it. Not finished, that review holds the run as a step's does.

A pull request already handed over for the merge goes back to a draft whenever origin's branch moved during a sync (sync_gate), even one that stopped short after its push: origin then has code no preview and no QA has seen. The hand-off is taken back the same way qa_retest takes it back (pr_unhandoff in qa.sh), from the run, from the menu's sync and from a step's start.

One kind of conflict needs no session. The deferred logs (.sclaude/*/deferred/*.tsv) are rows that both sides append to — a feature's friction reviews on its branch, deferred_to_main on main — and their merge is the rows of both. When they are the only files in conflict, sclaude merges main in itself, with main's rows first and then the rows the branch added since the two parted (against the merge base), less those main added since then, and pushes (sync_deferred). Against the base, not the branch's whole copy: rows the branch took from main at an earlier merge and main has since removed — the monthly review removes what it decided — would otherwise come back. Less main's additions, not all of main's copy: deferred_to_main sends a branch's rows to main, and they come once, but a row the branch repeats on purpose stays repeated. deferred_to_main works against <from> the same way: it applies to main's copy what the range did since — the rows added appended, the rows taken out (a review settling them, a file deleted) removed — so main can lose rows to a branch as well as gain them. The menu's line about such a merge says so, rather than naming a session.

The sync runs the same way at a step's start and from the menu (sync_offer), and neither asks, even when a session resolves the conflicts: the branch has to merge with main before its preview and its merge whatever is answered, so a "no" only put the same session off. sync_gate holds origin's branch against the head the hand-off was made on (handoff in the state): commits it lacks — the sync's, or ones that came by other hands, a push from another machine, GitHub's "Update branch" — are unchecked code, and the hand-off goes back for them, said in those words. A ref here that only lags behind that head is not.

The menu's own "Sync with main" (cmd_sync), there at every step, uses the same check: its line says how many files would conflict, and choosing it for a merge that would conflict goes to the sync rather than leaving the tree half-merged for the person to untangle — from a phone they could not. A plain merge from either that stops anyway is backed out (sync_plain_merge). The merge with main a step makes at its start (sync_branch) goes the same way, and asks nothing: it once asked, a "no" was remembered for that state of main, and all it bought was the same merge later, before the preview, after step 3 and the review had worked on a branch that was not what merges; a plain merge there that was backed out leaves the step to open on the branch as it stood. Before step 3 the branch may not be on origin yet; the session then leaves it local, and the prompt says nothing of a pull request or of QA.

A branch origin has never seen is put on top of main before every local regression, with no question (sync_unpublished): rebased when it rebases cleanly over a clean tree, left as it is otherwise. Main moving during step 2 once made the suite fail on the branch's older copy of a file main had changed, and a fixing session was opened only to rebase. A pushed branch is not rewritten; its merge with main stays the question above.


Generated from docs/sclaude.md; edit it there, then rebuild with wiki/build.py.

Clone this wiki locally