Skip to content

linearize_children: dedup Line refs deterministically - #451

Open
stephane-additive wants to merge 1 commit into
aws-samples:masterfrom
additiveai:fix-linearize-children-nondet-order
Open

linearize_children: dedup Line refs deterministically#451
stephane-additive wants to merge 1 commit into
aws-samples:masterfrom
additiveai:fix-linearize-children-nondet-order

Conversation

@stephane-additive

Copy link
Copy Markdown

`linearize_children` uses:

```python
lines = set([w.line for w in words_in_elements])
```

`Line` doesn't override `hash`/`eq`, so this set is identity-hashed and iterates in `id()`-order — nondeterministic across processes, and even across repeated allocations in a single process once slots get recycled. Same Textract JSON can render as different markdown across runs, which breaks anything downstream that hashes the rendered text.

Fix: `list(dict.fromkeys(...))` — same dedup, first-occurrence order.

linearize_children uses:

    lines = set([w.line for w in words_in_elements])

Line doesn't override __hash__/__eq__, so this set is identity-hashed
and iterates in id()-order — nondeterministic across processes, and
even across repeated allocations in a single process once slots get
recycled. Same Textract JSON can render as different markdown across
runs, which breaks anything downstream that hashes the rendered text.

Replace the set(...) with list(dict.fromkeys(...)) — same dedup, but
iterates in first-occurrence order.
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.

1 participant