fix(cortex): handle git diff errors in _check_if_diff to prevent silent PR skip
loading diff…
_verify_ref_exists() to check if base_branch is a valid git ref before attempting diff_check_if_diff() to provide diagnostic information about why git operations fail_sanitise_mercury_after_workflow (secondary fix)When git diff fails (e.g., base branch doesn't exist due to shallow clone or wasn't properly fetched), _check_if_diff was silently returning False (no diff), which caused PRs to not be created even when agents made changes.
Root cause: The check if "diff" not in out + err would return False when git errors out, because the error message doesn't contain "diff".
Production incident: workflow_id q6d7q6vp, run_number 2 - PR was not created despite agents making 10+ file edits.
Instead of just raising an exception, the fix now:
_verify_ref_exists) - checks if base_branch is a valid git ref before attempting diffThis helps diagnose WHY the failure occurs rather than just catching it.
test_check_if_diff_raises_error_on_nonexistent_base_branchtest_check_if_diff_raises_error_on_git_diff_failurepytest cortex/tests/test_common/test_git_utils.py - 22 tests passing)make fmt passes🤖 Generated with Claude Code