fix(branchsync): recover reviewed equal-tree rewrites - #854
Conversation
Confidence Score: 5/5The PR appears safe to merge with its new recovery path constrained by matching review authority, exact tree equality, submitted-work preservation, atomic ref verification, and database compare-and-swap checks. No concrete changed-code failure remains; the implementation fails closed when its Git, worktree, review-authority, or database assumptions change and retains the existing final adoption checks. Reviews (1): Last reviewed commit: "fix(branchsync): trust reviewed head bef..." | Re-trigger Greptile |
|
Speaking as Kun's firstmate: First look at HEAD Diff review: only recovers when recorded head equals durable VISION.md:
Require failed "not raised through no-mistakes" (opened-event; not ruleset-required). Waiting on hosted CI before merge. |
Summary
Terminal custody recovery currently refuses a live gate head when a pipeline rewrites commit history, even if the reviewed terminal commit and live commit produce the same Git tree.
This change permits that narrow recovery case. It requires the recorded terminal head to match the durable review-approved head, proves that reviewed head preserves the submitted work, verifies that the live head has the same tree, and then uses ref and database compare-and-swap checks before returning custody.
Synthetic reproduction
Given:
L: the submitted local commitA: the reviewed terminal commit, which preservesLB: the live gate commit after a history-only rewritetree(A) == tree(B)AnorBis an ancestor of the otherA terminal
axi sync --recovercurrently returnsblocked_recover_unverified_head. With this change, it adoptsB, preserves the pre-recovery local head underrefs/no-mistakes/recover-local/<run>, and remains idempotent on a repeated recovery.Safety
The ordinary descendant recovery path is unchanged. The new path also requires:
Different trees, dropped local work, rewritten operator content, unreviewed recorded heads, conflicting or symbolic refs, active runs, dirty worktrees, and branch races all refuse without mutating refs, the worktree, remotes, or the run row.
Compatibility
There is no schema, CLI, configuration, or protocol change. Existing descendant recovery behavior stays intact. The added database operation only tightens the terminal equal-tree verification transaction.
Validation
go test ./internal/branchsync -run '^TestRecoverTerminalUnverified(EqualTreeRewriteAdoptsLiveGateHead|RewriteNegativeControls)$' -count=1 -vgo test ./internal/db -run '^TestVerifyTerminalRunHeadRewriteUsesRecordedReviewCAS$' -count=1 -vmake lintGOFLAGS='-count=1 -p=1' make testbash scripts/e2e.sh -tags=e2e -count=1 -timeout 20m -p=1 ./internal/e2e/... ./internal/pipeline/steps/...c302eaf66dade1f01eddf1f8ea6e7456d06fe03b0ca24f6f7516ab32b8e27697Review order
internal/branchsync/sync.goandinternal/db/run.gofor the proof and CAS boundaries.internal/branchsync/recover_test.goandinternal/db/run_test.gofor positive, negative, anchor, and race coverage.internal/e2e/axi_journey_test.gofor the public recovery and idempotency journey.internal/git/git.gofor atomic stdin-backedgit update-refsupport.