Skip to content

Read events.parquet by row group when over the cap - #1499

Merged
neuromechanist merged 4 commits into
devfrom
fix/issue-1498-get-events-row-groups
Sep 24, 2026
Merged

neuromechanist merged 4 commits into
devfrom
fix/issue-1498-get-events-row-groups

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Closes #1498. get_events refused every recording of a dataset whose events.parquet was over the whole-file cap, even when the request named one recording. nm000132 (ERP CORE), NEMAR's example dataset, is 2.4 MB but 153,722 rows, so every one of its 240 recordings was declined, each only a few hundred rows.

The converter writes the file sorted by store_path, and every row group carries min/max statistics for it (write_events_parquet in scripts/zarr/generate_zarr.py). So the row groups that can hold a recording are known from the footer alone. For a file over a cap, get_events now reads only those row groups and applies the same caps to them instead of the file.

Changes

  • storeRowGroupSpan (backend/src/mcp/tools/get-events.ts): the contiguous run of row groups whose store_path statistics can contain the store, with its row count and compressed bytes. It returns null when any row group lacks min_value/max_value (the deprecated min/max are ignored; older writers compared them signed). Comparison is in UTF-8 byte order, as parquet's.
  • Over a cap, the read passes rowStart/rowEnd for that run, and keeps and validates only the requested store's rows. On that path only the requested store is cached: the [] placeholders for other stores are written only after a whole-file read, since the other stores may continue into row groups that were not read.
  • Still declined, saying which: a file with no store_path statistics, and a recording whose own row groups are over a cap. The public URL remedy is unchanged.
  • The converter's writer names the dependency, so a change to its ordering knows what it affects.
  • The MCP's dataset id description names nm000132 (ERP CORE), NEMAR's example, instead of nm000329.
  • Fixtures from scripts/zarr/generate_mcp_test_fixture.py:
    • row-groups-events.parquet: 120,000 rows in three row groups, with one store's 20 events across a boundary.
    • no-stats-events.parquet: the same rows without statistics.
    • oversized-events.parquet: its rows moved under a store the index has, so the existing "declined" test now exercises the per-recording cap.

Testing

  • mcp-recording-tools.test.ts: 44 pass. The new cases cover:
    • a recording's exact rows read across two row groups, with every page read after the footer ending before the third row group;
    • no cache entry for neighboring stores, and a neighbor then served its own 79,990 rows;
    • a store the statistics place nowhere, which answers no rows with the note and reads no pages;
    • both refusals;
    • storeRowGroupSpan on the real footers, the UTF-8 byte order, and the deprecated statistics.
  • 10 single-line mutations of the new code each fail the suite: the old refusal, the row range dropped, placeholders on a store read, other stores' partial rows kept, a UTF-16 comparison, the span cap removed, deprecated statistics accepted, the span off by one row group either way, and the whole-file bound widened.
  • Full bun test: 7510 pass, 0 fail. bun run typecheck, Biome on the changed files.

Reaches the NEMAR assistant only through production (mcp.nemar.org), so it needs the next dev to main release.

A 120,000-row file in three row groups, sorted by store_path with
statistics, one store straddling a boundary; the same rows without
statistics; and the oversized file's rows moved under a store the index
knows, so reading by row group is over the cap too (#1498).

Tested: generated with scripts/zarr/generate_mcp_test_fixture.py; row
groups and statistics checked with pyarrow.
get_events refused every recording of a dataset whose events.parquet
was over the row cap: nm000132 (ERP CORE) is 2.4 MB but 153,722 rows.
It now reads only the row groups whose store_path statistics can hold
the recording asked for, applies the caps to those, and caches only
that recording (#1498). A file without statistics, or a recording whose
own row groups are over a cap, is still declined, saying which.

Tested: mcp-recording-tools.test.ts (44 pass), including the byte
ranges read; 10 single-line mutations each fail it; full bun test
(7510 pass, 0 fail), typecheck, biome.
NEMAR's example dataset is now ERP CORE; the dataset id description
every MCP tool carries names it instead of nm000329.

Tested: typecheck; mcp-recording-tools.test.ts passes.
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1499

Version: 0.10.6-PR1499.817cb40
Commit: 817cb40


🤖 Updated on each push.

Review of #1499: the rename left one {@link} naming readWholeEventsParquet.

Tested: comment only; bun run typecheck.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review response

One Sonnet review. One finding, fixed in the latest commit: a {@link readWholeEventsParquet} left by the rename now names readEventsParquet.

The review confirmed against hyparquet 1.30.0's own source that rowStart/rowEnd plan only the row groups they overlap and return rows in file order. It also confirmed:

  • a truncated min_value/max_value is still a valid bound under the parquet spec, so ignoring the exactness flags is right;
  • the converter's code-point sort equals UTF-8 byte order, so it matches compareUtf8;
  • the byte cap uses the compressed size that is actually fetched;
  • the row-group path can only ever cache the requested store.

Two mutations of its own (keeping other stores' rows, an off-by-one on the max bound) each failed the suite.

This branch was previously deployed

1 inactive deployment
npm — 817cb40f Deployed Sep 24, 2026 by neuromechanist via publish #2842
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