Opened 6 years ago

Last modified 17 months ago

#3858 new defect

Make AI serialization fully "reproducible"

Reported by: Imarok Owned by: Silier
Priority: Must Have Milestone: Work In Progress
Component: AI Keywords: AI, Serialization, beta
Cc: Patch: Phab:D2573

Description (last modified by elexis)

This would allow rejoining multiplayer games with AI without having an OOS. As said in this posthttps://wildfiregames.com/forum/index.php?/topic/20592-out-of-sync-error-still-a-known-issue/&do=findComment&comment=314691 the state of the AI after serialization is not exactly the same state as before.

Attachments (5)

AITerritory.patch (5.2 KB ) - added by mimo 6 years ago.
let the AI recomputes territories only when receiving TerritoriesChanged events, to cure one of the nonreproducibilities
AITerritory-v2.patch (5.5 KB ) - added by mimo 6 years ago.
fixed version taking DiplomacyChanged events into account
oos.zip (531.9 KB ) - added by Silier 23 months ago.
logs.zip (276.8 KB ) - added by Silier 22 months ago.
this._entitiesModifications oos
commands.txt (4.4 KB ) - added by Silier 22 months ago.
replay to this._entitiesModifications oos

Download all attachments as: .zip

Change History (22)

by mimo, 6 years ago

Attachment: AITerritory.patch added

let the AI recomputes territories only when receiving TerritoriesChanged events, to cure one of the nonreproducibilities

by mimo, 6 years ago

Attachment: AITerritory-v2.patch added

fixed version taking DiplomacyChanged events into account

comment:1 by mimo, 6 years ago

In 18096:

petra: recomputes territory only when receiving some events, refs #3858

comment:2 by elexis, 6 years ago

Milestone: Alpha 21Backlog

Correct me if you are planning to work on this in the near future.

comment:3 by mimo, 6 years ago

In 18219:

AI: fix serialization of template changes, fixes #3993, refs #3858

Last edited 6 years ago by mimo (previous) (diff)

comment:4 by Imarok, 5 years ago

Keywords: beta added

comment:5 by elexis, 5 years ago

Description: modified (diff)

https://code.wildfiregames.com/D105 introduces a hint that MP games with AI are not supported. This string should be removed once this ticket becomes fixed.

comment:6 by elexis, 5 years ago

In 19491:

Translate the Out-Of-Sync error message and send it to the JS GUI for convenience and future extension.
Add a hint that multiplayer games with AI are currently not supported.

Differential Revision: https://code.wildfiregames.com/D105
Reviewed By: leper
Refs #3858

comment:7 by Silier, 2 years ago

Related duplicate: #5648

comment:8 by Silier, 2 years ago

Milestone: BacklogWork In Progress
Owner: set to Silier

So far I located this:
AttackManager:

this.bombingAttacks is not serialised nor restored properly

Last edited 2 years ago by Silier (previous) (diff)

comment:9 by Silier, 23 months ago

From last oos test done with bb and Stan, ai playing as ptolemy player id = 4:

  "resourceCount": {
    "food": 240, "wood": 210, "stone": 306, "metal": 302
  },

vs

  "resourceCount": {
  "food": 290, "wood": 210, "stone": 306, "metal": 252
},
"resourcesUsed": {
    "food": 250,
    "wood": 100,
    "stone": 0,
    "metal": 0
  }

VS

 "resourcesUsed": {
    "food": 200,
    "wood": 100,
    "stone": 0,
    "metal": 50
  },

reason why it differs: here is production queue from cc

