Skip to content

fix: tolerate a cycles balance increase on DTS resume - #11141

Open
mraszyk wants to merge 2 commits into
masterfrom
mraszyk/dts-resume-cycles-increase
Open

fix: tolerate a cycles balance increase on DTS resume#11141
mraszyk wants to merge 2 commits into
masterfrom
mraszyk/dts-resume-cycles-increase

Conversation

@mraszyk

@mraszyk mraszyk commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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.

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>
@github-actions github-actions Bot added the fix label Aug 14, 2026
…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>

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.

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.

@mraszyk
mraszyk marked this pull request as ready for review August 14, 2026 14:00
@mraszyk
mraszyk requested a review from a team as a code owner August 14, 2026 14:00
@zeropath-ai

zeropath-ai Bot commented Aug 14, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to c61581e.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/execution_environment/src/execution/call_or_task.rs
      Resume: stricter cycles balance check when resuming DTS execution
Enhancement ► rs/execution_environment/src/execution/install_code.rs
      Resume: stricter cycles balance check when resuming install_code DTS execution
Enhancement ► rs/execution_environment/src/execution/install_code/tests.rs
      Add/modify tests for DTS install_code with cycle balance changes and new constants/structures
Enhancement ► rs/execution_environment/src/execution/response.rs
      Resume: stricter cycles balance check when resuming DTS response calls
Enhancement ► rs/execution_environment/src/execution_environment/tests.rs
      Add test scaffolding for long-running and paused executions, and new scenarios for cycle balance changes
Enhancement ► rs/execution_environment/src/execution_environment/tests.rs
      Introduce long-running execution helpers and related test utilities

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