Commit b98ffd0
committed
Fix duplicate Foundry actor on createActor sync race
Symptom: creating one character actor in Foundry produced two actors
sharing the same chronicle entityId, with chronicle holding a single
entity. The dashboard reported both as synced because both carried the
flag, but they were competing for the same chronicle row.
Cause: when _handleCreateActor POSTs the new entity, chronicle's
entity.created WebSocket broadcast fires before (or alongside) the
POST response. _onCharacterCreated runs, finds no Foundry actor with
the entity's id flag (the originator hasn't returned yet to set it),
and creates a fresh actor. The originator then sets the flag on its
own actor too, leaving two flagged actors.
Fix: track Foundry-originated creates in an in-flight Map keyed by
actor.id holding actor.name. Set on entry to _handleCreateActor,
clear in finally. _onCharacterCreated checks the in-flight names; on
match, it skips creation and lets the originating handler link the
existing actor when its POST returns. Match by name because the
incoming Foundry actor doesn't have the new chronicle entity id yet.
Existing duplicates from before this fix must be cleaned up manually
by deleting the newer of each duplicate pair.1 parent 7f98338 commit b98ffd0
1 file changed
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
| |||
192 | 201 | | |
193 | 202 | | |
194 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
195 | 219 | | |
196 | 220 | | |
197 | 221 | | |
| |||
344 | 368 | | |
345 | 369 | | |
346 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
347 | 378 | | |
348 | 379 | | |
349 | 380 | | |
| |||
388 | 419 | | |
389 | 420 | | |
390 | 421 | | |
| 422 | + | |
| 423 | + | |
391 | 424 | | |
392 | 425 | | |
393 | 426 | | |
| |||
0 commit comments