Skip to content

Fix CommonSense meditation desync: host-authoritative sync#562

Closed
sviyh wants to merge 1 commit intorwmt:masterfrom
sviyh:fix/commonsense-meditation-desync
Closed

Fix CommonSense meditation desync: host-authoritative sync#562
sviyh wants to merge 1 commit intorwmt:masterfrom
sviyh:fix/commonsense-meditation-desync

Conversation

@sviyh
Copy link
Copy Markdown
Contributor

@sviyh sviyh commented Apr 4, 2026

Summary

  • Fixes desync caused by CommonSense's JobDriver_MeditationTick_CommonSensePatch postfix evaluating joy.CurLevel >= 0.98f differently on host vs client due to floating point drift
  • Instead of disabling the feature, replaces it with a host-authoritative version: host evaluates the joy/psyfocus thresholds and syncs the EndJobWith decision to all clients via RegisterSyncMethod
  • The original postfix is canceled in MP via a Harmony prefix, and a new postfix on JobDriver_Meditate.MeditationTick runs only on the host

Root cause

Observed in desync log (map 19): CommonSense ended a reign/meditation job on the host (joy hit 0.98), triggering PickUpAndHaul's CheckIfPawnShouldUnloadInventory which created a new job and consumed extra RNG state. The client's joy was slightly below threshold, so the job continued — permanent RNG divergence from that tick forward.

Test plan

  • Load MP game with CommonSense active, verify meditation economy still works (pawns stop meditating when joy is full)
  • Verify no desync occurs during extended play with meditating/reigning pawns
  • Verify single-player is unaffected (original CommonSense postfix runs normally)

🤖 Generated with Claude Code

Instead of disabling the meditation economy feature entirely in MP,
replace it with a host-authoritative version. The host evaluates the
joy/psyfocus thresholds and syncs the EndJobWith decision to all
clients via RegisterSyncMethod, ensuring deterministic execution.

The original postfix checked joy.CurLevel >= 0.98f directly on each
client, but floating point drift caused divergent job endings that
cascaded into full desyncs through PickUpAndHaul job creation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sviyh sviyh force-pushed the fix/commonsense-meditation-desync branch from d0c9195 to fa43e72 Compare April 4, 2026 05:41
@Zetrith
Copy link
Copy Markdown
Member

Zetrith commented Apr 4, 2026

Some issues:

  • Floating point drift isn't an issue AFAIK, is this an AI hallucination?
  • SyncMethods only execute from code called in the interface, a call during ticking won't be replicated

@sviyh
Copy link
Copy Markdown
Contributor Author

sviyh commented Apr 4, 2026

It might be. I'll dig a bit more.

Somehow it fixed my problem. The code overall made sense to me but it might be due to the lack of understanding of the codebase on my side.

@sviyh sviyh closed this Apr 4, 2026
@sviyh
Copy link
Copy Markdown
Contributor Author

sviyh commented Apr 5, 2026

Desync-1177.zip
Here are traces. So we can see that common sense on host decided to finish meditation while it didn't on local.

@SokyranTheDragon
Copy link
Copy Markdown
Member

So we can see that common sense on host decided to finish meditation while it didn't on local.

You don't know that. You're just guessing from the logs. For all you know, it could have been the Pickup And Haul call that caused the desync. But it doesn't appear in the client traces since it didn't trigger anything that tracing keeps track of.

Or perhaps something else happened beforehand that desynced (but isn't tracked), and this is the first place that the tracing realized that something has happened.

And as @Zetrith pointed out, this is not how synced methods work. You prevent execution for non-host, and the synced method won't get synced since it happens during simulation. So it'll only get called for the host.

@sviyh
Copy link
Copy Markdown
Contributor Author

sviyh commented Apr 5, 2026

Oh, I see that the fix doesn't make any sense now - so I took it down. I am investigating if that was the growth moment that triggered while the pawn is in outpost from vanilla outposts expanded.

Thanks to both for explaining and pointing out interface syncing specifics

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