Skip to content

fix(engine): settle cleanup discard triggers - #7120

Merged
matthewevans merged 5 commits into
mainfrom
ship/fix-engine-settle-cleanup-discard-triggers
Aug 9, 2026
Merged

fix(engine): settle cleanup discard triggers#7120
matthewevans merged 5 commits into
mainfrom
ship/fix-engine-settle-cleanup-discard-triggers

Conversation

@matthewevans

@matthewevans matthewevans commented Aug 9, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Cleanup-phase discard actions now correctly resolve triggered effects before advancing the game.
    • Improved handling of priority, delayed triggers, replacement choices, and automatic phase progression.
    • Prevented discard events from being processed more than once.
    • Ensured replacement choices occur before related effects or phase advancement.
  • Tests

    • Added comprehensive coverage for cleanup discards, trigger ordering, batching, turn control, damage, draws, and replacement effects.

@matthewevans
matthewevans enabled auto-merge August 9, 2026 02:23
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@matthewevans, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 26 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 34203d01-5be4-4703-a493-be05fcdb384e

📥 Commits

Reviewing files that changed from the base of the PR and between 0974927 and e62aee6.

📒 Files selected for processing (1)
  • crates/engine/tests/integration/cleanup_discard_trigger_pipeline.rs
📝 Walkthrough

Walkthrough

Cleanup discard handling now uses the standard post-action SBA and trigger pipeline before phase advancement. New integration tests cover trigger settlement, batching, delayed triggers, ordering, priority, replacement choices, and normal cleanup progression.

Changes

Cleanup discard trigger pipeline

Layer / File(s) Summary
Settle cleanup discard events
crates/engine/src/game/engine_resolution_choices.rs
Cleanup discard events now pass through post-action SBA and trigger settlement. The handler synchronizes waiting state and advances only when priority is restored and the stack is empty.
Validate pipeline behavior
crates/engine/tests/integration/cleanup_discard_trigger_pipeline.rs, crates/engine/tests/integration/main.rs
Integration tests cover trigger counts, batching, delayed triggers, ordering, controlled-turn priority, replacement choices, repeated cleanup, and phase advancement. The test module is registered in the integration suite.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CleanupDiscardHandler
  participant PostActionPipeline
  participant WaitingState
  participant PhaseAdvancement
  CleanupDiscardHandler->>WaitingState: synchronize provisional priority
  CleanupDiscardHandler->>PostActionPipeline: settle discard events
  PostActionPipeline->>WaitingState: synchronize resulting waiting state
  CleanupDiscardHandler->>PhaseAdvancement: advance when priority is restored and stack is empty
Loading

Possibly related PRs

  • phase-rs/phase#6933: Also changes cleanup-discard handling and phase or stack settlement in engine_resolution_choices.rs.
  • phase-rs/phase#7074: Changes discard-frame and discard-resolution handling in engine_resolution_choices.rs.
  • phase-rs/phase#7075: Changes cleanup and trigger settlement involving zone-change tracking and batched trigger processing.

Suggested labels: bug

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: settling cleanup-discard triggers in the engine.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ship/fix-engine-settle-cleanup-discard-triggers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
crates/engine/tests/integration/cleanup_discard_trigger_pipeline.rs (1)

337-343: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Resolve the trigger ordering so the test proves settlement, not only the pause.

The test stops at the OrderTriggers pause. It never submits the ordering. The half that the fix changes — both triggers reach the stack, and cleanup does not advance until they resolve — stays unverified. A regression that drops the second trigger after ordering still passes this test.

Add the ordering submission and assert both Magmakin entries reach the stack, then assert the phase is still Cleanup.

Line 343 (assert_eq!(artillerists.len(), 2)) asserts a fixture value, not engine behavior. Remove it or replace it with a stack-content assertion.

As per path instructions: "A test must exercise the FAILURE path the fix prevents and drive the engine through its production pipeline."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/engine/tests/integration/cleanup_discard_trigger_pipeline.rs` around
lines 337 - 343, Extend the test after the OrderTriggers pause by submitting the
trigger ordering through the production pipeline, then assert both Magmakin
trigger entries are present on the stack and the phase remains Cleanup. Remove
the fixture-only artillerists.len() assertion and replace it with stack-content
validation that would fail if the second trigger were dropped.

Source: Path instructions

crates/engine/src/game/engine_resolution_choices.rs (1)

4466-4480: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Rename the pipeline flags or replace them with a typed options enum.

At this settlement call site, the two positional false arguments are not named. Passing false, false depends on the current skip_trigger_scan, skip_deferred_trigger_drain order, which is not obvious from engine_resolution_choices.rs alone. Add a short inline comment naming them, or pass a typed post-action options struct.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/engine/src/game/engine_resolution_choices.rs` around lines 4466 -
4480, The settlement call to engine_priority::run_post_action_pipeline_from
currently uses ambiguous positional false flags. Add a concise inline comment
identifying each argument as skip_trigger_scan and skip_deferred_trigger_drain,
or replace the booleans with the existing typed post-action options mechanism if
available; preserve both flags as disabled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/engine/tests/integration/cleanup_discard_trigger_pipeline.rs`:
- Around line 414-448: Update the cleanup-discard replacement test around
setup_cleanup_discard to create at least one discard observer, such as a
Magmakin, while preserving the replacement setup. Add a paired positive
reach-guard confirming that the observer is present or otherwise reached the
settlement pipeline, so the stack-empty negative assertion can fail if the early
return in engine_resolution_choices is removed.

---

Nitpick comments:
In `@crates/engine/src/game/engine_resolution_choices.rs`:
- Around line 4466-4480: The settlement call to
engine_priority::run_post_action_pipeline_from currently uses ambiguous
positional false flags. Add a concise inline comment identifying each argument
as skip_trigger_scan and skip_deferred_trigger_drain, or replace the booleans
with the existing typed post-action options mechanism if available; preserve
both flags as disabled.

In `@crates/engine/tests/integration/cleanup_discard_trigger_pipeline.rs`:
- Around line 337-343: Extend the test after the OrderTriggers pause by
submitting the trigger ordering through the production pipeline, then assert
both Magmakin trigger entries are present on the stack and the phase remains
Cleanup. Remove the fixture-only artillerists.len() assertion and replace it
with stack-content validation that would fail if the second trigger were
dropped.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5dd07d89-a2f2-4e3f-b7ca-ab4e538dc335

📥 Commits

Reviewing files that changed from the base of the PR and between df99c20 and cdfb3a3.

📒 Files selected for processing (3)
  • crates/engine/src/game/engine_resolution_choices.rs
  • crates/engine/tests/integration/cleanup_discard_trigger_pipeline.rs
  • crates/engine/tests/integration/main.rs

Comment thread crates/engine/tests/integration/cleanup_discard_trigger_pipeline.rs Outdated
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Generated for head e62aee61311a4ccbd3447c0a3fd74fd82d670ca3.

Parse changes introduced by this PR · 0 card(s), 0 signature(s) (baseline: main de0b04ecbe76)

11 card(s) had Oracle-text changes (errata/reprint) — excluded as non-parser.
New cards in head: 138.

@matthewevans
matthewevans added this pull request to the merge queue Aug 9, 2026
Merged via the queue into main with commit 69a45bf Aug 9, 2026
13 checks passed
@matthewevans
matthewevans deleted the ship/fix-engine-settle-cleanup-discard-triggers branch August 9, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant