Skip to content

fix(castle-siege): clean up a cycle end missed while the server was down - #1351

Open
icheat2win wants to merge 3 commits into
MUnique:masterfrom
icheat2win:fix/castle-siege-missed-cycle-end
Open

icheat2win wants to merge 3 commits into
MUnique:masterfrom
icheat2win:fix/castle-siege-missed-cycle-end

Conversation

@icheat2win

Copy link
Copy Markdown
Contributor

Part of the Castle Siege epic (#735).

Problem

The EndCycle clean-up (registrations, marks, selected guilds) only runs on the transition into EndCycle. If the server is down at that moment, it starts directly in the next cycle's early RegisterGuild, and OnEnterStateAsync skips the reload on startup. The old registrations and the old selected guild list survive into the next cycle.

Change

On initialization, CastleSiegePlugIn.CleanUpMissedCycleEndAsync checks the persisted selected guilds (CastleSiegeData.Guilds). They only exist from Notify to EndCycle, so finding them while the schedule is before Notify means the clean-up never ran. It then clears the registrations and the selected guilds and logs a warning.

This needs no schema change. Limitation (documented): a cycle which ended without any guild selection leaves no trace, so its registrations can't be told apart from new ones and stay. A complete fix would persist the time of the last cycle end, which needs a DataModel property and a migration; I left that out to keep this small.

Documented on the Castle Siege page.

Tests

Three new tests in CastleSiegeStateMachineTests: restart in RegisterGuild with stale selected guilds clears both; restart in RegisterGuild without them keeps the current registration; restart in Ready keeps the registration.

Ran the full MUnique.OpenMU.Tests suite with --no-build: 2445 passed, 2 skipped.


Generated by Claude Code

When the server starts before the guild selection of a cycle and still
finds the selected guilds of the previous battle, the EndCycle clean-up
never ran. Clear the old registrations and selected guilds then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011xNc764bgrPZRQYCRzPj1x
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T16:11:45.267436Z
We couldn’t complete this review. Comment @codex review to try again.
e662d82 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codacy-production

codacy-production Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 12 complexity · 31 duplication

Metric Results
Complexity 12
Duplication 31

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@sven-n sven-n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: tests/MUnique.OpenMU.Tests/CastleSiegeStateMachineTests.cs:644-700 uses Assert.Multiple(async () => { await ... }) in three new tests. The synchronous Assert.Multiple delegate can become async void, so persistence assertions after an incomplete await may execute outside the assertion scope. Please use await Assert.MultipleAsync(...) or await persistence reads before a synchronous assertion block. The recovery heuristic in src/GameLogic/CastleSiege/CastleSiegePlugIn.cs:262-284 also cannot identify missed cycle ends when no guild was selected; this limitation is documented, but deserves an explicit test.

…missed-cycle-end

# Conflicts:
#	docs-website/docs/server-features/castle-siege.md
…ver the detection limitation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011xNc764bgrPZRQYCRzPj1x

This branch has not been deployed

No deployments
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.

3 participants