Skip to content

refactor!: one GraphQL row-cost model, typed errors, one executor - #341

Merged
patrickleet merged 2 commits into
v5from
refactor/v5-review-26a-query-cost
Nov 25, 2026
Merged

patrickleet merged 2 commits into
v5from
refactor/v5-review-26a-query-cost

Conversation

@patrickleet

Copy link
Copy Markdown
Collaborator

Task 26 stage A ([[tasks/v5-review-26]]): the query side. Stacked on #340. Live-delivery sharing is stage B.

What changed

  • Cost model (src/graphql/cost.rs, docs/graphql-query-cost.md):
    • A page costs limit × (1 + rows nested under one row), using each list's resolved limit. One object costs 1 + nested.
    • Checked per root field against max_rows before any SQL runs. Arithmetic saturates.
    • The engine and the CLI client compiler share the same functions.
    • One unit per knob: max_depth, max_fields, max_rows, page limits, list widths, timeout.
    • Regression test d8_explicit_limits_multiply_into_the_row_budget: 1000×1000 is refused, while 1000×199 (exactly 200,000) is admitted. The old fixed fan-out of 5 ignored limit.
  • Typed errors:
    • CompileError (TooDeep, TooManyRows, ListTooLong, InvalidResponseKey, InvalidFilter, UnsupportedOnCellStore, BadRequest, Internal) and ExecuteError (Timeout, Failed) replace substring classification.
    • Detail never reaches the client. compile_client_where returns Option.
  • One executor:
    • execute_plan is generic over a GraphqlBackend (begin_read, fetch, gateway_versions) and replaces the four arms. Plans are held in Arc.
    • Postgres sends BEGIN … READ ONLY; SET LOCAL statement_timeout as one message.
    • Postgres round trips per root field (log_statement=all): 4 → 3 without gateway, 5 → 3 with it.
    • Plain reads run as REPEATABLE READ READ ONLY.
  • Plan capture and smaller fixes:
    • GraphqlEngine::plan(..) with a typed PlanRecorder replaces the sentinel-error capture.
    • PROOF_TABLES is exported by the projection store, tested against both migration directories. SQLite now includes its own migration.
    • VersionError enum.
    • The manifest is borrowed at all 8 request-path sites.
    • The root_field metric label is the schema field, not the alias.
    • Golden fingerprints are replaced by rebuild-equality checks.
    • Dead accumulator methods are removed.

Decision to confirm

The default max_rows is 200,000. At 20,000 an existing test (sibling children + children_aggregate.nodes lists) was refused. At 200,000 the limit still refuses nested lists at the maximum page size (1,001,000) and two default-sized nested levels (1,010,100). It is one constant.

Breaking changes

  • The builder's max_complexity becomes max_fields; max_rows is new.
  • The manifest execution shape changed (ClientComplexityWeights is gone), so every schema fingerprint changes. In the CLI goldens only the schemaHash lines differ.
  • Renamed: client_application_surface_with_schema_roles → client_application_surface, surface_for_application_contract → surface_for_application.
  • Removed: graphql_sdl_from_schemas, core_sdl_for_catalog, and the plan-capture types.
  • Client-visible:
    • "query too complex" becomes "row budget exceeded".
    • Join-key failures are now INTERNAL.
    • Subscription compile errors no longer leak detail.
    • The metric label for aliased queries changes.

Tests

Run locally:

  • Workspace check (all features), no-default, each feature alone: OK.
  • cargo test --workspace --all-features with Postgres: passes (distributed lib 1,227).
  • Postgres GraphQL suites and tests/gateway-postgres/run.py (primary/standby): pass.
  • CLI with --include-ignored: 342 passed, 0 failed (rerun by me).
  • JS: 849 passed. e2e-celld: 31 passed. e2e-ui offline: pass.
  • wasm32 workers, game cells and the domain check: pass. Game server tests: pass.
  • New and changed tests 30×: 0 failures.

Not done

Row budget is the product of resolved page limits, checked per root
field against max_rows before SQL runs; engine and CLI share the cost
functions. CompileError/ExecuteError replace substring classification.
One execute_plan generic over the backend: Postgres opens the read-only
transaction and sets the timeout in one round trip (5 -> 3 per root
field). GraphqlEngine::plan replaces sentinel-error plan capture;
PROOF_TABLES comes from the projection store; manifests are borrowed on
request paths; the root_field metric label is the schema field.

BREAKING CHANGE: max_complexity becomes max_fields and max_rows
(default 200,000) is new; the manifest execution shape and every schema
fingerprint change; "query too complex" is now "row budget exceeded";
client_application_surface_with_schema_roles and
surface_for_application_contract are renamed; graphql_sdl_from_schemas
and core_sdl_for_catalog are removed.

Implements [[tasks/v5-review-26]]
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2183393-ce18-4770-b3b9-514454bba1df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@patrickleet
patrickleet changed the base branch from refactor/v5-review-25d-gateway-delivery to v5 November 25, 2026 00:25
@patrickleet
patrickleet merged commit 25648c2 into v5 Nov 25, 2026
27 checks passed
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