{"record":{"id":"ca8866bdcd450787","repo":"FoundationAgents/OpenManus","slug":"no-edit-history-found-for-path","errorCode":null,"errorMessage":"No edit history found for {path}.","messagePattern":"No edit history found for (.+?)\\.","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"app/tool/str_replace_editor.py","lineNumber":399,"sourceCode":"        self._file_history[path].append(file_text)\n\n        # Prepare success message\n        success_msg = f\"The file {path} has been edited. \"\n        success_msg += self._make_output(\n            snippet,\n            \"a snippet of the edited file\",\n            max(1, insert_line - SNIPPET_LINES + 1),\n        )\n        success_msg += \"Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.\"\n\n        return CLIResult(output=success_msg)\n\n    async def undo_edit(\n        self, path: PathLike, operator: FileOperator = None\n    ) -> CLIResult:\n        \"\"\"Revert the last edit made to a file.\"\"\"\n        if not self._file_history[path]:\n            raise ToolError(f\"No edit history found for {path}.\")\n\n        old_text = self._file_history[path].pop()\n        await operator.write_file(path, old_text)\n\n        return CLIResult(\n            output=f\"Last edit to {path} undone successfully. {self._make_output(old_text, str(path))}\"\n        )\n\n    def _make_output(\n        self,\n        file_content: str,\n        file_descriptor: str,\n        init_line: int = 1,\n        expand_tabs: bool = True,\n    ) -> str:\n        \"\"\"Format file content for display with line numbers.\"\"\"\n        file_content = maybe_truncate(file_content)\n        if expand_tabs:","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/tool/str_replace_editor.py#L381-L417","documentation":"Thrown by str_replace_editor's undo_edit when the per-file edit history stack (self._file_history[path]) is empty. The tool keeps an in-memory history keyed by path; if no prior edit was recorded for that exact path in this session/process, there is nothing to revert.","triggerScenarios":"Calling undo_edit on a file that was never edited via this editor instance, or calling undo_edit more times than edits were made (each undo pops one entry). Also occurs after process restart, since history is in-memory only, or when the path key differs (e.g. relative vs absolute path spelling of the same file).","commonSituations":"Agent flows that assume persistent undo across sessions; mixing edits made through other tools or manual writes (not tracked in history); path normalization mismatches ('./app/main.py' vs 'app/main.py') creating distinct history keys.","solutions":["Only call undo_edit after at least one successful edit through the same editor instance and the same path spelling.","Check history length before undoing (if the API exposes it) or track edit counts on your side.","Use a canonical absolute path for every edit and undo so history keys always match.","If history was lost (restart), restore content from version control instead of undo_edit."],"exampleFix":"// before\nawait editor.undo_edit('app/main.py')  // process restarted, history empty -> error\n// after\nif editor._file_history.get('app/main.py'):  # or track edits yourself\n    await editor.undo_edit('app/main.py')\nelse:\n    await operator.write_file('app/main.py', restore_from_git_or_backup())","handlingStrategy":"validation","validationCode":"if not editor._file_history.get(path):\n    raise RuntimeError(f'no history for {path}; restore from VCS instead')","typeGuard":null,"tryCatchPattern":"try:\n    await editor.undo_edit(path)\nexcept ToolError as e:\n    if 'No edit history found' in str(e):\n        await operator.write_file(path, git_checkout(path))  # fallback restore\n    else:\n        raise","preventionTips":["Use one canonical absolute path for every edit and undo so history keys match.","Track edit counts per file in your own code and never undo more times than you edited.","Do not rely on undo across process restarts — history is in-memory; keep VCS or backups for durable recovery."],"tags":["file-editing","undo","in-memory-state","agent-tools"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}