ReviewOS

stacks/wildloop

Fix conquest stats & ownership accounting in ProcessActivityConquestAction

#951
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Problem

The split path has accounting inconsistencies: stats are updated even when a split doesn't produce a valid (>= MIN_TERRITORY_SIZE) polygon in some branches; total_territories_owned semantics (currently-owned vs lifetime) are ambiguous across split events; and the 'split - retained portion' history row attributes previous_owner_id in a way that's easy to misread. See app/Actions/Territory/ProcessActivityConquestAction.ts (split branch + updateConquestStats).

Acceptance

  • Only mutate stats when the corresponding territory create/update succeeds (transactional).
  • Clarify and document owned-count semantics; fix double-counting on splits.
  • Tests for full-takeover, partial-split, and below-threshold cases.
9 days ago

Fixed in 519c2d3. Accounting semantics are now documented in the action header and enforced:

  • Idempotency: an activity that already produced battle events is a no-op on re-POST (no double-conquest on client retry).
  • Ownership guard: you can only conquer with your own activity (was missing entirely; 403 otherwise).
  • Exact deltas: the previous owner loses the territory's actual shrinkage (original − retained) while the conqueror gains the new piece's area — no invented area from geometric rounding.
  • Splits increment the original's conquest_count, the retained-portion history row no longer misattributes previous_owner_id, splits don't count as territories_lost (current vs lifetime semantics), and whole takeovers fold the ownership run into longest_ownership_days.
  • Per-territory isolation (try/catch) with stats written only after territory writes succeed — the ordering-based equivalent of a transaction given the ORM exposes none.

Covered by scripts/verify-conquest-accounting.ts (replay no-op, 403, counts unchanged) and the full-takeover / partial-split / below-threshold paths in scripts/verify-territory-battles.ts.

Sign in to comment on this issue.