Repository navigation
fix: Refund the prepayment of an install_code dropped by a subnet split - #11464
Merged
Merged
Conversation
…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]>
Contributor
There was a problem hiding this comment.
🟡 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]>
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]>
|
✅ No security or compliance issues detected. Reviewed everything up to 5fc5519. Security OverviewDetected Code Changes
|
schneiderstefan
approved these changes
Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SystemState::drop_in_progress_management_calls_after_split()drops the canister'sAbortedInstallCodetask on subnet B, discarding theprepaid_execution_cyclesrecorded 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_cyclesgauge and contributing nothing to theInstructionsby-use-case counter, which is exactly right when nothing was consumed.🤖 Generated with Claude Code