Skip to content

Add delay before disconnected army's ACUs are killed#7153

Open
lL1l1 wants to merge 3 commits into
developfrom
fix/abandon-acu-delay
Open

Add delay before disconnected army's ACUs are killed#7153
lL1l1 wants to merge 3 commits into
developfrom
fix/abandon-acu-delay

Conversation

@lL1l1

@lL1l1 lL1l1 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description of the proposed changes

  • Adds a delay when an army is abandoned before the ACU is killed.

    Should fix online replays being cut off at the point where someone disconnected due to the disconnected player reporting a game over state.

    The way a game over state is reported is that when a player disconnects from the game, their instance of the game thinks everyone else disconnected, so it runs the abandonment code for all other players. Without a delay, this causes all ACUs to explode and the sim to tell the UI to report a game over state. It's a bit unintuitive that the sim runs and gets time to report an end state while exiting the game, but that is how SessionEndGame() works (it pauses the game and pauses are a request to the sim that happen on a small delay of sim beats).

  • Move all extra delays to threads so that EndGameGracePeriod in KillArmy is a consistent delay players can rely on.

Testing done on the proposed changes

ACUs no longer explode before exiting when testing multiplayer. I don't have a good way to test the replays because I don't understand how they're saved on the server (I looked a little at the parser and server but didn't dig into it and figure stuff out) and my idea above is just a hypothesis.

Checklist

Summary by CodeRabbit

  • Bug Fixes
    • Added a grace period delay before ACUs/commanders are destroyed when a player disconnects, preventing replay cutoffs at the first disconnected player.

lL1l1 added 2 commits June 21, 2026 22:06
Fixes online replays being cut off at the point where someone disconnected due to the disconnected player reporting a game over state.
to make KillArmy's timing consistent across different scenarios
@lL1l1 lL1l1 added the area: sim Area that is affected by the Simulation of the Game label Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces AbandonedArmyGracePeriod (3 seconds) and a DelayedKillUnits helper in SimUtils.lua. The disconnect/abandon flow is updated so unsafe ACU destruction and safe-commander teleportation are deferred or threaded asynchronously rather than executed immediately. A changelog entry documents the fix.

Changes

Delayed ACU explosion on disconnect

Layer / File(s) Summary
Grace period constant and DelayedKillUnits helper
lua/SimUtils.lua
Adds AbandonedArmyGracePeriod = 3 alongside EndGameGracePeriod, and a local DelayedKillUnits(toKill, delaySec) that forks a thread, waits delaySec, then calls KillUnits.
Delayed kill and async teleport in disconnect/abandon flow
lua/SimUtils.lua, changelog/snippets/fix.7153.md
KillUnsafeCommanders now schedules unsafe commanders via DelayedKillUnits instead of killing inline. KillAbandonedArmy's Explode path uses DelayedKillUnits; both the KillArmyOnDelayedRecall and Recall paths call FakeTeleportUnits through ForkThread. Changelog entry added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • FAForever/fa#6965: Refactored the same defeat/abandon/disconnect logic in SimUtils.lua, centralizing Kill* helpers that this PR now extends with delayed behavior.

Poem

🐇 A pause before the boom, just three seconds wide,
The ACU waits a beat before its final stride.
No more cutoff replays, the recording won't lie,
A graceful little delay before commanders die.
Hop hop, the fix is in — no abrupt goodbye! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a delay before disconnected army ACUs are killed.
Description check ✅ Passed The description includes all required sections with sufficient detail: clear description of changes, testing performed, and a completed checklist confirming annotations, changelog snippet, and reviewer requests.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 fix/abandon-acu-delay

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 and usage tips.

@lL1l1 lL1l1 requested review from BlackYps and speed2CZ June 22, 2026 09:14
@lL1l1 lL1l1 marked this pull request as ready for review June 22, 2026 09:14
@lL1l1 lL1l1 changed the title Add AbandonedArmyGracePeriod Add delay before disconnected army's ACUs are killed Jun 22, 2026

@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

🧹 Nitpick comments (1)
lua/SimUtils.lua (1)

1275-1285: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Document that unsafe commanders are killed asynchronously.

KillUnsafeCommanders now schedules destruction after AbandonedArmyGracePeriod, so unsafe commanders may still be alive after Line 1284. A short comment makes that contract clear for callers.

Proposed clarification
-    DelayedKillUnits(unsafeCommanders, AbandonedArmyGracePeriod)
+    -- Unsafe commanders remain alive until the grace period elapses; callers only receive the immediately safe set.
+    DelayedKillUnits(unsafeCommanders, AbandonedArmyGracePeriod)
🤖 Prompt for 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.

In `@lua/SimUtils.lua` around lines 1275 - 1285, Add a comment in the
KillUnsafeCommanders function to document that the DelayedKillUnits call
schedules destruction asynchronously. Place the comment near the
DelayedKillUnits invocation with unsafeCommanders to clarify that unsafe
commanders are killed after the AbandonedArmyGracePeriod delay, not immediately,
so they may still exist as valid units after the function returns. This
documents the asynchronous contract for callers relying on this function's
behavior.
🤖 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 `@changelog/snippets/fix.7153.md`:
- Line 1: Fix the typo in the changelog entry in the fix.7153.md file by
changing the word "cuttting" to "cutting" in the sentence that reads "This
should fix replays cuttting off at the first disconnected player."

---

Nitpick comments:
In `@lua/SimUtils.lua`:
- Around line 1275-1285: Add a comment in the KillUnsafeCommanders function to
document that the DelayedKillUnits call schedules destruction asynchronously.
Place the comment near the DelayedKillUnits invocation with unsafeCommanders to
clarify that unsafe commanders are killed after the AbandonedArmyGracePeriod
delay, not immediately, so they may still exist as valid units after the
function returns. This documents the asynchronous contract for callers relying
on this function's behavior.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: fb3a1c0d-5254-4ce8-80af-afc1f5d9bab3

📥 Commits

Reviewing files that changed from the base of the PR and between c80d63c and b0b5ebc.

📒 Files selected for processing (2)
  • changelog/snippets/fix.7153.md
  • lua/SimUtils.lua

@@ -0,0 +1 @@
- (#7153) Add a delay before ACUs explode when their player disconnects. This should fix replays cuttting off at the first disconnected player. No newline at end of file

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the changelog typo.

cuttting should be cutting.

Proposed fix
-- (`#7153`) Add a delay before ACUs explode when their player disconnects. This should fix replays cuttting off at the first disconnected player.
+- (`#7153`) Add a delay before ACUs explode when their player disconnects. This should fix replays cutting off at the first disconnected player.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- (#7153) Add a delay before ACUs explode when their player disconnects. This should fix replays cuttting off at the first disconnected player.
- (`#7153`) Add a delay before ACUs explode when their player disconnects. This should fix replays cutting off at the first disconnected player.
🤖 Prompt for 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.

In `@changelog/snippets/fix.7153.md` at line 1, Fix the typo in the changelog
entry in the fix.7153.md file by changing the word "cuttting" to "cutting" in
the sentence that reads "This should fix replays cuttting off at the first
disconnected player."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: sim Area that is affected by the Simulation of the Game type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant