Skip to content

ship/fix ai validate restored and target continuations - #7104

Merged
matthewevans merged 10 commits into
mainfrom
ship/fix-ai-validate-restored-and-target-continuations
Aug 8, 2026
Merged

ship/fix ai validate restored and target continuations#7104
matthewevans merged 10 commits into
mainfrom
ship/fix-ai-validate-restored-and-target-continuations

Conversation

@matthewevans

@matthewevans matthewevans commented Aug 8, 2026

Copy link
Copy Markdown
Member
  • fix(ai): validate restored and target continuations
  • test(ai): cover target surcharge proposal boundary

Summary by CodeRabbit

  • Bug Fixes
    • Restored games and multiplayer sessions now fail safely when required card data is unavailable, without partially changing game state.
    • Resumed and restored games better preserve card details, random sequences, and replay validity.
    • AI target selection no longer offers outdated or invalid targets.
    • AI correctly excludes unpayable actions while retaining valid alternatives.
    • Players can cancel eligible casts during target selection.
    • AI fallback behavior now consistently follows issued legal actions and handles no-target scenarios correctly.

@matthewevans
matthewevans enabled auto-merge August 8, 2026 16:50
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5607db23-d866-4bce-afef-57db5245bce3

📥 Commits

Reviewing files that changed from the base of the PR and between fe67e0f and e41dffb.

📒 Files selected for processing (1)
  • crates/phase-ai/src/policies/hand_disruption.rs
💤 Files with no reviewable changes (1)
  • crates/phase-ai/src/policies/hand_disruption.rs

📝 Walkthrough

Walkthrough

Restoration and multiplayer resume now require card-database rehydration. AI target candidates now use current prompts and reducer validation. Fallback actions consume issued decision-contract candidates. WASM tests cover restoration, payment legality, legacy states, replay invalidation, and RNG continuity.

Changes

State restoration

Layer / File(s) Summary
Mandatory card-database rehydration
crates/engine-wasm/src/lib.rs
Restore and multiplayer resume paths rehydrate restored state and fail before state mutation when no card database is loaded.
WASM restoration fixtures and coverage
crates/engine-wasm/src/lib.rs
Fixtures and tests cover restored prompts, payment-dependent targets, legacy objects, replay invalidation, multiplayer resume, and RNG restoration.

Validated AI target actions

Layer / File(s) Summary
Current target candidate enumeration
crates/engine/src/ai_support/candidates.rs
Target selection uses current legal targets, preserves permitted CancelCast, and rejects stale target-slot entries.
Reducer-validated candidate contracts
crates/engine/src/ai_support/context.rs, crates/engine/src/ai_support/mod.rs, crates/engine/src/game/casting.rs, crates/phase-ai/src/policies/hand_disruption.rs
Target-selection contracts use reducer validation when pending mana obligations can change. Supporting cost-stability logic and target-selection fixtures are updated.
Fallback use of issued actions
crates/phase-ai/src/search.rs
fallback_action selects issued ChooseTarget and CancelCast candidates instead of rebuilding target actions.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant phase_ai_search
  participant AiDecisionContract
  participant legal_actions_full
  participant FilterPipeline
  phase_ai_search->>AiDecisionContract: request target decision
  AiDecisionContract->>legal_actions_full: enumerate current target actions
  legal_actions_full->>FilterPipeline: validate candidates
  FilterPipeline-->>AiDecisionContract: return legal candidates
  AiDecisionContract-->>phase_ai_search: issue ChooseTarget or CancelCast
Loading
sequenceDiagram
  participant Restore
  participant Rehydration
  participant CardDatabase
  participant GameState
  Restore->>Rehydration: restore state
  Rehydration->>CardDatabase: load card definitions
  CardDatabase-->>Rehydration: definitions or error
  Rehydration->>GameState: install rehydrated state
Loading

Possibly related PRs

Suggested labels: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title identifies the main changes: AI validation for restored states and target continuations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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
📝 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-ai-validate-restored-and-target-continuations

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.

@matthewevans
matthewevans force-pushed the ship/fix-ai-validate-restored-and-target-continuations branch from 5a8196f to f3307e7 Compare August 8, 2026 16:54

@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

🤖 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-wasm/src/lib.rs`:
- Around line 1842-1844: In crates/engine-wasm/src/lib.rs#L1842-L1844, call
rehydrate_restored_state_from_card_db before rehydrate_rng and the debug_mode
assignment; in crates/engine-wasm/src/lib.rs#L1905-L1910, perform the same
card-database restoration before assigning the fresh RNG state. Ensure both
restoration paths validate required resources before any GameState mutation.
🪄 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: 6648a541-38ea-490c-bceb-3c4d69e58426

📥 Commits

Reviewing files that changed from the base of the PR and between 4d27655 and f3307e7.

📒 Files selected for processing (5)
  • crates/engine-wasm/src/lib.rs
  • crates/engine/src/ai_support/candidates.rs
  • crates/engine/src/ai_support/context.rs
  • crates/engine/src/ai_support/mod.rs
  • crates/phase-ai/src/search.rs

Comment thread crates/engine-wasm/src/lib.rs Outdated
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

Generated for head e41dffb63fbd8e60c4a15dbf5c71bb4b5ab813f6.

Parse changes introduced by this PR

✓ No card-parse changes detected.

@matthewevans
matthewevans force-pushed the ship/fix-ai-validate-restored-and-target-continuations branch from c42f488 to 72f9d43 Compare August 8, 2026 18:40
@matthewevans
matthewevans added this pull request to the merge queue Aug 8, 2026
Merged via the queue into main with commit 95415aa Aug 8, 2026
17 checks passed
@matthewevans
matthewevans deleted the ship/fix-ai-validate-restored-and-target-continuations branch August 8, 2026 20:06
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