Skip to content

get_events: filter rows by column value and project columns - #1501

Merged
neuromechanist merged 4 commits into
devfrom
feature/issue-1500-get-events-filter
Sep 24, 2026
Merged

neuromechanist merged 4 commits into
devfrom
feature/issue-1500-get-events-filter

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1500.

What changed

get_events gains two optional inputs and one output field, so a model can ask for the events it needs instead of reading every column of every event.

  • where: column name to allowed values, for example {"event_type": ["face", "scrambled_face"]}. A row is kept when every named column holds, compared as a string, one of the values listed; a null never matches. total_count and truncated count the rows kept.
  • columns: the columns to return. onset_s and sample_index always come back, so a projected row may now omit store_path and group_name; the output row schema says so (eventRowOutputSchema), while the parquet read and the cache still validate every row against the full eventRowSchema.
  • columns_summary, on every answer: each column except the two times, with its distinct and null counts, and its values when there are at most 50, each at most 100 characters. It is computed before where, so a filter that keeps nothing still says what it could have asked for.
  • A where or columns name the recording's events do not have is refused with the columns they do have, never answered with an empty list.
  • The tool description tells a caller to look at columns_summary with limit: 1 first, then narrow.

Filtering runs on the rows already read and cached, so a filtered call after an unfiltered one reads nothing new.

Why

The chat assistant reads a tool result into its context. For ERP CORE (nm000132), one N170 recording is 640 events and 220,341 bytes of JSON. An ERP image of faces against scrambled faces needs 160 of those rows and three columns, about 14 KB. #1499 made the file readable; this makes the answer usable.

Tests

  • backend/test/mcp-schema-parity.test.ts: accept and reject cases at each new bound, for both zod copies (129 pass).
  • backend/test/mcp-recording-tools.test.ts: against the real nm000329 fixture parquet, whose first store is 36 left_hand and 36 right_hand events, so every count is exact. Covers paging a filtered set, string comparison of a number, AND across columns with its note, nulls, projection, refusals, the summary's pre-filter view, the cache, the events.tsv fallback, and the summary's bounds at and past each limit.
  • 13 single-line mutations of the new guards, each killed by a test.
  • bun run typecheck, bun run lint, and the full bun test (7540 pass, 223 skip, 0 fail).
  • After the dev deploy: nm000132's N170 recording filtered to faces and scrambled faces answers 160 rows (checked against mcp-test once staging has a dataset with event types; nm000132 itself reaches production with the next release).

Adds the where and columns inputs and the columns_summary output to the
wire contract and its zod 4 mirror (#1500). A returned row may now omit
store_path and group_name when columns projects them away; onset_s and
sample_index stay required.

Tested: bun test backend/test/mcp-schema-parity.test.ts (129 pass), with
accept and reject cases at each new bound.
where keeps rows whose named columns hold a listed value, compared as
strings, and total_count and truncated count the rows kept. columns
returns onset_s, sample_index and the columns named. columns_summary,
computed before where, lists each column's values so a caller can build
a filter from one small call. A column the recording lacks is refused
with the columns it has. Closes #1500.

Tested: bun test on the four MCP suites (229 pass) and the contract
unit test (75 pass); 13 single-line mutations of the new guards, each
killed by a test.
@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@PR1501

Version: 0.10.6-PR1501.cf26bf2
Commit: cf26bf2


🤖 Updated on each push.

columns_summary leaves out store_path and group_name, which the request
already names; where and columns still accept them. The unknown-column
refusal now runs before the summary, so a refused call does not pay for a
pass over every value. The descriptions say values are listed only for a
column with few. Adds tests for where on a group with no events (the
before > 0 guard) and for filtering on the store and group. Review
findings on #1501.

Tested: bun test on the four MCP suites (231 pass); removing the before > 0
guard, or summarizing the store and group again, each fails a test.
Section 5.4 lists where, columns and columns_summary, and notes the
row-group read #1498 added for files over the whole-file bounds.

Tested: docs only.
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review response

Two Sonnet reviews: code and error handling, and tests with documentation.

Code and error handling

  • The summary was computed before the refusal. A request about to be refused paid for a pass over every value. The unknown-column check now runs first; it needs only the column names (2d25c97).
  • The summary runs on every call, including cache hits. Kept as it is, on purpose. The summary depends on the group the call resolves, and the cache entry is per store, so caching it would need a summary per group in every entry and a schema bump. The pass is linear in the recording's cells, a few thousand for a typical recording. At the 100,000-row ceiling it is one pass beside the read the same call already makes.
  • A BigInt in a passthrough column would crash JSON.stringify. Not reachable with NEMAR's files, so no change. events_schema in scripts/zarr/generate_zarr.py (line 3586) writes every column beyond the fixed ones as a dictionary-encoded string. The only INT64 is sample_index, which toSafeSampleIndex already converts. A future producer that wrote an integer extra column would already break the unprojected answer and the cache write, not only columns, so the fix belongs with that producer change.

Tests and documentation

  • The before > 0 guard on the where note was untested. A new test sends where against the declared group with no events; removing the guard now fails it.
  • columns_summary listed store_path and group_name. They are the store and group the request names, so the summary leaves them out. where and columns still accept them, and a test shows both. Dropping the exclusion fails the summary test.
  • The descriptions overstated the summary. They said "every column and its values"; they now say values are listed when a column has few. This covers the tool description, the where note, the contract JSDoc and the zod 4 description.
  • .context/mcp-server-design.md section 5.4 was stale. It now lists the three new fields, and notes the row-group read get_events refuses ERP CORE: the row cap applies to the whole file #1498 added (cf26bf2).

Gates: the four MCP suites pass (231 tests), plus typecheck and biome.

This branch was previously deployed

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