Log inBook a Demo
BuildMidFrontendAuto-graded

Fix an undo history that replays stale commands

The editor's undo and redo corrupt user data in some sequences; make the engine follow its documented contract.UndoRedo in history.py drives an editor's undo and redo. Each command has apply and revert, and the manager keeps the state plus an undo stack and a redo stack. It passes a quick click-through, but users report redo bringing back edits they had already replaced with new ones. Fix it to follow the rules in the brief, including an empty history and one capped by max_history.
35 min
python

You're done when

  • A new command after an undo clears the redo stack, so redo can't bring back the branch that was undone.
  • Undo with nothing left to undo returns the state unchanged and doesn't raise.
  • Redo with nothing left to redo returns the state unchanged and doesn't raise.
  • Redo right after a new command, with no undo in between, changes nothing.
  • With max_history set, only the most recent commands can be undone; once those are used up, further undos change nothing.

What it measures

Data structuresKeeping the state and both stacks consistent through any sequence of calls.
Class invariantsPutting the rules inside the class, so no order of public calls can break them.
Edge casesHow an empty or full history is handled: no crash and no drift in the state.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

35 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo