Skip to content

fix: run the outcall cycles migration regardless of subnet activity - #11219

Merged
mraszyk merged 1 commit into
masterfrom
mraszyk/migrate-outcalls-cycles-every-round
Aug 24, 2026
Merged

mraszyk merged 1 commit into
masterfrom
mraszyk/migrate-outcalls-cycles-every-round

Conversation

@mraszyk

@mraszyk mraszyk commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

The migration added in #10844, which brings the HTTPOutcalls / ECDSAOutcalls entries of SubnetMetrics::consumed_cycles_by_use_case up to the legacy scalar fields, was invoked from observe_consumed_cycles_with_use_case. That only fires when the subnet observes a subnet-level use case, and those are only observed on HTTP outcalls, threshold signature outcalls, canister deletion and cycles lost to dropped messages. A subnet that does none of these never runs the migration and its use-case entries stay stale indefinitely.

This is not hypothetical: on mainnet subnet
2fq7c-slacv-26cgz-vzbx2-2jrcs-5edph-i5s2j-tck77-c3rlz-iobzx-mqe, consumed_cycles_ecdsa_outcalls is 244_900_000_000_000 while the ECDSAOutcalls use-case entry is 228_370_000_000_000, a gap of 16_530_000_000_000 cycles. Its consumed_cycles_by_use_case_as_counters map is empty, which (since that map is incremented on the very same code path) shows that no subnet-level use case has been observed there since the counters were introduced in #9922, i.e. well before the migration was deployed.

The migration now runs from the scheduler's finish_round, which is documented as running unconditionally after each round and is also reached by the heap-delta early return and by checkpoint_round_with_no_execution. Running it once per round instead of per observation is equivalent, because the call sites bump the scalar field and the matching use-case entry by the same amount: max(entry, scalar) + delta == max(entry + delta, scalar + delta). It is also idempotent, so the extra invocations are harmless.

The migration added in #10844, which brings the HTTPOutcalls / ECDSAOutcalls
entries of SubnetMetrics::consumed_cycles_by_use_case up to the legacy scalar
fields, was invoked from observe_consumed_cycles_with_use_case. That only fires
when the subnet observes a subnet-level use case, and those are only observed on
HTTP outcalls, threshold signature outcalls, canister deletion and cycles lost
to dropped messages. A subnet that does none of these never runs the migration
and its use-case entries stay stale indefinitely.

This is not hypothetical: on mainnet subnet
2fq7c-slacv-26cgz-vzbx2-2jrcs-5edph-i5s2j-tck77-c3rlz-iobzx-mqe,
consumed_cycles_ecdsa_outcalls is 244_900_000_000_000 while the ECDSAOutcalls
use-case entry is 228_370_000_000_000, a gap of 16_530_000_000_000 cycles. Its
consumed_cycles_by_use_case_as_counters map is empty, which (since that map is
incremented on the very same code path) shows that no subnet-level use case has
been observed there since the counters were introduced in #9922, i.e. well
before the migration was deployed.

The migration now runs from the scheduler's finish_round, which is documented as
running unconditionally after each round and is also reached by the heap-delta
early return and by checkpoint_round_with_no_execution. Running it once per
round instead of per observation is equivalent, because the call sites bump the
scalar field and the matching use-case entry by the same amount:
max(entry, scalar) + delta == max(entry + delta, scalar + delta). It is also
idempotent, so the extra invocations are harmless.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions github-actions Bot added the fix label Aug 19, 2026
@mraszyk
mraszyk marked this pull request as ready for review August 19, 2026 18:26
@mraszyk
mraszyk requested a review from a team as a code owner August 19, 2026 18:26
@zeropath-ai

zeropath-ai Bot commented Aug 19, 2026

Copy link
Copy Markdown

✅ No security or compliance issues detected. Reviewed everything up to ab33d4a.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/execution_environment/src/scheduler.rs
    Backfill the HTTP/ECDSA outcall cycles from legacy scalar fields into use cases in finish_round()
Enhancement ► rs/execution_environment/src/scheduler/tests/metrics.rs
    Add test for migrating outcalls cycles into use cases on idle subnet
Enhancement ► rs/replicated_state/src/metadata_state.rs
    Make migrate_outcalls_cycles_to_use_cases public and remove inlined migration call from observe path; update comments
Enhancement ► rs/replicated_state/src/metadata_state/tests.rs
    Add tests for migrating outcalls scalar fields into use cases and related scenarios

@mraszyk
mraszyk added this pull request to the merge queue Aug 24, 2026
Merged via the queue into master with commit b834a9a Aug 24, 2026
43 checks passed
@mraszyk
mraszyk deleted the mraszyk/migrate-outcalls-cycles-every-round branch August 24, 2026 06:31
pull Bot pushed a commit to bit-cook/ic that referenced this pull request Sep 22, 2026
…finity#11202)

The cycles consumed by HTTP and ECDSA outcalls are tracked both in the
legacy scalar fields consumed_cycles_http_outcalls /
consumed_cycles_ecdsa_outcalls of SubnetMetrics and in the
consumed_cycles_by_use_case map, which a migration introduced in dfinity#10844
keeps in lockstep with those fields. dfinity#11219 fixed that migration to run
once per round from the scheduler's `finish_round`, i.e. regardless of
subnet activity, so the map entries can no longer go stale on a subnet
that performs no outcalls.
I could now successfully confirm that the migration completed on all
subnets with a DFINITY-owned node.

This switches all readers over to the map:

- get_consumed_cycles_http_outcalls / get_consumed_cycles_ecdsa_outcalls
now read the HTTPOutcalls / ECDSAOutcalls entries of
consumed_cycles_by_use_case, via a new helper that also backs the
existing Schnorr / VetKd / dropped messages getters.
- consumed_cycles_total and consumed_cycles_total_v28 add those entries
instead of the scalar fields.

The scalar fields are still observed and serialized, so that downgrading
to an earlier replica version keeps observing the correct totals; only
their reads are gone.

The fixtures that populate only the scalar fields
(`canonical_encoding_subnet_metrics`, the `state_manager` tree hash
fixture and `consumed_cycles_total_is_the_same_across_a_restart`) now
run the migration first, the way the scheduler does once per round. The
expected canonical encodings and state hashes are unchanged.

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants