Skip to content

t1049: Stash dirty worktree before rebase (follow-up)#1481

Merged
marcusquinn merged 1 commit intomainfrom
bugfix/t1049-stash
Feb 14, 2026
Merged

t1049: Stash dirty worktree before rebase (follow-up)#1481
marcusquinn merged 1 commit intomainfrom
bugfix/t1049-stash

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Feb 14, 2026

Summary

Follow-up to t1049. Stash (not reset) dirty worktree state before rebasing to prevent cannot rebase: uncommitted changes errors.

Why stash instead of reset

The AI conflict resolver runs git add during resolution. If the rebase then fails, those staged changes persist. On the next rebase attempt, git refuses with "uncommitted changes".

Using git stash instead of git reset + checkout because:

  • Changes are recoverable via git stash list if a human had uncommitted work
  • The stash message includes the task ID for traceability
  • Same effect (clean worktree for rebase) but non-destructive

Summary by CodeRabbit

  • Chores
    • Improved the automated rebase workflow to better manage repository state and preserve uncommitted changes. Enhanced the process to safely maintain work-in-progress modifications during conflict resolution and subsequent operations, reducing the risk of losing local work during automation.

…d changes' error

Failed AI conflict resolution leaves staged changes in the worktree.
Subsequent rebase attempts fail with 'cannot rebase: uncommitted changes'.

Uses git stash (not reset) so changes are recoverable via git stash list
in case a human had uncommitted work in the worktree.
@gemini-code-assist
Copy link

Summary of Changes

Hello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the rebase process within the deployment script. It introduces a pre-rebase check that intelligently handles uncommitted changes by stashing them, thereby preventing common rebase errors and improving the recoverability of developer work, particularly in scenarios involving automated conflict resolution.

Highlights

  • Prevented rebase failures: Implemented a mechanism to stash dirty worktree state before initiating a rebase operation, specifically addressing issues where an AI conflict resolver might leave staged changes that cause subsequent rebase attempts to fail.
  • Improved error handling and recoverability: Switched from a destructive git reset approach to git stash, ensuring that any uncommitted changes are recoverable via git stash list and providing better traceability with stash messages including the task ID.
Changelog
  • .agents/scripts/supervisor/deploy.sh
    • Modified the rebase_sibling_pr function to include stashing of dirty worktree before rebase.
    • Updated comments to reflect the new stashing logic and its benefits.
Activity
  • No activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

Walkthrough

Enhances the rebase_sibling_pr workflow function in the deploy script by adding a stash mechanism to preserve uncommitted changes before initiating a rebase. Combines existing stale rebase state abort logic with new conditional git stashing to safeguard any dirty index or worktree during conflict resolution.

Changes

Cohort / File(s) Summary
Rebase Workflow Enhancement
.agents/scripts/supervisor/deploy.sh
Added conditional git stash logic before rebase initiation to preserve uncommitted work; stale rebase state is aborted first, then dirty index/worktree is stashed, allowing subsequent conflict resolution steps to safely recover changes without losing work.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Possibly related PRs

Poem

🧐 Before the rebase chaos takes its toll,
We stash your work in git's safe stole,
No lost commits, no midnight dread,
Just clean rebases and peace ahead!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main change: stashing dirty worktree before rebase in the t1049 task context, matching the PR's primary objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/t1049-stash

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
.agents/scripts/supervisor/deploy.sh (1)

2191-2193: Stash failure is swallowed — rebase will still fail downstream, but consider logging.

If git stash push fails (e.g., untracked files conflicting, or a corrupt index), the || true lets execution continue into the rebase with a dirty worktree, which will then fail with "uncommitted changes." The downstream rebase failure handling covers this, but the root cause would be obscured in logs.

Consider capturing the stash exit code to log a more specific diagnostic when the subsequent rebase fails:

🔧 Optional: capture stash failure for better diagnostics
 	if [[ -n "$(git -C "$git_dir" status --porcelain 2>/dev/null)" ]]; then
 		log_warn "rebase_sibling_pr: stashing dirty worktree for $task_id"
-		git -C "$git_dir" stash push -m "auto-stash before rebase ($task_id)" 2>>"$SUPERVISOR_LOG" || true
+		if ! git -C "$git_dir" stash push -m "auto-stash before rebase ($task_id)" 2>>"$SUPERVISOR_LOG"; then
+			log_warn "rebase_sibling_pr: git stash failed for $task_id — rebase may fail due to dirty worktree"
+		fi
 	fi

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 5 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sat Feb 14 17:58:32 UTC 2026: Code review monitoring started
Sat Feb 14 17:58:32 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 5

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 5
  • VULNERABILITIES: 0

Generated on: Sat Feb 14 17:58:35 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

@marcusquinn marcusquinn merged commit 5cd2d44 into main Feb 14, 2026
10 of 11 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the rebase logic by stashing a dirty worktree to prevent errors, which is a good improvement. My review includes two suggestions: one to correct a misleading comment to accurately reflect the new stashing mechanism, and another to align an error redirection with the repository's style guide for better logging and debuggability. None of the provided rules contradict these comments.

Comment on lines +2180 to +2181
# 2. Reset index and restore working tree (prevents "uncommitted changes" errors
# left by the AI conflict resolver's git-add on a subsequently aborted rebase)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This comment is misleading as it mentions 'Reset index and restore working tree', but the implementation now uses git stash. The PR description correctly explains the choice of stash over reset. To avoid confusion and maintain consistency, please update the comment to reflect that the worktree is cleaned by stashing changes.

Suggested change
# 2. Reset index and restore working tree (prevents "uncommitted changes" errors
# left by the AI conflict resolver's git-add on a subsequently aborted rebase)
# 2. Stash dirty index/worktree (prevents "uncommitted changes" errors
# left by the AI conflict resolver's git-add on a subsequently aborted rebase)

# Stash dirty index/worktree — failed AI resolution can leave staged
# changes even after rebase --abort clears the rebase state.
# Uses stash (not reset) so changes are recoverable via `git stash list`.
if [[ -n "$(git -C "$git_dir" status --porcelain 2>/dev/null)" ]]; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository style guide (line 50), 2>/dev/null should generally be avoided in favor of redirecting errors to a log file. To improve debuggability and adhere to the style guide, please redirect stderr to $SUPERVISOR_LOG. This will help diagnose issues if git status fails unexpectedly.

Suggested change
if [[ -n "$(git -C "$git_dir" status --porcelain 2>/dev/null)" ]]; then
if [[ -n "$(git -C \"$git_dir\" status --porcelain 2>>\"$SUPERVISOR_LOG\")" ]]; then
References
  1. Line 50: 2>/dev/null is acceptable ONLY when redirecting to log files, not blanket suppression. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant