← Back to Pull requests

feat(engine): decode only the columns a query reads, after the gates (P53) #278

Closed
unknown closed this pull request without merging on Nov 22, 2026 17:56 UTC
View on GitHub
unknown unknown commented on Nov 21, 2026 09:33 UTC
Author

What and why

Plan item P53 (docs/V1_PLAN.md). Closes #247. register_parquet_many decoded every column of every object into a MemTable before sql() planned or gated the query. So a query that the plan gate or the count-column check refused had already decoded the whole dataset into Arrow memory, which is not zeroized, and an accepted query decoded columns it never read. A schema mismatch between objects also came out of MemTable::try_new as QueryError::Execution, a 400 that blamed the caller's SQL for a storage fault.

  • Registration reads footers only. register_parquet_many and register_parquet_declared keep their signatures and register a small TableProvider, ParquetTable, instead of a MemTable. It parses each object's footer from its wiped_copy buffer, without the column statistics (their minimum and maximum are values from the data), and keeps the buffer to decode from. Objects whose columns differ (names, types or nullability, in order) are refused as QueryError::Parquet(ParquetStage::Schema): 502, never 400. The declared schema and row cap (ADR 0012) and the row limit are still checked at registration, from the footers. The query service then zeroizes its own decrypted copies, since the scope keeps its own until it drops.

  • Decoding happens in the scan. ParquetTable::scan decodes, from every object, only the projected root columns (ParquetRecordBatchReaderBuilder::with_projection(ProjectionMask::roots(..))) into a MemorySourceConfig plan that is dropped with the query. DataFusion calls scan while it builds the physical plan from the final logical plan, which sql() does only after the read-only check, the plan allowlist, the count-column check and the runtime-failure check. So a refused query decodes nothing, and the projection is that of the plan that runs, after any rewrite (P58). The engine copies no plaintext into non-zeroizing memory beyond the decoded Arrow arrays.

  • Decode limits against the projected footers. Before a scan decodes, the rows and the uncompressed bytes the footers report for its columns, summed over the query's scans, must fit QUERY_MAX_DECODED_ROWS and QUERY_MAX_DECODED_MIB. Each sql() call carries its own DecodeBudget in its session config. Decoded rows are counted again against the declared row cap and each footer's count.

  • Errors keep their meaning. A refusal or failure inside a scan crosses DataFusion's planner as a typed external error (ScanFault) and comes back as QueryError::Parquet, LimitExceeded or DeclarationMismatch, never QueryError::Execution (400). map_query_error only gains a comment.

  • Docs. docs/ARCHITECTURE.md: the query diagram; "QueryScope memory hygiene", which now says decryption stays whole-object because each object is one HPKE envelope, so projection reduces decode work, not decrypt work; "Resource limits"; "The snapshot as written"; the research diagram. docs/THREAT_MODEL.md: the resource-limit residual's wording on decode limits, and "Unzeroized working memory" now names the Parquet decoder's internal buffers. ADR 0013's decode rows and gated-mode sentence; docs/PROJECT_SCOPE.md; the QueryLimits docs; backend/.env.example; CHANGELOG.md (Security).
  • Changes to existing behaviour: objects of one snapshot whose columns differ answer 502 instead of 400. A query over a few columns of a dataset whose whole decoded size passes QUERY_MAX_DECODED_MIB now runs, while a query that reads its table twice (a self-join) counts it twice. A byte-limit refusal now comes when the query runs, not at registration. ExecutionStage::Prepare is gone (after the read-only check, sql() builds the DataFrame itself, as execute_logical_plan did for a query), and ParquetStage gains Schema.

    For reviewers:

  • The budget sums over scans. The issue asks for the caps against the projected columns. Decoding now happens per scan rather than once per table, so without a sum a query naming the table N times would decode it N times, outside the memory pool and the time limit. A gated query has one scan (the plan allowlist), so nothing changes for it.

  • Eager decode in scan, as the issue specifies, not batches streamed from execute. Each scan's decoded columns live as long as the query's plan, as the MemTable held the whole table before.

  • EXPLAIN in ungated mode decodes. It builds the physical plan, so its scans decode, within the budget. A scan failure there shows up as a physical_plan_error row holding the fault's fixed message, not as an error. Gated mode refuses EXPLAIN at the plan gate.

  • Decoder buffers. parquet-rs decompresses compressed pages into its own buffers, which are not zeroized. That was true before this change too; the residual did not name them, and now does.

  • ADR 0013 is edited, not superseded. It is still proposed, and its "where it is checked" rows and its gated-mode sentence would otherwise be wrong: the decode limits now depend on the dataset and on which of its columns the SQL reads, never on its rows.

  • Branch. main is merged in (a80f815, whose tree equals main's), not rebased. The branch started from #243's commits before it merged, which main now carries.

  • P73 records latency and peak memory before and after. The engine query benchmark does not exist yet (docs/BENCHMARKS.md, "Still to come"), so no numbers are recorded here. In the wide-table test, the two-column aggregate reads 204 KB of the 4.3 MB its footers report.

  • P78's refusal checklist has no issue yet, so nothing is ticked.

  • Code owners. quackxide-engine/src/, platform-api/src/, docs/THREAT_MODEL.md and docs/adr/ are owned; AxolDad is an owner of all four.
  • How it was tested

    New tests:

  • quackxide-engine/tests/decode.rs. Its seam is a copy of a dataset with column chunks overwritten and its footer intact, so decoding an overwritten chunk fails:

  • - a_query_the_gates_refuse_decodes_no_column: over a copy with every chunk overwritten, row egress and a join (plan gate), a missing n and MAX(age) AS n (count-column check), a cast that can fail (ADR 0011) and SET each get their own refusal, so nothing was decoded. An accepted query that reads columns fails to decode them, and COUNT(*) AS n, which reads none, answers.
    - a_two_column_aggregate_on_the_wide_table_decodes_only_those_columns: on synth-data's wide table (23 columns, 20,000 rows), an aggregate over region and i00 matches the intact table over a copy whose other 21 columns are overwritten, and reading any other column fails. With max_decoded_bytes at exactly those two columns' footer bytes the query passes; one byte less is refused before decoding.
    - a_corrupt_data_page_is_a_parquet_failure_not_the_callers_sql: a valid footer and corrupt data pages in age (its dictionary page intact) fail as QueryError::Parquet, gated and ungated; queries over the other columns answer.
  • quackxide-engine unit tests:

  • - every_scan_of_a_query_counts_toward_the_decode_limits: a self-join is refused one row or one byte under twice the table, the single scan runs twice on one scope, and both scans fit at exactly twice;
    - objects_with_unlike_columns_are_refused_as_a_parquet_failure: a renamed column, a nullability change and an extra column;
    - the_table_formats_and_keeps_no_values_from_the_data: the table's Debug and its parsed footer hold no value from the data, and the footer has no column statistics;
    - dropping_the_scope_releases_its_tables: after a query, the table, with the engine's copy it holds (zeroized on drop, by type), is released with the scope;
    - decode_limits_refuse_a_compressible_dataset_from_its_footer (P52's) now expects the byte refusal from the query, where that check moved.
  • platform-api/tests/query_api.rs: a_stored_object_with_a_corrupt_data_page_is_502 (in both modes; intact columns still answer, and a gate refusal is still 422) and a_snapshot_whose_objects_have_unlike_columns_is_502.
  • tests/bypass.rs, tests/disclosure.rs, tests/engine_query.rs, decrypted_objects_zeroize_on_drop and decryption_failure_midway_fails_closed_and_releases_the_slot pass unchanged, as do P52's limit tests.

    Checklist

  • scripts/check.sh passes locally (its secret-scan step was skipped: gitleaks is not installed locally)

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs (no new kind or outcome: these keep engine.query "denied" and "failed")

  • Fails closed on missing configuration, key material, or attestation

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md): test data is generated in the tests

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made (none was; ADR 0013's decode rows are updated)
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: abendrothj Review duration: 1943m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #278"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%