Skip to content

fix(grid): say when memory, not the row limit, cut the results short - #541

Merged
EVWorth merged 1 commit into
mainfrom
fix/grid-truncation-reason
Sep 5, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/grid-truncation-reason

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Closes #413.

The bug

Both reasons a result set can come back short set the same boolean, so the banner gave the same advice either way:

Results truncated to 10,000 rows. Add a LIMIT clause to fetch fewer rows.

When the memory guard stopped the fetch, that points at the wrong lever. Someone already running LIMIT 10000 reads it, concludes the limit is binding, and raises it — asking for more of the resource that had just run out. Nothing in the UI mentions memory at all.

The fix

QueryResult carries truncation_reason: Option<TruncationReason> (row_limit | memory_guard), and rows_truncated is derived from it at the single place a truncated result is built, so the flag and the reason cannot drift apart.

The banner text moves into truncationMessage, which names the cause and the lever that actually helps — for memory, a narrower projection or a WHERE clause, and explicitly not a larger LIMIT.

An absent reason falls back to stating the row count and claiming nothing about why. A result from a backend predating the field shouldn't be guessed at.

Derivation is now truncation_for, which prefers memory when both apply. In the streaming path the guard cannot in fact be the answer — tripping it breaks out of the fetch loop, so the statement-complete marker never arrives and that case is handled after the loop. The branch is kept anyway so both sites derive the reason identically, and a change to the control flow cannot quietly restore the wrong advice.

Verified

  • 5 unit tests on truncation_for, including memory winning over a simultaneously-reached row limit
  • 2 integration tests against MySQL 8, asserting the reason survives the round trip: RowLimit when the limit is hit, None when it is not
  • 4 unit tests on truncationMessage
  • 2 banner tests, both of which fail against the previous copy — verified by reverting the span and re-running

Full local run: 1697 unit, 297 browser, 58 Rust lib, clippy/tsc/dprint/eslint clean.

Not verified

The post-loop MemoryGuard block firing under real memory pressure. The guard's 512 MB floor is hardcoded and execute constructs the guard itself, so there is no way to provoke it without starving the machine. Every piece it depends on is covered; the block that joins them up is not.

Filed as #540, which proposes an injectable floor. That issue also carries a related question I could not answer for the same reason: the timeout path deliberately kills the server-side statement before returning, and the memory path just stops reading — flagged as a question, not asserted as a bug.

🤖 Generated with Claude Code

Closes #413.

Both reasons a result set can come back short set the same boolean, so the
banner gave the same advice either way:

  Results truncated to 10,000 rows. Add a LIMIT clause to fetch fewer rows.

When the memory guard was what stopped the fetch, that is wrong advice
pointed at the wrong lever. Someone already running LIMIT 10000 reads it,
concludes the limit is binding, and raises it — asking for more of the
resource that had just run out. Nothing in the UI mentions memory.

QueryResult now carries truncation_reason: Option<TruncationReason>, and
rows_truncated is derived from it at the single place a truncated result is
built, so the flag and the reason cannot drift apart. The banner text moves
to truncationMessage, which names memory or the row limit, and says which
lever actually helps: for memory, a narrower projection or a WHERE clause,
explicitly not a larger LIMIT.

An absent reason falls back to stating the row count and claiming nothing
about why — a result from an older backend should not be guessed at.

The derivation is now truncation_for, which prefers memory when both apply.
In the streaming path the guard cannot in fact be the answer: tripping it
breaks out of the fetch loop, so the statement-complete marker never arrives
and that case is handled after the loop. The branch is kept anyway so both
sites derive the reason identically and a change to the control flow cannot
quietly restore the wrong advice.

Verified:

- five unit tests on truncation_for, including memory winning over a
  simultaneously-reached row limit
- two integration tests against MySQL 8, asserting the reason survives the
  round trip: RowLimit when the limit is hit, None when it is not
- four unit tests on truncationMessage, and two banner tests, both of which
  fail against the previous copy

Not verified: the post-loop MemoryGuard block firing under real memory
pressure. The guard's 512 MB floor is hardcoded and cannot be injected, so
there is no way to provoke it in a test without starving the machine. Every
piece it depends on is covered; the block itself is not. Follow-up filed.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit 4518ee6 into main Sep 5, 2026
10 checks passed
@EVWorth
EVWorth deleted the fix/grid-truncation-reason branch September 5, 2026 15:41
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.

[P1] [bug] Truncation banner blames LIMIT when MemoryGuard triggered — misleading

1 participant