Skip to content

Premerge-enabled inplace safety check failure on ILPA corpus #35

@stevenobiajulu

Description

@stevenobiajulu

Summary

When premergeRuns: true (now the default), the ILPA corpus comparison with reconstructionMode: 'inplace' fails the round-trip safety check (rejectText mismatch) and falls back to rebuild mode.

Reproduction

npx tsx -e "
import { compareDocuments } from './packages/docx-core/src/index.js';
import { readFile } from 'fs/promises';

const [orig, rev] = await Promise.all([
  readFile('tests/test_documents/redline/ILPA-Model-Limited-Partnership-Agreement-WOF_v2.docx'),
  readFile('tests/test_documents/redline/ILPA-Model-Limited-Parnership-Agreement-Deal-By-Deal_v1.docx'),
]);

const result = await compareDocuments(orig, rev, {
  engine: 'atomizer',
  reconstructionMode: 'inplace',
  // premergeRuns defaults to true
});

console.log(result.reconstructionModeUsed); // 'rebuild'
console.log(result.fallbackReason);         // 'round_trip_safety_check_failed'
"

What was ruled out

Likely root cause

The safety check failure occurs because inplace reconstruction produces incorrect output when operating on premerged run topology. Premerge changes atom boundaries (larger merged runs → different atoms), which causes the inplace modifier's run-splitting/placement logic to reconstruct differently, producing text that doesn't match the original on reject-all.

Investigation direction

  1. Run per-pass reject-text diagnostics to identify the exact paragraph/run where the mismatch occurs
  2. Trace through the inplace modifier's run-splitting/placement logic for that specific case
  3. The pipeline baseline extraction at line 496 is correct and should NOT be moved

Current workaround

Tests that need inplace mode for ILPA have been updated to expect rebuild fallback rather than passing premergeRuns: false.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions