adeu icon indicating copy to clipboard operation
adeu copied to clipboard

Multi-run replacements emit duplicate w:del IDs rejected by OpenXML validation

Open 6uimorais opened this issue 2 months ago • 1 comments

Summary

Thank you for maintaining Adeu. While integrating tracked document editing with an independent OpenXML validation gate, I found a small reproducible case where process_batch reports success but the saved document contains sibling w:del elements with the same w:id.

The reproduction below is entirely synthetic. It does not require an LLM, MCP transport, a customer document, or existing tracked changes.

Environment

  • Node: @adeu/[email protected]; also reproduced on the current main (0374c2e).
  • Python: reproduced on the same main, Python 3.13.7.
  • Independent validator: @ooxml-tools/[email protected], Microsoft365 target (Open XML SDK validation).

Minimal reproduction (Python)

import io
from pathlib import Path
from docx import Document
from docx.oxml.ns import qn
from docx.shared import Pt
from adeu.models import ModifyText
from adeu.redline.engine import RedlineEngine

doc = Document()
p = doc.add_paragraph("Before ")
for index, text in enumerate(["red ", "green ", "blue"]):
    p.add_run(text).font.size = Pt(12 + index)
doc.add_paragraph("Untouched paragraph.")
source = io.BytesIO()
doc.save(source)
source.seek(0)
Path("input.docx").write_bytes(source.getvalue())

engine = RedlineEngine(source, author="Reviewer")
report = engine.process_batch([
    ModifyText(target_text="red green blue", new_text="violet")
])
output = engine.save_to_stream().getvalue()
Path("output.docx").write_bytes(output)
result = Document(io.BytesIO(output))
print(report["edits_applied"])
print([node.get(qn("w:id")) for node in result.element.xpath("//w:del")])

Before the proposed fix, this reports one applied edit and deletion IDs ['1', '1', '1']. The Node equivalent is new RedlineEngine(doc, "Reviewer").process_batch([{type: "modify", target_text: "red green blue", new_text: "violet"}]) on the same input.

Validate the two files independently:

npx --yes @ooxml-tools/[email protected] input.docx --format docx --office-version Microsoft365 --output-format json
npx --yes @ooxml-tools/[email protected] output.docx --format docx --office-version Microsoft365 --output-format json

The input has no validation errors. The Node output reports:

Sem_UniqueAttributeValue
Attribute 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:id'
should have unique value. Its current value '1' duplicates with others.
Part: /word/document.xml
Path: /w:document[1]/w:body[1]/w:p[1]/w:del[3]

Expected behavior / impact

Replacing or deleting text across ordinary Word runs should preserve their formatting and produce a document accepted by the OpenXML validator. In an integration that validates before publishing a revision, this error blocks saving despite a successful engine report. This report concerns validation; I have not tested the reproduction in desktop Microsoft Word and am not claiming that Word refuses to open it.

Likely cause and proposed approach

Both engines allocate a deletion ID once per resolved edit, then reuse it for each run's separate deletion wrapper. I understand the grouping goal discussed in #16. A narrowly scoped approach is to keep adjacent deleted runs inside one w:del wrapper, preserving their individual run properties and the compact logical-change presentation. When an intervening node prevents coalescing, keep that node in place and allocate a fresh ID for the separate wrapper.

This appears distinct from #114: this reproduction involves only the main document part and no pre-existing revision IDs.

I have a candidate fix in both engines, with mirrored regression tests for replacement/deletion, run formatting, intervening nodes, save/reload, accept/reject, and preservation of another author's revisions. I will link the PR here. Feedback on the approach, particularly logical-change grouping across structural boundaries, would be welcome.

6uimorais avatar Sep 11 '26 23:09 6uimorais

Thanks for the report!

mkorpela avatar Sep 12 '26 22:09 mkorpela