> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superdoc.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# history.undo

> Undo the most recent history-safe mutation in the document.

## Summary

Undo the most recent history-safe mutation in the document.

* Operation ID: `history.undo`
* API member path: `editor.doc.history.undo(...)`
* Mutates document: `yes`
* Idempotency: `non-idempotent`
* Supports tracked mode: `no`
* Supports dry run: `no`
* Deterministic target resolution: `yes`

## Expected result

Returns a HistoryActionResult with noop flag, revision before/after, optional noop reason, and optional ref-effect fields such as inserted, removed, invalidatedRefs, remappedRefs, and affectedStories.

## Input fields

*No fields.*

### Example request

```json theme={null}
{}
```

## Output fields

| Field                          | Type                    | Required | Description                                                                                                                                            |
| ------------------------------ | ----------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `affectedStories`              | StoryLocator\[]         | no       |                                                                                                                                                        |
| `collaboration`                | object                  | no       |                                                                                                                                                        |
| `collaboration.affectedShards` | string\[]               | no       |                                                                                                                                                        |
| `collaboration.mode`           | enum                    | no       | `"session-local"`, `"single-shard"`, `"journaled-multi-shard"`                                                                                         |
| `collaboration.opId`           | string                  | no       |                                                                                                                                                        |
| `collaboration.undoGroupId`    | string                  | no       |                                                                                                                                                        |
| `diagnosticCode`               | string                  | no       |                                                                                                                                                        |
| `inserted`                     | EntityAddress\[]        | no       |                                                                                                                                                        |
| `invalidatedRefs`              | AffectedRef\[]          | no       |                                                                                                                                                        |
| `noop`                         | boolean                 | yes      |                                                                                                                                                        |
| `reason`                       | enum                    | no       | `"EMPTY_UNDO_STACK"`, `"EMPTY_REDO_STACK"`, `"NO_EFFECT"`, `"no-undo-available"`, `"no-redo-available"`, `"history-entry-missing"`, `"apply-rejected"` |
| `remappedRefs`                 | AffectedRefRemapping\[] | no       |                                                                                                                                                        |
| `removed`                      | EntityAddress\[]        | no       |                                                                                                                                                        |
| `revision`                     | object                  | yes      |                                                                                                                                                        |
| `revision.after`               | string                  | yes      |                                                                                                                                                        |
| `revision.before`              | string                  | yes      |                                                                                                                                                        |
| `status`                       | enum                    | no       | `"applied"`, `"noop"`, `"rejected"`, `"partial"`, `"repaired"`                                                                                         |
| `textRangeShifts`              | TextRangeShift\[]       | no       |                                                                                                                                                        |
| `updated`                      | EntityAddress\[]        | no       |                                                                                                                                                        |

### Example response

```json theme={null}
{
  "inserted": [
    {
      "entityId": "entity-789",
      "entityType": "comment",
      "kind": "entity"
    }
  ],
  "noop": true,
  "reason": "EMPTY_UNDO_STACK",
  "revision": {
    "after": "example",
    "before": "example"
  }
}
```

## Pre-apply throws

* `CAPABILITY_UNAVAILABLE`

## Non-applied failure codes

* None

## Raw schemas

<Accordion title="Raw input schema">
  ```json theme={null}
  {
    "additionalProperties": false,
    "properties": {},
    "type": "object"
  }
  ```
</Accordion>

<Accordion title="Raw output schema">
  ```json theme={null}
  {
    "additionalProperties": false,
    "properties": {
      "affectedStories": {
        "items": {
          "$ref": "#/$defs/StoryLocator"
        },
        "type": "array"
      },
      "collaboration": {
        "additionalProperties": false,
        "properties": {
          "affectedShards": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "mode": {
            "enum": [
              "session-local",
              "single-shard",
              "journaled-multi-shard"
            ]
          },
          "opId": {
            "type": "string"
          },
          "undoGroupId": {
            "type": "string"
          }
        },
        "required": [
          "mode"
        ],
        "type": "object"
      },
      "diagnosticCode": {
        "type": "string"
      },
      "inserted": {
        "items": {
          "$ref": "#/$defs/EntityAddress"
        },
        "type": "array"
      },
      "invalidatedRefs": {
        "items": {
          "$ref": "#/$defs/AffectedRef"
        },
        "type": "array"
      },
      "noop": {
        "type": "boolean"
      },
      "reason": {
        "enum": [
          "EMPTY_UNDO_STACK",
          "EMPTY_REDO_STACK",
          "NO_EFFECT",
          "no-undo-available",
          "no-redo-available",
          "history-entry-missing",
          "apply-rejected"
        ]
      },
      "remappedRefs": {
        "items": {
          "$ref": "#/$defs/AffectedRefRemapping"
        },
        "type": "array"
      },
      "removed": {
        "items": {
          "$ref": "#/$defs/EntityAddress"
        },
        "type": "array"
      },
      "revision": {
        "additionalProperties": false,
        "properties": {
          "after": {
            "type": "string"
          },
          "before": {
            "type": "string"
          }
        },
        "required": [
          "before",
          "after"
        ],
        "type": "object"
      },
      "status": {
        "enum": [
          "applied",
          "noop",
          "rejected",
          "partial",
          "repaired"
        ]
      },
      "textRangeShifts": {
        "items": {
          "$ref": "#/$defs/TextRangeShift"
        },
        "type": "array"
      },
      "updated": {
        "items": {
          "$ref": "#/$defs/EntityAddress"
        },
        "type": "array"
      }
    },
    "required": [
      "noop",
      "revision"
    ],
    "type": "object"
  }
  ```
</Accordion>

<Accordion title="Raw success schema">
  ```json theme={null}
  {
    "additionalProperties": false,
    "properties": {
      "affectedStories": {
        "items": {
          "$ref": "#/$defs/StoryLocator"
        },
        "type": "array"
      },
      "collaboration": {
        "additionalProperties": false,
        "properties": {
          "affectedShards": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "mode": {
            "enum": [
              "session-local",
              "single-shard",
              "journaled-multi-shard"
            ]
          },
          "opId": {
            "type": "string"
          },
          "undoGroupId": {
            "type": "string"
          }
        },
        "required": [
          "mode"
        ],
        "type": "object"
      },
      "diagnosticCode": {
        "type": "string"
      },
      "inserted": {
        "items": {
          "$ref": "#/$defs/EntityAddress"
        },
        "type": "array"
      },
      "invalidatedRefs": {
        "items": {
          "$ref": "#/$defs/AffectedRef"
        },
        "type": "array"
      },
      "noop": {
        "type": "boolean"
      },
      "reason": {
        "enum": [
          "EMPTY_UNDO_STACK",
          "EMPTY_REDO_STACK",
          "NO_EFFECT",
          "no-undo-available",
          "no-redo-available",
          "history-entry-missing",
          "apply-rejected"
        ]
      },
      "remappedRefs": {
        "items": {
          "$ref": "#/$defs/AffectedRefRemapping"
        },
        "type": "array"
      },
      "removed": {
        "items": {
          "$ref": "#/$defs/EntityAddress"
        },
        "type": "array"
      },
      "revision": {
        "additionalProperties": false,
        "properties": {
          "after": {
            "type": "string"
          },
          "before": {
            "type": "string"
          }
        },
        "required": [
          "before",
          "after"
        ],
        "type": "object"
      },
      "status": {
        "enum": [
          "applied",
          "noop",
          "rejected",
          "partial",
          "repaired"
        ]
      },
      "textRangeShifts": {
        "items": {
          "$ref": "#/$defs/TextRangeShift"
        },
        "type": "array"
      },
      "updated": {
        "items": {
          "$ref": "#/$defs/EntityAddress"
        },
        "type": "array"
      }
    },
    "required": [
      "noop",
      "revision"
    ],
    "type": "object"
  }
  ```
</Accordion>

<Accordion title="Raw failure schema">
  ```json theme={null}
  {
    "additionalProperties": false,
    "properties": {
      "failure": {
        "additionalProperties": false,
        "properties": {
          "code": {
            "enum": [
              "CAPABILITY_UNAVAILABLE"
            ]
          },
          "details": {},
          "message": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ],
        "type": "object"
      },
      "success": {
        "const": false
      }
    },
    "required": [
      "success",
      "failure"
    ],
    "type": "object"
  }
  ```
</Accordion>
