Skip to content

fix: Refund the prepayment of an install_code dropped by a subnet split - #11464

Merged
mraszyk merged 3 commits into
masterfrom
mraszyk/refund-split-dropped-install-code
Sep 7, 2026
Merged

mraszyk merged 3 commits into
masterfrom
mraszyk/refund-split-dropped-install-code

Conversation

@mraszyk

@mraszyk mraszyk commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

SystemState::drop_in_progress_management_calls_after_split() drops the canister's AbortedInstallCode task on subnet B, discarding the prepaid_execution_cycles recorded in it. The cycles are never returned to the canister, so it stays charged for an execution that never happens: an aborted execution discards the slices it had already run and starts over when retried, and this one is never retried — subnet A' rejects the corresponding call, unwinding the operation there as well.

TaskQueue::remove_aborted_install_code_task() now returns the prepayment and the caller refunds it in full.

The refund is deterministic across subnet B's replicas and conserves cycles: they move back from consumed to the canister's balance, lowering the consumed_cycles gauge and contributing nothing to the Instructions by-use-case counter, which is exactly right when nothing was consumed.

🤖 Generated with Claude Code

…plit

`drop_in_progress_management_calls_after_split()` drops the canister's
`AbortedInstallCode` task on subnet B, discarding the
`prepaid_execution_cycles` recorded in it. The cycles are never returned
to the canister, so it stays charged for an execution that never happens:
an aborted execution discards the slices it had already run and starts
over when retried, and this one is never retried -- subnet A' rejects the
corresponding call, unwinding the operation there as well.

`remove_aborted_install_code_task()` now returns the prepayment and the
caller refunds it in full. The refund is deterministic across subnet B's
replicas and conserves cycles: they move back from consumed to the
canister's balance, lowering the consumed cycles gauge and contributing
nothing to the `Instructions` counter, which is exactly right when
nothing was consumed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

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 online-split fixture refunds a prepayment it never charged, masking cycle creation in the integration test.

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

Pull request overview

Refunds prepaid execution cycles when subnet splitting drops an aborted install_code.

Changes:

  • Returns prepayment details when removing aborted install tasks.
  • Refunds balances and adjusts consumption metrics.
  • Adds split/refund tests.
File summaries
File Description
rs/replicated_state/src/canister_state/system_state.rs Applies the refund after task removal.
rs/replicated_state/src/canister_state/system_state/task_queue.rs Returns removed task prepayment.
rs/replicated_state/src/canister_state/tests.rs Tests balance and metric restoration.
rs/replicated_state/tests/replicated_state.rs Updates online-split expectations.
Review details
  • Files reviewed: 4/4 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.

Address review feedback: the fixture recorded a nonzero
`prepaid_execution_cycles` in the `AbortedInstallCode` task without ever
charging it to the canister. The refund on the split then handed the
canister 3 cycles it had never paid, and the `consumed_cycles` gauge
absorbed the mismatch through its saturating subtraction, so the scenario
the test exercised was not one the replica can actually reach.

Charge the prepayment before enqueueing the task, and assert explicitly
that `CANISTER_2` is back to its pre-prepayment balance after the split,
rather than leaving conservation implicit in the mirrored construction of
the expected state.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

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

The implementation conserves cycles and includes focused unit and integration coverage.

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

Three review nits on the split refund tests:

  * The unit test claimed the `Instructions` counter was still zero
    before the split but only asserted it afterwards. Assert it in both
    places, so the comment is backed by the test rather than by the
    reader.
  * Dropped the comment explaining why `online_split` charges the
    prepayment; the `consume_cycles` call says it.
  * Raised that prepayment from 3 to 1,000,000 cycles and asserted that
    all of it lands in the balance and the consumed cycles gauge, rather
    than taking the charge on faith.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

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

The refund logic is focused, consistent with existing cycle accounting, and adequately tested.

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

@mraszyk
mraszyk marked this pull request as ready for review September 7, 2026 09:40
@mraszyk
mraszyk requested a review from a team as a code owner September 7, 2026 09:40
@zeropath-ai

zeropath-ai Bot commented Sep 7, 2026

Copy link
Copy Markdown

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

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/replicated_state/src/canister_state/system_state.rs
    Implement refund of prepaid execution cycles when dropping aborted install code tasks after split
► rs/replicated_state/src/canister_state/system_state/task_queue.rs
    Refactor remove_aborted_install_code_task to return prepaid cycles and support refunds
► rs/replicated_state/src/canister_state/tests.rs
    Add test for refunding prepayment of aborted canister install dropped after split
► rs/replicated_state/tests/replicated_state.rs
    Update test to handle prepaid install_code task refunds during online split

@mraszyk
mraszyk added this pull request to the merge queue Sep 7, 2026
Merged via the queue into master with commit 0f341f6 Sep 7, 2026
48 checks passed
@mraszyk
mraszyk deleted the mraszyk/refund-split-dropped-install-code branch September 7, 2026 10:40
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