Merge contiguous stack prefixes as one operation #51

Open AtlantisPleb opened this 4h ago

Outcome

Merging a stacked PR lands it and every open layer below it through one orchestrated operation, restacks the layers above, and survives crashes between the git refs and the metadata database.

Context

docs/stacked-prs.md sections 13 and 5.9–5.13 define the behavior. Git refs and PostgreSQL are two durable stores; reconciliation is required, not optional. Follow the existing receipt conventions for the durable outcome.

Acceptance criteria

  • The merge request names the selected PR, expected heads per layer, expected stack version, merge method, direct-or-queue action, and an idempotency key. The server returns an operation identifier immediately; clients poll for the result.
  • Preflight validates a contiguous lowest-open prefix, the ancestry chain, expected head OIDs, approvals and checks where that surface exists, actor permission, permitted merge method, and no conflicting active operation. All validation completes before any ref moves.
  • Merge commit method creates one group merge commit whose tree equals the selected top head. Squash method creates one commit per PR chained on trunk, so each trunk commit diffs to exactly one layer. Rebase method replays each layer's unique commits in order; the final tree equals the top head.
  • Layers above the selected prefix restack onto the new trunk result using their stored boundaries. Merged lower branches stay intact until upper restacks succeed or boundaries pin.
  • A reconciler compares planned refs, actual refs, and metadata state; it finalizes, retries, or marks operations partial after a crash. Documented semantics: landed lower PRs stay merged when an upper step fails.

Verification

Domain tests per merge method asserting exact resulting histories, prefix enforcement (no skipping), restack-after-merge, and injected crash recovery. Run mix precommit.

Dependencies

Cascading rebase (#50); the batch-CAS primitive (#46).

  1. AtlantisPleb opened this issue 4h ago
Sign in with GitHub to comment on this issue.