Skip to content

An XLSX header over two rows names each column from both rows - #308

Merged
zlareb1 merged 13 commits into
mainfrom
fix/extractor-xlsx-two-row-header
Nov 7, 2026
Merged

zlareb1 merged 13 commits into
mainfrom
fix/extractor-xlsx-two-row-header

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Related: #157

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

An XLSX header over two rows, a cell merged across columns grouping the names under it, names each column from both rows (2025 / H1, 2025 / H2); before, the second row of names was read as a row of data and the columns were 2025 and 2025 (2).

Why

The issue's extraction gate names merged spreadsheet headers. Scoring the reference extractor on a labelled workbook found that a header like Region | 2025 (merged over two columns) | Note, with H1 and H2 under 2025, reads as one header row: the columns are Region, 2025, 2025 (2), Note, typed mixed, and the first data row is Region, H1, H2, Note. A dataset built from it has wrong column names, mixed types where the values are numbers, and a spurious row in every aggregate.

Design

  • In xlsxfile, after the sheet's merges are spread: when a range merged across columns sits in the header row alone, and the row right under it holds text cells under that range and, everywhere else, nothing or only cells merged down from the header row (Region over A1:A2), the header is both rows. Any other cell in that row, text or not, makes it data. Each column's name is the first row's cell and the second's joined by /; a cell merged down both rows (Region, Note) or with nothing under it is its own name, and one with nothing above (a range merged for its formatting alone) takes the second row's (_named_over). A joined name is each cell's name as _names reads it (tabular.read_name, folded), so a cell padded with spaces reads as its words, and a cell whose name reads as nothing gives way to the other row's; text past what a name reads is counted as cut (Rows.cut_names, which _names adds to its count); it keeps at most 1,001 characters of each cell, what a name reads (tabular.NAME_READ_CHARS, now the one bound _names and the join share, more than the 500 a column's name holds, so a cut is still counted): a cell of a megabyte merged over thousands of columns would otherwise be copied into each of their names, a cost the artifact's cell budget does not see.
  • tabular.Rows gains header_rows (1 by default), which becomes the table's header_rows (2 here; the contract already allows any count), and the span of a header-only block and of a table with no rows under its header. The data rows start under the second row; the table's locator still starts at the header's first row.
  • Each distinct header cell is read once, as _names reads it once, however many columns a merge spreads it over (the join caches read_name by cell), and a pair of cells over many columns shares one joined name, which _names reads once too. A range the cell budget left unspread groups nothing (_spread now returns the ranges it skipped, as they were read, rather than counting them); one merged with no value does, and so does one whose last cell holds a value of its own (a hidden cell's kept content).
  • Which columns the header row's merges cover is found in one pass over the merges and one over the columns (_covered), so a sheet of a million merges in its header row costs no more than reading them, as MAX_MERGES promises.
  • The guard keeps every other sheet as it was, but for the ambiguous text row above: a merge over columns with numbers or other values under it (a total row, data right under a merged header) is no second header row, and a range merged down rows is no group.
  • xlsxfile.PARSER_VERSION becomes 2.

A title merged over the whole first row above a header row (Sales 2025 over Region | Q1) meets the rule too, and its text heads each name (Sales 2025 / Region). So does a first data row of text alone under merges that cover every column it fills (Name over A:B, Contact over C:D, then Alice | Smith | [email protected] | Paris): nothing in the sheet tells it from sub-headers under the groups, so it reads as the second header row, as the docs say, and the columns keep those names until the sheet is changed. Telling them apart would take reading the rows below for a pattern, a guess either way. That keeps the title's text in the table instead of a first data row of names; reading it as a sheet title apart from the header would be a further rule, left out here.

Alternatives: a two-row header whenever the second row is all text (a data row of names reads as a header); asking the caller to say how many header rows a sheet has (no option for it exists, and every caller would have to know its sheets).

Scope and risk

Touches the reference extractor's XLSX reader and the shared tabular.Rows; CSV, Parquet and PDF tables keep one header row. No server, wire or schema change. A workbook ingested earlier keeps its artifact and dataset until extracted again. Extracted again, a workbook with a two-row header gets new column names, so an approval of its dataset does not carry over (an approval carries only to a revision with the same column names in the same order): its dataset is inferred again, and while it needs clarification knowledge.query answers 422 until a writer approves it again.

Compatibility, rollout and rollback

  • Wire: none; tables[].header_rows was already in the contract and is now 2 for such a header.
  • Operator steps: none; a writer re-approves the dataset of a workbook whose header this change renames, once it is extracted again.
  • Rollback: reverting leaves artifacts whose tables have two header rows, which the server reads as any.

Tests

  • tests/unit/test_document_extraction_tables.py: the two-row header reads as Region, 2025 / H1, 2025 / H2, Note (typed string, number, number, string), one data row, header_rows 2, the table cited from row 1 and its first row block from row 3; a title merged over the header row heads each name; the existing workbook whose merged header has data under it still reads one header row, and so does a sheet whose row under a merged header is data with a text or a number in a column outside the merge (Alice or 17 in A2); a sheet of a two-row header and no rows cites rows 1 to 2 in its table and its header block; a column with nothing under its name beside a two-row header keeps its name; a range merged with no value takes the names under it; a header cell padded with a thousand spaces over a second header row reads as Revenue / H1 with nothing counted as cut, one with text after the padding is cut and counted, and one of padding then text gives way to the names under it, counted as cut; _covered marks the columns a million spans cover in one pass; a merged cell over 50 columns is read once; a merge the cell budget left unspread groups no header, a narrow one and one past the last column alike, run through the real budget (a budget of six cells: the rows take five, the merge is read and is too big to spread; without the filter on the skipped ranges both cases fail); the second header row counts against the rows a table holds, as the docs say (with the cap at three rows, a two-row header keeps two of its three rows and counts the third, S rows 5-), since the row cap is applied while the sheet streams, before the header is known; a megabyte header cell merged over 200 columns over a second header row gives names cut to 500 characters and counted as cut, and a joined name holds at most 1,001 characters of either cell, what a name reads.
  • The full unit suite passes on the final head (27,700 passed; the four CSV sniff-timing cases fail as on main on this host), as do make format lint typecheck.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked: the guard against data under a merged header, the rows and locators, and a review at every push.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited. (Not applicable: no migration.)
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version. (Not applicable: no plugin file changes.)
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed. (Not applicable.)
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 13 commits November 6, 2026 23:46
A range merged across columns of the header row, over text cells in the
row under it, makes a header of both rows: each column is named from
both (2025 / H1), header_rows is 2, and the values start under it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…erged down

Outside the merged range, the second row may hold only cells merged down
from the first, so a data row of text is no header. A two-row header
with no rows under it cites both rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A cell of a megabyte merged over many columns was copied into each
joined name, past what the cell budget counts. Each side is cut to more
than a column name holds, so the cut is still reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…is counted

Which columns the header row's merges cover is found in time linear in
the merges and the columns. A joined name reads each cell as a name
does and records a cut, which the name count reports, and a side that
reads as nothing gives way to the other.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…nothing

The joined names read each distinct cell once, as the names do, so a
long cell merged over many columns costs one scan. A range the cell
budget did not spread names only its first column and no longer groups
the row under it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…oined cells are called cells

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… it returns

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…gainst the cap, as stated

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…header rows is tested

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/extractor-xlsx-two-row-header branch from 3d80f7e to 55e3bf4 Compare November 7, 2026 07:09
@zlareb1
zlareb1 merged commit 0a5e3af into main Nov 7, 2026
31 of 32 checks passed
@zlareb1
zlareb1 deleted the fix/extractor-xlsx-two-row-header branch November 7, 2026 07:14
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