fix(plan): abort git merge on conflict and restore clean repo state #7251

Merged
HAL9000 merged 1 commits from bugfix/merge-conflict-abort into master 2026-04-19 17:40:53 +00:00

1 Commits

Author SHA1 Message Date
hamza.khyari fa01cee7d2 fix(plan): abort git merge on conflict and restore clean repo state
CI / helm (pull_request) Successful in 34s
CI / push-validation (pull_request) Successful in 35s
CI / build (pull_request) Successful in 3m50s
CI / lint (pull_request) Successful in 4m9s
CI / quality (pull_request) Successful in 4m38s
CI / typecheck (pull_request) Successful in 4m58s
CI / security (pull_request) Successful in 5m11s
CI / e2e_tests (pull_request) Successful in 7m37s
CI / integration_tests (pull_request) Successful in 10m46s
CI / unit_tests (pull_request) Successful in 11m36s
CI / coverage (pull_request) Successful in 14m45s
CI / docker (pull_request) Successful in 1m36s
CI / benchmark-regression (push) Failing after 0s
CI / benchmark-publish (push) Failing after 0s
CI / status-check (pull_request) Successful in 4s
CI / helm (push) Successful in 41s
CI / lint (push) Successful in 3m54s
CI / quality (push) Successful in 4m13s
CI / typecheck (push) Successful in 4m40s
CI / security (push) Successful in 4m41s
CI / build (push) Successful in 3m49s
CI / push-validation (push) Successful in 22s
CI / e2e_tests (push) Successful in 6m54s
CI / integration_tests (push) Successful in 10m24s
CI / unit_tests (push) Successful in 11m23s
CI / coverage (push) Successful in 14m57s
CI / docker (push) Successful in 2m13s
CI / status-check (push) Successful in 4s
When plan apply encounters a merge conflict (user edited the same file
between execute and apply), the git merge leaves conflict markers in
the project files and the repo in an unmerged state.

Fix:
- Read conflict detail from CalledProcessError.stdout (git writes
  conflict info to stdout, not stderr)
- Run git merge --abort to restore the repo to a clean state
- Catch subprocess.TimeoutExpired on both merge and abort calls
- Check abort return code and include error detail on failure
- Return False from _apply_sandbox_changes on failure so the calling
  code does NOT complete the apply phase
- Transition plan to constrained state via service.constrain_apply()
  per spec §18334-18336 (plan may revert to Strategize for re-planning)
- Fall back to 'Unknown merge error' when stdout+stderr are empty

Tests: 7 Behave scenarios covering merge conflict abort, abort failure,
_apply_sandbox_changes return value (True/False), clean merge, merge
timeout, abort timeout, and flat file copy failure.

ISSUES CLOSED: #7250
2026-04-19 17:10:17 +00:00