Skip to content

refactor(network): Sort command list fast path by sort number - #3052

Open
CryoTheRenegade wants to merge 2 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:bugfix/netcommandlist-sort-number
Open

refactor(network): Sort command list fast path by sort number#3052
CryoTheRenegade wants to merge 2 commits into
TheSuperHackers:mainfrom
CryoTheRenegade:bugfix/netcommandlist-sort-number

Conversation

@CryoTheRenegade

@CryoTheRenegade CryoTheRenegade commented Aug 2, 2026

Copy link
Copy Markdown

Changed the cached NetCommandList::addMessage insertion path to use getSortNumber(), matching the full list traversal.

For normal commands this is equivalent to getID(). ACK commands override it with the ID of the command being acknowledged, so using it consistently prevents incorrect ACK ordering.

Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated

@Skyaero42 Skyaero42 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Starting to look better, but still a few points of attention and some formatting

Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
@Caball009

Caball009 commented Aug 3, 2026

Copy link
Copy Markdown

I'm a bit concerned this may affect retail compatibility. Please test this change in a multiplayer match. You can use two local instances, one with the change and one without.

@CryoTheRenegade

Copy link
Copy Markdown
Author

I'm a bit concerned this may affect retail compatibility. Please test this change in a multiplayer match. You can use two local instances, one with the change and one without.

Tested with latest weekly as control, no issues seen (had 2 instances of tracy in the background and nothing weird happened, but im not very good at playing against myself so i didnt stress it out too much :/)

@CryoTheRenegade
CryoTheRenegade force-pushed the bugfix/netcommandlist-sort-number branch from 4c4ac92 to 727de6a Compare August 4, 2026 17:33
@xezon
xezon requested a review from Skyaero42 August 5, 2026 19:39
@xezon

xezon commented Aug 5, 2026

Copy link
Copy Markdown

The title says that this is a bug fix. What is the bug that can be observed in the game before this fix?

@CryoTheRenegade

Copy link
Copy Markdown
Author

The cached fast path could order network commands differently from the full scan. Peers can then consume commands in different orders, causing multiplayer desync. This makes both paths use the same ordering: type, player, then sort number

@Caball009

Caball009 commented Aug 6, 2026

Copy link
Copy Markdown

Would you mind writing test code that forces a mismatch because of this bug? FWIW I did something similar for a similar PR here: https://www.github.com/TheSuperHackers/GeneralsGameCode/pull/2736/changes/f386e5fb030acf148f7d038c6c2a09808ab7425d

@CryoTheRenegade

CryoTheRenegade commented Aug 6, 2026

Copy link
Copy Markdown
Author

Added test code (https://github.com/CryoTheRenegade/GeneralsGameCode/tree/test/netcommandlist-order-repro)

Core/Tools/Scratch/reproduce_netcommandlist_order.cpp is a self-contained harness that mirrors NetCommandList::addMessage with a toggle between the pre-fix fast-path key (getID()) and the fix (getSortNumber()), brute-forcing arrival orders. Over 20000 randomized cases the final command order diverges in ~4% of them.

The game catches this live and runs the correct order, but we should not be relying on a fallback when we can get it right the first time

@CryoTheRenegade
CryoTheRenegade force-pushed the bugfix/netcommandlist-sort-number branch 2 times, most recently from 727de6a to 4cf2901 Compare August 6, 2026 22:41
@CryoTheRenegade CryoTheRenegade changed the title bugfix(network): Sort command list fast path by sort number refactor(network): Sort command list fast path by sort number Aug 6, 2026

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code is difficult to read and understand.

Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
@CryoTheRenegade
CryoTheRenegade force-pushed the bugfix/netcommandlist-sort-number branch from a43b0c8 to 728969a Compare August 10, 2026 02:19
@Caball009
Caball009 self-requested a review August 13, 2026 21:31

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change is now a mix of refactor and fix; is that right? If yes, can we split it into 2 commits or 2 pull requests to merge to main?

Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp Outdated
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp
@CryoTheRenegade
CryoTheRenegade force-pushed the bugfix/netcommandlist-sort-number branch from 728969a to 0ac54e8 Compare August 15, 2026 16:56
@CryoTheRenegade

Copy link
Copy Markdown
Author

Yes, the PR now includes the fix and some cleanup added during review. I kept one PR and split it into two commits so each part is clear.

@xezon

xezon commented Aug 15, 2026

Copy link
Copy Markdown

Yes, the PR now includes the fix and some cleanup added during review. I kept one PR and split it into two commits so each part is clear.

Ok that is good. Please add pull id to commit titles

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing Fix Is fixing something, but is not user facing labels Aug 15, 2026
Comment thread Core/GameEngine/Source/GameNetwork/NetCommandList.cpp
@CryoTheRenegade
CryoTheRenegade force-pushed the bugfix/netcommandlist-sort-number branch from 0ac54e8 to bfff4b5 Compare August 15, 2026 19:42
@CryoTheRenegade

Copy link
Copy Markdown
Author

Done.

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

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NetCommandList::addMessage sorts messages by id using different functions

5 participants