fix: tolerate a cycles balance increase on DTS resume - #11141
Open
mraszyk wants to merge 2 commits into
Open
Conversation
Every kind of paused execution re-creates its helper from the current clean canister state when it is resumed and thus compares the cycles balance of that state with the balance at the start of the DTS execution. The comparison used to reject any change of the balance; it now only rejects a decrease, which the recorded steps replayed on the clean canister state might no longer be able to cover. An increase is safe: all cycles changes of a DTS execution are applied relative to the balance of the clean canister state (the Wasm execution reports a `CyclesBalanceChange` delta and the prepaid execution cycles are refunded relative as well), so the additional cycles are preserved. The new tests `dts_resume_succeeds_after_cycles_increase` and `dts_install_code_resume_succeeds_after_cycles_increase` are the counterparts of `dts_resume_fails_due_to_cycles_decrease` and `dts_install_code_resume_fails_due_to_cycles_decrease`: they add cycles to the canister while its execution is paused and assert that the execution completes and that the added cycles are not lost. The former runs every scenario twice, once without adding cycles, and asserts that the two final balances differ by exactly the added cycles. The setup of all the scenarios is now shared by the tests that decrease and increase the cycles balance. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…eded `paused_execution_resumes_after_cycles_increase` used to state that the resumed execution must not fail to resume without asserting it: a failed resume also ends the execution, so the check that no execution is left is satisfied either way. It now asserts that the remaining slices executed further instructions, which a failed resume never does because it aborts the paused Wasm execution. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Allows paused DTS executions to resume after a cycles balance increase while continuing to reject decreases.
Changes:
- Relax cycles-balance validation across all DTS execution helpers.
- Add shared paused-execution test setup.
- Verify successful resume and preservation of added cycles.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
rs/execution_environment/src/execution/response.rs |
Allows response callbacks to resume after balance increases. |
rs/execution_environment/src/execution/install_code/tests.rs |
Adds install-code balance-increase coverage. |
rs/execution_environment/src/execution/install_code.rs |
Relaxes install-code resume validation. |
rs/execution_environment/src/execution/call_or_task.rs |
Relaxes call and task resume validation. |
rs/execution_environment/src/execution_environment/tests.rs |
Adds shared DTS scenarios and balance-preservation tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
✅ No security or compliance issues detected. Reviewed everything up to c61581e. Security Overview
Detected Code Changes
|
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.
Every kind of paused execution re-creates its helper from the current clean canister state when it is resumed and thus compares the cycles balance of that state with the balance at the start of the DTS execution. The comparison used to reject any change of the balance; it now only rejects a decrease, which the recorded steps replayed on the clean canister state might no longer be able to cover.
An increase is safe: all cycles changes of a DTS execution are applied relative to the balance of the clean canister state (the Wasm execution reports a
CyclesBalanceChangedelta and the prepaid execution cycles are refunded relative as well), so the additional cycles are preserved.The new tests
dts_resume_succeeds_after_cycles_increaseanddts_install_code_resume_succeeds_after_cycles_increaseare the counterparts ofdts_resume_fails_due_to_cycles_decreaseanddts_install_code_resume_fails_due_to_cycles_decrease: they add cycles to the canister while its execution is paused and assert that the execution completes and that the added cycles are not lost. The former runs every scenario twice, once without adding cycles, and asserts that the two final balances differ by exactly the added cycles. The setup of all the scenarios is now shared by the tests that decrease and increase the cycles balance.