Skip to content

fix: return RuleViolation for invalid trades to prevent AI turn stalls#182

Merged
njbrake merged 1 commit intomainfrom
fix/invalid-trade-hang
Apr 7, 2026
Merged

fix: return RuleViolation for invalid trades to prevent AI turn stalls#182
njbrake merged 1 commit intomainfrom
fix/invalid-trade-hang

Conversation

@njbrake
Copy link
Copy Markdown
Contributor

@njbrake njbrake commented Apr 7, 2026

Summary

  • After Monopoly depletes resources, the AI would repeatedly propose trades offering resources it doesn't have (e.g., offering Wood with 0 Wood). Each invalid trade silently returned Ok(()), consuming action/trade slots and causing the AI turn to last ~2 minutes while the game appeared frozen.
  • Changed handle_trade to return Err(RuleViolation) when validate_trade fails, so invalid trades don't count toward limits. Added narration message explaining the failure.
  • Added regression test verifying trade validation rejects offers with insufficient resources.

Test plan

  • All 431 tests pass (1 new regression test)
  • cargo clippy clean
  • cargo fmt clean
  • Manual test: play a game, have AI play Monopoly card, verify AI turn completes quickly without getting stuck proposing invalid trades

🤖 Generated with Claude Code

After Monopoly depletes resources, the AI would propose trades offering
resources it doesn't have. These invalid trades silently returned Ok(()),
consuming action/trade slots and causing ~2-minute AI turns while the
game appeared frozen. Now returns RuleViolation so invalid trades don't
count, the AI moves on faster, and narration explains the failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@njbrake njbrake merged commit 373375f into main Apr 7, 2026
5 checks passed
@njbrake njbrake deleted the fix/invalid-trade-hang branch April 7, 2026 20:23
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