Skip to content

fix(engine): make mana payments atomic - #5793

Merged
matthewevans merged 1 commit into
phase-rs:mainfrom
nishu-builder:fix/atomic-mana-payment
Jul 14, 2026
Merged

fix(engine): make mana payments atomic#5793
matthewevans merged 1 commit into
phase-rs:mainfrom
nishu-builder:fix/atomic-mana-payment

Conversation

@nishu-builder

Copy link
Copy Markdown
Contributor

Summary

Makes mana payment atomic when demand-aware hybrid selection has to retry without the demand hint. A failed first spend now rolls back completely before the fallback attempt, so a payable spell is not rejected because the failed attempt consumed part of the caller's pool.

Files changed

  • crates/engine/src/game/mana_payment.rs
  • crates/engine/tests/integration/atomic_mana_payment.rs
  • crates/engine/tests/integration/main.rs

CR references

  • CR 107.4f
  • CR 118.13a
  • CR 601.2b
  • CR 601.2h
  • CR 609.4b

Implementation method (required)

Method: /engine-implementer

Track

Developer

LLM

Model: codex-5
Thinking: high
Tier: Standard

Verification

  • Required checks ran clean, or the exact CI-owned alternative is stated below.

  • Gate A output below is for the current committed head.

  • Final review-impl below is clean for the current committed head.

  • Both anchors cite existing analogous code at the same seam.

  • tilt get uiresource clippy - Tilt unavailable in this worktree; used the documented direct fallback.

  • cargo fmt --all - passed.

  • cargo fmt --all -- --check - passed.

  • git diff --check - passed.

  • cargo clippy-strict - passed on head a4788b91e612640b5422382bc8cd81d31c59441a.

  • cargo test -p engine - passed on head a4788b91e612640b5422382bc8cd81d31c59441a: 16573 unit tests passed; 6 coverage_parse_diff tests passed; 9 set_check tests passed; 3041 integration tests passed; doc tests passed with 7 ignored.

  • cargo test -p engine atomic_mana_payment::paradox_surveyor_demand_fallback_casts_and_resolves - passed on head a4788b91e612640b5422382bc8cd81d31c59441a: 1 integration test passed.

  • ./scripts/gen-card-data.sh - passed on head a4788b91e612640b5422382bc8cd81d31c59441a: generated card data for 35397 faces; coverage summary 31335/35397 cards supported (88.5%); 1072 parser warnings.

  • cargo coverage - passed on head a4788b91e612640b5422382bc8cd81d31c59441a: 31335/35397 cards supported (88.5%).

  • cargo semantic-audit - passed on head a4788b91e612640b5422382bc8cd81d31c59441a: 32389 cards audited, 292 existing findings.

Gate A

Gate A PASS head=a4788b91e612640b5422382bc8cd81d31c59441a base=6d7821dced9623609edea342b47dd9c704ff0b36

Anchored on

  • crates/engine/src/game/mana_payment.rs:853 - existing reduce_cost_by_pool scratch-pool dry run keeps affordability simulation separate from caller pool mutation.
  • crates/engine/src/game/mana_payment.rs:1033 - existing pay_cost_with_demand_and_choices payment authority owns demand-aware hybrid and Phyrexian payment selection.

Final review-impl

Final review-impl PASS head=a4788b91e612640b5422382bc8cd81d31c59441a

Claimed parse impact

None.

Validation Failures

Resolved local environment issue: the first direct clippy fallback attempt hit No space left on device in the generated harness target. I removed that generated target cache and reran the required checks cleanly.

CI Failures

None.

@github-actions github-actions Bot added the needs-maintainer AI-contribution PR requires human triage (Non-dev track or unresolved gaps) label Jul 14, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request implements atomic mana payments in the game engine by ensuring that failed payment attempts do not leak partial payments into the player's mana pool, adhering to CR 601.2h. It refactors pay_cost_with_demand_and_choices to use a scratch pool and fall back to a second attempt without hand demand if the first attempt fails due to insufficient mana. Additionally, the PR updates several Magic Comprehensive Rules (CR) references in the documentation, introduces comprehensive unit tests for payment failures and successes, and adds a new integration test module for atomic mana payments. There are no review comments, and the changes are architecturally sound and compliant with the repository's style guide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@github-actions

Copy link
Copy Markdown

Parse changes introduced by this PR

✓ No card-parse changes detected.

@matthewevans matthewevans self-assigned this Jul 14, 2026
@matthewevans
matthewevans force-pushed the fix/atomic-mana-payment branch from a4788b9 to e6a578d Compare July 14, 2026 09:22

@matthewevans matthewevans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — mana-payment retries now commit only a complete payment.

✅ Clean

  • The transaction boundary is the existing pay_cost_with_demand_and_choices authority at crates/engine/src/game/mana_payment.rs:1033; every casting and mana-ability caller uses it.
  • CR 601.2h explicitly forbids partial payments. The scratch-pool first attempt and demand-free fallback preserve the original pool on either failure path.
  • The registered GameRunner::cast(...).resolve() regression at crates/engine/tests/integration/atomic_mana_payment.rs:17 fails without the rollback, while focused tests preserve full unit provenance on failure and commit.

Recommendation: approve and enqueue.

@matthewevans matthewevans added the bug Bug fix label Jul 14, 2026
@matthewevans
matthewevans added this pull request to the merge queue Jul 14, 2026
@matthewevans matthewevans removed their assignment Jul 14, 2026
Merged via the queue into phase-rs:main with commit 81ce9fd Jul 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug fix needs-maintainer AI-contribution PR requires human triage (Non-dev track or unresolved gaps)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants