Skip to content

fix: surface merge API errors and use a fresh sequence for merge/sync - #295

Merged
Ruari-Phipps merged 1 commit into
mainfrom
ruari/fix/merge-sequence-mismatch
Aug 28, 2026
Merged

fix: surface merge API errors and use a fresh sequence for merge/sync#295
Ruari-Phipps merged 1 commit into
mainfrom
ruari/fix/merge-sequence-mismatch

Conversation

@Ruari-Phipps

@Ruari-Phipps Ruari-Phipps commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Make merge_branch/sync_branch send a freshly fetched branch sequence instead of the projection-cached one, and return the Sourcerer API error to callers instead of swallowing it. poly branch merge/sync print a retry hint on a sequence mismatch.

Motivation

A draft deployment finishing mid-merge appends a deploymentCompleted event to the branch, so Sourcerer rejects the merge with SEQUENCE_MISMATCH. Today that surfaces as a blank Merge failed: and a retry resends the same stale sequence.

Changes

  • sdk.merge_branch / sdk.sync_branch: fetch the sequence via fetch_last_known_sequence_number() before the call (as delete_branch already does)
  • sync_client.merge_branch / sync_branch: return the SourcererAPIError message in errors ({"path": [], "message": ...}) instead of (False, [], [])
  • poly branch merge / poly branch sync: print "The branch changed while merging… Re-run the merge." when an error is a sequence mismatch

Test strategy

  • Added/updated unit tests
  • Manual CLI testing (poly <command>)
  • Tested against a live Agent Studio project
  • N/A (docs, config, or trivial change)

Checklist

  • ruff check . and ruff format --check . pass
  • pytest passes
  • No breaking changes to the poly CLI interface (or migration path documented)
  • Commit messages follow conventional commits

@Ruari-Phipps
Ruari-Phipps requested a review from a team August 27, 2026 17:08
@github-actions

This comment has been minimized.

@Ruari-Phipps
Ruari-Phipps force-pushed the ruari/fix/merge-sequence-mismatch branch from b9084df to 98f7ec4 Compare August 27, 2026 17:24
@github-actions

This comment has been minimized.

A draft deployment finishing while a branch is being merged appends a
deploymentCompleted event to the branch, so the merge is rejected with
SEQUENCE_MISMATCH. Two things made that worse than a transient failure:

- merge_branch/sync_branch sent the projection-cached sequence, so a plain
  retry resent the stale value. They now fetch the branch sequence fresh,
  matching delete_branch.
- sync_client swallowed the SourcererAPIError and returned no errors, so
  callers (and CI) saw "Merge failed:" with no reason. The API error is now
  returned in `errors`, and `poly branch merge`/`sync` print a retry hint
  when it is a sequence mismatch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Ruari-Phipps
Ruari-Phipps force-pushed the ruari/fix/merge-sequence-mismatch branch from 98f7ec4 to 73974a7 Compare August 28, 2026 09:37
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Base (main) PR Change
75.9% 76.2% +0.4% ✅

Changed file coverage

File Coverage Change
poly/handlers/sdk.py 42.6% +9.0% ✅
poly/handlers/sync_client.py 57.1% +7.4% ✅
poly/cli_commands/branch.py 58.7% -0.0% ⚠️

@Ruari-Phipps
Ruari-Phipps merged commit 8be3f53 into main Aug 28, 2026
6 checks passed
@Ruari-Phipps
Ruari-Phipps deleted the ruari/fix/merge-sequence-mismatch branch August 28, 2026 11:18
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.

2 participants