-
Notifications
You must be signed in to change notification settings - Fork 7
t1049: Fix auto-rebase: abort stale rebase state before retrying #1480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2175,6 +2175,15 @@ rebase_sibling_pr() { | |||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # t1049: Abort any stale rebase state from a prior crash before starting | ||||||||||||||||||||||||||||||||||||||||||||
| # a new rebase. Without this, git refuses with "already a rebase-merge directory". | ||||||||||||||||||||||||||||||||||||||||||||
| local pre_git_state_dir | ||||||||||||||||||||||||||||||||||||||||||||
| pre_git_state_dir="$(git -C "$git_dir" rev-parse --git-dir 2>/dev/null)" | ||||||||||||||||||||||||||||||||||||||||||||
| if [[ -d "$pre_git_state_dir/rebase-merge" || -d "$pre_git_state_dir/rebase-apply" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||
| log_warn "rebase_sibling_pr: aborting stale rebase state for $task_id" | ||||||||||||||||||||||||||||||||||||||||||||
| git -C "$git_dir" rebase --abort 2>>"$SUPERVISOR_LOG" || true | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2178
to
+2185
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# First, check if the file exists and examine its structure
if [ -f ".agents/scripts/supervisor/deploy.sh" ]; then
echo "=== File found ==="
wc -l ".agents/scripts/supervisor/deploy.sh"
else
echo "File not found at expected path"
find . -name "deploy.sh" -type f 2>/dev/null | head -5
fiRepository: marcusquinn/aidevops Length of output: 124 🏁 Script executed: #!/bin/bash
# Examine the specific lines mentioned in the review
if [ -f ".agents/scripts/supervisor/deploy.sh" ]; then
echo "=== Lines 2178-2185 ==="
sed -n '2178,2185p' ".agents/scripts/supervisor/deploy.sh" | cat -n
echo ""
echo "=== Context: Lines 2170-2210 ==="
sed -n '2170,2210p' ".agents/scripts/supervisor/deploy.sh" | cat -n
fiRepository: marcusquinn/aidevops Length of output: 3058 🏁 Script executed: #!/bin/bash
# Verify git rev-parse behavior with a temporary test repo
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
# Create a test repo
git init "$tmpdir/testrepo" >/dev/null 2>&1
echo "=== Non-worktree case ==="
result=$(git -C "$tmpdir/testrepo" rev-parse --git-dir 2>/dev/null)
echo "Result: '$result'"
if [[ "$result" == /* ]]; then
echo "Status: Absolute path (unexpected for regular repo)"
else
echo "Status: Relative path (as claimed in review)"
fi
# Create an initial commit and add worktree
cd "$tmpdir/testrepo" && git commit --allow-empty -m "init" >/dev/null 2>&1
git worktree add "$tmpdir/wt" -b testbranch >/dev/null 2>&1
echo ""
echo "=== Worktree case ==="
result=$(git -C "$tmpdir/wt" rev-parse --git-dir 2>/dev/null)
echo "Result: '$result'"
if [[ "$result" == /* ]]; then
echo "Status: Absolute path (as claimed in review)"
else
echo "Status: Relative path (contradicts review claim)"
fi
# Test the actual path resolution behavior
echo ""
echo "=== Path resolution behavior test ==="
cd "$tmpdir" || exit 1
non_worktree_gitdir=$(git -C "$tmpdir/testrepo" rev-parse --git-dir 2>/dev/null)
echo "From testrepo: '$non_worktree_gitdir'"
# Test if -d check works with the relative path
if [[ -d "$non_worktree_gitdir" ]]; then
echo "Relative path check PASSES from current dir"
else
echo "Relative path check FAILS from current dir"
fi
# Test if -d check works with constructed absolute path
if [[ -d "$tmpdir/testrepo/$non_worktree_gitdir" ]]; then
echo "Constructed absolute path check PASSES"
else
echo "Constructed absolute path check FAILS"
fiRepository: marcusquinn/aidevops Length of output: 375 🏁 Script executed: #!/bin/bash
# Find where $git_dir is initialized in the rebase_sibling_pr function
sed -n '2150,2180p' ".agents/scripts/supervisor/deploy.sh" | cat -nRepository: marcusquinn/aidevops Length of output: 1214 🏁 Script executed: #!/bin/bash
# Search for git_dir assignments in the function context
rg 'git_dir=' ".agents/scripts/supervisor/deploy.sh" -B 2 -A 2 | head -50Repository: marcusquinn/aidevops Length of output: 370 🏁 Script executed: #!/bin/bash
# Look for the function definition and early variable assignments
sed -n '2100,2180p' ".agents/scripts/supervisor/deploy.sh" | grep -E 'rebase_sibling_pr|git_dir|use_worktree' | cat -nRepository: marcusquinn/aidevops Length of output: 748 🏁 Script executed: #!/bin/bash
# Check for other instances of the same pattern at lines 2197-2198 and 2234-2235
echo "=== Lines 2195-2200 ==="
sed -n '2195,2200p' ".agents/scripts/supervisor/deploy.sh" | cat -n
echo ""
echo "=== Lines 2230-2240 ==="
sed -n '2230,2240p' ".agents/scripts/supervisor/deploy.sh" | cat -nRepository: marcusquinn/aidevops Length of output: 1356 🏁 Script executed: #!/bin/bash
# Verify that git_dir can indeed be either trepo or tworktree at line 2178
# and test what rev-parse returns for an actual worktree
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
git init "$tmpdir/main_repo" >/dev/null 2>&1
cd "$tmpdir/main_repo"
git commit --allow-empty -m "init" >/dev/null 2>&1
git worktree add "$tmpdir/worktree_path" -b test-branch >/dev/null 2>&1
echo "=== Test 1: Main repo with -C ==="
main_git_dir=$(git -C "$tmpdir/main_repo" rev-parse --git-dir 2>/dev/null)
echo "Result: '$main_git_dir'"
echo "Is absolute: $(if [[ \"$main_git_dir\" == /* ]]; then echo 'YES'; else echo 'NO'; fi)"
echo ""
echo "=== Test 2: Worktree with -C ==="
wt_git_dir=$(git -C "$tmpdir/worktree_path" rev-parse --git-dir 2>/dev/null)
echo "Result: '$wt_git_dir'"
echo "Is absolute: $(if [[ \"$wt_git_dir\" == /* ]]; then echo 'YES'; else echo 'NO'; fi)"
echo ""
echo "=== Test 3: Directory existence check from different CWD ==="
cd "$tmpdir" || exit 1
# Simulate the bug: check with relative path from wrong CWD
if [[ -d "$main_git_dir" ]]; then
echo "Check '-d \"$main_git_dir\"' from $tmpdir: FOUND (unexpected!)"
else
echo "Check '-d \"$main_git_dir\"' from $tmpdir: NOT FOUND (confirms bug)"
fi
# Fixed version: prepend the repo path
fixed_path="$tmpdir/main_repo/$main_git_dir"
if [[ -d "$fixed_path" ]]; then
echo "Check '-d \"$fixed_path\"': FOUND (fix works)"
else
echo "Check '-d \"$fixed_path\"': NOT FOUND"
fiRepository: marcusquinn/aidevops Length of output: 387 Relative path from When This directly breaks the crash-recovery feature for the primary (non-worktree) use case. The fix requires normalizing relative paths: 🐛 Construct absolute path for git directory local pre_git_state_dir
pre_git_state_dir="$(git -C "$git_dir" rev-parse --git-dir 2>/dev/null)"
+ # rev-parse --git-dir returns a relative path (e.g., ".git") for non-worktree repos;
+ # make it absolute so the -d checks resolve correctly.
+ if [[ "$pre_git_state_dir" != /* ]]; then
+ pre_git_state_dir="$git_dir/$pre_git_state_dir"
+ fi
if [[ -d "$pre_git_state_dir/rebase-merge" || -d "$pre_git_state_dir/rebase-apply" ]]; then
log_warn "rebase_sibling_pr: aborting stale rebase state for $task_id"
git -C "$git_dir" rebase --abort 2>>"$SUPERVISOR_LOG" || true
fiNote: The same pattern exists at lines 2197–2198 and 2234–2235 (both in conditional branches after the rebase is initiated), though those are pre-existing. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$use_worktree" == "true" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||
| # Worktree is already on the branch — rebase in place | ||||||||||||||||||||||||||||||||||||||||||||
| if ! git -C "$git_dir" rebase origin/main 2>>"$SUPERVISOR_LOG"; then | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
2>/dev/nullon line 2181 to suppress potential errors fromgit rev-parseviolates the repository style guide. The guide specifies that errors should be redirected to log files rather than being suppressed. This makes debugging more difficult if an unexpected issue occurs (e.g., if$git_diris not a valid git repository).A more robust approach is to redirect stderr to the supervisor log and explicitly check if a git directory was found before proceeding.
References
2>/dev/nullis only acceptable when redirecting to log files, not for blanket suppression of errors. The suggested change redirects stderr to the supervisor log to comply with this rule. (link)