"queue": [
    {
      "id": 4,
      "player": 4,
      "unitTemplate": "units/ptol_infantry_pikeman_b",
      "count": 2,
      "metadata": {
        "role": "worker",
        "base": 2
      },
      "resources": {
        "food": 50,
        "metal": 0,
        "stone": 0,
        "wood": 50
      },

vs

 "queue": [
    {
      "id": 4,
      "player": 4,
      "unitTemplate": "units/ptol_infantry_javelinist_b",
      "count": 2,
      "metadata": {
        "role": "worker",
        "base": 2
      },
      "resources": {
        "food": 25,
        "metal": 25,
        "stone": 0,
        "wood": 50
      },

comment:10 by Silier, 23 months ago

Another difference is with rng number in AIManager and one ai has one extra key in metadata with empty object

by Silier, 23 months ago

Attachment: oos.zip added

comment:11 by elexis, 23 months ago

pyrogenesis -replay="/home/user/.local/share/0ad/replays/0.0.24/2020-01-14_0023/commands.txt" -mod=public -rejointest=1

Initializing the secondary simulation
	
	WARNING: JavaScript warning: simulation/ai/petra/_petrabot.js line 157
	reference to undefined property this.queueManager
	ERROR: JavaScript error: simulation/ai/petra/_petrabot.js line 157
	TypeError: this.queueManager is undefined
	  PETRA.PetraBot.prototype.Serialize@simulation/ai/petra/_petrabot.js:157:3
	ERROR: AI script Serialize call failed
	ERROR: JavaScript error: simulation/ai/petra/_petrabot.js line 157
	TypeError: this.queueManager is undefined
	  PETRA.PetraBot.prototype.Serialize@simulation/ai/petra/_petrabot.js:157:3
	ERROR: AI script Serialize call failed
	Writing serializationtest-data to serializationtest/2020-01-14_0001
	Simulation2.cpp(337): Assertion failed: "0 && (L"Serialization test failure")"
	Assertion failed: "0 && (L"Serialization test failure")"
	Location: Simulation2.cpp:337 (ReportSerializationFailure)

comment:12 by Silier, 23 months ago

From another test: Rng codes from serialisation and deserialisation:

WARNING: Seserialise rngString 67211753696534

WARNING: Seserialise rngString 67211753696534

WARNING: Deserialise rngString 67211753696534

WARNING: Seserialise rngString 270851547002234

WARNING: Seserialise rngString 270851547002234

WARNING: Seserialise rngString 270851547002234

WARNING: Seserialise rngString 270851547002234

ERROR: Out-Of-Sync on turn 80 Players: Angen Dumping state to C:\Users\Slavomír\AppData\Local\0ad\logs\oos_dump.txt

WARNING: Seserialise rngString 270851547002234

but when comparing oos dumps from bb:

  AIManager:
    num ais: 2
    rng: "67211753696534"

    turn: 0
    useSharedScript: true
    sharedData: {
  "players": [
    3,
    4
  ],

from me:

 AIManager:
    num ais: 2

    rng: "270851547002234"
    turn: 0
    useSharedScript: true
    sharedData: {
  "players": [
    3,
    4
  ],

Notice that I have newer rng than he does.That would explain problem with units in queue because ai picks units at random.

comment:13 by Silier, 23 months ago

Possibly all this calls are causing change of rng for aimanager when deserialising and making matches incompatible.

AttackPlan

L131 	// Put some randomness on the attack size
	var variation = 0.8 + 0.4*Math.random();

DiplomacyManager

L34 
	this.sentDiplomacyRequestLapseTime = 120 + randFloat(10, 100);

common-api gamestate

L47 			techName = pickRandom([techData._template.top, techData._template.bottom].filter(tech => !this.playerData.disabledTechnologies[tech])) || techData._template.top;

comment:14 by elexis, 22 months ago

Patch: Phab:D2573

comment:15 by Silier, 22 months ago

After loading saved game: WARNING: PlayerID 2 | Petra: HugeAttack 5 has an inaccessible target with indices 3 1 from units/ptol_support_female_citizen

Reported on forum by gameboy: https://wildfiregames.com/forum/index.php?/topic/27524-warning/

Edit: Map issue

Last edited 17 months ago by Silier (previous) (diff)

by Silier, 22 months ago

Attachment: logs.zip added

this._entitiesModifications oos

by Silier, 22 months ago

Attachment: commands.txt added

replay to this._entitiesModifications oos

comment:16 by Silier, 22 months ago

if (this._entitiesModifications.has(evt.entity) && !this._entities.has(evt.entity)) error("entity is in modifications but not in entities");

at L254 in shared.js triggers

ERROR: entity is in modifications but not int entities what means entity is not removed from this._entitesModifications.

this._entities is rebuilt from state.entities and not serialised like this._entitiesModifications, so state.entities contains different data than it should.

entity.js L562 is adding starting entities to this._entitiesModifications

Last edited 22 months ago by Silier (previous) (diff)

comment:17 by Silier, 20 months ago

When loading game, entity without position is assigned to transport plan but not onboard https://wildfiregames.com/forum/index.php?/topic/27948-petra-javascript-errors/

Last edited 20 months ago by Silier (previous) (diff)
Note: See TracTickets for help on using tickets.