Skip to content

[P2][test] MemoryGuard's 512 MB floor is hardcoded, so the memory-truncation path cannot be tested #540

Closed

Description

@EVWorth

What

MemoryGuard::check in src-tauri/crates/mas-core/src/query/executor.rs compares against a literal:

if available_mb < 512 {
    self.triggered = true;

execute builds the guard itself (let mut mem_guard = MemoryGuard::new();), so there is no way for a test to choose the floor. Provoking the real one means starving the machine of RAM, which no test should do.

Why it matters

The consequence showed up while fixing #413. When the guard trips, the fetch loop breaks and a block after the loop pushes the partial result with TruncationReason::MemoryGuard. That block is the only thing that produces a memory-truncated result, and it is not exercised by any test.

Everything around it is covered — truncation_for picks the reason, truncationMessage renders it, the banner tests assert both variants, and integration tests confirm the RowLimit reason survives a real round trip. The block that joins them up is not.

Suggested fix

Give the guard an injectable floor and default it to today's value:

impl MemoryGuard {
    fn new() -> Self { Self::with_floor_mb(512) }
    fn with_floor_mb(floor_mb: u64) -> Self { ... }
}

Then let execute take one (or take a floor), so an integration test can pass a floor of u64::MAX — always tripping — and assert that a multi-row SELECT comes back with rows_truncated == true and truncation_reason == Some(MemoryGuard). That exercises the real control flow rather than the pieces.

While there, 512 deserves a named constant either way.

Related, and deliberately not folded in

The guard's break may leave the statement running server-side. The timeout path a few lines up explicitly does drop(stream) then KILL QUERY, with a comment saying that abandoning the stream would leave the statement running. The memory path breaks out and does neither.

If that reasoning holds for timeouts it should hold here. I have not verified what sqlx does with a fetch_many stream dropped mid-result, and could not, for the same reason this issue exists — the guard cannot be triggered on demand. Flagging it as a question rather than asserting it is a bug. An injectable floor would make it answerable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/resultskind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions