Skip to content

Fix sync race conditions and prevent endless loops - #63

Closed
L3P3 with Copilot wants to merge 3 commits into
improve-syncfrom
copilot/sub-pr-62
Closed

Fix sync race conditions and prevent endless loops#63
L3P3 with Copilot wants to merge 3 commits into
improve-syncfrom
copilot/sub-pr-62

Conversation

Copilot AI commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Synchronization logic had three critical issues causing incorrect "world removed from remote" alerts during first-time uploads and potential infinite sync loops.

Changes

  • Prevent endless sync loop: world_store_sync_check while loop used static world_list_merged reference. After syncing, the same world object could match the condition again since its properties weren't mutated. Now explicitly marks worlds as synced by setting local = remote = Math_max(local, remote) before next iteration.

  • Fix database rename race: During first-time world upload, chunks_rename ran in parallel with data upload. If upload failed mid-flight, IndexedDB could have new ID while state retained old ID. Changed to await chunks_rename() before upload starts.

  • Enable error recovery: Re-enabled commented code that resets mod_r = WORLD_STORED_NOT when world missing from remote, allowing retry. Removed production debugger statement.

// Before: could loop infinitely
while (world_syncable = world_list_merged.find(world => 
    world.local !== world.remote
)) {
    await world_store_sync(world_syncable);
    // world_syncable.local/remote unchanged, matches again
}

// After: marks synced
while (world_syncable = world_list_merged.find(world => 
    world.local !== world.remote
)) {
    await world_store_sync(world_syncable);
    const synced = Math_max(world_syncable.local, world_syncable.remote);
    world_syncable.local = world_syncable.remote = synced;
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 6, 2026 12:06
Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues with world upload synchronization Fix sync race conditions and prevent endless loops Jan 6, 2026
Copilot AI requested a review from L3P3 January 6, 2026 12:10
@L3P3 L3P3 closed this Jan 8, 2026
@L3P3
L3P3 deleted the copilot/sub-pr-62 branch January 8, 2026 12:57
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.

2 participants