feat(battle-node): clear RealParticipant outbound archive on session terminate

Closes audit Md11. BattleSession.RunAsync now clears each
RealParticipant.Outbound archive immediately before the TerminateAsync
cascade, releasing the heavy dict the moment the battle ends instead of
waiting for the participant to be GC'd. Bots (NoOp / Scripted) don't
expose an OutboundSequencer, so the 'p is RealParticipant rp' conditional
cast is the natural filter.

Tests: 1 new BattleSessionTerminateCascadeTests — pre-load the archive,
drive RunAsync to completion via TestWebSocket.CompleteIncoming, assert
the archive is empty. Suite: 939 → 948.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-02 13:10:15 -04:00
parent 10d9f74d05
commit 5c4e427fab
2 changed files with 66 additions and 0 deletions

View File

@@ -86,6 +86,13 @@ public sealed class BattleSession
catch { /* swallow */ }
}
// Audit Md11 — release per-participant outbound archives at battle-end
// (only RealParticipant has one; bots don't archive). Heavy state is
// dropped synchronously here so the participant's TerminateAsync doesn't
// need to keep the dict alive through its disposal handshake.
if (A is RealParticipant rpA) rpA.Outbound.Clear();
if (B is RealParticipant rpB) rpB.Outbound.Clear();
await Task.WhenAll(
A.TerminateAsync(BattleFinishReason.NormalFinish),
B.TerminateAsync(BattleFinishReason.NormalFinish))