8000 Fail undo/redo with an explanation instead of AttributeError by floraschouw · Pull Request #53 · gimp-mcp/gimp-mcp · GitHub
[go: up one dir, main page]

Skip to content

Fail undo/redo with an explanation instead of AttributeError - #53

Open
floraschouw wants to merge 1 commit into
gimp-mcp:mainfrom
floraschouw:fix/undo-redo-unsupported-on-gimp3
Open

floraschouw wants to merge 1 commit into
gimp-mcp:mainfrom
floraschouw:fix/undo-redo-unsupported-on-gimp3

Conversation

@floraschouw
@floraschouw floraschouw commented Sep 1, 2026 •
Copy link
Copy Markdown

Fixes #42.

This does not make undo work

I could not find a way to. On GIMP 3.2.4:

  • Gimp.Image exposes undo_disable, undo_enable, undo_freeze, undo_group_start, undo_group_end, undo_is_enabled, undo_thaw — stack management only. No undo(), no redo().
  • The PDB has 1034 procedures. The only matches for "undo" are the seven gimp-image-undo-* stack calls. There is no gimp-edit-undo, and gimp-edit-* covers only copy/cut/paste.
  • There are no action-dispatch procedures either (nothing matching action or gimp-gui-*), so a plug-in cannot reach Edit > Undo indirectly.

Undo appears to be deliberately GUI-only in GIMP 3.x. If there is a route I missed, I would genuinely like to know and will rework this.

So the tools now fail with a message naming the limitation instead of raising AttributeError, in the same spirit as the untracked-image path in #52.

The docstrings are the substantive part

The handler change only swaps one error for a better one. What actually protects a caller is the tool description, since that is what an MCP client reads when deciding whether to call something.

The old text was:

Undo one or more operations on an image.
...
Returns: {steps_undone}

which reads as a working rollback primitive and invites an agent to plan a multi-step pipeline around being able to revert, then discover mid-run that it cannot. The new text says the tool always fails and points at what does work:

  • duplicate the layer (duplicate_layer) and delete the copy to revert, or
  • verify with get_state_snapshot before a change that is hard to reverse.

redo was broken the same way

#42 reports only undo, but _redo called image.redo() and failed identically. Both are covered here.

Undo groups already work

Worth recording, because it is the actual answer for a human operator: the plug-in already wraps its operations in undo_group_start / undo_group_end, so a single Ctrl+Z in GIMP reverts one whole plug-in operation rather than twenty internal steps. The new error messages say this, so a user who hits the failure learns the working alternative.

Verification

Against a running GIMP 3.2.4 on Windows 10, over MCP:

call before after
undo(steps=1) 'Image' object has no attribute 'undo' explicit error naming the limitation, pointing to Ctrl+Z
redo(steps=2) 'Image' object has no attribute 'redo' explicit error naming the limitation, pointing to Ctrl+Y

python -m py_compile passes on both files. ruff check is unchanged at 421 findings across the two files — no new violations.

Summary by CodeRabbit

  • Bug Fixes

    • Undo and redo actions now return a clear explanation when unavailable through GIMP plug-ins, instead of attempting unsupported operations.
  • Documentation

    • Updated undo and redo tool guidance to clarify GIMP 3.x limitations.
    • Added alternative suggestions for managing reversible edits, including duplicate layers and state snapshots.

Both tools called image.undo() / image.redo(), which do not exist on GIMP
3.x, so every call raised:

    'Image' object has no attribute 'undo'

There is no fix that makes them work. GIMP 3.2 exposes undo *stack*
management only -- undo_group_start/end, undo_freeze/thaw,
undo_disable/enable -- and none of the 1034 procedures in the PDB performs
an undo or a redo. GIMP has no action-dispatch procedures either, so a
plug-in cannot reach Edit > Undo. Undo remains a GUI-only operation.

So the tools now fail with a message naming the limitation and pointing at
Ctrl+Z / Ctrl+Y, instead of raising AttributeError.

The server-side docstrings matter as much as the handlers here: they are
what an MCP client reads when deciding whether to call a tool, and the old
text ("Returns: {steps_undone}") invites an agent to plan a workflow around
being able to roll back. They now say the tool always fails and suggest
working on a duplicate layer, or verifying with get_state_snapshot before
a hard-to-reverse change.

gimp-mcp#42 reports the undo crash; redo was broken identically and is fixed here
too.

Fixes gimp-mcp#42

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai
coderabbitai Bot commented Sep 1, 2026 •
Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: cac47459-4d30-4ed2-bf9a-c54c87b146e7

📥 Commits

Reviewing files that changed from the base of the PR and between 09bfb2d and a670bfb.

📒 Files selected for processing (2)
  • gimp-mcp-plugin.py
  • gimp_mcp_server.py

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


Walkthrough

The plugin no longer calls unavailable GIMP image undo or redo methods. It returns explicit unsupported-operation errors. Server tool documentation now explains the limitation and available alternatives.

Changes

Undo and redo handling

Layer / File(s) Summary
Plugin history error handling
gimp-mcp-plugin.py
The plugin defines shared unsupported-operation messages and returns them immediately from _undo and _redo.
Tool documentation updates
gimp_mcp_server.py
The undo and redo documentation describes the GIMP 3.x plug-in limitation, keyboard shortcuts, and alternative workflows.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to a670b

Undo and redo now fail with clear explanations instead of unexpected AttributeError exceptions, while documenting available alternatives. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR fixes the reported AttributeError for undo and the suspected equivalent redo failure by returning explicit limitation errors. However, issue #42 expects the last operation to be undone, and the… Implement undo and redo through the supported GIMP 3.x PDB procedures, or update issue #42 to explicitly change its acceptance criteria from performing the operations to reporting that they are unsupported.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: undo and redo now return explanatory err 8000 ors instead of raising AttributeError.
Out of Scope Changes check ✅ Passed The changes remain within scope. They update undo and redo behavior and document the GIMP 3.x limitation and alternatives. No unrelated code changes are identified.
Full details: Linked Issues check

Explanation

The PR fixes the reported AttributeError for undo and the suspected equivalent redo failure by returning explicit limitation errors. However, issue #42 expects the last operation to be undone, and the PR does not implement undo or redo execution.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Warning

⚠️ This pull request shows signs of AI-generated slop (defensive_cruft). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

@maorcc maorcc added the bug Something isn't working label Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

undo tool crashes: 'Image' object has no attribute 'undo'

2 participants

0