Skip to content

fix(sockets): move debounce to server side#1265

Merged
icecrasher321 merged 2 commits intostagingfrom
fix/sockets-last-char-final
Sep 6, 2025
Merged

fix(sockets): move debounce to server side#1265
icecrasher321 merged 2 commits intostagingfrom
fix/sockets-last-char-final

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Move subblock / variable debounces to the server side. Client queue was getting clogged and last few characters were getting dropped.

Type of Change

  • Bug fix

Testing

Manually

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 Sep 6, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 6, 2025 0:49am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 6, 2025 0:49am

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 significant architectural change that moves debouncing logic from client-side to server-side for subblock and variable updates in a collaborative workflow editing system. The change addresses a critical user experience issue where rapid typing was causing the last few characters to be dropped due to client-side operation queue congestion.

Key Changes:

  1. Server-side debouncing implementation: New handlers in subblocks.ts and variables.ts implement 25ms server-side debouncing with operation coalescing. Multiple rapid updates to the same subblock/variable are batched together and written to the database as a single operation.

  2. Client-side simplification: The operation queue store removes all debouncing logic and timeouts, replacing them with immediate coalescing that keeps only the latest pending operation for each unique field. This prevents queue buildup while maintaining deduplication.

  3. Enhanced socket management: A new emitToWorkflow method is added to RoomManager to provide clean type-safe broadcasting. The handlers exclude sender sockets from broadcasts to prevent local state conflicts during collaborative editing.

  4. Component cleanup: Input components (LongInput, ShortInput) remove manual flush operations on blur since server-side debouncing eliminates the need for client-side flush logic.

  5. Improved retry logic: Different retry strategies are implemented - longer timeouts and more retries for text operations vs structural operations, improving reliability during network issues.

This change integrates with the existing workflow state management system by maintaining the same external API while fundamentally changing how updates are persisted. The server-side approach ensures data integrity in collaborative scenarios and prevents the queue clogging that was causing character loss.

Confidence score: 4/5

  • This PR addresses a critical UX issue with a well-architected solution that should significantly improve reliability
  • Score reflects the complexity of real-time collaborative editing changes and potential edge cases with socket management
  • Pay close attention to the socket handler files and operation queue store for proper error handling and edge cases

9 files reviewed, 5 comments

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs September 6, 2025 00:44 Inactive
@icecrasher321 icecrasher321 merged commit 1e14743 into staging Sep 6, 2025
6 checks passed
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
* fix(sockets): move debounce to server side

* remove comments / unused onBlur
@waleedlatif1 waleedlatif1 deleted the fix/sockets-last-char-final branch September 25, 2025 22:40
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