Skip to content

fix(comments): new comments are not registered in commentsIds.xml, so Word offers to repair the file #33

Closed

Description

@michaelgasser

Version: docx-cli 0.28.0, release binary (Windows x64), Windows 11, Word 16 (365).

What happens

comments add writes the comment into word/comments.xml and the
commentRangeStart / commentRangeEnd / commentReference into word/document.xml, but does not
add the matching w16cid:commentId to word/commentsIds.xml, nor a w15:commentEx to
word/commentsExtended.xml. On a Word-saved input — i.e. any real document — the package is left
inconsistent from the first added comment onwards, and Word shows "This file contains unreadable
content. Recover?"
on open.

Repro

Attached: fixture-comments-base.docx (7.6 KB). It is a clean package with 2 comments and all
three parts populated 2 / 2 / 2; the side-parts carry Word's shape (w16cid:commentId with
paraId+durableId, w15:commentEx with paraId+done, both keyed to the comment paragraph's
w14:paraId), and docx validate reports valid — 6 parts checked.

$ docx comments add fixture-comments-base.docx --anchor "dritte Absatz" --text "Dritter Kommentar." --author "Test Reviewer"
c2
part before after one comments add
word/comments.xml 2 3
word/commentsIds.xml 2 2
word/commentsExtended.xml 2 2

docx validate still reports valid — 6 parts checked afterwards.

Evidence from the document that hit it

18.5 MB report, 63 pages, 2'366 paragraphs, 25 comments, saved by Word before the session. After the
session the parts stood at 25 / 3 / 4 — the 3 and 4 are the comments the file already had and its two
reply threads. Word offered recovery and rebuilt both side-parts:

part as written by docx-cli after Word's repair
word/comments.xml 25 25
word/commentsIds.xml 3 25
word/commentsExtended.xml 4 25
document.xml commentRangeStart / End / Reference 25 / 25 / 25 25 / 25 / 25

Comment texts and anchors survive the repair unchanged, but comment ids are renumbered (measured:
c23 → c105, c28 → c49, c40 → c598), so any external reference to a comment handle is
invalidated by it. That is what makes this more than cosmetic: the reviewer is handed a repaired copy
of the file they were asked to redline, with every handle shifted.

Expected

One commentId and one commentEx per comment, keyed by the comment's paragraph w14:paraId,
written on comments add and removed on comments delete — the shape Word itself writes.

Where it likely lives

src/cli/comments/add.tsx contains no reference to commentsIds, commentsExtended or paraId.
A reply does produce an entry (measured: 4 comments, one a reply → 2 commentEx entries), so the
write path exists in the reply flow — likely through the CommentsView that CLAUDE.md describes as
owning the part. This looks like one omitted registration plus a missing rebuild path; I did not read
the save path far enough to name the call site.

Suggested regression test

tests/cli/comments.test.ts: on a fixture whose side-parts already list its comments, after two
comments add the entry count in commentsIds.xml and commentsExtended.xml equals the comment
count. The attached file is exactly that fixture, so it can become tests/fixtures/comments-base.docx
as-is.

Notes

fixture-comments-base.docx

Activity

  1. kklimuk commented on Nov 6, 2026

    @kklimuk
    Owner

    Shipped in v0.29.0 (#35 plus follow-ups on main).

    What changed

    • Every save that touches comments now reconciles commentsExtended.xml / commentsIds.xml / commentsExtensible.xml against comments.xml:
      • adds missing entries (durableId = the comment's paraId, as Word does);
      • prunes stale entries;
      • de-duplicates durableIds;
      • re-keys out-of-range w14:paraIds, which docx-cli < 0.14.1 wrote, together with their entries.
    • Existing reply links and resolved state are never touched.
    • Opening and saving a file that an older docx-cli wrote repairs it. docx validate FILE --fix does the same explicitly.

    What live Word showed (Word for Mac 16.114.4, tested on 2026-11-05)
    The exact state in this report (a comment missing from both commentsIds and commentsExtended) opened without a repair prompt, with alerts on and with alerts off. Word added the missing entries itself on save. It's still a real problem, because Word loses data on that save:

    • a reply missing its own commentEx entry becomes a top-level comment;
    • a resolved comment missing its own entry becomes unresolved;
    • with no commentsExtended part at all, every thread and resolved flag is lost.

    In our tests the only comment state that stopped Word from opening the file was a commentReference pointing at a comment that doesn't exist. validate reports that as an error, and --fix removes it.

    If your Word build does show the repair prompt for the file you attached, please reopen with the Word version. We couldn't download the attachment, so we built our own repro.

  2. kklimuk commented on Nov 6, 2026

    @kklimuk
    Owner

    @michaelgasser thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions