Skip to content

feat(subnet-splitting): make destination orchestrators restart the replica - #11238

Merged
pierugo-dfinity merged 32 commits into
masterfrom
pierugo/subnet-splitting/orchestrator
Sep 22, 2026
Merged

pierugo-dfinity merged 32 commits into
masterfrom
pierugo/subnet-splitting/orchestrator

Conversation

@pierugo-dfinity

@pierugo-dfinity pierugo-dfinity commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

This PR implements changes to the orchestrator to support subnet splitting.

Today, the orchestrator tries to determine the latest CUP by looking at its local CUP's subnet ID. It contacts peers determined by this subnet's membership at the latest registry version and looks for a potential recovery (or genesis for a new subnet) CUP for this subnet, also at the latest registry version.

The proposed change are the following:

  • The orchestrator still looks at its local CUP subnet ID.
  • Before contacting peers or looking at the registry, first look inside the registry for a potential split that was scheduled between the local CUP's registry version and the latest version. If there is one, manually overwrite the subnet ID with the new expected one (source or destination).
  • If the subnet ID of our local CUP is different from the subnet ID of the latest CUP, restart the replica.

Note that, unlike @kpop-dfinity's original design, the proposed implementation does not change the existing behaviour during membership changes that are independent of a subnet split. In his approach, orchestrators would fetch & verify CUPs from the subnet ID they were part of at the latest registry version. Though simpler, this could negatively affect situations where nodes get moved from one subnet to the other without a split, since they would leave the subnet before being able to finish their work. It would also make recoveries harder.

Happy path

  • All orchestrators will detect the split as soon as the registry changes are in, meaning that already before the split actually triggers, source orchestrators will start fetching CUPs from the source subset of nodes and destination orchestrators from the complement.
  • Each of them also verify the received CUP according to the post-split membership's public key. This means that until the split is actually triggered, all destination orchestrators will reject received CUPs, since those served CUPs are still the original subnet's signed by the original public key. This can be a problem if there was an upgrade scheduled shortly before (see An upgrade was scheduled shortly before a split but we're unlucky).
  • When the split actually triggers
    • Source orchestrators fetch the post-split CUP from source peers, validate it with the new source's public key and do not do much more. Their subnet ID doesn't change and the replicas continue to run.
    • Destination orchestrators fetch the post-spilt CUP from destination peers, validate it with the destination's public key and detect that their subnet ID changed. They restart their replicas.

Note: if an upgrade was scheduled shortly before or after a split, it should still "just work" (except if we are unlucky, see later below). If it was scheduled after, the subnet anyways does not bump the registry version past the scheduled split, so the upgrade will simply be triggered on a following summary. If it was scheduled shortly before in such a way that its registry version ends up in the Scheduled (and thus also PostSplit) summary, the orchestrators will execute the upgrade right at the same time as the split. It shouldn't lead to misbehaviour.

Unhappy paths

An upgrade was scheduled shortly before a split but we're unlucky

As explained previously, destination orchestrators will not pick up CUPs created between the moment the registry schedules the split and the split actually triggers:

  • If the split is scheduled when the subnet is at height H=498, replicas create a summary at height H=500 without Scheduled status because the registry version is not stable, then create a CUP. Then, destination orchestrators will not adopt this CUP because the signature doesn't verify. If this CUP indicates an upgrade (scheduled during the previous interval), half of the subnet (intended for source) will upgrade while the other half (intended for destination) will stay stuck. We'd have to split the state manually and recover both halves individually, just like in the next scenario.

Subnet stalls between the registry scheduled the split but before the subnet actually triggers it

Any recovery CUP would pin the latest registry version, which contains the post-split topology. This mean that if such a scenario were to happen, we would have to split the state manually and upload them to the respective halves. All orchestrators are looking for potential recovery CUPs according to the post-split membership already as soon as the registry changes are observed, so the two subnets can be recovered individually.

  • If the orchestrators only looked at the subnet ID of their local CUP, the original subnet would have to be recovered "as a whole" but a registry CUP pins the latest registry version. Thus destination orchestrators would adopt it while also determining that they are not part of the subnet anymore and would delete their state. They would then join the destination subnet with an empty state with height 0, just like a newly created subnet. Though they would be responsible for a bunch of live canisters of the original subnet. It would be a giant mess.

One half manages to create a post-split CUP and make progress while the other half stays stuck

Be it source or destination, orchestrators will always fetch peer/registry CUPs according to their post-split membership and will not be confused by the other half's "normal" CUPs that will be created past the split. For the same reason, it is also possible to recover this stuck half without affecting the other one.

@github-actions github-actions Bot added the feat label Aug 20, 2026
@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/subnet-splitting/orchestrator branch from bad2b0c to 3ef8534 Compare August 26, 2026 08:20
@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/subnet-splitting/orchestrator branch from 3ef8534 to fcfbf7e Compare August 26, 2026 09:12
@pierugo-dfinity pierugo-dfinity added the CI_ALL_BAZEL_TARGETS Runs all bazel targets label Aug 26, 2026
@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/subnet-splitting/orchestrator branch from fcfbf7e to 0599d90 Compare August 28, 2026 14:06
Base automatically changed from pierugo/subnet-splitting/batch-delivery to master August 31, 2026 12:50
@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/subnet-splitting/orchestrator branch from 0599d90 to 27c00d3 Compare August 31, 2026 15:12
@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/subnet-splitting/orchestrator branch from c525a8b to b87847d Compare September 8, 2026 14:02
@pierugo-dfinity
pierugo-dfinity requested a balanced review from Copilot September 9, 2026 13:18
@pierugo-dfinity pierugo-dfinity changed the title feat(subnet-splitting): make the orchestrator restart destination replicas feat(subnet-splitting): make destination orchestrators restart the replica Sep 9, 2026

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.

🔵 Needs a closer look

Two moderate CUP-provider issues remain, including potentially unbounded repeated registry scans.

Pull request overview

Adds subnet-splitting support to CUP discovery and restarts destination replicas after subnet identity changes.

Changes:

  • Detects scheduled splits and targets post-split CUP sources.
  • Restarts destination replicas when subnet IDs change.
  • Prevents registry CUP construction from split records.
File summaries
File Review
rs/orchestrator/src/upgrade.rs Handles subnet changes and replica restarts.
rs/orchestrator/src/registry_helper.rs Simplifies subnet lookup.
rs/orchestrator/src/error.rs Adds invalid split-assignment errors.
rs/orchestrator/src/catch_up_package_provider.rs Detects splits and fetches post-split CUPs. Two moderate issues remain: repeated expected warnings and unbounded registry-version scanning.
rs/consensus/cup_utils/src/lib.rs Excludes splitting records from registry CUP construction.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

🟡 Changes recommended

Restart state is not retry-safe, and chained destination-side splits can leave nodes targeting the wrong subnet.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread rs/orchestrator/src/upgrade.rs Resolved

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.

🟡 Changes recommended

The pre-split-upgrade test writes the wrong subnet and replica version, leaving that interaction unverified.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread rs/orchestrator/src/upgrade.rs Resolved
Comment thread rs/orchestrator/src/upgrade.rs Resolved

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.

🟡 Changes recommended

CUP signer metadata is unauthenticated but is used to update subnet assignment, enabling state loss or denial of service.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread rs/orchestrator/src/upgrade.rs Resolved
Comment thread rs/consensus/cup_utils/src/lib.rs Resolved
@pierugo-dfinity
pierugo-dfinity marked this pull request as ready for review September 10, 2026 13:31
@pierugo-dfinity
pierugo-dfinity requested a review from a team as a code owner September 10, 2026 13:31
@zeropath-ai

zeropath-ai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

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

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/consensus/cup_utils/src/lib.rs
    Enhance CUP creation to exclude subnet-splitting CUP types when building registry CUPs
► rs/orchestrator/src/catch_up_package_provider.rs
    Add handling for SubnetSplitting CupType in CUP provider logic
    Introduce maybe_mutate_subnet_id_due_to_split to adjust subnet_id if a split is pending
    Expand tests to cover subnet splitting scenarios, registry version handling, and post-split CUP fetching
    Add utilities and test scaffolding for split registry state and CUP serving
    Implement tests for getting latest CUP under split conditions and ignore ahead-of-version peer CUPs

@pierugo-dfinity
pierugo-dfinity force-pushed the pierugo/subnet-splitting/orchestrator branch from 67217ba to b5fa49c Compare September 17, 2026 14:07

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.

🔵 Needs a closer look

It changes state-preserving subnet transition, recovery, CUP validation, and replica restart behavior in operationally critical paths.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@pierugo-dfinity
pierugo-dfinity added this pull request to the merge queue Sep 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Sep 22, 2026
@pierugo-dfinity
pierugo-dfinity added this pull request to the merge queue Sep 22, 2026
Merged via the queue into master with commit 8896451 Sep 22, 2026
38 checks passed
@pierugo-dfinity
pierugo-dfinity deleted the pierugo/subnet-splitting/orchestrator branch September 22, 2026 15:24
AleDema pushed a commit to AleDema/ic that referenced this pull request Oct 11, 2026
…inity#11768)

During an NNS Recovery on Failover Nodes, the failover nodes'
orchestrators detect it by consistently looking for a
`cup_contents.registry_store_uri` in their subnet's
`CatchUpPackageContents` at the latest registry version and download a
recovery local store before restarting the orchestrator process. If the
download fails, the upgrade loop retries at the next iteration.

## Problem
Since the recovery CUP was persisted *before* attempting the download,
the next iteration of the loop now tries to determine its `subnet_id`
out of the recovery CUP, but the latter's registry version corresponds
to the new registry, that we haven't extracted yet. The upgrade loop is
then
[stuck](https://sourcegraph.com/r/github.com/dfinity/ic@0422ba2f4e80356900dd4a3edde2abbfe203e1b6/-/blob/rs/orchestrator/src/upgrade.rs?L798-801)
inside `fn get_subnet_id` because it doesn't have the CUP's registry
version available.

This download almost always fails the first time in
`sr_nns_failover_nodes_test` because the UVM isn't fully ready yet by
the time the nodes attempt to download.

## Then why did it not flake before?

The system test setup is not 100% realistic as the original registry has
1 version and the parent NNS registry has 2 versions. The recovery CUP
has registry version 2, which *by chance* (or non-chance), is still
valid even when adding the parent NNS mutations on top of the original
registry. By modifying the system test and adding a few dummy versions
to the original registry (see changes), which is much more realistic,
the test starts failing.

## Then why did it not appear in the mainnet NNS setup?

The mainnet NNS setup also uses NNS recovery on failover nodes, and with
an original registry with many more versions than the parent NNS, so why
does it work there?
We were lucky: in this setup, the UVM is already [setup
before](https://sourcegraph.com/r/github.com/dfinity/ic@0422ba2f4e80356900dd4a3edde2abbfe203e1b6/-/blob/rs/tests/testnets/mainnet_nns/src/lib.rs?L244-245)
attempting this whole process, so the download never fails and we never
stay stuck in a loop.

## Why did it appear only now?

dfinity#11238 recently made the upgrade loop
read the `subnet_id` between the CUP is persisted but before attempting
to download the local store. This is the exact same `fn get_subnet_id`
that returns an error in the scenario described above.

## Proposed solution

Make a failed download retry-safe. To do so, we propose to not persist a
CUP when it actually corresponds "to a different registry". This means
we should look for the `registry_store_uri` before determining the
latest CUP (which persists it). Though this is not sufficient: when
restarting the orchestrator process, we want to have persisted the
recovery CUP (such that the new process sees it). Thus, persist it
precisely just before restarting the process. If the download failed,
the CUP wouldn't get persisted and we retry the download in the next
iteration.

P.S.: also stop leaking tempdirs if anything fails
P.S. 2: also remove the name on the restored IC to collect IC node logs
of the latter (see how
[`sync_with_vector`](https://sourcegraph.com/r/github.com/dfinity/ic@0422ba2f4e80356900dd4a3edde2abbfe203e1b6/-/blob/rs/tests/driver/src/driver/vector_vm.rs?L144)
only reads the unnamed IC)
maksym-arutyunyan pushed a commit to maksym-arutyunyan/ic that referenced this pull request Oct 20, 2026
dfinity#11744)

There is quite a lot going on in this PR. It is more of a `refactor` of
the orchestrator's process manager but it still introduces the following
functional changes (motivated by existing issues, thus `fix`):
- Today, when `stop`ping a process, we just send a `SIGTERM` and
instantly return. There's no guarantee that the process actually
terminated, just that "it probably will in the future". This is great
for not blocking the thread, but it is in contradiction with
- The logic of stopping the replica before removing the state when
leaving a subnet (today, there's technically a race where the state is
removed while the replica is still running for a bit),
- The logic of stopping-then-starting the replica when a recovery CUP is
observed or the subnet ID changes,
- The logic of stopping-then-starting `ic-boundary` when the domain name
changes,
- The [upcoming](dfinity#11349) logic of
stopping-then-starting `ic-gateway` when its config changes.

This PR thus modifies `stop` to block until the process actually
terminated: if `stop` returned `Ok(())`, the process is guaranteed to
have terminated, which fixes the cases above.
- Moreover, `stop` does so by waiting up to 30 seconds, then tries again
with `SIGKILL` for up to 10 seconds. This is in concordance with how
systemd does it and allows force-killing a stuck process. This also
means that this function could take up to 40 seconds to return, and
blocks a tokio worker thread doing so (though I think that's acceptable
since it should be very rare and the runtime has many threads).
- The previous point means that the upgrade loop could hold a write-lock
on `MultipleProcessesManager` for up to 40 seconds, preventing the
dashboard from serving the processes' PIDs (that need a read-lock to
that manager). Provide the dashboard with only a view of the processes'
PIDs, not needing a lock on the entire manager. Also generalize over any
number of processes with a type-erased `trait ProcessObserver`.
  - P.S.: We now display `ic-boundary`'s PID on the dashboard.
- Today, the `stop_replica_if_recovery_cup_or_subnet_changed` function
in the upgrade loop is fragile because it assumes we will always reach
it on the iteration where we observe the recovery CUP or subnet-split.
Though, if there was an error between the observation and that call,
then the next iteration would not re-observe it and the replica would
not be restarted (this was already mentioned
[here](dfinity#11238)).
- We fix this by moving this responsibility out of the upgrade loop and
move it to every implementer of `Process`. This allows to simplify the
upgrade loop and to remove the `IcBoundaryManager`'s custom restart
logic by including it directly into `ProcessManager<P>` for any `P:
Process`.
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.

3 participants