Skip to content

improvement(sockets): cleanup debounce logic + add flush mechanism to…#1152

Merged
icecrasher321 merged 4 commits intostagingfrom
improvement/sockets-cleanup
Aug 27, 2025
Merged

improvement(sockets): cleanup debounce logic + add flush mechanism to…#1152
icecrasher321 merged 4 commits intostagingfrom
improvement/sockets-cleanup

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Sockets server cleanup of unused fields debouncedMs. Add operation flushing capability to not lose operations on switching workflows or quick refresh.

Type of Change

  • Bug fix

Testing

Tested persistence, quick switching of workflows + refresh after long copying of ops.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Aug 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Aug 27, 2025 6:34pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Aug 27, 2025 6:34pm

@vercel vercel bot temporarily deployed to Preview – docs August 27, 2025 18:13 Inactive
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR implements a comprehensive refactor of the socket operation management system to address data loss issues during workflow transitions. The changes replace component-level debouncing with a centralized operation queue system that provides robust flushing mechanisms.

The core architectural improvement is the replacement of simple timeout-based debouncing with a more sophisticated system that stores pending operations alongside their timeouts. The operation queue store now maintains PendingDebouncedOperation objects that contain both the timeout reference and the actual operation data, enabling recovery of pending operations that would previously be lost during navigation or page refreshes.

Key changes include:

  • Centralized debouncing: Removed debounceMs parameters from individual components like the Code component's useSubBlockValue hook, consolidating all debouncing logic into the operation queue store
  • Operation flushing mechanisms: Added flushAllDebounced(), flushDebouncedForBlock(), flushDebouncedForWorkflow(), and flushDebouncedForVariable() methods to immediately process pending operations before workflow switches or page unloads
  • Enhanced data persistence: Integrated flush calls into critical navigation points including the beforeUnload handler, socket context workflow switching, and input component blur events
  • Workflow-aware processing: Implemented priority-based operation processing that favors operations for the currently registered workflow, improving performance in multi-workflow environments
  • Cleanup mechanisms: Added cancelOperationsForWorkflow() to properly clean up operations when leaving workflows

The refactor removes a complex global window-based subblock update mechanism from the collaborative workflow system, replacing it with the more reliable operation queue approach. This eliminates potential race conditions and memory leaks while providing better maintainability.

Confidence score: 4/5

  • This PR addresses a real data loss issue with a well-architected solution that centralizes operation management
  • Score reflects the comprehensive nature of changes across multiple critical files in the collaborative editing system
  • Pay close attention to the operation queue store implementation and socket context changes as these handle the core data persistence logic

8 files reviewed, 2 comments

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs August 27, 2025 18:30 Inactive
@icecrasher321 icecrasher321 merged commit 89f7d2b into staging Aug 27, 2025
5 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/sockets-cleanup branch August 29, 2025 05:01
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
simstudioai#1152)

* improvement(sockets): cleanup debounce logic + add flush mechanism to not lose ops

* fix optimistic update overwritten race condition

* fix

* fix forever stuck in processing
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.

1 participant