Skip to content

feat(sync): merge upstream releases into main instead of rebasing - #59

Merged
tomorrowflow merged 1 commit into
mainfrom
feat/sync-merge-mode
Oct 13, 2026
Merged

tomorrowflow merged 1 commit into
mainfrom
feat/sync-merge-mode

Conversation

@tomorrowflow

Copy link
Copy Markdown
Owner

Problem

The scheduled upstream sync (scripts/sync-and-deploy.sh → .sandcastle/sync.ts) rebased the fork's commits onto each new upstream release cut, then force-pushed main:

  • It stranded. The agent gets one turn, and a large release bump means replaying 100 or more commits. It stranded mid-rebase on 2026-09-07, on 2026-10-08 and on 2026-10-12, and each time left the checkout mid-rebase for a maintainer.
  • It carried old release commits. It replayed earlier release cuts' release-only commits, which duplicated changes.
  • It could erase merged PRs. A force-push from a checkout that is behind origin/main drops whatever it lacks.

2026.10.5 was synced by hand as a merge (#57). This PR makes the scheduled sync do the same.

Solution

The host starts the sync:

  • It runs the preflight, fetches upstream and picks the target (pinned with --target, or the newest release/X.Y.Z).
  • The new scripts/sync-merge-release.mjs starts git merge --no-ff --no-commit and applies the mechanical resolutions:
    • upstream CI the fork doesn't keep
    • package.json version hunks, which keep the fork's other changes
    • release-owned files and pnpm-lock.yaml
    • files only an earlier release cut changed (no fork-side commit outside upstream refs)
    • the root version pin and deploy:globally
  • A file one side deleted, or a merge that never started, goes to a person or the agent instead of being guessed.
  • When main already contains the release, the agent never starts.

The agent resolves the remaining conflicts, commits the merge (git commit --no-edit), then installs, builds, checks, runs the tests and verifies fork features. The rules in .sandcastle/sync-prompt.md come from the 10.5 merge.

The host publishes. It pushes only a committed, clean merge that contains both the release and everything origin/main had, and no files the sync created and left uncommitted. The push is a plain fast-forward.

On failure (a stop gate, an agent crash, a merge that didn't start, a failed check or a rejected push), the attempt is parked on sync/attempt-<X.Y.Z>-<time> and main is reset to origin/main. The next run starts clean, and no stash is involved.

docs/UPSTREAM-SYNC.md and scripts/sync-and-deploy.sh now describe the merge flow, and the docs warn against squash-merging a sync (#57 and #58 lost their ancestry that way).

Impact

  • The Mon/Thu cron can be re-enabled once this merges. It's paused in the operator's crontab.
  • The fork's history keeps its merged PRs.
  • main already records release/2026.10.5 as merged, so the next run merges only what the next release changed since 10.5.

Evidence

  • Replay on the real 10.5 merge: run on the pre-sync fork main (936d08b) against release/2026.10.5, the script resolved 195 of 216 conflicts. Its 175 content resolutions are byte-identical to chore(sync): merge upstream release/2026.10.5 #57's hand resolution (git diff --cached d226c4617d8 is empty for those files). The same 21 files were left for judgment.

  • Tests: pnpm test test/scripts/sync-merge-release.test.ts --maxWorkers=1 passes 4 tests in 3.1 s. Synthetic repositories cover:

    • every rule, including the CI file the fork keeps;
    • a release deletion that must not be emptied;
    • a merge git refuses to start;
    • the up-to-date no-op.

    Three mutations each make a test fail: an "earlier cut" rule that takes every file, CI removal that ignores the fork's own files, and dropping the deletion guard.

  • .sandcastle/sync.ts typechecks against the installed sandcastle (tsc --noEmit). oxlint and oxfmt pass on the changed files.

  • Review: an independent review found six defects in the first version, all fixed here: crash paths that left the merge in progress, uncommitted new files, a deleted file becoming an empty file, an unchecked merge start, fragile parking, and a rejected push leaving main ahead.

  • Not exercised end to end: the agent turn itself has not run. The first scheduled run after re-enabling the cron is that proof. A failure there parks and resets instead of stranding.

🤖 Generated with Claude Code

The scheduled sync rebased the fork's commits onto each new upstream
release cut and force-pushed main. It stranded mid-replay three times
(the agent gets one turn), replayed earlier cuts' release commits, and a
force-push from a behind checkout can erase merged PRs.

The host now starts the sync itself: it picks the target release, and
scripts/sync-merge-release.mjs begins `git merge --no-ff --no-commit`
and applies every mechanical resolution (upstream CI the fork does not
keep, package.json version hunks, release-owned files, the lockfile,
files only an earlier release cut changed, the root version pin). When
main already contains the release, the agent never starts. The agent
resolves the rest, commits the merge, and builds and checks it. The host
publishes only a committed, clean merge that contains both the release
and everything origin/main had, with a plain fast-forward push. Any
failure parks the attempt on sync/attempt-<X.Y.Z>-<time> and puts main
back on origin/main, so no run strands the checkout.

Replayed on the real 2026.10.5 merge, the script's 175 mechanical
resolutions match the hand resolution of #57 byte for byte and leave
the same 21 files for judgment.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@tomorrowflow
tomorrowflow marked this pull request as ready for review October 13, 2026 10:04
@tomorrowflow
tomorrowflow merged commit 06a38a0 into main Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant