Skip to content

extradoc: fix insertTable footprint undercount corrupting downstream edits - #76

Open
cassus wants to merge 1 commit into
think41:mainfrom
cassus:fix/insert-table-footprint
Open

extradoc: fix insertTable footprint undercount corrupting downstream edits#76
cassus wants to merge 1 commit into
think41:mainfrom
cassus:fix/insert-table-footprint

Conversation

@cassus

@cassus cassus commented Jul 22, 2026

Copy link
Copy Markdown

Closes #74.

Context & disclosure. I hit this bug personally while using reconcile_v3
in SUGGEST mode, and I've personally verified that this fix resolves it on a
real document. That said, the investigation, the fix, and most of this write-up
are largely AI-generated (Claude Opus) — I found the bug and confirmed the fix,
but the prose and code are largely AI-authored, so please weight the detail
accordingly.

This surfaced specifically through SUGGEST mode, which isn't generally
available yet and whose main PR hasn't landed — so it's completely fine if you'd
rather not merge this now. I'm opening it mainly to share the finding upstream
so anyone who hits the same thing can benefit, merged or not. I also haven't
tested whether the same bug (or fix) manifests in direct edits without
SUGGEST mode.

This project has been really useful to me and I'd like to give back: if you want
more human attention, deeper testing, or changes to make this mergeable, I'm
happy to engage personally and put in the work — just say the word.

What

_batch_insert_size_from_reqs (reconcile_v3/lower.py) undercounted the
footprint of a body insertTable by one \n, returning the bare table
skeleton 1 + rows*(1+cols*2) instead of 3 + rows*(1+cols*2). That value
feeds post_insert_shift, so every matched-paragraph update op downstream of
an inserted table (in the same batch) was shifted one char early — corrupting
in-paragraph edits (text landing mid-word or past the wrong \n).

The corrected 3 + rows*(1+cols*2) matches the sibling accounting in
_final_doc_size_from_reqs (2 + rows*(1+cols*2) + 1), which was already
correct; the two functions had silently disagreed by exactly the missing
newline. See #74 for the full root-cause, the real-API probe, and why the
offline mock hid the bug.

Changes

  • reconcile_v3/lower.py — footprint corrected to 3 + rows*(1+cols*2).
  • mock/table_ops.py::handle_insert_table — emit the trailing carrier
    paragraph only when nothing (or another table) follows, so the offline
    oracle models the real span+1 instead of masking the bug.
  • tests/reconcile_v3/test_story_content_update_bug.py — toy simulator
    updated to the real footprint; exercises the regression.

Verification

  • Full unit suite green (701 passed locally).
  • Real-API SUGGEST push of an 8-amendment document: 227/227 paragraphs accept
    to exact desired text, in order (was 7/227 garbled before the fix).

…edits

_batch_insert_size_from_reqs undercounted an insertTable's footprint by one
newline: it returned the bare table span 1 + rows*(1+cols*2) instead of
span + 1. That value feeds post_insert_shift for matched-element updates, so
every update op downstream of an inserted table was shifted one char early,
garbling in-paragraph edits (append landing past the paragraph \n, mid-word
drift).

A controlled real-API probe confirms an insertTable shifts following content
by exactly one \n around the table span — the pre-split newline mid-document
or the trailing carrier at end-of-segment, never both. The correct footprint
is 3 + rows*(1+cols*2), matching _final_doc_size_from_reqs.

The offline mock hid the bug because mock/table_ops emitted both newlines; it
now adds the carrier only when nothing (or another table) follows, so the
oracle models the real span+1. Toy simulator in the story-content test
updated to match.

Verified: full suite green; a real SUGGEST push of an 8-amendment document
now accepts 227/227 paragraphs in order (was 7/227 before the fix).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

insertTable footprint undercount corrupts downstream paragraph edits (reconcile_v3)

1 participant