> For the complete documentation index, see [llms.txt](https://stemma.sh/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stemma.sh/docs/understand-the-model/revisions.md). Agents can also search and read this documentation through its [MCP server](https://stemma.sh/docs/~gitbook/mcp).

# Revisions

Tracked changes are stemma's reason to exist. This chapter is the mental model; the [editing chapter](https://stemma.sh/docs/understand-the-model/editing.md) covers how to author them.

## The type system

Word's revision machinery is richer than "inserted text, deleted text." Stemma models each kind as a first-class type with its own accept/reject semantics:

* **Text insertions and deletions** (`w:ins`/`w:del`), including runs nested inside other authors' revisions.
* **Moves** (`w:moveFrom`/`w:moveTo`) use a paired source and destination, but enumerate and resolve as ONE atomic revision: accepting lands the text at its destination, rejecting restores the original position, and either way every piece of the move's markup (both containers and the range bookmarks pairing them) leaves the document. This holds under bulk (`accept-all`/`reject-all`) and selective (by id, by author) resolution alike; a resolved document never carries a half-move.
* **Formatting changes** cover paragraph (`w:pPrChange`), run (`w:rPrChange`), table, row, cell, and section-properties changes. Each carries a complete snapshot of the *previous* formatting; rejecting restores that snapshot exactly, down to fields like keep-next and borders.
* **Paragraph-mark changes** have structural effects. Deleting a paragraph mark *joins two paragraphs* on accept (§17.13.5.15). This is the semantics hand-editing gets wrong most often.
* **Structural changes** include inserted or deleted table rows and whole tracked blocks.
* **Cell merges** (`w:cellMerge`, §17.13.5.3) record a change to a cell's vertical merge: `w:vMerge` is the merge after the change and `w:vMergeOrig` the merge before it, a missing attribute meaning not merged. Accept gives the cell the first, Reject the second, as Word does. A cell either one leaves as a continuation of the cell above loses its content, pending changes in it included, and a merge left with one cell is saved unmerged. The cell merges of one run of cells in one column are one revision, kind `cell_merge`. Word writes them only when it compares two documents; merging cells with Track Changes on is not tracked, in Word or in Stemma (`merge_cells`).

All of these are enumerable (`Document::revisions()` in Rust, `list_revisions` over MCP, `extract` in the CLI) and resolvable across every story, including the body, footnotes, tables, and section properties.

A `w:cellMerge` with neither attribute changes nothing, as the standard allows, and is ignored.

## Word author labels

Every revision carries a Word author label. It is a free-form display string, not an authenticated identity. Microsoft Word groups revisions with the same label, so choosing whether to reuse one is still an important attribution decision.

Stemma therefore requires confirmation before a write reuses any label that was present when the document was opened (`AuthorLabelCollision`). Pass `allow_existing_author: true` to continue that existing reviewer group. To keep an editing round separate, use a different label only when the user has chosen it; an agent must never invent one merely to clear the refusal.

The set checked by this guard is frozen at open time. A label first introduced in the current open session can be reused for additional edits in that session without the assertion. After saving and reopening, that label is part of the new document's open-time set and requires confirmation like every other existing label.

Direct materialization creates no Word revisions and emits no author label, so the collision policy does not apply to direct edits.

Two edge shapes of authorship are worth stating exactly:

* **A blank author label is a real author group.** Word anonymization ("Remove personal information") and some third-party tools write `w:author=""`. Stemma models that as the empty-string author: it enumerates as `author: ""` and is selectable as a group like any other name (the CLI selector token is the empty string, `--accept-author ""`).
* **A missing author label is refused.** A tracked change with no `w:author` attribute at all fails import (`missing required tracked change attribute: author`) rather than being silently adopted into some default identity, so an enumerated revision always has an author value.

## Revision ids are content-derived identities

An id is not read from the file's `w:id` attributes (Word does not keep those unique) and not a parse-order counter. The engine mints it as a hash of the change's own identity (kind, story, author, date, and content), plus a disambiguating ordinal among identical duplicates. Two consequences:

* **Durability.** A revision whose own content is untouched keeps its id across serialize/reopen and across resolution of *other* revisions. Ids enumerated before a selective resolve remain valid against its output, and against the saved file reopened tomorrow. One limit: among changes that look exactly alike (same kind, author, date and text), ids are kept by Stemma's own save, reopen and resolutions, but after another editor changes the file, lookalikes are numbered again by document order, so two of them can trade ids. Re-read ids after any edit made outside Stemma.
* **The re-key edge.** If an operation alters a surviving revision's content (or removes an identical-signature duplicate ahead of it), that survivor's signature, and so its id, changes. This is the honest edge of a content-derived identity: the id names *what the change is*, so a change that becomes something else is no longer addressable by its old name.

Practical discipline: read ids from the enumerator (`Document::revisions()`, MCP `list_revisions`, the CLI's `extract` or `read`, or a receipt), never from raw XML. (The one id that does mirror the XML is a change inside a textbox: it is the change's own `w:id`, and it is selectable only while that `w:id` is unique in the document; otherwise the enumerator reports it with id `0` and it is resolved only by accepting or rejecting everything.) Re-enumerating after each step is always safe and costs one read; author/all selectors need no id carrying at all. A selection naming an id that no longer exists fails loud (the CLI's refusal lists the ids actually pending) rather than resolving something else.

A selection is also refused, naming the ids to resolve together, when part of it has no result that is the same in every order. Accepting a deleted paragraph mark whose join into the next paragraph is blocked only by a table another pending change deletes is one such case: the join depends on that table's fate, so the two must be resolved together (or the table first). Resolving only some of the changes that share one table's earlier grid is the other.

## Accept and reject are not symmetric erasures

Both accepting and rejecting a change remove its marker. Therefore, "the marker is gone" tells you nothing about *which* happened. The difference is content: **accept keeps the new state; reject restores the prior state exactly.** If you need to verify a resolution (yours or anyone's), compare content, not markers: does the clause read twelve months or six?

```rust,no_run
use std::collections::HashSet;
use stemma::api::{Document, Resolution, ResolveSelectionAction, RuntimeError};

/// Reject one author's pending changes; leave everyone else's untouched.
fn reject_authors_changes(doc: &Document, author: &str) -> Result<Document, RuntimeError> {
    // Ids come from the census: each record carries `revision_id: u32`, and
    // `Resolution::Selective` takes the selection as a `HashSet<u32>`.
    let ids: HashSet<u32> = doc
        .revisions()
        .into_iter()
        .filter(|r| r.author.as_deref() == Some(author))
        .map(|r| r.revision_id)
        .collect();
    doc.project(Resolution::Selective { ids, action: ResolveSelectionAction::Reject })
}
```

The result of `project` is a full `Document`: verify the rejection by content (does the clause still read "twelve months"?), project it again for the next pass of a mixed triage, or serialize it as the resolved `.docx`; the [embedding page](https://stemma.sh/docs/reference/embedding.md#resolving-a-redline-tier-1) shows that whole flow. Runnable, with the content-level verification spelled out: `cargo run -p stemma --example resolve_a_redline`.

This has a useful corollary. A document's **committed text**, meaning what it says if every pending change is rejected, is derivable at any time. It is what your counterparty's "reject all" button produces. When stemma resolves selectively (accept this author's changes, reject that one change), the engine guarantees the untouched revisions are preserved marker-for-marker and the resolved ones land on the correct side of that line.

Next, read [Editing](https://stemma.sh/docs/understand-the-model/editing.md) for transactions, receipts, and the review-then-save discipline.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://stemma.sh/docs/understand-the-model/revisions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
