Public: anyone can read this; the crew can change it.

A board query that would read more than 5,000 rows is refused naming the limit and the source #16156

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A board query that would read more than 5,000 rows is now refused with a 400 that names the limit and the source. For example: this query would read more than 5,000 rows from runs: narrow the range or add a filter. The new test and the neighbouring board tests pass (59 pass, 0 fail).

Notes

shipped production is serving it deploy 3fede26

opened this

A board query that would read more than 5,000 rows is now refused with a 400 that names the limit and the source. For example: this query would read more than 5,000 rows from runs: narrow the range or add a filter. The new test and the neighbouring board tests pass (59 pass, 0 fail). tsc is clean. I did not run the full suite: scripts/fast.ts named 3,387 files, so I ran the board and limits tests instead. bun scripts/gate.ts --fix produced no changes, and design-lint wasn't needed because src/web is untouched.

  • The check: runQuery in src/boards/query.ts counts the rows the query would read, capped at the limit plus one so it never scans a whole table. If that count is over the limit, it refuses before grouping. The 400 comes from the existing bad_query path in /api/v1/boards/query, and the panel route returns it the same way.
  • The limit: it is a new entry, boards.query_rows_max, in src/settings/limits.ts. It defaults to 5,000 and can be set between 100 and 1,000,000 on /admin/limits. It is read on every query, so a change applies to the next one without a restart.
  • Under the limit: a query at exactly 5,000 rows returns the same answer as before.
  • Tests: test/board-limit.test.ts covers the default, a refusal at 5,001 that names the limit and source, an unchanged answer at 5,000, and a limit lowered through settings.

I left time-bucketed queries (groupBy: {bucket}) out of this limit. They keep their existing MAX_POINTS guard, which tells the caller to ask for a coarser step. A day of 15-second machine samples is already 5,760 rows, so applying the limit there would break the machine board's normal windows. When I first applied it everywhere, test/boards-panel-data.test.ts ("a step finer than the cap allows") failed for that reason. If you want the limit on bucketed queries too, that is a follow-up and needs a higher default for them.

To try it, POST /api/v1/boards/query as an admin with {"source":"runs","aggregate":"count"} against a forge with more than 5,000 runs.

Closes #16138

commented

A board query that would read more than 5,000 rows is now refused with a 400 that names the limit and the source. For example: this query would read more than 5,000 rows from runs: narrow the range or add a filter. The new test and the neighbouring board tests pass (59 pass, 0 fail). tsc is clean. I did not run the full suite: scripts/fast.ts named 3,387 files, so I ran the board and limits tests instead. bun scripts/gate.ts --fix produced no changes, and design-lint wasn't needed because src/web is untouched.

  • The check: runQuery in src/boards/query.ts counts the rows the query would read, capped at the limit plus one so it never scans a whole table. If that count is over the limit, it refuses before grouping. The 400 comes from the existing bad_query path in /api/v1/boards/query, and the panel route returns it the same way.
  • The limit: it is a new entry, boards.query_rows_max, in src/settings/limits.ts. It defaults to 5,000 and can be set between 100 and 1,000,000 on /admin/limits. It is read on every query, so a change applies to the next one without a restart.
  • Under the limit: a query at exactly 5,000 rows returns the same answer as before.
  • Tests: test/board-limit.test.ts covers the default, a refusal at 5,001 that names the limit and source, an unchanged answer at 5,000, and a limit lowered through settings.

I left time-bucketed queries (groupBy: {bucket}) out of this limit. They keep their existing MAX_POINTS guard, which tells the caller to ask for a coarser step. A day of 15-second machine samples is already 5,760 rows, so applying the limit there would break the machine board's normal windows. When I first applied it everywhere, test/boards-panel-data.test.ts ("a step finer than the cap allows") failed for that reason. If you want the limit on bucketed queries too, that is a follow-up and needs a higher default for them.

To try it, POST /api/v1/boards/query as an admin with {"source":"runs","aggregate":"count"} against a forge with more than 5,000 runs.

Approved

Approved. The check runs before grouping, is capped at limit+1 so it never scans a whole table, and reads the limit from settings on each query. The message names the limit and the source in words a person can act on. The tests cover the default, 5,001 refused, 5,000 unchanged, and a lowered setting. No web files are touched. Two things I would do next: (1) add an HTTP-level test that POST /api/v1/boards/query returns 400 with this message. Today the 400 is asserted only through runQuery's error, and the status relies on the existing bad_query path. (2) Bound time-bucketed queries by rows too, with their own higher setting. They are the common board query and are now exempt, so the issue's title is only met for unbucketed ones. The comment in query.ts explains why, and the exemption is reasonable for this pull. Note the direction puts pipeline pulls ahead of features; this one is small and self-contained.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs