Repository navigation
feat: Do not execute canister messages nor queries while cooling down - #11495
Conversation
While the subnet is cooling down the scheduler only drains its subnet queues: it executes no canister messages, no `Heartbeat` and no `GlobalTimer` tasks; and it inducts no messages on the same subnet (which is equivalent to routing them through the loopback stream, something a cooling down subnet does not do). Draining the subnet queues is what allows the calls the subnet has already accepted to be responded to. Rounds with skipped canister execution are counted in the new `round_skipped_canister_execution_due_to_cooling_down` metric. The query handler rejects all query calls with `ErrorCode::SubnetCoolingDown` (a `SysTransient` reject code), the ones addressed to the management canister included: the state a query would be evaluated against is frozen anyway. System queries, i.e. the `transform` functions of in-flight HTTP outcalls, are still executed, so that the outcalls the subnet has already made can be responded to while it drains its subnet queues. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Cooling-down query rejections currently bypass the query-handling metrics.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Prevents user queries and canister execution while a subnet cools down, while allowing subnet queues and system queries to drain outstanding work.
Changes:
- Skips canister execution and records skipped rounds.
- Rejects user queries with
SubnetCoolingDown. - Adds cooling-down test helpers and coverage.
File summaries
| File | Description |
|---|---|
rs/test_utilities/execution_environment/src/lib.rs |
Adds a cooling-down test helper. |
rs/replicated_state/src/metadata_state.rs |
Documents cooling-down behavior. |
rs/execution_environment/src/scheduler/tests.rs |
Tests scheduler behavior during cooldown. |
rs/execution_environment/src/scheduler/test_utilities.rs |
Adds scheduler test support. |
rs/execution_environment/src/scheduler/scheduler_metrics.rs |
Adds the skipped-round counter. |
rs/execution_environment/src/scheduler.rs |
Skips canister execution during cooldown. |
rs/execution_environment/src/query_handler/tests.rs |
Tests query rejection and system queries. |
rs/execution_environment/src/query_handler.rs |
Rejects user queries during cooldown. |
rs/execution_environment/src/execution_environment/tests.rs |
Uses the shared cooldown helper. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Addresses the Copilot review comment: create the root `MeasurementScope` before the cooling down check, so that rejected query calls are observed by the `execution_query_*` metrics, exactly like all other rejected queries. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The no-loopback-induction guarantee lacks direct test coverage.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
rs/execution_environment/src/scheduler.rs:478
- The new scheduler test covers ingress execution and heartbeats, but it never places a subnet-local request in a canister output queue. Consequently, the newly promised no-loopback-induction behavior is untested; moving this check after
induct_messages_on_same_subnet()would leave the test passing while mutating both canisters' queues during cooldown. Add a local output request and assert that it remains in the sender's output queue and is not added to the receiver's input queue after the round.
- Files reviewed: 9/9 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Addresses the Copilot review comment: adds a scheduler test that has a canister produce a request to a subnet-local canister in a round that ends before the request is inducted, then asserts that a cooling down round retains the request in the sender's output queue rather than inducting it into the receiver's input queue -- and that it is inducted again once the subnet stops cooling down. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Replaces the `SchedulerTest` covering canister message and heartbeat execution with a `StateMachine` test, which exercises the whole production path from the `cooling_down` registry flag down: an HTTP outcall response is delivered while the subnet is cooling down, showing that the subnet message is executed and its response routed to the canister, while the canister neither executes that response nor a single heartbeat, and query calls are rejected. Adds a `StateMachine::set_cooling_down()` helper to that end. The `SchedulerTest` covering same-subnet induction stays as it is: it requires a round that ends between executing a message and inducting the messages it produced, which only `max_heap_delta_per_iteration` can bring about. Also drops the justifications from the cooling down comments; the claim that a cooling down subnet's canister queues are frozen was wrong anyway, as messages in them can still time out. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The change affects consensus-critical scheduler behavior and should receive final human review despite comprehensive tests.
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 0 new
- Review effort level: Balanced
A cooling down subnet executes no canister messages, so it produces no messages to induct on the same subnet either; and a request for a local canister cannot be in an output queue at the beginning of a cooling down round in the first place: in the preceding round it is either inducted on the same subnet or, if that round ended in between, routed into the loopback stream, which is exempt from the stream limits. So the skipped induction is a consequence of skipping canister execution, not a separate guarantee: state it as such and drop the test that covered it (and the `SchedulerTest` helper it needed). Also mentions the on-low-wasm-memory hook, which -- unlike `Heartbeat` and `GlobalTimer` -- is a persistent part of a canister's task queue and is thus left there, unexecuted, while the subnet is cooling down; and spells out why a cooling down subnet still executes system queries. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
✅ No security or compliance issues detected. Reviewed everything up to 6e872d3. Security OverviewDetected Code Changes
|
… it is merged into A subnet that is cooling down now also stops serving query calls (#11495), so the two steps of this test that queried a canister of `M` while it was cooling down can no longer do so: * Step 10 checked that `U1`'s `install_code` calls installed the universal canister module, which a query reveals because a canister without a module rejects every query. That check moves to step 17, where `R` serves the merged-in canisters and answers for them again. Step 10 now checks the rejection itself, as the counterpart to step 8's ingress rejection. * Step 11 read the iteration counters of both call loops to show they are stalled. `UT` is on `T` and is still read directly; for `US` on `M`, the number of rounds `M` skipped canister execution in stands in, which is the stronger statement: while it grows, `M` executes no canister message at all. Verified with `bazel test //rs/tests/message_routing:subnet_cooling_down_test_head_nns`, which passed in 1090s (the plain `subnet_cooling_down_test` target is tagged `manual`: it runs the mainnet NNS, which knows neither the `cooling_down` subnet record field nor the `MergeSubnets` proposal). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…wn (dfinity#11519) Adds `cooling_down` to the small set of `UpdateSubnetPayload` fields the engine controller canister may set, alongside `subnet_admins` and `is_halted`. The engine controller can thus let a cloud engine subnet quiesce -- drain its subnet queues and its streams while executing no canister messages and serving no queries (see dfinity#11495) -- before halting it. The scope check exists twice: once in the engine controller proxy (`ensure_only_allowed_fields_set`) and once as a defence-in-depth check in the registry (`ensure_engine_controller_payload_scope`). Both are widened, and their exhaustive destructuring of `UpdateSubnetPayload` keeps them from drifting. Every other field remains rejected for that caller, and the registry still requires the target subnet to be of type `CloudEngine`. The stale comment in `engine_controller.did`, which claimed only `subnet_id` and `subnet_admins` could be set, now names the actual surface. **Tests:** the registry's `engine_controller_cannot_set_cooling_down` becomes `engine_controller_can_set_cooling_down`, asserting the flag round-trips both ways on a `CloudEngine` subnet; the proxy gains `ensure_only_allowed_fields_set_accepts_cooling_down`, and its combined-fields test now sets all three allowed fields. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
While a subnet is cooling down it now stops executing regular canister messages
and stops serving query calls, so that all it still does is quiesce: drain its
subnet queues and its streams.
Execution: while the subnet is cooling down, the scheduler only drains its
subnet queues. It executes no canister messages and no canister tasks: neither
HeartbeatnorGlobalTimer-- these are not even enqueued, as the check breaksout of
inner_round()right beforeadd_heartbeat_and_global_timer_tasks()--nor the on-low-wasm-memory hook, which, being a persistent part of a canister's
task queue, is simply left there until the subnet stops cooling down. It follows
that a cooling down subnet also has no messages to induct on the same subnet.
Rounds with skipped canister execution are counted in the new
round_skipped_canister_execution_due_to_cooling_downmetric.Queries: the query handler rejects all query calls with
ErrorCode::SubnetCoolingDown(aSysTransientreject code), the ones addressedto the management canister included. System queries, i.e. the
transformfunctions of HTTP outcalls, are still executed, because subnet messages are still
executed by a cooling down subnet. Rejected query calls are observed by the
execution_query_*metrics, exactly like all other rejected queries.The test is a
StateMachinetest, i.e. it exercises the whole production pathfrom the
cooling_downregistry flag down: an HTTP outcall response is deliveredwhile the subnet is cooling down, showing that the subnet message is executed and
its response routed to the canister, while the canister neither executes that
response nor a single heartbeat, and query calls are rejected. To that end it adds
a
StateMachine::set_cooling_down()helper, which sets the flag in the subnet'sregistry record at a new registry version.
🤖 Generated with Claude Code