Skip to content

Undo the branch when create's commit fails - #29

Merged
DomBlack merged 1 commit into
explain-signing-failuresfrom
undo-create-when-commit-fails
Oct 9, 2026
Merged

DomBlack merged 1 commit into
explain-signing-failuresfrom
undo-create-when-commit-fails

Conversation

@DomBlack

@DomBlack DomBlack commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Create makes the branch, checks it out and registers it with gh stack before it commits, so a failed commit (a signing key nobody could unlock, a pre-commit hook saying no) left a tracked branch sat at the parent's commit with nothing of its own and the changes still staged. The error didn't say so either; from the MCP side it looked like nothing had happened, and calling stack_create again fails because the branch already exists. The only way out was to notice it in stack_view and reach for stack_modify instead.

Create now undoes itself when the commit fails: the branch is forgotten through Update (an empty stack goes with it), we switch back to the parent and delete the branch. Both point at the same commit so the staged changes are untouched, and the error says nothing was created and to run create again once the cause is fixed. If the undo itself fails the error says what was left behind and that modify -c commits on it. The tool description and architecture notes say the same.

@DomBlack
DomBlack added this pull request to stack #31 October 9, 2026 16:30
@DomBlack
DomBlack requested a balanced review from Copilot October 9, 2026 16:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Cancellation can prevent cleanup and leave the created branch checked out but untracked.

3 open findings
What changed in this PR

Adds rollback handling when branch creation succeeds but the commit fails.

Changes:

  • Removes failed-create branches while preserving staged changes.
  • Improves signing-failure recovery guidance.
  • Adds rollback tests and updates MCP/architecture documentation.
File Description
pkg/​app/​create.go Implements failed-create rollback.
pkg/​app/​modify.go Adds Modify retry guidance.
pkg/​app/​staging.go Makes signing guidance command-specific.
pkg/​app/​mutate_test.go Tests rollback outcomes.
pkg/​mcp/​tools.go Documents MCP create behavior.
docs/​architecture.md Documents rollback design.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/app/create.go
Comment thread pkg/app/modify.go
Comment thread pkg/mcp/tools.go Outdated
Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:00
@DomBlack
DomBlack force-pushed the undo-create-when-commit-fails branch from ecf4d78 to a41f85d Compare October 9, 2026 17:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Rollback can delete a successfully created commit when the subsequent SHA lookup fails.

1 open finding
3 resolved since last review

🧠 Review effort: Balanced

Comment thread pkg/app/create.go
Create makes the branch, checks it out and registers it with gh stack before it commits, so a failed commit (a signing key nobody could unlock, a pre-commit hook saying no) left a tracked branch sat at the parent's commit with nothing of its own and the changes still staged. The error didn't say so either; from the MCP side it looked like nothing had happened, and calling stack_create again fails because the branch already exists. The only way out was to notice it in stack_view and reach for stack_modify instead.

Create now undoes itself when the commit fails: the branch is forgotten through Update (an empty stack goes with it), we switch back to the parent and delete the branch. Both point at the same commit so the staged changes are untouched, and the error says nothing was created and to run create again once the cause is fixed. If the undo itself fails the error says what was left behind and that modify -c commits on it. The tool description and architecture notes say the same.
Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:17
@DomBlack
DomBlack force-pushed the undo-create-when-commit-fails branch from a41f85d to e3f17b9 Compare October 9, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Rollback can still delete a successfully committed branch when tip verification fails.

3 open findings
1 resolved since last review

🧠 Review effort: Balanced

Comment thread pkg/app/create.go
Comment on lines +127 to +128
if tip, ok, terr := a.d.Git.Tip(ctx, repo, name); terr == nil && ok {
if parentTip, _, perr := a.d.Git.Tip(ctx, repo, parent); perr == nil && tip != parentTip {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

If git can't resolve either ref, the undo's own git calls fail the same way and the error reports what was left behind rather than silently deleting anything, since each step checks its error. A branch -D after a commit that did land is also still in the reflog. Not going to add more ceremony for that corner.

Comment thread docs/architecture.md
Comment on lines +194 to +195
and the staged changes are still staged; the error says to run it again. If the undo itself
fails the error says what was left behind and that `modify -c` commits on it.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

The step text already covers both states: it says to check git stack log, commit with modify -c if the branch is still tracked, otherwise delete it. The architecture note is the summary; I'll leave it at that.

Comment thread pkg/mcp/tools.go
Name: "stack_create",
Title: "Create a stacked branch",
Description: "Create a new branch on top of the current branch, commit staged changes with the given message, and register it in the stack. From the trunk this starts a new stack. Fails with not_at_top when the current branch is not the top of its stack.",
Description: "Create a new branch on top of the current branch, commit staged changes with the given message, and register it in the stack. From the trunk this starts a new stack. Fails with not_at_top when the current branch is not the top of its stack. If the commit fails (signing_failed, a hook) the branch is removed again and the changes stay staged, so fix the cause and call it again; should removing it fail too, next_steps says what was left behind and how to commit on it.",

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Same answer as on the architecture note: next_steps for the failed-undo case already distinguishes still tracked (modify -c) from untracked (delete it), so a client reads that rather than the description. Leaving the description as the summary.

@DomBlack
DomBlack merged commit aaaaef2 into main Oct 9, 2026
6 checks passed
@DomBlack
DomBlack deleted the undo-create-when-commit-fails branch October 9, 2026 17:40
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.

2 participants