Skip to content

feat(query-handler): return 503 on state-delegation mismatch in queries - #12064

Draft
pierugo-dfinity wants to merge 2 commits into
masterfrom
pierugo/query-handler/serve-503
Draft

pierugo-dfinity wants to merge 2 commits into
masterfrom
pierugo/query-handler/serve-503

Conversation

@pierugo-dfinity

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block approval of the query delegation-verification changes.

No open issues 🎉

What changed in this PR

This PR makes query execution verify NNS delegations against the certified state used to build each data certificate. Public query endpoints return HTTP 503 when verification fails, rather than serving an inconsistent certificate.

Changes:

  • Move delegation verification into the query handler and propagate verification failures to HTTP responses, logs, and metrics.
  • Adapt query interfaces, test runtimes, replay, and PocketIC to the delegation-reader API.
  • Add coverage for delegation consistency, certificate metadata, and HTTP 503 responses.
File Description
rs/​state_machine_tests/​src/​lib.rs Adapt delegated queries to use a reader with relaxed range checks.
rs/​replica_tests/​src/​lib.rs Update query inputs and error handling.
rs/​replica_tests/​Cargo.toml Add the logger dependency.
rs/​replica_tests/​BUILD.bazel Add the Bazel logger dependency.
rs/​replay/​src/​player.rs Update replay query inputs and failure messages.
rs/​pocket_ic_server/​src/​pocket_ic.rs Pass delegations without separate metadata.
rs/​interfaces/​src/​execution_environment.rs Define reader-based query inputs and a verification error variant.
rs/​interfaces/​Cargo.toml Add the delegation-reader dependency.
rs/​interfaces/​BUILD.bazel Add the Bazel delegation-reader dependency.
rs/​http_endpoints/​public/​tests/​test.rs Test HTTP 503 responses for delegation verification failures.
rs/​http_endpoints/​public/​src/​query.rs Select range checks and map verification failures to HTTP 503.
rs/​http_endpoints/​nns_delegation_reader/​test_utils/​BUILD.bazel Expose test utilities to execution-environment tests.
rs/​http_endpoints/​nns_delegation_reader/​src/​reader.rs Verify delegations before returning them with metadata.
rs/​http_endpoints/​nns_delegation_manager/​src/​lib.rs Re-export the delegation validation error type.
rs/​execution_environment/​src/​query_handler/​tests.rs Test matching, mismatched, and absent delegations.
rs/​execution_environment/​src/​query_handler.rs Verify delegations against the certificate’s exact certified state.
rs/​execution_environment/​Cargo.toml Add delegation test utilities.
rs/​execution_environment/​BUILD.bazel Add delegation utilities and state-manager mocks for tests.
Cargo.lock Record the added dependencies.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the changes to verify query delegations against the certified state.

No open issues 🎉

Review effort: Balanced

@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/query-handler/serve-503 branch from 87306c8 to 4a54480 Compare November 13, 2026 15:39
@pierugo-dfinity
pierugo-dfinity requested a balanced review from Copilot November 13, 2026 15:39
@pierugo-dfinity
pierugo-dfinity changed the base branch from master to pierugo/delegations/snapshot November 13, 2026 15:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the delegation-verification changes.

No open issues 🎉

Review effort: Balanced

Base automatically changed from pierugo/delegations/snapshot to master November 16, 2026 14:57
The query handler verifies the NNS delegation against the exact certified state the
data certificate is built from, and only embeds it if it is consistent. Otherwise the
query fails with `QueryExecutionError::DelegationInconsistentWithState`, which the HTTP
endpoint turns into a 503 so that clients retry once the replica has a fresh delegation.

`QueryExecutionInput` carries the `NNSDelegationSnapshot` and the `CanisterRangesCheck` to
apply, and `NNSDelegationSnapshot::get_delegation_with_metadata` (which did not verify the
delegation) is replaced by `NNSDelegationSnapshot::build_verified_with_metadata`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/query-handler/serve-503 branch from 4a54480 to da6a28d Compare November 16, 2026 15:12

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants